From: Prajwal on
On Aug 1, 11:58 am, Camille <camille.sega...(a)gmail.com> wrote:
> Dear All,
>
> I am fairly new to mathematica. I am stuck with a problem I cannot solve.=
I would like to call a previous equation into the function Function. If a =
type directly the expression or copy paste it, it works. However, when I ca=
ll the expression by its name it does not.
> Here is the code for a more precise explanation:
>
> In: ll
> Out: d + a x + h x^2 + b y + e x y + c z + j z^2
>
> In: Function[##, a x + b y + c z + d + e x y + h x^2 + j z^2] & @@ {Listp=
}
> Out: Function[{a, b, c, d, e, h, j},
> a x + b y + c z + d + e x y + h x^2 + j z^2]
>
> It works well and I can use it to generate as many equations I want by re=
placing the variables a,b,c,d,e,h,j.
> But if I do:
>
> In:Function[##, ll] & @@ {Listp}
> Out:Function[{a, b, c, d, e, h, j}, ll]
>
> And I cannot use it.
>
> Any suggestions?
>
> Thanks in advance. Do not hesitate to post if you need some further infor=
mation. Sorry for my bad english.
>
> Camille


Since the function "Function" has HoldAll attribute, the expressions
in its arguments are not evaluated by default.Try:

Function[##, Evaluate[ ll]] & @@ {Listp}

--
Prajwal

From: Raffy on
On Aug 1, 1:58 am, Camille <camille.sega...(a)gmail.com> wrote:
> Dear All,
>
> I am fairly new to mathematica. I am stuck with a problem I cannot solve. I would like to call a previous equation into the function Function. If a type directly the expression or copy paste it, it works. However, when I call the expression by its name it does not.
> Here is the code for a more precise explanation:
>
> In: ll
> Out: d + a x + h x^2 + b y + e x y + c z + j z^2
>
> In: Function[##, a x + b y + c z + d + e x y + h x^2 + j z^2] & @@ {Listp}
> Out: Function[{a, b, c, d, e, h, j},
> a x + b y + c z + d + e x y + h x^2 + j z^2]
>
> It works well and I can use it to generate as many equations I want by replacing the variables a,b,c,d,e,h,j.
> But if I do:
>
> In:Function[##, ll] & @@ {Listp}
> Out:Function[{a, b, c, d, e, h, j}, ll]
>
> And I cannot use it.
>
> Any suggestions?
>
> Thanks in advance. Do not hesitate to post if you need some further information. Sorry for my bad english.
>
> Camille

I'd suggest something like:
ClearAll[injector];
injector[expr_, args_] := expr& //. Table[args[[i]]->Slot[i],
{i,Length[args]}];

Usage:
injector[a+b+c, {a,b}] === #1+#2+c&

Your example:
injector[ll, Listp] === #4 + #1 x + #6 x^2 + #2 y + #5 x y + #3 z + #7
z^2 &

Identity:
injector[expr, args]@@args === expr

From: David Bailey on
On 01/08/10 09:58, Camille wrote:
> Dear All,
>
> I am fairly new to mathematica. I am stuck with a problem I cannot solve. I would like to call a previous equation into the function Function. If a type directly the expression or copy paste it, it works. However, when I call the expression by its name it does not.
> Here is the code for a more precise explanation:
>
> In: ll
> Out: d + a x + h x^2 + b y + e x y + c z + j z^2
>
> In: Function[##, a x + b y + c z + d + e x y + h x^2 + j z^2]& @@ {Listp}
> Out: Function[{a, b, c, d, e, h, j},
> a x + b y + c z + d + e x y + h x^2 + j z^2]
>
> It works well and I can use it to generate as many equations I want by replacing the variables a,b,c,d,e,h,j.
> But if I do:
>
> In:Function[##, ll]& @@ {Listp}
> Out:Function[{a, b, c, d, e, h, j}, ll]
>
> And I cannot use it.
>
> Any suggestions?
>
> Thanks in advance. Do not hesitate to post if you need some further information. Sorry for my bad english.
>
> Camille
>
Since you say you are fairly new to Mathematica, I am wondering if you
are adopting the above, rather obscure style from choice. I would simply
define a named function to do what you want:

In[2]:= buildExpression[a_,b_,c_,d_,e_,h_,j_]:=a x+b y+c z+d+e x y+h
x^2+j z^2;

In[5]:= buildExpression[1,2,3,4,5,6,7]

Out[5]= 4+x+6 x^2+2 y+5 x y+3 z+7 z^2

In[6]:= buildExpression[q+1,q+2,q+3,q+4,q+5,q+6,q+7]

Out[6]= 4+q+(1+q) x+(6+q) x^2+(2+q) y+(5+q) x y+(3+q) z+(7+q) z^2

David Bailey

http://www.dbaileyconsultancy.co.uk