# The Interpretation of Textual Forms

ToExpression[input] | create an expression by interpreting strings or boxes |

Converting from strings or boxes to expressions.

In[1]:= |

Out[1]= |

In[2]:= |

Out[2]= |

In[3]:= |

Out[3]= |

In any *Mathematica* session, *Mathematica* is always effectively using ToExpression to interpret the textual form of your input as an actual expression to evaluate.

If you use the notebook front end for *Mathematica*, then the interpretation only takes place when the contents of a cell are sent to the kernel, say for evaluation. This means that within a notebook there is no need for the textual forms you set up to correspond to meaningful *Mathematica* expressions; this is only necessary if you want to send these forms to the kernel.

FullForm | explicit functional notation |

InputForm | one-dimensional notation |

StandardForm | two-dimensional notation |

The hierarchy of forms for standard *Mathematica* input.

In[4]:= |

Out[4]= |

In[5]:= |

Out[5]= |

In[6]:= |

Out[6]= |

Built into *Mathematica* is a collection of standard rules for use by ToExpression in converting textual forms to expressions.

These rules define the *grammar* of *Mathematica*. They state, for example, that should be interpreted as Plus[x, y], and that should be interpreted as Power[x, y]. If the input you give is in FullForm, then the rules for interpretation are very straightforward: every expression consists just of a head followed by a sequence of elements enclosed in brackets. The rules for InputForm are slightly more sophisticated: they allow operators such as , , and , and understand the meaning of expressions where these operators appear between operands. StandardForm involves still more sophisticated rules, which allow operators and operands to be arranged not just in a one-dimensional sequence, but in a full two-dimensional structure.

*Mathematica* is set up so that FullForm, InputForm, and StandardForm form a strict hierarchy: anything you can enter in FullForm will also work in InputForm, and anything you can enter in InputForm will also work in StandardForm.

If you use a notebook front end for *Mathematica*, then you will typically want to use all the features of StandardForm. If you use a text-based interface, however, then you will typically be able to use only features of InputForm.

When you use StandardForm in a *Mathematica* notebook, you can enter directly two-dimensional forms such as or annotated graphics. But InputForm allows only one-dimensional forms.

If you copy a StandardForm expression whose interpretation can be determined without evaluation, then the expression will be pasted into external applications as InputForm. Otherwise, the text is copied in a linear form that precisely represents the two-dimensional structure using . When you paste this linear form back into a *Mathematica* notebook, it will automatically "snap" into two-dimensional form.

ToExpression[input,form] | attempt to create an expression assuming that input is given in the specified textual form |

Importing from other textual forms.

StandardForm and its subsets FullForm and InputForm provide precise ways to represent any *Mathematica* expression in textual form. And given such a textual form, it is always possible to convert it unambiguously to the expression it represents.

TraditionalForm is an example of a textual form intended primarily for output. It is possible to take any *Mathematica* expression and display it in TraditionalForm. But TraditionalForm does not have the precision of StandardForm, and as a result there is in general no unambiguous way to go back from a TraditionalForm representation and get the expression it represents.

Nevertheless, ToExpression[input, TraditionalForm] takes text in TraditionalForm and attempts to interpret it as an expression.

In[7]:= |

Out[7]= |

In[8]:= |

Out[8]= |

When TraditionalForm output is generated as the result of a computation, the actual collection of boxes that represent the output typically contains special Interpretation objects or other specially tagged forms that specify how an expression can be reconstructed from the TraditionalForm output.

The same is true of TraditionalForm that is obtained by explicit conversion from StandardForm. But if you edit TraditionalForm extensively, or enter it from scratch, then *Mathematica* will have to try to interpret it without the benefit of any additional embedded information.