2
$\begingroup$

I am trying to find the function that converts the result of FullForm back into a standard pretty looking output. Here is what I mean:

expr = FullForm[2 + 2 Sin[x]]

> Plus[2,Times[2,Sin[x]]]

Normal[expr]
Evaluate[expr]
DisplayForm[expr]

> Plus[2,Times[2,Sin[x]]]   (* not good, it's still displays as text *)

% 

> 2+2Sin[x]  (* good, I have a pretty formula again *)

Ok, so evaluating % just after does the trick, but it's not a function call. I was wondering what is the proper function that does this:

ProperFunctionCall[expr]

> 2+2Sin[x]

The secondary question is: does ProperFunctionCall works on all types of inputs, for example, would it work on:

expr2=FullForm[Graphics[Disk[]]];
ProperFunctionCall[expr2]

and show the pretty black disk instead of the text ?

I had a look at the online help of all the entries of ?*Form that seemed meaningful but it did not help me. I also had a look at this post and a few others, but it does not seem to be the same problem so the answer did not help either.

Thanks.

$\endgroup$
3
  • 4
    $\begingroup$ ProperFunctionCall = First. $\endgroup$
    – Kuba
    Commented May 19, 2017 at 18:35
  • 1
    $\begingroup$ ProperFunctionCall = # /. FullForm -> Identity & $\endgroup$
    – Michael E2
    Commented May 19, 2017 at 22:58
  • $\begingroup$ Related: (3098), (44189) $\endgroup$
    – Mr.Wizard
    Commented May 20, 2017 at 15:33

1 Answer 1

6
$\begingroup$

FullForm, as well as all other *Form functions are wrappers which display in a special way. They are meant for display only. Normally one never assigns them to a variable.

You should almost never need to do something like

expr = FullForm[2 + 2 Sin[x]]

This expression cannot even be computed with because Head[expr] === FullForm. (Consequently, you could extract the contents with First[expr].)

Instead, use

expr = 2 + 2 Sin[x]

Now you can re-use expr in calculations. If you need to look at its full form, use

expr // FullForm

This is also discussed in point (8) here. A very common mistake is to assign matrix = MatrixForm[...]. But then Head[matrix] === MatrixForm, so it cannot be used in typical computations such as matrix.matrix.

$\endgroup$
1
  • 3
    $\begingroup$ Or to do both at once use parentheses: (expr = 2 + 2 Sin[x])//FullForm $\endgroup$
    – Bob Hanlon
    Commented May 19, 2017 at 18:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.