====================================================================
OrderlyDifferentialPolynomial examples
====================================================================

Many systems of differential equations may be transformed to equivalent 
systems of ordinary differential equations where the equations are expressed 
polynomially in terms of the unknown functions.  In FriCAS, the domain 
constructors OrderlyDifferentialPolynomial (abbreviated ODPOL) and
SequentialDifferentialPolynomial (abbreviation SDPOL) implement two
domains of ordinary differential polynomials over any differential
ring.  In the simplest case, this differential ring is usually either
the ring of integers, or the field of rational numbers.  However,
FriCAS can handle ordinary differential polynomials over a field of
rational functions in a single indeterminate.

The two domains ODPOL and SDPOL are almost identical, the only difference 
being the choice of a different ranking, which is an ordering of the 
derivatives of the indeterminates.  The first domain uses an orderly ranking, 
that is, derivatives of higher order are ranked higher, and derivatives of 
the same order are ranked alphabetically.  The second domain uses a 
sequential ranking, where derivatives are ordered first alphabetically 
by the differential indeterminates, and then by order.  A more general 
domain constructor, DifferentialSparseMultivariatePolynomial (abbreviation 
DSMP) allows both a user-provided list of differential indeterminates
as well as a user-defined ranking.  We shall illustrate ODPOL(FRAC INT), 
which constructs a domain of ordinary differential polynomials in an 
arbitrary number of differential indeterminates with rational numbers 
as coefficients.

  dpol:= ODPOL(FRAC INT)
    OrderlyDifferentialPolynomial Fraction Integer
                            Type: Domain

A differential indeterminate w may be viewed as an infinite sequence of 
algebraic indeterminates, which are the derivatives of w. To facilitate 
referencing these, FriCAS provides the operation makeVariable to convert 
an element of type Symbol to a map from the natural numbers to the 
differential polynomial ring.

  w := makeVariable('w)$dpol
    theMap(DPOLCAT-;makeVariable;AM;17!0,0)
 Type: (NonNegativeInteger -> OrderlyDifferentialPolynomial Fraction Integer)

  z := makeVariable('z)$dpol
    theMap(DPOLCAT-;makeVariable;AM;17!0,0)
 Type: (NonNegativeInteger -> OrderlyDifferentialPolynomial Fraction Integer)

The fifth derivative of w can be obtained by applying the map w to the 
number 5.  Note that the order of differentiation is given as a subscript 
(except when the order is 0).

  w.5
    w
     5
                      Type: OrderlyDifferentialPolynomial Fraction Integer

  w 0
    w
                      Type: OrderlyDifferentialPolynomial Fraction Integer

The first five derivatives of z can be generated by a list.

  [z.i for i in 1..5]
    [z ,z ,z ,z ,z ]
      1  2  3  4  5
                    Type: List OrderlyDifferentialPolynomial Fraction Integer

The usual arithmetic can be used to form a differential polynomial from
the derivatives.

  f:= w.4 - w.1 * w.1 * z.3 
           2
    w  - w  z
     4    1  3
                    Type: OrderlyDifferentialPolynomial Fraction Integer

  g:=(z.1)**3 * (z.2)**2 - w.2
      3  2
    z  z   - w
     1  2     2
                    Type: OrderlyDifferentialPolynomial Fraction Integer

The operation D computes the derivative of any differential polynomial.

  D(f)
           2
    w  - w  z  - 2w w z
     5    1  4     1 2 3
                    Type: OrderlyDifferentialPolynomial Fraction Integer

The same operation can compute higher derivatives, like the fourth derivative.

  D(f,4)
            2                               2
     w  - w  z  - 8w w z  + (- 12w w  - 12w  )z  - 2w z w
      8    1  7     1 2 6         1 3      2   5     1 3 5
   + 
                                         2
     (- 8w w  - 24w w )z  - 8w z w  - 6w  z
          1 4      2 3  4     2 3 4     3  3
                         Type: OrderlyDifferentialPolynomial Fraction Integer

The operation makeVariable creates a map to facilitate referencing the 
derivatives of f, similar to the map w.

  df:=makeVariable(f)$dpol
    theMap(DPOLCAT-;makeVariable;AM;17!0,0)
 Type: (NonNegativeInteger -> OrderlyDifferentialPolynomial Fraction Integer)

The fourth derivative of f may be referenced easily.

  df.4
            2                               2
     w  - w  z  - 8w w z  + (- 12w w  - 12w  )z  - 2w z w
      8    1  7     1 2 6         1 3      2   5     1 3 5
   + 
                                         2
     (- 8w w  - 24w w )z  - 8w z w  - 6w  z
          1 4      2 3  4     2 3 4     3  3
                    Type: OrderlyDifferentialPolynomial Fraction Integer

The operation order returns the order of a differential polynomial, 
or the order in a specified differential indeterminate.

  order(g)
    2
                    Type: PositiveInteger

  order(g, 'w)
    2
                    Type: PositiveInteger

The operation differentialVariables returns a list of differential 
indeterminates occurring in a differential polynomial.

  differentialVariables(g)
    [z,w]
                    Type: List Symbol

The operation degree returns the degree, or the degree in the differential 
indeterminate specified.

  degree(g)
       2  3
     z  z
      2  1
                    Type: IndexedExponents OrderlyDifferentialVariable Symbol

  degree(g, 'w) 
    1
                    Type: PositiveInteger

The operation weights returns a list of weights of differential monomials 
appearing in differential polynomial, or a list of weights in a specified 
differential indeterminate.

  weights(g)
    [7,2]
                    Type: List NonNegativeInteger

  weights(g,'w)
    [2]
                    Type: List NonNegativeInteger

The operation weight returns the maximum weight of all differential 
monomials appearing in the differential polynomial.

  weight(g)
    7
                    Type: PositiveInteger

A differential polynomial is isobaric if the weights of all differential 
monomials appearing in it are equal.

  isobaric?(g)
    false
                    Type: Boolean

To substitute differentially, use eval. Note that we must coerce 'w to 
Symbol, since in ODPOL, differential indeterminates belong to the domain 
Symbol.  Compare this result to the next, which substitutes algebraically
(no substitution is done since w.0 does not appear in g).

  eval(g,['w::Symbol],[f])
              2                           2        3  2
     - w  + w  z  + 4w w z  + (2w w  + 2w  )z  + z  z
        6    1  5     1 2 4      1 3     2   3    1  2
                    Type: OrderlyDifferentialPolynomial Fraction Integer

  eval(g,variables(w.0),[f])
       3  2
     z  z   - w
      1  2     2
                    Type: OrderlyDifferentialPolynomial Fraction Integer

Since OrderlyDifferentialPolynomial belongs to PolynomialCategory, all 
the operations defined in the latter category, or in packages for the 
latter category, are available.

  monomials(g)
        3  2
     [z  z  ,- w ]
       1  2     2
                    Type: List OrderlyDifferentialPolynomial Fraction Integer

  variables(g)
    [z ,w ,z ]
      2  2  1
                    Type: List OrderlyDifferentialVariable Symbol

  gcd(f,g)
    1
                    Type: OrderlyDifferentialPolynomial Fraction Integer

  groebner([f,g])
             2     3  2
     [w  - w  z ,z  z   - w ]
       4    1  3  1  2     2
                    Type: List OrderlyDifferentialPolynomial Fraction Integer

The next three operations are essential for elimination procedures in
differential polynomial rings.  The operation leader returns the leader
of a differential polynomial, which is the highest ranked derivative
of the differential indeterminates that occurs.

  lg:=leader(g)
     z
      2
                    Type: OrderlyDifferentialVariable Symbol

The operation separant returns the separant of a differential polynomial, 
which is the partial derivative with respect to the leader.

  sg:=separant(g)
       3
    2z  z
      1  2
                    Type: OrderlyDifferentialPolynomial Fraction Integer

The operation initial returns the initial, which is the leading coefficient 
when the given differential polynomial is expressed as a polynomial in 
the leader.

  ig:=initial(g)
      3
    z
     1
                    Type: OrderlyDifferentialPolynomial Fraction Integer

Using these three operations, it is possible to reduce f modulo the 
differential ideal generated by g.  The general scheme is to first 
reduce the order, then reduce the degree in the leader.  First, eliminate 
z.3 using the derivative of g.

  g1 := D g
       3               2  3
    2z  z z  - w  + 3z  z
      1  2 3    3     1  2
                    Type: OrderlyDifferentialPolynomial Fraction Integer

Find its leader.

  lg1:= leader g1
    z
     3
                    Type: OrderlyDifferentialVariable Symbol

Differentiate f partially with respect to this leader.

  pdf:=D(f, lg1)
        2
    - w
       1
                    Type: OrderlyDifferentialPolynomial Fraction Integer

Compute the partial remainder of f with respect to g.

  prf:=sg * f- pdf * g1
       3         2        2  2  3
    2z  z w  - w  w  + 3w  z  z
      1  2 4    1  3     1  1  2
                     Type: OrderlyDifferentialPolynomial Fraction Integer

Note that high powers of lg still appear in prf.  Compute the leading 
coefficient of prf as a polynomial in the leader of g.

  lcf:=leadingCoefficient univariate(prf, lg)
       2  2
    3w  z
      1  1
                     Type: OrderlyDifferentialPolynomial Fraction Integer

Finally, continue eliminating the high powers of lg appearing in prf to 
obtain the (pseudo) remainder of f modulo g and its derivatives.

  ig * prf - lcf * g * lg
       6         2  3        2  2
    2z  z w  - w  z  w  + 3w  z  w z
      1  2 4    1  1  3     1  1  2 2
                     Type: OrderlyDifferentialPolynomial Fraction Integer

See Also:
o )show OrderlyDifferentialPolynomial

