Function Repository Resource:

UnformalizeSymbols

Source Notebook

Convert formal symbols in an expression into non-formal versions

Contributed by: Paco Jain (Wolfram Research)

ResourceFunction["UnformalizeSymbols"][expr]

converts all formal symbols in expr to their non-formal counterparts.

Details and Options

ResourceFunction["UnformalizeSymbols"] only replaces formal symbols from the System` context.
ResourceFunction["UnformalizeSymbols"] takes the following options:
"DeferQ"Falsewhether to wrap replaced symbols in Defer
"TargetContext"Automaticthe context to place converted symbols into
By default, formal symbols are converted to non-formal symbols in the current context, as given by $Context. To place output symbols into another context, use the option "TargetContext".

Examples

Basic Examples (3) 

Convert formal symbols to their non-formal counterparts:

In[1]:=
ResourceFunction["UnformalizeSymbols"][\[FormalA] + \[FormalB]]
Out[1]=

UnformalizeSymbols works on Latin, Greek and other symbols for which there exists a formal version in the Wolfram Language:

In[2]:=
ResourceFunction["UnformalizeSymbols"][\[FormalPhi]/8]
Out[2]=
In[3]:=
ResourceFunction["UnformalizeSymbols"][Cos[\[FormalSampi]]]
Out[3]=

UnformalizeSymbols works on both uppercase and lowercase letters:

In[4]:=
ResourceFunction[
 "UnformalizeSymbols"][(\[FormalR]/\[FormalCapitalA]) \[FormalLambda] + \[FormalCapitalLambda]]
Out[4]=

Options (4) 

DeferQ (2) 

By default, symbols in the output of UnformalizeSymbols may ultimately evaluate, should they have definitions. Here, a has a value in "Global`" and so does not appear in the final result:

In[5]:=
a = 2;
ResourceFunction["UnformalizeSymbols"][\[FormalA] + \[FormalB]]
Out[5]=

With the setting "DeferQ" True, replaced symbols are wrapped in Defer prior to output, preventing their evaluation until given explicitly as input (using , Evaluate in Place, etc.):

In[6]:=
ResourceFunction["UnformalizeSymbols"][\[FormalA] + \[FormalB], "DeferQ" -> True]
Out[6]=
In[7]:=
InputForm[%]
Out[7]=

TargetContext (2) 

By default, replaced symbols in the output of UnformalizeSymbol are in the current context:

In[8]:=
$Context = "yourContext`";
ResourceFunction[
 "UnformalizeSymbols"][{\[FormalCapitalLambda], \[FormalCapitalR], \[FormalT]}]
Out[9]=

A different context can be specified via the "TargetContext" option:

In[10]:=
ResourceFunction[
 "UnformalizeSymbols"][{\[FormalCapitalLambda], \[FormalCapitalR], \[FormalT]}, "TargetContext" -> "myContext`"]
Out[10]=

Version History

  • 2.1.0 – 24 June 2021

Related Resources

License Information