Modeling Physics with Differential-Algebraic Equations

Lecture 5

Differential Algebra

COMASIC (M2)

Khalil Ghorbal [email protected]

K. Ghorbal (INRIA) 1 COMASIC M2 1 / 29 Outline

1 Differential Algebra

2 Multi-Mode DAEs (Structural Analysis)

K. Ghorbal (INRIA) 1 COMASIC M2 1 / 29 Summary

• Gr¨obner Bases are central objects in Computer Algebra Systems • Elimination Theory generalizes Gaussian elimination (BLT Forms) • Qualitative Analysis of ODE via their algebraic invariant sets

This Lecture • Differential Algebra (Quick Introduction) • Hybrid Aspects: Challenges

K. Ghorbal (INRIA) 2 COMASIC M2 2 / 29 Generalities

R denotes a commutative unitary ring. • a ∈ R is a zero divisor if and only if there exists b ∈ R, b 6= 0 such that ab = 0. • 0 is a trivial zero divisor. • Domains are rings where the only zero divisor is zero. • Quotient of a ring R by an ideal I : R/I . • f¯ (or f ) is zero in R/I if and only if f is in the ideal I . • R/I , residue class ring (not necessarily a domain).

• M is a multiplicatively closed subset of R if and only if m1m2 ∈ M for all m1, m2 in M.

K. Ghorbal (INRIA) 3 COMASIC M2 3 / 29 Prime and Primary Ideals

The zero divisors of the residue class ring are important. Prime Ideals The ideal p is said to be prime if and only if • R/p is a domain. • R/p does not have nontrivial zero divisors. • ab ∈ p if and only if either a ∈ p or b ∈ p.

Primary Ideals The ideal q is said to be primary if and only if • all zero divisors of R/q are nilpotent. • ab ∈ q if and only if either am ∈ q or bm ∈ q for some positive natural number m. √ The radical of a primary ideal, q, is a prime ideal.

K. Ghorbal (INRIA) 4 COMASIC M2 4 / 29 Examples

• Any maximal ideal is prime, the converse is not true. • For a ring R,(X ) is a prime ideal of R[X ] but it is not maximal ((X ) ⊂ (X , Y )). • Intuition: points of a given affine space are not the only irreducible varieties – this will be given a precise meaning later. Lines and circles are also irreducible.

K. Ghorbal (INRIA) 5 COMASIC M2 5 / 29 Localization

−1 • One constructs the ring RM (or M R), the ring R localized at M, r with elements of the form m where r ∈ R and s ∈ M. • For r1 , r2 in R , the “+” composition law is defined by m2r1+m1r2 . m1 m2 M m1m2 • Let ϕM denote the ring homomorphism R → RM , then

−1 ϕM [(ϕM (I ))] = I : M

K. Ghorbal (INRIA) 6 COMASIC M2 6 / 29 Saturation Ideals

Let I be an ideal of R and M a multiplicatively closed subset of R. Then

I : M = {f ∈ R | ∃m ∈ M , mf ∈ I } . is a Saturation ideal.

Let q be a primary ideal. • If M ∩ I 6= ∅ then I : M = R. • If M ∩ q = ∅ then q : M = q. s Suppose one has a primary decomposition of I : I = ∩i=1qi , then \ I : M = qi

qi ∩M=∅

K. Ghorbal (INRIA) 7 COMASIC M2 7 / 29 Sylvester

d d−1 • f = ad X + ad−1X + ··· + a1X + a0 e e−1 • g = be X + be−1X + ··· + b1X + b0 • (d, e) 6= (0, 0) The Sylvester Matrix of f and g is the following (d + e) square matrix.

 ad 0 ··· 0 be 0 ··· 0  ad−1 ad ··· 0 be−1 be ··· 0     .. ..  ad−2 ad−1 . 0 be−2 be−1 . 0   . . . .   ......   . . . ad . . . be   . . . .   . . . .  S(f , g) =  . . ··· ad−1 . . ··· be−1  .   a a ··· a b b ··· .   0 1 d−2 0 1   . . . .   0 a .. . 0 b .. .   0 0   ......   . . . a1 . . . b1  0 0 ··· a0 0 0 ··· b0

K. Ghorbal (INRIA) 8 COMASIC M2 8 / 29 Examples

f = X 4 + 3X 3 − 1 f = X 2 − X + 1 g = −1 g = X − 2

−1 0 0 0   1 1 0  0 −1 0 0 −1 −2 1      0 0 −1 0  1 0 −2   0 0 0 −1

K. Ghorbal (INRIA) 9 COMASIC M2 9 / 29

R is a domain. Let f and g be two in R[X ]. The resultant of f and g, res(f , g), is the of the Sylvester matrix of f and g. Properties • f and g have a common root (on an algebraic field extension of R) if and only if res(f , g) = 0. • res(f , g) = (f , g). That is, there exists polynomials u and v of respective degrees less that e and d, such that res(f , g) = uf + vg.

K. Ghorbal (INRIA) 10 COMASIC M2 10 / 29 Differential Ring

Derivation A derivation δ on R is a map R → R satisfying: • δ(a + b) = δ(a) + δ(b) • δ(ab) = δ(a)b + aδ(b)

• Notation: δa is often used instead of δ(a).

• δ1 and δ2 commute if and only if δ1δ2a = δ2δ1a for all a ∈ R. • High-order derivatives δh are inductively defined as δ(δh−1a). • Ordinary differential ring has a single derivation.

• Partial differential ring has a family ∆ = {δ1, . . . , δm} of pairwise commuting derivations. • Same definitions apply for a field k.

K. Ghorbal (INRIA) 11 COMASIC M2 11 / 29 Definitions

c ∈ R is a constant if and only if δc = 0 for all δ ∈ ∆. If k if a differential field, then the set of constants is a subfield of k. Differential Ideal A differential ideal a of a ∆-ring R is an ideal of R such that

∀δ ∈ ∆, ∀a ∈ a, δa ∈ a .

• The intersection of an arbitrary number of differential ideals is a differential ideal • The finite sum of differential ideals is also a differential ideal • [S] denotes the differential ideal generated by S ⊂ R.

K. Ghorbal (INRIA) 12 COMASIC M2 12 / 29 Examples

Example 1

 d • R = Z[X ], ∆ = dX , is a differential ring. • a = (2, 2X ) is a differential ideal. • [X ] = R (δX = 1)

Example 2

X  d • R = Z[X , e ], ∆ = dX , is a differential ring. • a = (eX ) is a differential ideal. • [X ] = R (δX = 1)

K. Ghorbal (INRIA) 13 COMASIC M2 13 / 29 Derivation Order

• Θ: free multiplicative monoid generated by ∆ = {δ1, . . . , δm}. e1 em • θ ∈ Θ has the form δ1 ··· δm , ei ∈ N. • order of θ is defined as e1 + ··· + em. e1 em • Θ acts on R by θa = δ1 ··· δm a

K. Ghorbal (INRIA) 14 COMASIC M2 14 / 29 Differential Ring (1/2)

• Let R be a ∆-ring.

• ΘX = {Xθ,j }1≤j≤n,θ∈Θ, n > 0, family of indeterminates. • R[ΘX ] has a unique ∆-ring structure extending the ∆-ring structure of R by δXθ,j = Xδθ,j , for all δ ∈ ∆, θ ∈ Θ. • R[ΘX ], equipped with this structure is called Differential Polynomial Ring,

• in the differential indeterminates Xj = X1,j .

• R[ΘX ] is denoted by R{X1,..., Xn} or simply R{X }

• We write Xθ,j by θYj (partial derivative of Yj )

• The order of θYj is defined as the order of θ

K. Ghorbal (INRIA) 15 COMASIC M2 15 / 29 Differential Polynomial Ring (2/2)

• A Differential Monomial is a finite power product of derivatives of the form θYj Q ek • k (θk Yjk ) , the θk (and likewise the Yjk ) are not necessarily distinct • A differential polynomial is a finite sum of terms aM where a ∈ R and M is a differential monomial n o • R{X } has a structure of differential ring with ∆ = ∂ ∂(θYj ) 1≤j≤n,θ∈Θ

K. Ghorbal (INRIA) 16 COMASIC M2 16 / 29 Examples

• R{X1, X2}, ∆ = {δ1, δ2} 4 3 • θ1 = δ1δ2 4 • θ2 = δ2 3 • θ3 = δ1δ2 2 • (θ1X1)(θ2X1)(θ3X2) X2 is a monomial or order 7 and degree 5 The determinant of dimension 2:

X1 X2 W = δX1 δX2 is a differential polynomial in R{X1, X2}.

• W = X1δX2 − X2δX1 2 2 • δW = X1δ X2 − X2δ X1

• The partial derivative of W with respect to δX2 is X1

K. Ghorbal (INRIA) 17 COMASIC M2 17 / 29 Differential Equations

• Given a ∆ differential ring R, to each element f of R{X }, one associates a (partial) differential equation f = 0. • Likewise for a finite subset of S ⊂ R{X }, one gets a system of partial differential equations. • The differential ideal [S] is associated with S and contains all the equations derived from S by addition, multiplication by elements of R{X } and differentiation.

K. Ghorbal (INRIA) 18 COMASIC M2 18 / 29 Triangular Forms

As seen in the purely algebraic case, one wants to define a weaker notion of triangular forms suitable for the differential case. We thus need to define reduction and hence ordering over differential monomials. Triangular Form A system S ⊂ R{X } is in triangular form if its element can be rearranged as S1, S2,..., Sk ,... such that each Sk involves at least one derivative

θk Xjk which does not appear in S1,..., Sk−1. In particular S1 ∈/ R. Example

2 S1 : δ X2 + X2 2 2 S := S2 : δ X2 + X2 + X3 2 S3 : δ X2 + X1 2 S is in triangular form with respect to X2, X3, X1 (or δ X2, X3, X1) There are other definitions of triangular forms. K. Ghorbal (INRIA) 19 COMASIC M2 19 / 29 Ranking

Definition A ranking of X1,..., Xn is a total ordering on ΘX such that for all u, v ∈ ΘX and δ ∈ ∆, u ≤ δu, and u ≤ v implies δu ≤ δv.

• A ranking is said to be orderly if ord(u) ≤ ord(v) implies u ≤ v.

• A ranking is said to be unmixed if for every i, j, Xi ≤ Xj implies θXi ≤ Xj for every θ ∈ Θ.

K. Ghorbal (INRIA) 20 COMASIC M2 20 / 29 Analogies

Pure Algebra Differential Algebra Monomials Differential Monomials Polynomials Differential Polynomials Ordering Ranking Hilbert Basis Theorem Ritt-Raudenbush Basis Theorem Characteristic Sets (Ritt-Kolchin) Gr¨obner Bases Coherent Sets (Rosenfeld) Regular Chains (Boulier et al.)

K. Ghorbal (INRIA) 21 COMASIC M2 21 / 29 Outline

1 Differential Algebra

2 Multi-Mode DAEs (Structural Analysis)

K. Ghorbal (INRIA) 21 COMASIC M2 21 / 29 A Simple Clutch

 0 ω1 = f1(ω1, τ1)(e1)  0  ω = f2(ω2, τ2)(e2)  2  when γ do ω1 − ω2 = 0 (e3) and τ1 + τ2 = 0 (e4)   when ¬γ do τ = 0 (e )  1 5  and τ2 = 0 (e6)

K. Ghorbal (INRIA) 22 COMASIC M2 22 / 29 Simulation with Dymola

model ClutchBasic parameter Real w01=1; parameter Real w02=1.5; parameter Real j1=1; parameter Real j2=2; parameter Real k1=0.01; parameter Real k2=0.0125; parameter Real t1=5; The following error was detected at time: 5.002 parameter Real t2=7; Real t(start=0, fixed=true); Error: Singular inconsistent scalar system Boolean g(start=false); for f1 = ((if g then w1-w2 else 0.0)) Real w1(start = w01, fixed=true); Real w2(start = w02, fixed=true); /(-(if g then 0.0 else 1.0)) = -0.502621/-0 Real f1; Integration terminated before reaching Real f2; equation "StopTime" at T = 5 der(t) = 1; g = (t >= t1) and (t <= t2); j1*der(w1) = -k1*w1 + f1; j2*der(w2) = -k2*w2 + f2; 0 = if g then w1-w2 else f1; f1 + f2 = 0; end ClutchBasic;

K. Ghorbal (INRIA) 23 COMASIC M2 23 / 29 Simulation with Mathematica

NDSolve[{ w1’[t] == -0.01 w1[t] + t1[t], 2 w2’[t] == -0.0125 w2[t] + t2[t], t1[t] + t2[t] == 0, s[t] (w1[t] - w2[t]) + (1 - s[t]) t1[t] == 0, w1[0] == 1.0, w2[0] == 1.5, s[0] == 0, WhenEvent[t == 5, {s[t] -> 1} ] }, {w1, w2, t1, t2,s}, {t, 0, 7}, DiscreteVariables -> s]

K. Ghorbal (INRIA) 24 COMASIC M2 24 / 29 Simulation with Mathematica

ω ω

t 2 4 6 8 10 12 14 2500 -200

2000 -400 ω1 ω1 -600 1500 ω2 ω2 -800 1000 -1000 500 -1200

t -1400 2 4 6 8 10 12 14

K. Ghorbal (INRIA) 25 COMASIC M2 25 / 29 Expected Simulation

ω

2.0

1.8

1.6 ω1

1.4 ω2

1.2

1.0 t 2 4 6 8 10 12 14

K. Ghorbal (INRIA) 26 COMASIC M2 26 / 29 Main Ideas

Structural Analysis • Enforcing a Causality Principle: A guard must be evaluated before its guarded equation • Extend the definition of the derivative operator for discrete event changes • Unlocking Overdetermined systems by a ”forward shift” • Call the classical structural index reduction algorithm for underdetermined systems

Resets Computation • Impulse Analysis • Standardization (limits computation)

K. Ghorbal (INRIA) 27 COMASIC M2 27 / 29 A Simple Clutch

 • ∂ ω1 = ω1 + ∂f1(ω1, τ1)(e1 )  • ∂  ω2 = ω2 + ∂f2(ω2, τ2)(e2 )  • • •  when γ do ω1 − ω2 = 0 (e3 ) and τ1 + τ2 = 0 (e4)   when ¬γ do τ = 0 (e )  1 5  and τ2 = 0 (e6)

K. Ghorbal (INRIA) 28 COMASIC M2 28 / 29 mode ¬γ : index 0 τ1 = 0; τ2 = 0; start 0 ω1 = a1ω1 + b1τ1; 0 ω2 = a2ω2 + b2τ2

when ¬γ do when γ do τ1 = 0; τ2 = 0; τ1 = NaN; τ2 = NaN; − − − b2ω1 +b1ω2 ω1 = ω1 ; ω1 = ; − b1+b2 ω2 = ω2 ω2 = ω1 done done

mode γ : index 1 τ1 = (a2ω2 − a1ω1)/(b1 + b2); τ2 = −τ1; 0 0 ω1 = a1ω1 + b1τ1; ω2 = a2ω2 + b2τ2; constraint ω1 − ω2 = 0

K. Ghorbal (INRIA) 29 COMASIC M2 29 / 29