Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #1306

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

From Peter Pein <petsie@dordos.net>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Subject: Re: Rational[a,b] vs Rational[1,2]
Date 2011-03-31 08:59 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <in1fp3$4di$1@smc.vnet.net> (permalink)
References <ik844j$mtr$1@smc.vnet.net>

Show all headers | View raw


Am 25.02.2011 12:34, schrieb Jack L Goldberg 1:
> I am a bit puzzled.  In view of the on-going debate, when ought one
> use Rational[a,b].  Put a bit differently, is there a snippet of code
> in which one would prefer Rational[a,b] to a/b?
>

well, this is constructed but could happen in praxis:

In[1]:= ser=Normal[Series[(Sqrt[1+x]+Sqrt[x])^2,{x,0,5}]]
Out[1]= 1+2 Sqrt[x]+2 x+x^(3/2)-x^(5/2)/4+x^(7/2)/8-(5 x^(9/2))/64

In[2]:= Cases[ser,Except[_.*Power[x,Rational[_,2]]],1]
Out[2]= {1,2 x}

In[3]:= Cases[ser,Except[_.*Power[x,_ /2]],1]
Out[3]= {1,2 Sqrt[x],2 x,x^(3/2),-(x^(5/2)/4),x^(7/2)/8,
          -((5 x^(9/2))/64)}

this happens, because the internal representation of ser is:

In[4]:= FullForm @ ser
Out[4]//FullForm= Plus[1, Times[2, Power[x, Rational[1, 2]]], Times[2, 
x], Power[x, Rational[3, 2]], Times[Rational[-1, 4], Power[x, 
Rational[5, 2]]], Times[Rational[1, 8], Power[x, Rational[7, 2]]], 
Times[Rational[-5, 64], Power[x, Rational[9, 2]]]]

So it can be (and mostly is) essential in pattern matching.

Peter

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: Subject: Re: Rational[a,b] vs Rational[1,2] Peter Pein <petsie@dordos.net> - 2011-03-31 08:59 +0000

csiph-web