Algebraic expressions

In Maple, you have symbols, which parallel identifiers in C++, but unlikely most programming languages, symbols do not have to be initialized, and if they are never assigned a value, they just retain their uniqueness as a symbol.

[> x;

$x$

We note two items:

  1. Maple is interpreted like Matlab and Python.
  2. Every statement must be ended by a semicolon. You can actually have multiple statements per line (separated by semicolons), but there isn't often much call for this.

When you press Enter, the statement where the cursor currently is at is evaluated.

If you want to evaluate a statement, but don't care to see the output, you can end the statement with a colon instead of a semicolon.

Algebraic operators include +, -, * (multiplication), / (division) and ^ (exponentiation). Both + and - can act as unary or binary operators.

You can create a more complex algebraic expression by combining symbols and binary and linear operators:

[> 3*x;

$3x$

You will notice that the output appears closer to what you would write on paper. This is described in Maple as pretty printing.

[> 3*x^2 + 4*x + 1;

$3x^2 + 4x + 1$

[> -7*(x + 1)*(x - 2);

$-7(x + 1)(x - 2)$

[> 4*(x + 5)*(y + 4/3)/(x + y);

$\frac{4(x + 5)\left(y + \frac{4}{3}\right)}{x + y}$

[> 1/(1/x + 1/y);

$\frac{1}{\frac{1}{x} + \frac{1}{y}}$

You will note that Maple does not really do too much to simplify expressions:

[> (x + 1)*(x - 2) - (x^2 - x - 2);

$(x + 1)(x - 2) - x^2 + x + 2$

You will note that this expression is actually equal to zero, if you were to expand $(x + 1)(x - 2)$. The negation, however, is distributed across the $x^2 - x - 2$.

Another point is that Maple will automatically remove any common factors in rational numbers and other algebraic expressions:

[> -12/15*(x + 18/33)*(x - 154/2);

$-\frac{4\left( x + \frac{6}{11}\right)(x - 77)}{5}$

[> (x + 2)^3*(x + 1)/(x + 2)^4;

$\frac{x + 1}{x + 2}$

[> 3/2*x^2 + 5/9*x - 1/3 + 9/5*x^2 + 13/2*x + 12;

$\frac{33}{10}x^2 + \frac{127}{18}x + \frac{35}{3}$

Expansions

We will now look at our first algorithm implemented as a function in Maple: expand( ... ). This function distributes products over sums, so $4x(y + z)$ will be rewritten as $4xy + 4xz$ and $3(x + 1)(x - 1)$ will be rewritten as $3x^2 - 3$:

[> expand( (x + 1)*(x + 2)*(x + 5) );

$x^3 + 8x^2 + 17x + 10$

expand(...) is our first example a function in Maple. A function takes zero or more arguments and applies an algorithm to the arguments to produce a result. In this case, the result is an algebraic expansion of the one argument. Here is another example:

[> expand( 12/8*(5*x + 1/2)*(7*y + 2/9)*(3*z - 5/2) );

$\frac{315}{2} x y z -\frac{525}{4} x y +5 x z -\frac{25}{6} x +\frac{63}{4} y z -\frac{105}{8} y +\frac{1}{2} z - \frac{5}{12}$

Automatic simplification

You will make a few observations when you enter expressions in Maple:

First, all rational or floating-point computations are immediately computed where possible.

Second, if you have a rational or floating-point number multiplying a sum in parentheses, then the result is immediately expanded:

[> 3.2*(1 + 1.9*y + 4.5);

$3.2x + 6.08 + 14.40$

This doesn't happen if the product has multiple terms:

[> 3*(x + 1)*(x + 2);

$3(x + 1)(x + 2)$

Third, if you have a sum of expressions times scalars, and the expressions are the same, then Maple will automatically add the scalars:

[> 3*(x + 1)^2 + 4*y - 7*(x + 1)^2 + 9*y;

$-4(x + 1)^2 + 13y$

Fourth, the order in which terms in a sum or product may be rearranged, as commutativity is assumed:

[> a*b*b*a*a*b*a;

$a^4b^3$

[> y*x + x - y + y*x*y;

$y^2x + yx + x - y$

[> 3*x*y + 3*y + 4*x + x*y^2;

$y^2x + 3yx + 4x + 3y$

If you were to restart Maple, you would find that the order changes:

[> restart;
[> 3*x*y + 3*y + 4*x + x*y^2;

$xy^2 + 3xy + 4x + 3y$

[> y*x + x - y + y*x*y;

$xy^2 + xy + x - y$

Contrast $y^2x$ and $yx$ in the first versus $xy^2$ and $xy$ in the second.

You may guess that Maple follows this approach: Once Maple sees an expression, such as $xy^2$ or $y^2x$, then if it sees something equivalent, it converts what it saw the second time to what it has already previously seen.

Finally, this author is not sure if there is a documented list of all such automatic simplifications, but in general, they are only performed to simplify expressions while maintaining their algebraic correctness. There may be one value of an expression for which an automatic simplification is not valid, but these are isolated points:

[> 1/(1/x);

$x$

Technically, this simplification is false if $x = 0$, for the reciprocal is undefined, and hence the reciprocal of the reciprocal is also undefined; however, this only occurs for a single value of $x$.

Basically, you should not expect Maple to "leave your expressions alone". If you are trying to typeset a mathematical expression, use LaTeX.