I would like to know where this "FullForm" in Mathematica will be useful. Kindly provide some examples. I just started learning Mathematica. If my question is wrong or not correct. I'm sorry about that.
-
7Whenever a student asks me a question about Mathematica where I don't know the answer, I apply FullForm. Either this helps show what happened, or else it gives me time to think of something else. – bill s Sep 09 '19 at 19:05
1 Answers
Perhaps there are other uses, but I've primarily used FullForm to "see" what Mathematica "sees". This can be useful when you are trying to do replacements on something like $\frac{x}{\sqrt{5}}+y^2+1/z$. What Mathematica actually sees is
Plus[Times[Power[5, Rational[-1, 2]], x], Power[y, 2], Power[z, -1]]
You might want to do a replacement such as:
Plus[Times[Power[5, Rational[-1, 2]], x], Power[y, 2], Power[z, -1]]/.Rational[-1, 2] -> 6
(* 15625x + y^2 + 1/z *)
Replacements generally match to the FullForm and in some cases replacements will fail because Mathematica interprets it differently than you do. For example:
x/Sqrt[5] + y^2 + 1/z /. Sqrt[5] -> 6
This fails to give the expected result, because there is no Sqrt in the function by the time you go to run it.
Another place I've used FullForm is for inspecting the code for graphics and plots when they are misbehaving. There's a lot of stuff that happens behind the scenes when generating a plot, and so sometimes it's beneficial to see what the actual result of all that code is. For example, I can see what tick marks were chosen, and I can even replace them with my own tick marks after the fact if I desire. However, I would usually use InputForm for this as I find it slightly more readable.
- 10,081
- 20
- 30
-
4For inspecting graphics my
shortInputFormfunction is much more handy thanInputForm. – Alexey Popkov Sep 09 '19 at 17:19 -
And
InputFormcan be achieved by Ctrl+Shift+I. (There exist cases thatInputFormis missleading of course e.g.Sqrt[2] // InputForm.) – xzczd Sep 09 '19 at 17:38 -
5FullForm is tremendously useful for understanding precedence in pattern matching as well. That's where I most rely on it. – ktm Sep 09 '19 at 18:21