Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #5087

Re: Replace & Rationalize

From DrMajorBob <btreat1@austin.rr.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Replace & Rationalize
Date 2011-09-19 11:15 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <j57888$jca$1@smc.vnet.net> (permalink)
References <201109180810.EAA06285@smc.vnet.net>

Show all headers | 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


Thread

Re: Replace & Rationalize DrMajorBob <btreat1@austin.rr.com> - 2011-09-19 11:15 +0000

csiph-web