Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #5087 > unrolled thread
| Started by | DrMajorBob <btreat1@austin.rr.com> |
|---|---|
| First post | 2011-09-19 11:15 +0000 |
| Last post | 2011-09-19 11:15 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.soft-sys.math.mathematica
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Replace & Rationalize DrMajorBob <btreat1@austin.rr.com> - 2011-09-19 11:15 +0000
| From | DrMajorBob <btreat1@austin.rr.com> |
|---|---|
| Date | 2011-09-19 11:15 +0000 |
| Subject | Re: Replace & Rationalize |
| Message-ID | <j57888$jca$1@smc.vnet.net> |
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 top | Article view | comp.soft-sys.math.mathematica
csiph-web