1 2% Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd. 3% All rights reserved. 4% 5% Redistribution and use in source and binary forms, with or without 6% modification, are permitted provided that the following conditions are 7% met: 8% 9% - Redistributions of source code must retain the above copyright 10% notice, this list of conditions and the following disclaimer. 11% 12% - Redistributions in binary form must reproduce the above copyright 13% notice, this list of conditions and the following disclaimer in 14% the documentation and/or other materials provided with the 15% distribution. 16% 17% - Neither the name of The Numerical ALgorithms Group Ltd. nor the 18% names of its contributors may be used to endorse or promote products 19% derived from this software without specific prior written permission. 20% 21% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 22% IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 23% TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 24% PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 25% OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26% EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27% PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES-- LOSS OF USE, DATA, OR 28% PROFITS-- OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29% LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30% NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31% SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 33 34% Example file for DSMP, ODPOL, SDPOL 35 36Many systems of differential equations may be transformed to equivalent 37\index{differential equation} 38systems of ordinary differential equations where the equations are 39\index{equation!differential} 40expressed polynomially in terms of the unknown functions. 41\index{polynomial!differential polynomial} 42In \Language{}, the domain constructors 43\spadtype{OrderlyDifferentialPolynomial} 44\index{differential polynomial} 45(abbreviated \spadtype{ODPOL}) and 46\spadtype{SequentialDifferentialPolynomial} (abbreviation 47\spadtype{SDPOL}) implement two domains of ordinary differential 48polynomials over any differential ring. 49In the simplest case, this differential ring is usually either the ring of 50integers, or the field of rational numbers. 51However, \Language{} can handle ordinary differential polynomials over a 52field of rational functions in a single indeterminate. 53\exptypeindex{OrderlyDifferentialPolynomial} 54\exptypeindex{SequentialDifferentialPolynomial} 55 56The two domains \spadtype{ODPOL} and \spadtype{SDPOL} are almost 57identical, the only difference being the choice of a different ranking, 58which is an ordering of the derivatives of the indeterminates. 59The first domain uses an orderly ranking, that is, derivatives of higher 60order are ranked higher, and derivatives of the same order are ranked 61alphabetically. 62The second domain uses a sequential ranking, where derivatives are ordered 63first alphabetically by the differential indeterminates, and then by 64order. 65A more general domain constructor, 66\spadtype{DifferentialSparseMultivariatePolynomial} (abbreviation 67\spadtype{DSMP}) allows both a user-provided list of differential 68indeterminates as well as a user-defined ranking. 69We shall illustrate \spadtype{ODPOL(FRAC INT)}, which constructs a domain 70of ordinary differential polynomials in an arbitrary number of 71differential indeterminates with rational numbers as coefficients. 72\xtc{ 73}{ 74\spadcommand{dpol:= ODPOL(FRAC INT) \bound{dpol}} 75} 76 77\xtc{ 78A differential indeterminate \spad{w} may be viewed as an infinite 79sequence of algebraic indeterminates, which are the derivatives of 80\spad{w}. 81To facilitate referencing these, \Language{} provides the operation 82\spadfunFrom{makeVariable}{OrderlyDifferentialPolynomial} to convert an 83element of type \spadtype{Symbol} to a map from the natural numbers to the 84differential polynomial ring. 85}{ 86\spadcommand{w := makeVariable('w)\$dpol \free{dpol}\bound{w}} 87} 88\xtc{ 89}{ 90\spadcommand{z := makeVariable('z)\$dpol \free{dpol}\bound{z}} 91} 92\xtc{ 93The fifth derivative of \spad{w} can be obtained by applying the map 94\spad{w} to the number \spad{5.} 95Note that the order of differentiation is given as a subscript (except 96when the order is 0). 97}{ 98\spadcommand{w.5 \free{w}} 99} 100\xtc{ 101}{ 102\spadcommand{w 0 \free{w}} 103} 104\xtc{ 105The first five derivatives of \spad{z} can be generated by a list. 106}{ 107\spadcommand{[z.i for i in 1..5] \free{z}} 108} 109\xtc{ 110The usual arithmetic can be used to form a differential polynomial from 111the derivatives. 112}{ 113\spadcommand{f:= w.4 - w.1 * w.1 * z.3 \free{w}\free{z}\bound{f}} 114} 115\xtc{ 116}{ 117\spadcommand{g:=(z.1)^3 * (z.2)^2 - w.2 \free{z}\free{w}\bound{g}} 118} 119\xtc{ 120The operation \spadfunFrom{D}{OrderlyDifferentialPolynomial} 121computes the derivative of any differential polynomial. 122}{ 123\spadcommand{D(f) \free{f}} 124} 125\xtc{ 126The same operation can compute higher derivatives, like the 127fourth derivative. 128}{ 129\spadcommand{D(f,4) \free{f}} 130} 131\xtc{ 132The operation \spadfunFrom{makeVariable}{OrderlyDifferentialPolynomial} 133creates a map to facilitate referencing the derivatives of \spad{f}, 134similar to the map \spad{w}. 135}{ 136\spadcommand{df:=makeVariable(f)\$dpol \free{f}\bound{df}} 137} 138\xtc{ 139The fourth derivative of f may be referenced easily. 140}{ 141\spadcommand{df.4 \free{df}} 142} 143\xtc{ 144The operation \spadfunFrom{order}{OrderlyDifferentialPolynomial} 145returns the order of a differential polynomial, or the order 146in a specified differential indeterminate. 147}{ 148\spadcommand{order(g) \free{g}} 149} 150\xtc{ 151}{ 152\spadcommand{order(g, 'w) \free{g}} 153} 154\xtc{ 155The operation 156\spadfunFrom{differentialVariables}{OrderlyDifferentialPolynomial} returns 157a list of differential indeterminates occurring in a differential 158polynomial. 159}{ 160\spadcommand{differentialVariables(g) \free{g}} 161} 162\xtc{ 163The operation \spadfunFrom{degree}{OrderlyDifferentialPolynomial} returns 164the degree, or the degree in the differential indeterminate specified. 165}{ 166\spadcommand{degree(g) \free{g}} 167} 168\xtc{ 169}{ 170\spadcommand{degree(g, 'w) \free{g}} 171} 172\xtc{ 173The operation \spadfunFrom{weights}{OrderlyDifferentialPolynomial} returns 174a list of weights of differential monomials appearing in differential 175polynomial, or a list of weights in a specified differential 176indeterminate. 177}{ 178\spadcommand{weights(g) \free{g}} 179} 180\xtc{ 181}{ 182\spadcommand{weights(g,'w) \free{g}} 183} 184\xtc{ 185The operation \spadfunFrom{weight}{OrderlyDifferentialPolynomial} returns 186the maximum weight of all differential monomials appearing in the 187differential polynomial. 188}{ 189\spadcommand{weight(g) \free{g}} 190} 191\xtc{ 192A differential polynomial is {\em isobaric} if the weights of all 193differential monomials appearing in it are equal. 194}{ 195\spadcommand{isobaric?(g) \free{g}} 196} 197\xtc{ 198To substitute {\em differentially}, use 199\spadfunFrom{eval}{OrderlyDifferentialPolynomial}. 200Note that we must coerce \spad{'w} to \spadtype{Symbol}, since in 201\spadtype{ODPOL}, differential indeterminates belong to the domain 202\spadtype{Symbol}. 203Compare this result to the next, which substitutes {\em algebraically} (no 204substitution is done since \spad{w.0} does not appear in \spad{g}). 205}{ 206\spadcommand{eval(g,['w::Symbol],[f]) \free{f}\free{g}} 207} 208\xtc{ 209}{ 210\spadcommand{eval(g,variables(w.0),[f]) \free{f}\free{g}} 211} 212\xtc{ 213Since \spadtype{OrderlyDifferentialPolynomial} belongs to 214\spadtype{PolynomialCategory}, all the operations defined in the latter 215category, or in packages for the latter category, are available. 216}{ 217\spadcommand{monomials(g) \free{g}} 218} 219\xtc{ 220}{ 221\spadcommand{variables(g) \free{g}} 222} 223\xtc{ 224}{ 225\spadcommand{gcd(f,g) \free{f}\free{g}} 226} 227\xtc{ 228}{ 229\spadcommand{groebner([f,g]) \free{f}\free{g}} 230} 231\xtc{ 232The next three operations are essential for elimination procedures in 233differential polynomial rings. 234The operation \spadfunFrom{leader}{OrderlyDifferentialPolynomial} returns 235the leader of a differential polynomial, which is the highest ranked 236derivative of the differential indeterminates that occurs. 237}{ 238\spadcommand{lg:=leader(g) \free{g}\bound{lg}} 239} 240\xtc{ 241The operation \spadfunFrom{separant}{OrderlyDifferentialPolynomial} returns 242the separant of a differential polynomial, which is the partial derivative 243with respect to the leader. 244}{ 245\spadcommand{sg:=separant(g) \free{g}\bound{sg}} 246} 247\xtc{ 248The operation \spadfunFrom{initial}{OrderlyDifferentialPolynomial} returns 249the initial, which is the leading coefficient when the given differential 250polynomial is expressed as a polynomial in the leader. 251}{ 252\spadcommand{ig:=initial(g) \free{g}\bound{ig}} 253} 254\xtc{ 255Using these three operations, it is possible to reduce \spad{f} modulo the 256differential ideal generated by \spad{g}. 257The general scheme is to first reduce the order, then reduce the degree in 258the leader. 259First, eliminate \spad{z.3} using the derivative of \spad{g}. 260}{ 261\spadcommand{g1 := D g \free{g}\bound{g1}} 262} 263\xtc{ 264Find its leader. 265}{ 266\spadcommand{lg1:= leader g1 \free{g1}\bound{lg1}} 267} 268\xtc{ 269Differentiate \spad{f} partially with respect to this leader. 270}{ 271\spadcommand{pdf:=D(f, lg1) \free{f}\free{lg1}\bound{pdf}} 272} 273\xtc{ 274Compute the partial remainder of \spad{f} with respect to \spad{g}. 275}{ 276\spadcommand{prf:=sg * f- pdf * g1 \free{f}\free{sg}\free{pdf}\free{g1}\bound{prf}} 277} 278\xtc{ 279Note that high powers of \spad{lg} still appear in \spad{prf}. 280Compute the leading coefficient of \spad{prf} 281as a polynomial in the leader of \spad{g}. 282}{ 283\spadcommand{lcf:=leadingCoefficient univariate(prf, lg) \free{prf}\free{lg}\bound{lcf}} 284} 285\xtc{ 286Finally, continue eliminating the high powers of \spad{lg} appearing in 287\spad{prf} to obtain the (pseudo) remainder of \spad{f} modulo \spad{g} 288and its derivatives. 289}{ 290\spadcommand{ig * prf - lcf * g * lg \free{ig}\free{prf}\free{lcf}\free{g}\free{lg}} 291} 292\showBlurb{OrderlyDifferentialPolyomial} 293\showBlurb{SequentialDifferentialPolynomial} 294