A simple example of the use of formal symbols is for mathematical tasks that require the use of dummy variables. Most functions like Plot
will localize their dummy variables, but not all. For example, LinearModelFit
will not work with symbols that already have a value assigned to them:
x = 1;
LinearModelFit[RandomReal[1, {10, 2}], {1, x}, x]
(spits out errors)
This is where the formal symbols come in handy. Because they can never have a value assigned to them (under normal circumstances), they are ideal for this sort of thing:
LinearModelFit[RandomReal[1, {10, 2}], {1, \[FormalX]}, \[FormalX]]
The code above will always run because you can be sure that \[FormalX]
is not going to have a value.
edit
As pointed out in a comment, you can just Clear[x]
before using a function like LinearModelFit
if you're certain that this will not be a problem elsewhere. However, you can come up with very specific situations where things can still go wrong with that. For example, if you put a slider like Slider[Dynamic[x], {0, 1}]
in your notebook, manipulating that slider can affect running computations in the kernel because dynamic elements interrupt the kernel when they need to be updated. For example, try this:
Slider[Dynamic[x]]
Do[Print[x]; Pause[1], {10}]
You'll see that the printed values of x
change when you manipulate the slider. You can imagine that this could happen during computation that takes several seconds to complete. It's not very likely to happen, but if you use \[FormalX]
for your fit you'll know for certain that it won't.