Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #5087
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!nx01.iad01.newshosting.com!newshosting.com!newspump.sol.net!posts.news.twtelecom.net!nnrp2.twtelecom.net!not-for-mail |
|---|---|
| From | DrMajorBob <btreat1@austin.rr.com> |
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Replace & Rationalize |
| Date | Mon, 19 Sep 2011 11:15:20 +0000 (UTC) |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Sender | steve@smc.vnet.net |
| Approved | Steven M. Christensen <steve@smc.vnet.net>, Moderator |
| Message-ID | <j57888$jca$1@smc.vnet.net> (permalink) |
| References | <201109180810.EAA06285@smc.vnet.net> |
| Reply-To | drmajorbob@yahoo.com |
| Lines | 37 |
| NNTP-Posting-Date | 19 Sep 2011 10:18:23 GMT |
| NNTP-Posting-Host | 4fe4a6b4.news.twtelecom.net |
| X-Trace | DXC=]LSNcHf]Xoimedgn:b^=RbC_A=>8kQj6mm^eQlV`f18gB\@>^=oXgBaEFiONJ7[Gofg6WHD`a5hNg |
| X-Complaints-To | abuse@twtelecom.net |
| Xref | x330-a1.tempe.blueboxinc.net comp.soft-sys.math.mathematica:5087 |
Show key headers only | View raw
RuleDelayed is the key:
{0., 1.} /. x_ /; IntegerQ[Rationalize[x]] :> Rationalize[x]
{0, 1}
Your original (second) expression failed because
Rationalize[x]
x
hence your expression was (or may as well have been)
{0., 1.} /. x_ /; IntegerQ[Rationalize[x]] -> x
{0., 1.}
Bobby
On Sun, 18 Sep 2011 03:10:01 -0500, Chris Degnen <degnen@cwgsy.net> wrote:
> Further to a question on Stack Overflow I noticed a puzzling
> evaluation. Why does the second expression generate reals?
>
> (x \[Function]
> If[IntegerQ[Rationalize[x]], Rationalize[x], x]) /@ {0., 1.}
>
> {0., 1.} /. x_ /; IntegerQ[Rationalize[x]] -> Rationalize[x]
>
>
>
--
DrMajorBob@yahoo.com
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: Replace & Rationalize DrMajorBob <btreat1@austin.rr.com> - 2011-09-19 11:15 +0000
csiph-web