This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.


Order of terms in sum outputs

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.




Pref::keepOrder influences the output order of terms in sums.

Usually, the output system uses its own ordering of the terms in a sum to optimize the appearance of the output. This order may be different from the internal ordering of the sum. The output system prefers to re-order the terms such that the first term is positive.

Sometimes it is desirable to see the terms of a sum in the internal order. This can be achieved with Pref::keepOrder(Always).

By default, the term order of polynomials and domain elements is left unchanged.

Pref::keepOrder(NIL) restores the default state, which is DomainsOnly.

Pref::keepOrder() returns the currently set value.


Example 1

Here we create a domain element e, an expression f, and a polynomial p containing sums. With the default setting DomainsOnly, only the output of the expression f is not in the internal order:

d := newDomain("d"):  d::print := x -> extop(x):
e := new(d, b - a):  f := b - a:  p := poly(1 - x):
e, f, p

With the setting Always, e, f, and p are all printed in the internal order:

e, f, p

With the setting System, the output order differs from the internal ordering for e, f, and p:

e, f, p

Pref::keepOrder(NIL) restores the default state; Pref::keepOrder() returns the current setting:

Pref::keepOrder(NIL):  Pref::keepOrder()



The output always corresponds to the internal order.


In polynomials and domain elements, the ordering of terms corresponds to the internal order. Other sums may be re-ordered by the output system.

This is the default setting of Pref::keepOrder.


The output order of terms in sums is determined by the output system and does not necessarily correspond to the internal order.

Return Values

Previously defined value: Always, DomainsOnly, or System.

Was this topic helpful?