[newbie] how to expand function to original variables
Subject: [newbie] how to expand function to original variables
From: Hugo Coolens
Date: Tue, 19 Feb 2013 13:53:35 +0100
I guess you mean something like this:
subst([A=sqrt(p^2+2*p*sigma)-p,sigma=tau11+tau12+tau22,p=tau11*tau22],hjmax(A,sigma,p));
This gives indeed the expression I wanted but I wonder whether this is
really the best way to go as I now have to supply once more the
information which I already supplied in statements 1, 2 and 3 in
the code below?
On Tue, 19 Feb 2013, Rupert Swarbrick wrote:
> Hugo Coolens <coolens at kahosl.be> writes:
>> I have reworked the code as follows:
>>1. p(tau11,tau22):=tau11*tau22;
>>2. sigma(tau11,tau12,tau22):=tau11+tau12+tau22;
>>3. A(p,sigma):=sqrt(p^2+2*p*sigma)-p;
>> hjmax(A,sigma,p):=sqrt((1+A/p)/((1-A/sigma^2)^2+A/p));
>> subst(sigma(tau11,tau12,tau22),sigma,hjmax);
>> subst(p(tau11,tau22),p,hjmax);
>>
>> this gives me hjmax as a function of tau11, tau12 and tau22 which is
>> what I wanted. I just wondered whether the last two statements can be
>> combined in one?
>
> Yep, see the documentation for subst. The other syntax is something like
>
> subst ([foo1 = bar1, foo2 = bar2], expr)
>
> And this does the same as the iterated substitution:
>
> subst (bar1, foo1, subst (bar2, foo2, expr))
>
> (Well, almost. If bar2 contains foo1, you get slightly different
> behavior:
>
> (%i42) subst (bar1, foo1, subst (foo1, foo2, foo2 + 1));
> (%o42) bar1 + 1
> (%i43) subst ([foo1 = bar1, foo2 = bar2], foo2 + 1);
> (%o43) bar2 + 1
> )
>
>
> Rupert
>