lec7.mws

L-7 MCS 320 Wed 7 Sep 2005

> restart;

1. Basic Data Types

The basic data types are numbers: integers, rationals, floats, strings, etc.

> a := 3;

a := 3

> b := 3.0;

b := 3.0

> whattype(a); whattype(b);

integer

float

The type determines the effect of the operations.

> a + 10^(-20); b + 10^(-20);

300000000000000000001/100000000000000000000

3.0

> s := "x*y + 3*x^3 - 8";

s :=

> whattype(s);

string

> p := parse(s); # opposite to convert(p,string)

p := x*y+3*x^3-8

2. Expression Trees

Let us look into the structure of the polynomial p.  The p is an expression, a composite data type.

> op(p); whattype(p); nops(p);

x*y, 3*x^3, -8

+

3

We see that p is of type "+" and p consists of 3 operands.

> p1 := op(1,p); # select the first operand of p

p1 := x*y

> op(p1); whattype(p1);

x, y

*

> p2 := op(2,p); op(p2); whattype(p2);

p2 := 3*x^3

3, x^3

*

> op([2,2],p); # x^3 is the 2nd operand of the 2nd operand of p

x^3

> op([2,2,1],p); op([2,2,2],p); whattype(op([2,2],p));

x

3

^

> r := convert(p,`*`);  # we convert p from a `+` to a `*`

r := -24*x^4*y

> op(r);

-24, x^4, y

> q := convert(r,`+`);

q := -24+x^4+y

3. Attributes

Attributes are characteristics of a variable what a user can add to it.  It is mainly for human consumption, we could see it as an annotation or a comment to a variable.

> p := x^2 + x + 1;

p := x^2+x+1

> alias(alpha=RootOf(p));

alpha

> whattype(alpha);

function

To associate to alpha the meaning as a formal root we can add a string as an attribute to alpha:

> alpha := setattribute(alpha,"a formal root of x^2 + x + 1");

alpha := RootOf(_Z^2+_Z+1)

> attributes(alpha); # query the attributes of alpha

4. Properties

A property of a variable is used mainly for simplication purposes in calculations.  Unlike attributes, we use properties for calculating more efficiently, which means in symbolic computation that we may simplify more often.

> assume(x,real);

> simplify(sqrt(x^2));

abs(x)

Maple does the simplification because of the assumption, which is indicated by the flag x~.

5. Units

Units give meaning to calculations.

> convert(1,units,km,miles);

15625/25146

> evalf(%);

.6213711922

> with(Units[Standard]);

Warning, the name Unit has been rebound

Warning, the assigned names factor and polar now have a global binding

Warning, these protected names have been redefined and unprotected: *, +, -, /, <, <=, <>, =, Im, Re, ^, abs, add, arccos, arccosh, arccot, arccoth, arccsc, arccsch, arcsec, arcsech, arcsin, arcsinh, arctan, arctanh, argument, ceil, collect, combine, conjugate, convert, cos, cosh, cot, coth, csc, csch, csgn, diff, eval, evalc, evalr, exp, expand, floor, frac, int, ln, log, log10, max, min, mul, normal, root, round, sec, sech, seq, shake, signum, simplify, sin, sinh, sqrt, surd, tan, tanh, trunc, type, verify

[*, +, -, /, <, <=, <>, =, Im, Re, Unit, ^, abs, add, arccos, arccosh, arccot, arccoth, arccsc, arccsch, arcsec, arcsech, arcsin, arcsinh, arctan, arctanh, argument, ceil, collect, combine, conjugate,...[*, +, -, /, <, <=, <>, =, Im, Re, Unit, ^, abs, add, arccos, arccosh, arccot, arccoth, arccsc, arccsch, arcsec, arcsech, arcsin, arcsinh, arctan, arctanh, argument, ceil, collect, combine, conjugate,...[*, +, -, /, <, <=, <>, =, Im, Re, Unit, ^, abs, add, arccos, arccosh, arccot, arccoth, arccsc, arccsch, arcsec, arcsech, arcsin, arcsinh, arctan, arctanh, argument, ceil, collect, combine, conjugate,...[*, +, -, /, <, <=, <>, =, Im, Re, Unit, ^, abs, add, arccos, arccosh, arccot, arccoth, arccsc, arccsch, arcsec, arcsech, arcsin, arcsinh, arctan, arctanh, argument, ceil, collect, combine, conjugate,...

> a := 3*Unit(miles);

a := 3*Unit([mi])

> b := 7*Unit(km);

b := 7*Unit([km])

> c := a+b;

c := 1478504/125*Unit([m])

> evalf(c);

11828.03200*Unit([m])

After loading Units[Standard], Maple automatically converts to the metric system.