Re: Rational[a,b] vs Rational[1,2]

• To: mathgroup at smc.vnet.net
• Subject: [mg116641] Re: Rational[a,b] vs Rational[1,2]
• From: DrMajorBob <btreat1 at austin.rr.com>
• Date: Tue, 22 Feb 2011 04:45:03 -0500 (EST)

```The head of 1/2 is Rational, but the head of a/b is Times.

a/b//FullForm

Times[a,Power[b,-1]]

Replace looks at the arguments of Times, but it doesn't look within
"atoms". Rationals are "atoms", so there you go.

it says:

"You have to use Numerator and Denominator to extract parts of Rational
numbers."

Apparently that's the ONLY way to extract parts of a Rational, and that's
what we're supposed to glean from "have to".

First[1/2] returns 1/2 and an error message, for instance.

Bobby

On Mon, 21 Feb 2011 18:30:54 -0600, Richard Fateman
<fateman at eecs.berkeley.edu> wrote:

> I find it potentially hazardous that Head[]
> does not distinguish the cases of Head[1/2]
>
>
> Thus these both get transformed...
>
> 1/2  /. Rational[r_,s_]-> foo[r,s]
>
> Rational[a,b] /. Rational[r_,s_] -> foo[r,s]
>
>
> but compare ...
>
> 1/2  /. 2->4
>
> Rational[a,2] /. 2->4
>
> I'm not saying I'm surprised by this, of course.
>
> Perhaps Rational[a,b] should be converted to a/b unless both
> a and b are numbers.
>
> Oh, for some fun, try Rational[1/2,4].
>
>
> RJF
>
> PS, I used version 7.
>
>

--
DrMajorBob at yahoo.com

```

• Prev by Date: Re: How to deal with big matrix?
• Next by Date: Re: weibull plot on weibull scaled paper
• Previous by thread: Re: Rational[a,b] vs Rational[1,2]
• Next by thread: Re: Rational[a,b] vs Rational[1,2]