Description
An
expression is a symbolic representation of a mathematical expression. It retains some of the semantics of the mathematical expression, as well as enough information to print the expression nicely. In Macaulay2 expressions have two main functions: they are an intermediate phase in the conversion of a mathematical object to a
net that can be printed; and they are a way of holding and displaying a mathematical expression in an unevaluated form that can be both printed and evaluated.
Internally, each expression is a basic list whose elements may also be expressions. The elements that are not expressions are interpreted as themselves, and may be strings, symbols, numbers, etc. There are several types of expression that correspond to various sorts of mathematical entities, such as sums of class Sum, products, of class Product, fractions of class Divide, etc.
Expressions are produced with the function expression. The various methods installed for it try to bring as much of the semantic structure of the mathematical object to light. The following examples illustrate that, using peek and peek' to display the internal structure.
i1 : expression 4
o1 = 4
o1 : Expression of class Holder

i2 : peek oo
o2 = Holder{4}

i3 : d = expression (4)
o3 = 4
o3 : Expression of class Minus

i4 : peek oo
o4 = Minus{4}

i5 : QQ[x];

i6 : f = (x+1)^5
5 4 3 2
o6 = x + 5x + 10x + 10x + 5x + 1
o6 : QQ[x]

i7 : peek f
o7 = QQ[x]{x5+5x4+10x3+10x2+5x+1}

i8 : e = expression f
5 4 3 2
o8 = x + 5x + 10x + 10x + 5x + 1
o8 : Expression of class Sum

i9 : peek e
5 4 3 2
o9 = Sum{x , 5x , 10x , 10x , 5x, 1}

i10 : peek'_2 e
4 3 2
o10 = Sum{Power{x, 5}, Product{5, x }, Product{10, x }, Product{10, x },

Product{5, x}, 1}

i11 : peek'_11 e
o11 = Sum{Power{x, 5}, Product{5, Power{x, 4}}, Product{10, Power{x, 3}},

Product{10, Power{x, 2}}, Product{5, x}, 1}

The function
factor returns an expression.
i12 : c = factor f
5
o12 = (x + 1)
o12 : Expression of class Product

i13 : peek'_2 c
o13 = Product{Power{x + 1, 5}}

i14 : factor 240012
2 2
o14 = 2 3 59*113
o14 : Expression of class Product

Expressions can be evaluated using
value.
i15 : value e
5 4 3 2
o15 = x + 5x + 10x + 10x + 5x + 1
o15 : QQ[x]

i16 : value e == f
o16 = true

i17 : value c
5 4 3 2
o17 = x + 5x + 10x + 10x + 5x + 1
o17 : QQ[x]

The following operators can be applied to expressions:
SPACE,
*,
**,
+,
,
/,
==,
^, and
_. They are contagious, in the sense that when applied to an expression and a nonexpression, the nonexpression will be converted to an expression and the operator will be applied. Only the most trivial algebraic simplications are applied.
i18 : d + e
5 4 3 2
o18 =  4 + x + 5x + 10x + 10x + 5x + 1
o18 : Expression of class Sum

i19 : d + 4
o19 =  4 + 4
o19 : Expression of class Sum

i20 : d / 4
4
o20 = 
4
o20 : Expression of class Divide

i21 : d / 1
o21 = 4
o21 : Expression of class Minus

i22 : d == e
5 4 3 2
o22 = 4 == x + 5x + 10x + 10x + 5x + 1
o22 : Expression of class Equation
