Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #5061
| From | Andrzej Kozlowski <akoz@mimuw.edu.pl> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Replace & Rationalize |
| Date | 2011-09-18 12:21 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <j54nnd$92m$1@smc.vnet.net> (permalink) |
| 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}
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: Replace & Rationalize Andrzej Kozlowski <akoz@mimuw.edu.pl> - 2011-09-18 12:21 +0000
csiph-web