A wealth of knowledge is on display in MaplePrimes as our contributors share their expertise and step up to answer others’ queries. This post picks out one such response and further elucidates the answers to the posted question. I hope these explanations appeal to those of our readers who might not be familiar with the techniques embedded in the original responses.

Before I begin, a quick note that the content below was primarily created by one of our summer interns, Pia, with guidance and advice from me.

The Question: Rearranging the expression of equations

SY G wanted to be able to re-write an equation in terms of different variables.  SY G presented this example: 

I have the following two equations:

x1 = a-y1-d*y2;
x2 = a-y2-d*y1;

I wish to express the first equation in terms of y1 and x2, so that

x1 = c - b*y1+d*x2;

where c=a-a*d and b=1-d^2. How can I get Maple to rearrange the original equation x1 in term of y1, x2, c and b?

This question was answered by nm who provided code with a systematic approach:

restart;
eq1:=x1=a-y1-d*y2:
eq2:=x2=a-y2-d*y1:
z:=expand(subs(y2=solve(eq2,y2),eq1)):
z:=algsubs((a-a*d)=c,z):
algsubs((1-d^2)=b,z);

On the other hand, Carl Love answered this enquiry using a more direct and simple code:

simplify(x1=a-y1-d*y2, {a-y2-d*y1= x2, 1-d^2= b, a-a*d= c});

Let’s talk more about the expand, algsubs, subs, and simplify commands

First let’s take a look at the method nm used to solve the problem using the commands expand, subs, solve and algsubs.

The expand command, expand(expr, expr1, expr2, ..., exprn), distributes products over sums. This is done for all polynomials. For quotients of polynomials, only sums in the numerator are expanded; products and powers are left alone.

The solve command, solve(equations, variables), solves one or more equations or inequalities for their unknowns.

The subs command, subs(x=a,expr), substitutes a for x in the expression expr.

The function algsubs, algsubs(a = b, f),performs an algebraic substitution, replacing occurrences of a with b in the expression f.  It is a generalization of the subs command, which only handles syntactic substitution.

Let’s tackle the Maple code written by nm step by step:

1) restart;
The restart command is used to clear Maple’s internal memory

2)  eq1:=x1=a-y1-d*y2:
      eq2:=x2=a-y2-d*y1:
The names eq1 and eq2 were assigned to the equations SY G provided.

3) z:=expand(subs(y2=solve(eq2,y2),eq1)):
A new variable, z, was created, which will end up being x1 written in the terms SY G wanted.

  • solve(eq2,y2)
    • the solve command was used to solve the expression eq2 for the variable y2.

  • subs(y2=solve(eq2,y2),eq1)
    • The subs command was used to replace in expression eq1, y2 as determined by the solve step. 

  • expand(subs(y2=solve(eq2,y2),eq1))
    • The expand command was used to distribute products over sums. Note: this step served to ensure that the final output looked exactly how SY G wanted.

4) z:=algsubs((a-a*d)=c,z):
First, nm equated a-a*d to c, so later the algsubs command could be applied to substitute the new variable c into the expression z.

5) algsubs((1-d^2)=b,z);
Again, nm equated 1-d^2 to b, so later the algsubs command could be applied to substitute the new variable b into the expression z.

An alternate approach

Now let us check out Carl Love’s approach. Carl Love uses the simplify command in conjunction with side relations.

The simplify command has many calling sequences and one of them is the simplify(expr,eqns), that is known as simplify/siderels. A simplification of expr with respect to the side relations eqns is performed. The result is an expression which is mathematically equivalent toexpr but which is in normal form with respect to the specified side relations. Basically you are telling Maple to simplify the expression (expr) using the parameters (eqns) you gave to it.

 

I hope that you find this useful. If there is a particular question on MaplePrimes that you would like further explained, please let me know. 

Please Wait...