lec13.mws

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;

p := (x+y)^2+1/(x+y)^2

> normal(p);

(x^4+4*x^3*y+6*x^2*y^2+4*x*y^3+y^4+1)/(x+y)^2

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);

q := z^2+1/z^2

> nq := normal(q); # normalize

nq := (z^4+1)/z^2

> r := subs(z=x+y,nq); # go back to the original variables

r := ((x+y)^4+1)/(x+y)^2

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

x+y

> subsop([2,1]=x-y,r);

((x+y)^4+1)/(x-y)^2

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;

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);

6*c

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

c+5*a

> subs({c=b,b=a,a=c},p); # this is the proper, intended permutation

c+2*a+3*b

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);

a+2*b+3*c

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);

b+4*c

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);

p := (a+b+c)*(x+y+z)

> expand(p);

a*x+a*y+a*z+b*x+b*y+b*z+c*x+c*y+c*z

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);

q := d*(x+y+z)

> eq := expand(q);

eq := d*x+d*y+d*z

> r := subs(d=a+b+c,eq);

r := (a+b+c)*x+(a+b+c)*y+(a+b+c)*z

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

q := d*(x+y+z)

> eq := expand(q);

eq := d*x+d*y+d*z

> r := subs(d=op(1,p),eq); # substitution of d by first operand of p

r := (a+b+c)*x+(a+b+c)*y+(a+b+c)*z

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);

1

> p := randpoly(x,degree=3);

p := -35-85*x^3-55*x^2-37*x

> irreduc(p);

true

> alias(alpha=RootOf(p));

alpha, beta

> factor(p,alpha);

-(85*x^2+55*x+85*x*alpha+37+55*alpha+85*alpha^2)*(x-alpha)

Now we work with alpha, which is an algebraic number, just as any number.

> n := alpha^8;

n := alpha^8

> evala(%);

15917216/3017196125*alpha^2+41807521/603439225-214962584/3017196125*alpha

For a finite field, say modulo 23, we use the Expand.

> Irreduc(p) mod 23;

true

> f := Factor(p) mod 23;

f := 11+7*x^3+14*x^2+9*x

> #f3 := op(2,f); # if f would be reducible, then select factor

> alias(beta=RootOf(f));

alpha, beta

> Expand(beta^8) mod 23;

14*beta+15

> Expand((beta+1)^8) mod 23;

3*beta+3

3. Factorization: Exact, Symbolic, and Numeric

Exact factorization is over the rational numbers:

> f := (x - rand()/rand())*(x - rand()/rand());

f := (x-279229359488/373376915269)*(x-32062222085/722974121768)

> p := expand(f);

p := x^2-213846894526444863650649/269941847405050224475592*x+1119089217069569736560/33742730925631278059449

> factor(p);

1/269941847405050224475592*(722974121768*x-32062222085)*(373376915269*x-279229359488)

In a symbolic factorization, we extend the rational numbers with symbols, these symbols are roots of irreducible polynomials.

> factor(x^2+2);

x^2+2

> factor(x^2+2,{I,sqrt(2)});

(x+I*2^(1/2))*(x-I*2^(1/2))

We can tell Maple which numbers to add.

> factor(x^2+2,complex);

(x+1.414213562*I)*(x-1.414213562*I)

>

The numerical factorization is always over the complex numbers, this shows the fundamental theorem of algebra.