Creates an alias
MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
x1 = object1, x2 = object2, …, <Global>) alias(<Global>)
alias(x = object) defines
an abbreviation for
object. It changes the configuration
of the parser, replacing identifier
the input, and then replacing
alias(f(y1,y2,...) = object) defines
be a macro. It changes the configuration of the parser so that a function
call of the form
f(a1, a2, ...), where
a sequence of arbitrary objects of the same length as
is replaced by
a2 substituted for
and so on. No substitution takes place if the number of parameters
from the number of arguments
a1,a2,.... No substitution
takes place in the output.
You can define a macro without any arguments via
alias does not evaluate its arguments. Hence
it has no effect if the aliased identifier has a value, and
an alias for the right side of the alias definition and not for its
evaluation. See Example 2.
An alias is in effect from the time when the call to
been evaluated. It affects exactly those inputs that are parsed after
that moment. See Example 9. In particular,
an alias definition inside a procedure does
not affect the rest of the procedure.
You can create several alias definitions in a single call. Abbreviations and macros can be mixed.
alias() displays all currently defined aliases
and macros as a sequence of equations. For an abbreviation defined
alias(x = object), the equation
= object is printed. For a macro defined via
y2, ...) = object), the equation
f(y1, y2, ...)
= object is printed. See Example 11.
Each identifier can be aliased to only one object. Each object
can be abbreviated in only one way. Otherwise
By default, back-substitution of aliases in the output happens
only for abbreviations and not for macros. After a command of the
alias(x = object), both the unevaluated object
its evaluation are replaced by the unevaluated identifier
the output. See Example 2.
You can control the behavior of the back-substitution in the
output with the function
see the corresponding help page for details.
Alias substitutions are performed in parallel, both in the input and in the output. Thus it is not possible to define nested aliases. See Example 10.
If you use an identifier as an abbreviation, you cannot use
that same identifier directly. You must use
you can define another abbreviation or macro for the same identifier.
See Example 4.
If a macro
f(y1,y2,...,yn) with n arguments
is defined, you cannot call
f with n arguments
in its literal meaning any longer. However, you can still call
a different number of arguments. See Example 5.
You can define macros with different numbers of arguments at the same time. See Example 4.
An alias definition affects all kinds of input: interactive
input on the command line, input via the function
input, input from a file using
read (for the latter
two only if option
Plain is not set), and input
from a string using
text2expr. See Example 8.
An alias definition has no effect on the identifier used as an alias. In particular, that identifier retains its value and its properties. The alias and the aliased object are still distinguished by the evaluator. See Example 6.
Assigning a value to one of the identifiers on the left side of an alias definition, or deleting its value does not affect the alias substitution, neither in the input nor in the output. See Example 7.
alias with at least one argument changes
the parser configuration in the way described in the “Details”
d as a shortcut for
delete f, g, x, y: alias(d = diff): d(sin(x), x) = diff(sin(x), x); d(f(x, y), x) = diff(f(x, y), x)
Define a macro
x). Note that
not prevent alias substitution:
alias(Dx(f) = diff(f(x), x)): Dx(sin); Dx(f + g); hold(Dx(f + g))
After the call
unalias(d, Dx), no alias substitutions
happen any longer:
unalias(d, Dx): d(sin(x), x), diff(sin(x), x), d(f(x, y), x), diff(f(x, y), x); Dx(sin), Dx(f + g)
Suppose you want to avoid typing
therefore define an abbreviation
a for it:
longhardtotypeident := 10; alias(a = longhardtotypeident):
alias does not evaluate its arguments,
now an abbreviation for
not for the number
a + 1, hold(a) + 1, eval(hold(a) + 1)
longhardtotypeident := 2: a + 1, hold(a) + 1, eval(hold(a) + 1)
However, by default alias back-substitution in the output happens for both the identifier and its current value:
2, 10, longhardtotypeident, hold(longhardtotypeident)
Pref::alias(FALSE) switches alias
p := Pref::alias(FALSE): a, hold(a), 2, longhardtotypeident, hold(longhardtotypeident); Pref::alias(p): unalias(a):
Aliases are substituted and not just replaced textually. In
the following example,
3*succ(u) is replaced by
and not by
3*u+1, which a search-and-replace function
in a text editor would produce:
alias(succ(x) = x + 1): 3*succ(u); unalias(succ):
a to be an abbreviation for
Then the next alias definition is really an alias definition for
delete a, b: alias(a = b): alias(a = 2): type(a), type(b); unalias(b):
unalias first before defining another
alias for the identifier
unalias(a): alias(a = 2): type(a), type(b); unalias(a):
A macro definition can be added if the newly defined macro has
a different number of arguments.
all macros defined for
alias(a(x)=sin(x^2)): a(y); alias(a(x)=cos(x^2)):
Error: Invalid operand. [_power] Evaluating: alias
alias(a(x, y) = sin(x + y)): a(u, v); alias(): unalias(a):
a(x) = sin(x^2)
a(x, y) = sin(x + y)
A macro definition has no effect when called with the wrong number of arguments, and the sequence of arguments is not flattened:
alias(plus(x, y) = x + y): plus(1), plus(3, 2), plus((3, 2)); unalias(plus):
Expression sequences can appear on the right side of an alias definition, but they have to be enclosed in parenthesis:
alias(x = (1, 2)): f := 0, 1, 2, x; nops(f); unalias(x):
An identifier used as an abbreviation can still exist in its literal meaning inside expressions that were entered before the alias definition:
delete x: f := [x, 1]: alias(x = 1): f; map(f, type); unalias(x):
An identifier used as an alias does not have to have a value:
a := 5: alias(a = 7): 7, 5; print(a); unalias(a):
Alias definitions also apply to input from files or strings:
alias(a = 3): type(text2expr("a")); unalias(a)
An alias is valid for all input that is parsed after
alias. A statement in a command
line is not parsed before the previous commands in that command line
have been executed. In the following example, the alias is already
in effect for the second statement:
alias(a = 3): type(a); unalias(a)
This can be changed by entering additional parentheses:
(alias(a = 3): type(a)); unalias(a)
b to be an alias for
which in turn is defined to be an alias for
It is recommended to avoid such chains of alias definitions because
of probably unwanted effects.
b in the input is replaced by
but no additional substitution step is taken to replace this again
On the other hand, the number
2 is replaced
c in every output and that
then replaced by
When called without arguments,
displays all currently defined aliases:
alias(a = 5, F(x) = sin(x^2)): alias(); unalias(F, a):
F(x) = sin(x^2)
a = 5
Identifiers or symbolic expressions
of the form
Any MuPAD® objects
Definition of an alias in the global parser context.
When an alias is defined in a library or package source file,
it will be deleted automatically after reading the file. With the
the void object of type
Aliases are stored in the parser configuration table displayed
_parser_config(). Note that by default, alias
back-substitution happens for the right sides of the equations in
this table, but not for the indices. Use
display this table without alias back-substitution.
Aliases are not used while a file is read using
fread with the option
Conversely, if an alias is defined in a file which is read with the
Plain, the alias is only used until the
file has been read completely.