MathGroup Archive 2011

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

Search the Archive

Re: get a, b from numbers in the form a+b Pi

  • To: mathgroup at smc.vnet.net
  • Subject: [mg119196] Re: get a, b from numbers in the form a+b Pi
  • From: Murray Eisenberg <murray at math.umass.edu>
  • Date: Tue, 24 May 2011 06:00:05 -0400 (EDT)

The code

   {FullForm[Expand@#][[1, 1]],
      FullForm[Expand@#][[1, 2]]/\[Pi]}&  /@ nums

fails if the list nums includes, say, 2 (a number of form a + 0 Pi).

On 5/23/2011 6:23 AM, Stefan Salanski wrote:
> On May 22, 6:58 am, "1.156"<r... at piovere.com>  wrote:
>> I have lists  of numbers (Mathematica output) all numerically in the
>> form a + b*Pi and I'm trying to extract the values of a and b for
>> further work.
>>
>> Here's an example of the best I've been able to do so far:
>>
>> nums={1/2 (-2+\[Pi]),-2+(3 \[Pi])/4,-(11/3)+(5 \[Pi])/4,5/48 (-64+21
>> \[Pi]),-(61/5)+(63 \[Pi])/16,-(338/15)+(231 \[Pi])/32};
>> {FullForm[#][[1,1]],FullForm[#][[1,2]]/\[Pi]}&/@nums
>>
>> When I run this line of code 4 of the six input numbers give me the
>> {a,b} I'm looking for but the first and fourth entries fail because the
>> form isn't right. Possibly I could patch this scheme to look for a small
>> finite set of possibilities of input number form but I suspect I may a
>> long way from attacking this problem correctly.
>>
>> Can someone offer some other ideas on how to pull this off? Many thanks
>> for looking at this. Rob
>> --
>> Sent from my plain desktop PC.
>
> Interesting task you're describing, but I think I found what's
> throwing you off.
> Your code relies on each expression being of the form a+b Pi, so that
> you can FullForm to get it in the form Plus[a,b Pi] and then you pick
> off a and b. The cases where it doesnt work for you is when FullForm
> has head Times
> FullForm[1/2 (-2 + \[Pi])] = Times[Rational[1,2],Plus[-2,Pi]]
> The solution: hit it with Expand[] first, so that it does any
> multiplication/division and gets it into the form you want.
> FullForm[Expand[1/2 (-2 + \[Pi])]] = Plus[-1,Times[Rational[1,2],Pi]]
>
> so the final code is below,
> nums = {1/2 (-2 + \[Pi]), -2 + (3 \[Pi])/4, -(11/3) + (5 \[Pi])/4,
>     5/48 (-64 + 21 \[Pi]), -(61/5) + (63 \[Pi])/
>       16, -(338/15) + (231 \[Pi])/32};
> {FullForm[Expand@#][[1, 1]],
>     FullForm[Expand@#][[1, 2]]/\[Pi]}&  /@ nums
>
> hope that helps!
> -Stefan S
>

-- 
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305


  • Prev by Date: Re: Problem with MLGetReal(Double) in Mathlink
  • Next by Date: Re: A problem with NIntegrate
  • Previous by thread: Re: get a, b from numbers in the form a+b Pi
  • Next by thread: Re: get a, b from numbers in the form a+b Pi