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

MathGroup Archive 2011

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

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg116652] Re: Rational[a,b] vs Rational[1,2]
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Tue, 22 Feb 2011 06:25:56 -0500 (EST)

Yes, but are there any likely circumstances under which someone might type "Rational[a,b]" (rather than a/b - which is quite different) unless that person knew quite well what he was doing?

Andrzej Kozlowski


On 22 Feb 2011, at 10:45, Richard Fateman wrote:

> On 2/21/2011 6:04 PM, DrMajorBob wrote:
>> The head of 1/2 is Rational, but the head of a/b is Times.
> I know that.
> What is the head of Rational[a,b]?    where  a, b  are symbols, not
> numbers...
>
> FullForm[Rational[a,b]]
> says
> Rational[a,b]
>  also
> Head  says it is Rational.
>
>
>  BUT IT IS NOT A Rational.
> For example, Numerator[Rational[a,b]]  is not a, but   Rational[a,b]
>
>
> I am aware of the info about atoms and Rational, and Complex too.
>
> However, the situation above looks to me like it is hazardous.  Do you
> see what I am getting at?
> Regards
> RJF
>
>
>
>>
>> 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.
>>
>> Help explains this under "Possible Issues", and under "More
>> Information", 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]
>>>
>>> and Head[Rational[a,b]]
>>>
>>> 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.
>>>
>>>
>>
>>
>
>


  • Prev by Date: Re: Odd behaviour of solution of PDE
  • Next by Date: Re: Vector Runge-Kutta ODE solver with compilation?
  • Previous by thread: Re: Rational[a,b] vs Rational[1,2]
  • Next by thread: Re: Rational[a,b] vs Rational[1,2]