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 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 , Moderator Message-ID: 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 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 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