expr
Convert into an element of a basic domain
MuPAD® notebooks are not recommended. 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.
expr(object
)
expr(object)
converts object
into
an element of a basic domain, such that all subobjects are elements
of basic domains as well.
expr
is a type conversion function, for converting
an element of a more complex library domain, such as a polynomial or a matrix, into an element of a basic kernel
domain.
expr
proceeds recursively, such that all
subobjects of the returned object are elements of basic domains,
or infinities, or undefined
.
See Example 1 and Example 2.
The two special objects infinity
and complexInfinity
are
translated into identifiers with the same name by expr
.
Evaluating these identifiers yields the original objects. See Example 1.
If object
already belongs to a basic domain other
than DOM_POLY
,
then expr
is only applied recursively to the operands
of object
, if any.
If object
is a polynomial of domain typeDOM_POLY
,
then expr
is applied recursively to the coefficients
of object
, and afterwards the result is converted
into an identifier, a number, or an expression. See Example 1.
If object
belongs to a library domain T
with
an "expr"
slot, then the corresponding slot routine T::expr
is
called with object
as argument, and the result
is returned.
This can be used to extend the functionality of expr
to
elements of userdefined domains. If the slot routine is unable to
perform the conversion, it must return FAIL
. See Example 6.
If the domain T
does not have an "expr"
slot,
then expr
returns FAIL
.
The result of expr
is not evaluated further.
Use eval
to evaluate
it. See Example 4.
expr
converts a polynomial into an expression,
an identifier, or a number:
expr(poly(x^2 + y, [x])), expr(poly(x)), expr(poly(2, [x])); map(%, domtype)
expr
also works with the objects infinity
, complexInfinity
,
and undefined
:
expr(infinity), expr(complexInfinity), expr(undefined); map(%, domtype)
This example shows that expr
works recursively
on expressions. All subexpressions which are domain elements are converted
into expressions. The construction with hold(_plus)(..)
is
necessary since x + i(1)
would evaluate to FAIL
:
i := Dom::IntegerMod(7): hold(_plus)(x, i(1)); expr(%)
The function series
returns
an element of the domain Series::Puiseux
,
which is not a basic domain:
s := series(sin(x), x); domtype(s)
Use expr
to convert the result into an element
of domain type DOM_EXPR
:
e := expr(s); domtype(e)
Note that the information about the order term is lost after the conversion.
expr
does not evaluate its result. In this
example the polynomial p
has a parameter a
and
the global variable a
has a value. expr
applied
on the polynomial p
returns an expression containing a
.
If you want to insert the value of a
use the function eval
:
p := poly(a*x, [x]): a := 2: expr(p); eval(%)
A
is an element of type Dom::Matrix(Dom::Integer)
:
A := Dom::Matrix(Dom::Integer)([[1, 2], [3, 2]]); domtype(A)
In this case, expr
converts A
into
an element of type DOM_ARRAY
:
a := expr(A); domtype(a)
However, it is not guaranteed that the result is of type DOM_ARRAY
in
future versions of MuPAD^{®} as well. For example, the internal representation
of matrices might change in the future. Use coerce
to request the conversion into
a particular data type:
coerce(A, DOM_ARRAY)
A nested list
is an alternative representation
for a matrix:
coerce(A, DOM_LIST)
If a subobject belongs to a domain without an "expr"
slot,
then expr
returns FAIL
:
T := newDomain("T"): d := new(T, 1, 2); expr(d)
You can extend the functionality of expr
to
your own domains. We demonstrate this for the domain T
by
implementing an "expr"
slot, which returns a list
with the internal operands of its argument:
T::expr := x > [extop(x)]:
If now expr
encounters a subobject of type T
during
the recursive process, it calls the slot routine T::expr
with
the subobject as argument:
expr(d), expr([d, 3])

An arbitrary object 
Element of a basic domain.
object