It is well-documented!
According to the Documentation page for StandardForm
,
StandardForm
generates output that gives a unique and unambiguous
representation of Wolfram Language expressions, suitable for use as
input. »
StandardForm
is the standard format type used for both input and
output of Wolfram Language expressions in notebooks.
StandardForm
is based on boxes.
And then under the "Properties & Relations" section:
Use ToBoxes
to get the box representation of an expression in StandardForm
:
ToBoxes[x^2 + y^3, StandardForm]
RowBox[{SuperscriptBox["x", "2"], "+", SuperscriptBox["y", "3"]}]
Use ToExpression
to convert back:
ToExpression[%]
x^2 + y^3
Based on the above I would say that it is well-documented that ToExpression
and ToBoxes
are inverses of each other when we work exclusively in the StandardForm
(and the expression won't change during evaluation).
If one still isn't completely convinced, I would cite also Documentation pages for MakeExpression
(which ToExpression
uses under the hood) and MakeBoxes
(which ToBoxes
uses under the hood):
Use MakeExpression
to obtain the original expression in a held form:
MakeBoxes[1 + 1, StandardForm]
RowBox[{"1", "+", "1"}]
MakeExpression[%, StandardForm]
HoldComplete[1 + 1]
Summary
StandardForm
is the default form used in Wolfram System notebooks which provides a unique and unambiguous representation of Wolfram Language expressions, suitable for use as input. On the low level it is based on boxes and one can convert any WL expression into boxes using MakeBoxes
and then get the original expression backward in the held form using MakeExpression
.
So the actual functions which (when working exclusively in the StandardForm
) are exact inverses for each other are MakeBoxes
and MakeExpression
. Their only difference from ToBoxes
and ToExpression
is that they don't evaluate the expression.
Your particular issue
The issue you have encountered is indeed a minor bug.
You can fix it by making the following specific definition for MakeExpression
:
MakeExpression[FractionBox["1", "1"], StandardForm] = HoldComplete[Divide[1, 1]];
Now
Nest[(ToExpression[ToBoxes[#]] &), Hold[1/1], 10]
Hold[1 1/1]
and
Nest[(ToExpression[ToBoxes[#]] &), Hold[Divide[1, 1]], 10]
Hold[1/1]
If you wish to fix also the conversion of Hold[1/1]
input to Hold[1 1/1]
, you can add to the above a definition which will treat the 1/1
input in a special way:
MakeExpression[RowBox[{"1", "/", "1"}], StandardForm] = HoldComplete[Divide[1, 1]];
Now
Hold[1/1]
Hold[1/1]
Nest[(ToExpression[ToBoxes[#]] &), Hold[1/1], 10]
Hold[1/1]
A word of warning: I'm not absolutely sure that this solution is free from unexpected side-effects and won't break something in the system. If you encounter any issue, please let me know.
Hold[1/1]
is treated differently, apparently multiplied by1
(checked for version 8). But is there any place in the docs that saysToExpression
andToBoxes
are inverses of each other? I don't think that's what defines them. $\endgroup$