 
 
 
 
 
 
Re: Replace & Rationalize
- To: mathgroup at smc.vnet.net
- Subject: [mg121559] Re: Replace & Rationalize
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Mon, 19 Sep 2011 07:07:59 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <201109180810.EAA06285@smc.vnet.net>
- Reply-to: drmajorbob at yahoo.com
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 at 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 at yahoo.com
- References:
- Replace & Rationalize
- From: "Chris Degnen" <degnen@cwgsy.net>
 
 
- Replace & Rationalize

