Basic Examples (4)
Convert symbols to their formal counterparts:
FormalizeSymbols works on Latin, Greek and other symbols for which there exists a formal version in the Wolfram Language:
FormalizeSymbols works on both uppercase and lowercase letters:
FormalizeSymbols[expr,"Rules"] returns the rules that would be used for replacement in formalizing an expression:
Scope (2)
By default, FormalizeSymbols does not affect symbols with multi-character symbol names:
To replace multi-character symbols as well, use the setting "ExtraReplacements"→True:
By default, FormalizeSymbols only affects symbols in the current context (here "Global`"). To allow replacement of symbols in other contexts, use the option "ReplacementContexts":
Options (11)
EvaluateOnce (2)
In the special case that FormalizeSymbols is directly called on a bare symbol having an own value, its argument can be allowed to evaluate exactly once using the option setting "EvaluateOnce"→True, as in the following case:
Without this top-level evaluation, the above inputs would result in x:
With "EvaluateOnce"→True, evaluation does not proceed beyond top-level:
Contrast this result with using Evaluate, which triggers full evaluation:
ExcludeInputSymbols (1)
To exclude a given set of symbols from being replaced, use the option "ExcludeInputSymbols". Compare:
ExcludeTargetSymbols (1)
To exclude a given set of formal symbols as possible replacement characters, use the option "ExcludeTargetSymbols". Compare:
ExtraReplacements (2)
By default, FormalizeSymbols does not replace symbols that lack a direct formal equivalent:
To replace all symbols, regardless of name, use the setting "ExtraReplacements"→True:
ReplacementContexts (4)
The default setting of "ReplacementContexts"→Automatic replaces only symbols in $Context (here Global`):
The "ReplacementContexts" option can be set to a list of contexts for which symbols should be formalized:
With the setting "ReplacementContexts"→All, symbols in any context other than System` are replaced:
FormalizeSymbols automatically avoids symbol collisions:
With the option setting "Verbose"→True a warning is issued about potential collisions:
Verbose (1)
With the setting "Verbose"→ True, a message is issued whenever a “non-standard” replacement is made, either due to potential collisions or due to replacement of a symbol that lacks a direct formal equivalent (as possible when "ExtraReplacements"→True):
Properties and Relations (3)
FormalizeSymbols has the HoldFirst attribute to prevent (with default option settings) evaluation of defined symbols prior to replacement:
For the special case of pure symbols having OwnValues, pure HoldFirst behavior can be overridden using the "EvaluateOnce" option:
Contrast this result with using Evaluate, which triggers full evaluation:
Symbols within the System` context are never replaced. In particular, this includes Pi, N, C, D, E, I, K, and O