[Date Index]
[Thread Index]
[Author Index]
Re: Rational[a,b] vs Rational[1,2]
*To*: mathgroup at smc.vnet.net
*Subject*: [mg116645] Re: Rational[a,b] vs Rational[1,2]
*From*: DrMajorBob <btreat1 at austin.rr.com>
*Date*: Tue, 22 Feb 2011 04:45:47 -0500 (EST)
I think Mathematica expects us to create rationals in the usual way... by
dividing integers. When we do, Mathematica removes common factors and can
end up with an Integer, a Rational, Indeterminate, or ComplexInfinity.
If you try another method... good luck!
Bobby
On Mon, 21 Feb 2011 20:16:03 -0600, Richard Fateman
<fateman at eecs.berkeley.edu> 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.
>>>
>>>
>>
>>
>
--
DrMajorBob at yahoo.com
Prev by Date:
**Re: Delete elements from list..**
Next by Date:
**Re: FinancialData Function Not Working for Property "Members"**
Previous by thread:
**Re: Rational[a,b] vs Rational[1,2]**
Next by thread:
**Re: Rational[a,b] vs Rational[1,2]**
| |