uCalc API Version: 2.1.3-preview.2 Released: 6/17/2026

Warning

uCalc API Preview Release Notice:The documentation describes the intended behavior of the API. The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.

CreateAlias

Method

Product: 

Fast Math Parser

Class: 

uCalcBase

Creates a new symbol that behaves exactly like an existing symbol.

Syntax

CreateAlias(string, Item, bool, string)

Parameters

aliasName
string
The new name to register
targetItem
Item
The symbol to alias
commandAlias
bool
(Default = false)
If true, creates a Define() command alias instead of an expression alias
ignore
string
(Default = "")
Internal use only

Return

Item

Newly created alias Item

Remarks

Alias() defines an alternate name for an existing symbol (variable, function, operator, constant, etc.). When the parser encounters the alias, it behaves as though the original symbol were used.

Aliases are lightweight and efficient because they do not rewrite text. Instead, the alias internally points to the existing symbol’s definition.


How Aliases Work

When you create an alias:

  • A new symbol name is registered
  • The alias receives its own Item handle, used only for releasing the alias
  • All operational behavior (evaluation, type, callbacks, precedence, etc.) is delegated to the existing item

This makes aliases ideal for:

  • Synonyms (Sum → Add)
  • Backwards compatibility (Ln → Log)
  • Domain‑specific naming (Velocity → v)
  • Localization (Suma → Add)

Alias vs ExpressionTransformer().FromTo()

You could simulate an alias using:

ExpressionTransformer.FromTo("OldName", "NewName")

…but this performs text substitution, which modifies the expression string, and is slower.

Alias() is superior because it does not modify text and is faster.

Use Alias() whenever you simply want two names to refer to the same symbol.


Overloads

You may specify the existing symbol in two ways:

1. Using an Item object

Alias("NewName", uc.ItemOf("OldName"))

This is the preferred method when:

  • Multiple items share the same name (overloaded functions)
  • You want to alias a specific overload
  • You already have the Item reference

2. Using a string

Alias("NewName", "OldName")

This resolves the name using ItemOf().
If multiple items share the same name, the selection may not be obvious — use the Item overload instead.


Command Aliases

Setting commandAlias = true creates an alias only for the Define() command syntax, not for expressions.

Example:

Alias("Func", "Function", commandAlias: true)

This allows:

Define("Func: f(x) = x+1")

…but does not create an expression‑level alias.


Return Value

Returns an Item representing the alias.
Call .Release() on this Item to remove the alias.

(Command aliases return no Item and cannot be removed.)

Examples

Simple alias
				
					using uCalcSoftware;

var uc = new uCalc();
uc.DefineVariable("x = 10");

// Create alias: y behaves exactly like x
uc.CreateAlias("y", "x");

Console.WriteLine(uc.Eval("y + 5"));
				
			
15
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uc.DefineVariable("x = 10");

   // Create alias: y behaves exactly like x
   uc.CreateAlias("y", "x");

   cout << uc.Eval("y + 5") << endl;
}
				
			
15
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      uc.DefineVariable("x = 10")
      
      '// Create alias: y behaves exactly like x
      uc.CreateAlias("y", "x")
      
      Console.WriteLine(uc.Eval("y + 5"))
   End Sub
End Module
				
			
15
Alias using symbol object
				
					using uCalcSoftware;

var uc = new uCalc();
var MyVar = uc.DefineVariable("MyVar = 123");
var MyAlias = uc.CreateAlias("MyAlias", MyVar);

Console.WriteLine(uc.Eval("MyAlias")); // Contains same value as MyVar
uc.Eval("MyAlias = 456"); // Same as changing MyVar
Console.WriteLine(uc.EvalStr("MyVar")); // MyVar reflects change made in MyAlias
Console.WriteLine("");


// This section below shows how you can have Alias distinguish
// between different variables with the same name

uc.DefineFunction("MyFunc() = MyVar + 1");

// MyVar defined below is a new variable sharing the same name
// MyFunc() will still use the value of the original MyVar
var MyVarAlt = uc.DefineVariable("MyVar = 100");

// The function below uses the new MyVar variable
uc.DefineFunction("MyFunc2() = MyVar + 1");

Console.WriteLine(uc.Eval("MyFunc()"));
Console.WriteLine(uc.Eval("MyFunc2()"));
Console.WriteLine("");

uc.CreateAlias("MyAliasAlt", MyVarAlt);
uc.Eval("MyAlias = 200"); // Changes MyVar used in MyFunc()
uc.Eval("MyAliasAlt = 300"); // Changes MyVar used in MyFunc2()

Console.WriteLine(uc.Eval("MyFunc()"));
Console.WriteLine(uc.Eval("MyFunc2()"));
				
			
123
456

457
101

201
301
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto MyVar = uc.DefineVariable("MyVar = 123");
   auto MyAlias = uc.CreateAlias("MyAlias", MyVar);

   cout << uc.Eval("MyAlias") << endl; // Contains same value as MyVar
   uc.Eval("MyAlias = 456"); // Same as changing MyVar
   cout << uc.EvalStr("MyVar") << endl; // MyVar reflects change made in MyAlias
   cout << "" << endl;


   // This section below shows how you can have Alias distinguish
   // between different variables with the same name

   uc.DefineFunction("MyFunc() = MyVar + 1");

   // MyVar defined below is a new variable sharing the same name
   // MyFunc() will still use the value of the original MyVar
   auto MyVarAlt = uc.DefineVariable("MyVar = 100");

   // The function below uses the new MyVar variable
   uc.DefineFunction("MyFunc2() = MyVar + 1");

   cout << uc.Eval("MyFunc()") << endl;
   cout << uc.Eval("MyFunc2()") << endl;
   cout << "" << endl;

   uc.CreateAlias("MyAliasAlt", MyVarAlt);
   uc.Eval("MyAlias = 200"); // Changes MyVar used in MyFunc()
   uc.Eval("MyAliasAlt = 300"); // Changes MyVar used in MyFunc2()

   cout << uc.Eval("MyFunc()") << endl;
   cout << uc.Eval("MyFunc2()") << endl;
}
				
			
123
456

457
101

201
301
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim MyVar = uc.DefineVariable("MyVar = 123")
      Dim MyAlias = uc.CreateAlias("MyAlias", MyVar)
      
      Console.WriteLine(uc.Eval("MyAlias")) '// Contains same value as MyVar
      uc.Eval("MyAlias = 456") '// Same as changing MyVar
      Console.WriteLine(uc.EvalStr("MyVar")) '// MyVar reflects change made in MyAlias
      Console.WriteLine("")
      
      
      '// This section below shows how you can have Alias distinguish
      '// between different variables with the same name
      
      uc.DefineFunction("MyFunc() = MyVar + 1")
      
      '// MyVar defined below is a new variable sharing the same name
      '// MyFunc() will still use the value of the original MyVar
      Dim MyVarAlt = uc.DefineVariable("MyVar = 100")
      
      '// The function below uses the new MyVar variable
      uc.DefineFunction("MyFunc2() = MyVar + 1")
      
      Console.WriteLine(uc.Eval("MyFunc()"))
      Console.WriteLine(uc.Eval("MyFunc2()"))
      Console.WriteLine("")
      
      uc.CreateAlias("MyAliasAlt", MyVarAlt)
      uc.Eval("MyAlias = 200") '// Changes MyVar used in MyFunc()
      uc.Eval("MyAliasAlt = 300") '// Changes MyVar used in MyFunc2()
      
      Console.WriteLine(uc.Eval("MyFunc()"))
      Console.WriteLine(uc.Eval("MyFunc2()"))
   End Sub
End Module
				
			
123
456

457
101

201
301
Creating alternative names for Define commands
				
					using uCalcSoftware;

var uc = new uCalc();
uc.CreateAlias("VariableDefinition", "Variable", true);
uc.CreateAlias("Method", "Function", true);

uc.Define("VariableDefinition: MyVar = 123");
uc.Define("Method: MyFunc(x) = x * 10");

Console.WriteLine(uc.Eval("MyVar"));
Console.WriteLine(uc.Eval("MyFunc(5)"));
				
			
123
50
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uc.CreateAlias("VariableDefinition", "Variable", true);
   uc.CreateAlias("Method", "Function", true);

   uc.Define("VariableDefinition: MyVar = 123");
   uc.Define("Method: MyFunc(x) = x * 10");

   cout << uc.Eval("MyVar") << endl;
   cout << uc.Eval("MyFunc(5)") << endl;
}
				
			
123
50
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      uc.CreateAlias("VariableDefinition", "Variable", true)
      uc.CreateAlias("Method", "Function", true)
      
      uc.Define("VariableDefinition: MyVar = 123")
      uc.Define("Method: MyFunc(x) = x * 10")
      
      Console.WriteLine(uc.Eval("MyVar"))
      Console.WriteLine(uc.Eval("MyFunc(5)"))
   End Sub
End Module
				
			
123
50
Verifying alias removal and fallback behavior.
				
					using uCalcSoftware;

var uc = new uCalc();
uc.DefineVariable("a = 100");

var aliasB = uc.CreateAlias("b", "a");

Console.WriteLine($"Before release: {uc.EvalStr("b")}");
aliasB.Release();
Console.WriteLine($"After release: {uc.EvalStr("b")}");
				
			
Before release: 100
After release: Undefined identifier
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uc.DefineVariable("a = 100");

   auto aliasB = uc.CreateAlias("b", "a");

   cout << "Before release: " << uc.EvalStr("b") << endl;
   aliasB.Release();
   cout << "After release: " << uc.EvalStr("b") << endl;
}
				
			
Before release: 100
After release: Undefined identifier
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      uc.DefineVariable("a = 100")
      
      Dim aliasB = uc.CreateAlias("b", "a")
      
      Console.WriteLine($"Before release: {uc.EvalStr("b")}")
      aliasB.Release()
      Console.WriteLine($"After release: {uc.EvalStr("b")}")
   End Sub
End Module
				
			
Before release: 100
After release: Undefined identifier