Substitutions in Maple

804 Views Asked by At

Can any one tell me what am I doing wrong in the following expression in Maple?

subs(a*b*c=A, e*f/d=B, a*b*c*e*f/d)

I am getting the output $\frac{abcef}{d}$ and not $AB$


Update : after the suggestion of @String which wored just fine, I am now posting my real expression, because it seems that the algsubs gives an error. The actual expression looks like:

algsub(b*((f/d)^t-1)/e = A, algsubs((m-1)*i*g*h*c*sqrt(2)*sqrt(1/(j*g))*s = B, a-(b*((f/d)^t-1)/e+(m-1)*i*g*h*c*sqrt(2)*sqrt(1/(j*g))*s*sqrt((2*(1-(b+a)/c))/a-(1-(b+a)/c)^2/a^2)/d)*e))

Which you can simply copy and past to Maple to get it properly. However, with the algsubs, I get the error Error, (in algsubs) cannot compute degree of pattern in g

2

There are 2 best solutions below

3
On BEST ANSWER

You should use algsubs instead of subs. Unfortunately algsubs can only handle one substitution at the time so you will need a command like:

algsubs(e*f/d=B,algsubs(a*b*c=A,a*b*c*e*f/d))

for it to work.


Update

Regarding your update it appears that applyrule does a better job and is easier to use anyway:

applyrule([b*((f/d)^t-1)/e = A, (m-1)... =B],a-(... and so on ...)*e)

Also, I stored the parts of the code in variables, namely

rule1:=b*((f/d)^t-1)/e = A
rule2:=(m-1) ... =B
expression:=a-(... and so on ...)*e

and then applied the command

applyrule([rule1,rule2],expression)

which worked just fine!

3
On

You can use simplify with side relations (see ?simplify,siderels).

simplify(a*b*c*e*f/d, {a*b*c= A, e*f/d= B});

It is tricky to use subs when the left sides of the substitutions are more complicated than just single variables. For it to work the left sides must appear as syntactic subunits of the main expression.

For your more-complicated update to your original question, you need to first use subs to replace the syntactic subunits (f/d)^t-1 and sqrt(1/(j*g)) with single variables. Then use simplify with side relations.

simplify(
 subs(
      [(f/d)^t-1= C, sqrt(1/(j*g))= E], 
      a-(b*((f/d)^t-1)/e+(m-1)*i*g*h*c*sqrt(2)*sqrt(1/(j*g))*s*sqrt((2*(1-(b+a)/c))/a-(1-(b+a)/c)^2/a^2)/d)*e
 ),

 {b*C/e = A, (m-1)*i*g*h*c*sqrt(2)*E*s = B}
 );