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

*To*: mathgroup at smc.vnet.net*Subject*: [mg116709] Re: Rational[a,b] vs Rational[1,2]*From*: Daniel Lichtblau <danl at wolfram.com>*Date*: Thu, 24 Feb 2011 06:25:13 -0500 (EST)

ADL wrote: > On 22 Feb, 12:25, Andrzej Kozlowski <a... at mimuw.edu.pl> wrote: >> 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 >>>> <fate... 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. > > Letting aside the never-ending debate, I anyway think that: > > Rational[1/2, 4] // N > 0.5/4. > > is a little too much and should be fixed. > > ADL > What exactly is it you want "fixed"? StandardForm of objects with Head of Rational? Daniel Lichtblau Wolfram Research