Home > Archive > Mathematica > August 2006 > transforming a rule of lists to a list of rules
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
transforming a rule of lists to a list of rules
|
|
| Ken Senior 2006-08-30, 8:04 am |
| Hello everyone.
Does anyone know a way to transform a rule involving a list into a list
of individual rules, that is to interpret the rule elementwise? For
example, given
{a,b,c} -> {0,3,x}
is there a transformation which will turn this into
{a->0, b->3, c->x}
Thanks for the help!
Ken
| |
| Christoph Lhotka 2006-08-31, 4:06 am |
| Hello!
Use:
In[.]:=Inner[Rule,{a,b,c,...},{aa,bb,cc,...},List]
Out[.];={a->baa,b->bb,c->cc,...}
with kind regards
Christoph
On Wed, 30 Aug 2006 06:32:51 -0400 (EDT)
Ken Senior <Ken.Senior@nrl.navy.mil> wrote:
> Hello everyone.
>
> Does anyone know a way to transform a rule involving a list into a list
> of individual rules, that is to interpret the rule elementwise? For
> example, given
>
> {a,b,c} -> {0,3,x}
>
> is there a transformation which will turn this into
>
> {a->0, b->3, c->x}
>
> Thanks for the help!
>
> Ken
>
-- Mag. Christoph Lhotka --
University of Vienna / Institute for Astronomy
fon. +43 (1) 4277 51841
mail. lhotka@astro.univie.ac.at
| |
| Adriano Pascoletti 2006-08-31, 4:06 am |
|
On 30 ago 2006, at 12:32, Ken Senior wrote:
> Hello everyone.
>
> Does anyone know a way to transform a rule involving a list into a
> list
> of individual rules, that is to interpret the rule elementwise? For
> example, given
>
> {a,b,c} -> {0,3,x}
>
> is there a transformation which will turn this into
>
> {a->0, b->3, c->x}
>
> Thanks for the help!
>
> Ken
In[2]:=
Thread[{a, b, c} -> {0, 3, x}]
Out[2]=
{a -> 0, b -> 3, c -> x}
Adriano Pascoletti
| |
| Jens-Peer Kuska 2006-08-31, 4:06 am |
| Hi,
Thread[{a,b,c} -> {0,3,x}]
??
Regards
Jens
"Ken Senior" <Ken.Senior@nrl.navy.mil> schrieb im
Newsbeitrag news:ed3qil$rn5$1@smc.vnet.net...
| Hello everyone.
|
| Does anyone know a way to transform a rule
involving a list into a list
| of individual rules, that is to interpret the
rule elementwise? For
| example, given
|
| {a,b,c} -> {0,3,x}
|
| is there a transformation which will turn this
into
|
| {a->0, b->3, c->x}
|
| Thanks for the help!
|
| Ken
|
| |
| John Jowett 2006-08-31, 4:06 am |
| Ken,
Just apply Thread:
Thread[{a, b, c} -> {0, 3, x}]
{a -> 0, b -> 3, c -> x}
John Jowett
"Ken Senior" <Ken.Senior@nrl.navy.mil> wrote in message
news:ed3qil$rn5$1@smc.vnet.net...
Hello everyone.
Does anyone know a way to transform a rule involving a list into a list
of individual rules, that is to interpret the rule elementwise? For
example, given
{a,b,c} -> {0,3,x}
is there a transformation which will turn this into
{a->0, b->3, c->x}
Thanks for the help!
Ken
| |
| Sseziwa Mukasa 2006-08-31, 4:06 am |
|
On Aug 30, 2006, at 6:32 AM, Ken Senior wrote:
> Hello everyone.
>
> Does anyone know a way to transform a rule involving a list into a
> list
> of individual rules, that is to interpret the rule elementwise? For
> example, given
>
> {a,b,c} -> {0,3,x}
>
> is there a transformation which will turn this into
>
> {a->0, b->3, c->x}
>
> Thanks for the help!
Thread[{a,b,c}->{1,2,3}]
Regards,
Ssezi
| |
|
|
On Aug 30, 2006, at 6:32 AM, Ken Senior wrote:
> Hello everyone.
>
> Does anyone know a way to transform a rule involving a list into a
> list
> of individual rules, that is to interpret the rule elementwise? For
> example, given
>
> {a,b,c} -> {0,3,x}
>
> is there a transformation which will turn this into
>
> {a->0, b->3, c->x}
>
> Thanks for the help!
>
> Ken
Here is a newbie approach:
In[1]:=
rl = {a, b, c} -> {x, y, z}
Out[1]=
{a, b, c} -> {x, y, z}
In[2]:=
Table[rl[[1,i]] -> rl[[2,i]],
{i, 1, Length[rl[[1]]]}]
Out[2]=
{a -> x, b -> y, c -> z}
With the best,
János
----------------------------------------------
Trying to argue with a politician is like lifting up the head of a
corpse.
(S. Lem: His Master Voice)
| |
| Roger Bagula 2006-08-31, 4:06 am |
| Ken Senior wrote:
>Hello everyone.
>
>Does anyone know a way to transform a rule involving a list into a list
>of individual rules, that is to interpret the rule elementwise? For
>example, given
>
> {a,b,c} -> {0,3,x}
>
>is there a transformation which will turn this into
>
> {a->0, b->3, c->x}
>
>Thanks for the help!
>
>Ken
>
>
>
This seems to work:
Solve[a*(b-3)*(c-x)==0,{a,b,c}]
| |
| dennis 2006-08-31, 4:06 am |
| Ken,
How about
r= {a,b,c} -> {0,3,x}
MapThread[#1->#2&,{First[r],Last[r]}]
Dennis
Ken Senior wrote:
> Hello everyone.
>
> Does anyone know a way to transform a rule involving a list into a list
> of individual rules, that is to interpret the rule elementwise? For
> example, given
>
> {a,b,c} -> {0,3,x}
>
> is there a transformation which will turn this into
>
> {a->0, b->3, c->x}
>
> Thanks for the help!
>
> Ken
| |
|
| In[2]:=
fn[Rule[list1_List,list2_List]]:=Thread[
Rule[list1,list2]];
In[4]:=
fn[{a,b,c}->{0,3,x}]//InputForm
Out[4]//InputForm=
{a -> 0, b -> 3, c -> x}
dkr
| |
| Bob Hanlon 2006-08-31, 4:06 am |
| Thread[{a,b,c} -> {0,3,x}]
{a -> 0, b -> 3, c -> x}
Bob Hanlon
---- Ken Senior <Ken.Senior@nrl.navy.mil> wrote:
> Hello everyone.
>
> Does anyone know a way to transform a rule involving a list into a list
> of individual rules, that is to interpret the rule elementwise? For
> example, given
>
> {a,b,c} -> {0,3,x}
>
> is there a transformation which will turn this into
>
> {a->0, b->3, c->x}
>
> Thanks for the help!
>
> Ken
>
--
Bob Hanlon
hanlonr@cox.net
| |
| Jean-Marc Gulliet 2006-08-31, 4:06 am |
| Ken Senior wrote:
> Hello everyone.
>
> Does anyone know a way to transform a rule involving a list into a list
> of individual rules, that is to interpret the rule elementwise? For
> example, given
>
> {a,b,c} -> {0,3,x}
>
> is there a transformation which will turn this into
>
> {a->0, b->3, c->x}
>
> Thanks for the help!
>
> Ken
>
Hi Ken,
Use the Mathematica built-in function Thread [1].
In[1]:=
Thread[{a, b, c} -> {0, 3, x}]
Out[1]=
{a -> 0, b -> 3, c -> x}
Regards,
Jean-Marc
[1] http://documents.wolfram.com/mathem...unctions/Thread
| |
| David Park 2006-08-31, 4:06 am |
| Ken,
{a, b, c} -> {0, 3, x} // Thread
David Park
djmp@earthlink.net
http://home.earthlink.net/~djmp/
From: Ken Senior [mailto:Ken.Senior@nrl.navy.mil]
Hello everyone.
Does anyone know a way to transform a rule involving a list into a list
of individual rules, that is to interpret the rule elementwise? For
example, given
{a,b,c} -> {0,3,x}
is there a transformation which will turn this into
{a->0, b->3, c->x}
Thanks for the help!
Ken
| |
| Ken Levasseur 2006-08-31, 4:06 am |
| This doesn't test for whether the two lists have equal lengths, but
that would be easy to add:
In[15]:=
delist = #1 /. {({a__} -> {b__}) :> (Rule @@ #1 & ) /@ Transpose
[{{a}, {b}}]} &
Out[15]=
#1 /. {({a__} -> {b__}) :> (Rule @@ #1 & ) /@ Transpose[{{a}, {b}}]} &
In[16]:=
delist[{a, b, c} -> {0, 3, x}]
Out[16]=
{a -> 0, b -> 3, c -> x}
On Aug 30, 2006, at 6:32 AM, Ken Senior wrote:
> Hello everyone.
>
> Does anyone know a way to transform a rule involving a list into a
> list
> of individual rules, that is to interpret the rule elementwise? For
> example, given
>
> {a,b,c} -> {0,3,x}
>
> is there a transformation which will turn this into
>
> {a->0, b->3, c->x}
>
> Thanks for the help!
>
> Ken
>
Ken Levasseur
UMass Lowell
Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
| |
| Chris Chiasson 2006-08-31, 4:06 am |
| Thread
On 8/30/06, Ken Senior <Ken.Senior@nrl.navy.mil> wrote:
> Hello everyone.
>
> Does anyone know a way to transform a rule involving a list into a list
> of individual rules, that is to interpret the rule elementwise? For
> example, given
>
> {a,b,c} -> {0,3,x}
>
> is there a transformation which will turn this into
>
> {a->0, b->3, c->x}
>
> Thanks for the help!
>
> Ken
>
>
--
http://chris.chiasson.name/
| |
| Tony Harker 2006-08-31, 4:06 am |
| Thread is your friend here:
Thread[{a, b, c} -> {0, 3, x}]
Tony
Dr A.H. Harker
Department of Physics and Astronomy
University College London
Gower Street
London
WC1E 6BT
]->-----Original Message-----
]->From: Ken Senior [mailto:Ken.Senior@nrl.navy.mil]
]->Subject: transforming a rule of lists to a list of rules
]->
]->Hello everyone.
]->
]->Does anyone know a way to transform a rule involving a list
]->into a list of individual rules, that is to interpret the
]->rule elementwise? For example, given
]->
]-> {a,b,c} -> {0,3,x}
]->
]->is there a transformation which will turn this into
]->
]-> {a->0, b->3, c->x}
]->
]->Thanks for the help!
]->
]->Ken
]->
]->
|
|
|
|
|