InertForm
Parse
parse an expression to an inert form
Calling Sequence
Parameters
Description
Implicit Multiplication
Package Usage
Examples
Compatibility
Parse( expr, opts )
expr
-
string
implicitmultiply
(optional) true or false
lastread
(optional) unevaluated name
names
(optional) set or the string "all", as described below
corenames
(optional) set
variables
The Parse command accepts a string containing a Maple-syntax math expression, and returns an inert-form expression.
By parsing to inert form you can avoid automatic simplification that is normally done on mathematical expressions. For example, parsing "1+1" using the parse command will give you the answer 2, because Maple automatically simplifies expressions where multiple integer constants are added. Using this parser, the same "1+1" will give %+(1,1), where the terms are all present in a form that can be easily manipulated in a predictable way. For more information on automatic simplification, refer to the Maple Expressions chapter of the Maple Programming Guide.
The inert form rewrites the following (normally infix) operators: *, +, ^, /. It also prefixes all function calls with a percent character.
Note that the unary negation operator is not rewritten. Parse of "-x" will return -x, and Parse of "a-b" will return %+(a,-b). Similarly Parse of "-a+b" will return %+(-a,b), so there is no ambiguity, and an inert minus is not necessary, except in the case of -0, which will be parsed to %*(0,-1).
If a string contains multiple expressions separated by a semicolon, only the first expression is parsed. The lastread option can be used to find the character position of the last character included in the parsed result. Pass an unevaluated name, lastread='n', and the designated name will be assigned the integer position. This option should not be used in combination with implicitmultiply because some transformations are done to the string prior to true parsing, the offset returned will be unreliable.
Adding the optional parameter, implicitmultiply, or implicitmultiply=true will cause the parser to interpret some situations as implied multiplication.
An explicit space, such as in the expressions "2 x", or "x y", or "x 2", or "(x+4) y", is interpreted by Parse as multiplication.
A number followed by a variable or open parenthesis with no space, such as "2x", or "2(x-4)" is interpreted as multiplication between the number and subsequent expression.
Two back-to-back expressions surrounded by parentheses, such as "(x-1)(x+1)" is interpreted as multiplication between expressions.
Multi-letter variable names, if not otherwise specified by either the names or corenames options are interpreted as single letter variables multiplied together. Thus "xy" is parsed as "x*y", but "norm(x)" is also interpreted as "n*o*r*m*x".
The names option lets you specify which additional variable and function names should be accepted as a single entity. The additional names should be combined in set brackets, { } and denoted as strings. Calling Parse("norm(x)",implicitmultiply,names={"norm"}) will now be interpreted as a single function call, %norm(x) as opposed to multiplication of single-letter variables as in the previous paragraph.
names="all" can be used to specify that all multi-letter names should be interpreted as single entities instead of a multiplication of single-letter variables.
The corenames option works in conjunction with the names option to build a complete list of recognized multi-letter names. The union of corenames and names constitutes the full set of recognized names. corenames is predefined to include standard special functions like sin, cos, log, and Pi. For a complete definition, execute Describe(InertForm:-Parse).
By setting corenames={} you can override and eliminate all known names.
There is some ambiguity in identifying which names should be kept in the expression. Consider the case where expr = phi2, and names = {phi,phi2}. This could be interpreted as `%*`(phi,2) or as phi2. This command will return the latter. It matches the longest names first.
Related to names and corenames, the variables option lets you specify additional names that should always be treated as variables. For example, "x(y+1)" is normally interpreted as the function x called with arguments y+1. The other interpretation would be x multiplied by y+1. By specifying x in the set of variables, it will not be interpreted as a function name. See Describe(InertForm:-Parse) for the default list of variables (which includes x).
When implicitmultiply is enabled, the input should be restricted to mathematical expressions. Constructs like procedures and modules are not supported, and will likely trigger a syntax error.
This function is part of the InertForm package, so it can be used in the short form Parse(..) only after executing the command with(InertForm). However, it can always be accessed through the long form of the command by using InertForm[Parse](..).
In this example we will start with parsing a string to an inert form.
ex≔InertForm:-Parse⁡(1+2)/6
ex≔1+26
Behind the scenes this inert form uses functional forms of %/ and %+ instead of infix operators.
lprint⁡ex
(1 %+ 2) %/ 6
To convert to regular, active-form, use the value command. This expression will simplify automatically.
value⁡ex
12
Use the op command to access the raw data structure.
op⁡0,ex
`/`
op⁡1,ex
1+2
op⁡1,0,ex
`+`
op⁡1,1,ex
1
op⁡1,2,ex
2
op⁡2,ex
6
Inert form are used behind the scenes in other Maple commands to prevent automatic simplification, such as in the Quiz Command, or some of the step-by-step solvers:
Student:-Basics:-ExpandSteps⁡a2−113⁢a+13
a2−1a3+13=a+1⋅a−1a+1⋅13Factor=a−113divide=a−1⋅31Rewrite division as multiplication by reciprocal=3⁢a−3Multiply fraction and reduce by gcd
Below are some examples that show how the implicitmultiply option works. It assumes names are single-characters unless told otherwise.
InertForm:-Parse⁡cx2,implicitmultiply
c∗x∗2
InertForm:-Parse⁡c x 2,implicitmultiply
InertForm:-Parse⁡cx2,implicitmultiply,names=all
cx2
InertForm:-Parse⁡cx2,implicitmultiply,names=x2
c∗x2
InertForm:-Parse⁡phi1phi2,implicitmultiply,names=φ,φ1,φ2
φ1∗φ2
InertForm:-Parse⁡abcd,implicitmultiply,names=ab,abc,cd
abc∗d
InertForm:-Parse⁡varx^2,implicitmultiply,names=var
var∗x2
InertForm:-Parse⁡f(\"a b c\"),implicitmultiply
f⁡a b c
The InertForm[Parse] command was introduced in Maple 18.
For more information on Maple 18 changes, see Updates in Maple 18.
See Also
InertForm:-Display
parse
ProgrammingGuide/MapleExpressions
Download Help Document