L-13 MCS 320 Wednesday 21 September 2005
| > | restart; |
1. Formal and Algebraic Substitution
Substitution by means of the "subs" command is a powerful tool to manipulate expressions.
| > | p := (x+y)^2 + 1/(x+y)^2; |
| > | normal(p); |
By putting the expression on a common denominator has expanded the numerator.
We would like to prevent Maple from expanding the x+y. We will substitute the x+y in p by z:
| > | q := subs(x+y=z,p); |
| > | nq := normal(q); # normalize |
| > | r := subs(z=x+y,nq); # go back to the original variables |
Substitution is one of the means to avoid Maple from expanding.
We can partially substitute in an expression by the subsop command.
Suppose we want to substitute x+y by x-y, but only in the denominator of r.
| > | op([2,1],r); # first we locate where we want to substitute |
| > | subsop([2,1]=x-y,r); |
With subsop we substitute one operand of an expression.
Sometimes we want to substitute simultaneously. For example in permutations.
| > | p := a + 2*b + 3*c; |
Suppose we want to permutate the variables, turn p into c + 2*a + 3*b.
| > | subs(c=a,b=a,a=c,p); |
The substitution above was a sequential substitution, first c became a, and p = 4*a + 2*b, then b became a, and p turned into 6*a, and finally a became c, and p turned into 6*c.
| > | subs({c=a,b=a,a=c},p); # simultaneous substitution |
| > | subs({c=b,b=a,a=c},p); # this is the proper, intended permutation |
The last type of substitution is algebraic, suppose we want to replace the a+b by c, eliminating the a from p.
| > | subs(a+b=c,p); |
The subs is a formal substitution. Unless the a+b occurs as an operand of p, it will not be replaced.
With algsubs, we can perform the elimination, or symbolically we would say the simplification of the expression p:
| > | algsubs(a+b=c,p); |
The algsubs recognizes the algebraic structure of an expression.
2. Expansion of Polynomials and Algebraic Numbers
We can prevent an expansion by substitution:
| > | p := (a+b+c)*(x+y+z); |
| > | expand(p); |
We could expand partially, say by first expanding along the second factor of p:
we would like to see (a+b+c)*x + (a+b+c)*y + (a+b+c)*z.
| > | q := subs(a+b+c=d,p); |
| > | eq := expand(q); |
| > | r := subs(d=a+b+c,eq); |
We can avoid typing in the a+b+c, by using the subsop command:
| > | q := subsop(1=d,p); # substitution of the first operand op p by d |
| > | eq := expand(q); |
| > | r := subs(d=op(1,p),eq); # substitution of d by first operand of p |
For algebraic numbers we have the expand with a capital letter: Expand, but over a finite field only,
over the rational numbers we still use the evala command:
| > | randomize(1); |
| > | p := randpoly(x,degree=3); |
| > | irreduc(p); |
| > | alias(alpha=RootOf(p)); |
| > | factor(p,alpha); |
Now we work with alpha, which is an algebraic number, just as any number.
| > | n := alpha^8; |
| > | evala(%); |
For a finite field, say modulo 23, we use the Expand.
| > | Irreduc(p) mod 23; |
| > | f := Factor(p) mod 23; |
| > | #f3 := op(2,f); # if f would be reducible, then select factor |
| > | alias(beta=RootOf(f)); |
| > | Expand(beta^8) mod 23; |
| > | Expand((beta+1)^8) mod 23; |
3. Factorization: Exact, Symbolic, and Numeric
Exact factorization is over the rational numbers:
| > | f := (x - rand()/rand())*(x - rand()/rand()); |
| > | p := expand(f); |
| > | factor(p); |
In a symbolic factorization, we extend the rational numbers with symbols, these symbols are roots of irreducible polynomials.
| > | factor(x^2+2); |
| > | factor(x^2+2,{I,sqrt(2)}); |
We can tell Maple which numbers to add.
| > | factor(x^2+2,complex); |
| > |
The numerical factorization is always over the complex numbers, this shows the fundamental theorem of algebra.