## `Pref::keepOrder` -- order of terms in sum outputs

#### Introduction

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

#### Call(s)

`Pref::keepOrder(Always)`
`Pref::keepOrder(DomainsOnly)`
`Pref::keepOrder(System)`
`Pref::keepOrder(NIL)`
`Pref::keepOrder()`

#### Options

`Always` | - | the output always corresponds to the internal order
`DomainsOnly` | - | only polynomials and domain elements are printed in their internal order
`System` | - | the output system always decides the output order

#### Returns

the previously defined value: Always, DomainsOnly, or System.

#### Related Functions

`DOM_POLY`, `Dom::MultivariatePolynomial`, `Dom::Polynomial`, `Dom::UnivariatePolynomial`, `print`

#### Details

- 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.

#### Option: Always

- The output always corresponds to the internal order.

#### Option: DomainsOnly

- 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`.

#### Option: System

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

#### 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

                        - a + b, b - a, poly(- x + 1, [x])

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

    >> Pref::keepOrder(Always):
       e, f, p

                       - a + b, - a + b, poly(- x + 1, [x])

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

    >> Pref::keepOrder(System):
       e, f, p

                          b - a, b - a, poly(1 - x, [x])

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

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

                                    DomainsOnly

#### Changes

- `Pref::keepOrder` is now taken into account in both `PRETTYPRINT` modes.

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000