Convert into an element of a basic domain
This functionality does not run in MATLAB.
expr(object) converts object into an element of a basic domain, such that all sub-objects are elements of basic domains as well.
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.
If the domain T does not have an "expr" slot, then expr returns FAIL.
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(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(%)
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:
A nested list is an alternative representation for a matrix:
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 sub-object of type T during the recursive process, it calls the slot routine T::expr with the sub-object as argument:
expr(d), expr([d, 3])
Element of a basic domain.