Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Replace & Rationalize

  • To: mathgroup at smc.vnet.net
  • Subject: [mg121535] Re: Replace & Rationalize
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Sun, 18 Sep 2011 08:20:02 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201109180810.EAA06285@smc.vnet.net>

On 18 Sep 2011, at 10:10, 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]
>
>
>

Because you need RuleDelayed instead of Rule on the RHS, otherwise Rationalize[x] evaluates simply to x. Thus:

In[26]:= {0.,1.}/.x_/;IntegerQ[Rationalize[x]]:>Rationalize[x]
Out[26]= {0,1}






  • Prev by Date: Re: comments
  • Next by Date: Re: (x - 1) or (-1 + x)
  • Previous by thread: Replace & Rationalize
  • Next by thread: Re: Replace & Rationalize