lec12.mws

L-12 MCS 320 Monday 12 September 2005

> restart;

1. Internal Representations of Polynomials

We have seen expression trees:

> p := x^3 + 9*x + 8;

p := x^3+9*x+8

We have the high level commands to query the components of a polynomial:

> degree(p,x); coeffs(p); coeff(p,x,1);

3

8, 9, 1

9

The next level is the level of expressions, for which we use the "op" command:

> op(p);

x^3, 9*x, 8

By applying the op command further to the operands we can draw the expression tree.

However, Maple does not store the expressions as trees.  For memory efficiency, Maple stores every object (that is every symbol and every number) only once.  When every objects is stored only once, then also a substitution (which is a major tool in expression manipulation) can be performed efficiently.

> dismantle(p);

SUM(7)

  PROD(3)

     NAME(4): x

     INTPOS(2): 3

  INTPOS(2): 1

  NAME(4): x

  INTPOS(2): 9

  INTPOS(2): 8

  INTPOS(2): 1

Maple stores this polynomial as a sum of monomial times coefficient, as x^3 . 1 + x . 9 + 8 . 1.

> dismantle(x^3 + 9*x - 8);

SUM(7)

  PROD(3)

     NAME(4): x

     INTPOS(2): 3

  INTPOS(2): 1

  NAME(4): x

  INTPOS(2): 9

  INTNEG(2): -8

  INTPOS(2): 1

We see from the dismantle above that a minus 8 is stored as + (-8) times 1.

2. Side Effects on Substitutions

Suppose we would like to replace the leading coefficient of our polynomial p by Pi.

> q := subs(1=Pi,p);

q := x^3*Pi+9*x+8*Pi

> dismantle(q);

SUM(7)

  PROD(5)

     NAME(4): x

     INTPOS(2): 3

     NAME(4): Pi #[protected]

     INTPOS(2): 1

  INTPOS(2): 1

  NAME(4): x

  INTPOS(2): 9

  NAME(4): Pi #[protected]

  INTPOS(2): 8

Because every symbol and number is stored only once, the effect of the substitution is that also the constant term of our polynomial changed.  To explain this, we furthermore must know the internal representation of a polynomial as a sum of monomials times coefficients.

3. Directed Acyclic Graphs for Rational Expressions

For rational expressions, the "-1" is special as 1/x is stored as a power: x^(-1).

> r := (x^3 - 1)/(x-1);

r := (x^3-1)/(x-1)

> dismantle(r);

PROD(5)

  SUM(5)

     PROD(3)

        NAME(4): x

        INTPOS(2): 3

     INTPOS(2): 1

     INTNEG(2): -1

     INTPOS(2): 1

  INTPOS(2): 1

  SUM(5)

     NAME(4): x

     INTPOS(2): 1

     INTNEG(2): -1

     INTPOS(2): 1

  INTNEG(2): -1

We see that r is stored as the product of two powers: (x^3-1)^1 * (x-1)^(-1).

Because the -1 is used as exponent to represent the division, we have the following side effect:

> subs(-1=Pi,r);

(x^3+Pi)*(x+Pi)^Pi

The effect of this substitution is explained by how Maple stores divisions.