MathGroup Archive 2003

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

Search the Archive

Re: Conversion Function -> List


On 22 Nov 2003, at 16:17, Vadim Zelenkov wrote:

> Hello!
>
> Given a function
>     x y + Sin[x] Cos[y]
>
> I need to convert it into the list
>     {{x,y},{Sin[x],Cos[x]}}
>
> Generally, the purpose to convert a function
>     Sum[p[i,x] q[i[y], {i,1,n}]
>
> into the list
>     {{p[1,x],q[1,y]},...,{p[n,x],q[n,y]}
>
> How to do it using Mathematica?
>
> Thanks in advance!
>
> V.Z.
>
> P.S, If possible please duplicate your answers to 
> zelenkov[at]mail333.com
>
>
There are lots of ways. here are just two:


f[expr_] := expr /. {Plus -> List, Times -> List}

So

f[x*y + Sin[x]*Cos[y]]

{{x, y}, {Cos[y], Sin[x]}}

and

f[x*y + Sin[x]*Cos[y] + Log[x]*Log[y]]

{{x, y}, {Log[x], Log[y]}, {Cos[y], Sin[x]}}

etc.

Here is another way:


g[expr_] := (Level[#1, 1] & ) /@ Level[expr, 1]


g[x*y + Sin[x]*Cos[y]]

{{x, y}, {Cos[y], Sin[x]}}

and so on....


Andrzej Kozlowski
Chiba, Japan
http://www.mimuw.edu.pl/~akoz/


  • Prev by Date: RE: Conversion Function -> List
  • Next by Date: Re: Conversion Function -> List
  • Previous by thread: Conversion Function -> List
  • Next by thread: Re: Conversion Function -> List