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


Groups > comp.soft-sys.math.mathematica > #2605 > unrolled thread

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

Started by"1.156" <rob@piovere.com>
First post2011-05-22 10:58 +0000
Last post2011-05-23 10:23 +0000
Articles 10 — 10 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  get a, b from numbers in the form a+b Pi "1.156" <rob@piovere.com> - 2011-05-22 10:58 +0000
    Re: get a, b from numbers in the form a+b Pi "Nasser M. Abbasi" <nma@12000.org> - 2011-05-23 10:26 +0000
    Re: get a, b from numbers in the form a+b Pi Albert Retey <awnl@gmx-topmail.de> - 2011-05-23 10:28 +0000
    Re: get a, b from numbers in the form a+b Pi Wolfgang Windsteiger <Wolfgang.Windsteiger@risc.jku.at> - 2011-05-23 10:28 +0000
    Re: get a, b from numbers in the form a+b Pi Peter Breitfeld <phbrf@t-online.de> - 2011-05-23 10:28 +0000
    Re: get a, b from numbers in the form a+b Pi Peter Pein <petsie@dordos.net> - 2011-05-23 10:29 +0000
    Re: get a, b from numbers in the form a+b Pi Roland Franzius <roland.franzius@uos.de> - 2011-05-23 10:22 +0000
    Re: get a, b from numbers in the form a+b Pi Armand Tamzarian <mike.honeychurch@gmail.com> - 2011-05-23 10:26 +0000
    Re: get a, b from numbers in the form a+b Pi Stefan Salanski <wutchamacallit27@gmail.com> - 2011-05-23 10:23 +0000
    Re: get a, b from numbers in the form a+b Pi Ray Koopman <koopman@sfu.ca> - 2011-05-23 10:23 +0000

#2605 — get a, b from numbers in the form a+b Pi

From"1.156" <rob@piovere.com>
Date2011-05-22 10:58 +0000
Subjectget a, b from numbers in the form a+b Pi
Message-ID<iraq88$ls8$1@smc.vnet.net>
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.

[toc] | [next] | [standalone]


#2637

From"Nasser M. Abbasi" <nma@12000.org>
Date2011-05-23 10:26 +0000
Message-ID<irdcpa$3pl$1@smc.vnet.net>
In reply to#2605
On 5/22/2011 3:58 AM, 1.156 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

If you want to use your FullForm method, can't you then just
Expand first?

as in

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

{{-1,1/2},{-2,3/4},{-(11/3),5/4},{-(20/3),35/16},
{-(61/5),63/16},{-(338/15),231/32}}

It seems to have worked now on all of them.

--Nasser

[toc] | [prev] | [next] | [standalone]


#2643

FromAlbert Retey <awnl@gmx-topmail.de>
Date2011-05-23 10:28 +0000
Message-ID<irdcrl$3ri$1@smc.vnet.net>
In reply to#2605
Hi,

> 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

I was surprised that CoefficientList does work with Pi as a variable, 
which makes the whole task as simple as:

CoefficientList[#, Pi] & /@ nums

hth,

albert

[toc] | [prev] | [next] | [standalone]


#2644

FromWolfgang Windsteiger <Wolfgang.Windsteiger@risc.jku.at>
Date2011-05-23 10:28 +0000
Message-ID<irdcrv$3rr$1@smc.vnet.net>
In reply to#2605
Dear Rob,

if I understand correctly what you want, then I would suggest

Cases[Expand[nums], a_ + b_*Pi -> {a, b}]

It first expands all numbers to make sure that no factored forms occur 
anymore. Then find all the cases of the form a_ + b_*Pi (which are *all* 
in this example), and give back {a,b} instead of the matched a_ + b_*Pi 
number.

Hope that is what you were aiming for.

Ciao,
WW.

On 05/22/2011 12:58 PM, 1.156 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

[toc] | [prev] | [next] | [standalone]


#2647

FromPeter Breitfeld <phbrf@t-online.de>
Date2011-05-23 10:28 +0000
Message-ID<irdcsv$3sq$1@smc.vnet.net>
In reply to#2605
"1.156" 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.
>

Try this:

abRule = a_. + b_. Pi :> {a, b}
Expand[nums]
% /. abRule


-- 
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de

[toc] | [prev] | [next] | [standalone]


#2650

FromPeter Pein <petsie@dordos.net>
Date2011-05-23 10:29 +0000
Message-ID<irdctk$3ta$1@smc.vnet.net>
In reply to#2605
Am 22.05.2011 12:58, schrieb 1.156:
> 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

expanding the list nums might help (also adding some special cases):

Expand[Join[nums,{0,1,Pi}]]/.{x_?NumericQ/;FreeQ[x,Pi]:>{x,0},a_. +b_.
Pi:>{a,b}}

gives:
 {{-1,1/2},{-2,3/4},{-(11/3),5/4},{-(20/3),35/16},{-(61/5),63/16},{-(338/15),231/32},{0,0},{1,0},{0,1}}

hth,
Peter

[toc] | [prev] | [next] | [standalone]


#2651

FromRoland Franzius <roland.franzius@uos.de>
Date2011-05-23 10:22 +0000
Message-ID<irdchj$3it$1@smc.vnet.net>
In reply to#2605
Am 22.05.2011 12:58, schrieb 1.156:
> 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

CoefficientList[ nums, {\[Pi]}]

-- 

Roland Franzius

[toc] | [prev] | [next] | [standalone]


#2655

FromArmand Tamzarian <mike.honeychurch@gmail.com>
Date2011-05-23 10:26 +0000
Message-ID<irdcov$3pd$1@smc.vnet.net>
In reply to#2605
On May 22, 8:58 pm, "1.156" <r...@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.


Try mapping with Expand[nums]

Mike

[toc] | [prev] | [next] | [standalone]


#2656

FromStefan Salanski <wutchamacallit27@gmail.com>
Date2011-05-23 10:23 +0000
Message-ID<irdcj9$3kf$1@smc.vnet.net>
In reply to#2605
On May 22, 6:58 am, "1.156" <r...@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

[toc] | [prev] | [next] | [standalone]


#2658

FromRay Koopman <koopman@sfu.ca>
Date2011-05-23 10:23 +0000
Message-ID<irdcju$3kv$1@smc.vnet.net>
In reply to#2605
On May 22, 3:58 am, "1.156" <r...@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.

You need to Expand nums to get the terms into the form a + b*Pi.
Also, you can use Apply to change the Plus heads to List.

List@@#/{1,Pi}&/@Expand@nums

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web