Home : Maplesoft Products : Maple 18 : New Features in Maple 18 : Capturing Exact Student Input

Capturing Exact Student Input

The InertForm package gives you tools to prevent simplification and evaluation so that you can examine exactly what was entered.

For example, when students use Math Apps, they are sometimes asked to enter a mathematical expression into a Math Entry box. By default, when Maple is asked what the student entered, Maple applies the same automatic simplification rules as it would if the expression was entered elsewhere in Maple. For example “2/4” would be returned as “1/2”.

Consider the following input expressions in boxes A and B:

Box  A 

Box B 

Embedded component 

Embedded component 


Typing these expressions at a prompt or using the normal access functions for getting the expressions out of the math container will trigger some automatic built-in simplifications.    

DocumentTools:-Do(%BoxA); 1 

`/`(1, 2)

DocumentTools:-Do(%BoxB); 1 


Most of the time, this is what you want, since you are interested in the mathematical result, not the form it was entered in. But occasionally, you want to know exactly what the student entered, because you want the answer in a particular form. With the InertForm package, you can capture the exact input. 

The InertForm package allows you to extract the contents of a math entry box in a notation that will not evaluate. This notation has the advantage of being an unambiguous representation of a mathematical expression that follows strict rules that make it easy to take apart and compare with the desired response. 

InertForm:-FromMathContainer(BoxA); 1 

`%/`(2, 4)

InertForm:-FromMathContainer(BoxB); 1 

`%*`(8, `%/`(%sqrt(4), `%^`(4, 2)))

The syntax of a InertForm expression is such that: 

  • The operator or function name is prefixed with a % symbol.
  • Operators appear in a prefix location (before the operands), so 1 + 2 will appear as +(1,2), noting that + will be rewritten as %+.

This concept also allows you to easily build up expressions so they can be displayed in a precise way. 

expr := `%/`(`%+`(1, 2), 3); 1 

`%/`(`%+`(1, 2), 3)

InertForm:-Display(expr); 1 


The gray + symbol gives you a hint of the underlying structure, and cut & paste will preserve the underlying form. The Display command also provides an option to make it appear as a non-inert structure in every way. 

InertForm:-Display(expr, 'inert' = false); 1 

`+`(`*`(`/`(1, 3), `*`(`+`(1, 2))))

The InertForm package also provides commands for parsing 1-D math expressions. For example, consider the following input expressions in text boxes C and D:


Again, let's compare the standard way of getting the values from text boxes. 

DocumentTools:-Do(%TextBoxC); 1 


Note: The following command is expected to display an error message, as 3xy is not correct Maple syntax. Instead, 3*x*y is expected. 

DocumentTools:-Do(%TextBoxD); 1 

Error, (in unknown) incorrect syntax in parse: missing operator or `;` (near 3rd character of parsed string)

The Parse command will operate on the string returned by GetProperty. 


`%+`(1, 1)

Implicit multiplication is available as an option. Note that variable names will be assumed to be one character long in this case. 


`%+`(`%*`(3, `%*`(x, y)), `+`(`-`(`%*`(x, y))), %sin(x))

These expressions can be displayed at any time using the Display command. 

InertForm:-Display(`%+`(1, 1)); 1 


InertForm:-Display(`%+`(`%*`(3, `%*`(x, y)), `+`(`-`(`%*`(x, y))), %sin(x))); 1 


They can also be converted to regular infix-form in order to compute results. 

InertForm:-Value(`%+`(`%*`(3, `%*`(x, y)), `+`(`-`(`%*`(x, y))), %sin(x))); 1 

`+`(`*`(2, `*`(x, `*`(y))), sin(x))