Dependency Analysis for Hybrid Programs Yong Kiam Tan X B Y C A W D Z 1
Motivation Semantics of hybrid programs α : ( u , w ) ∈ � α � , e.g.: ⇒ w = u u � e � ( u , w ) ∈ � x := e � ⇐ x What relationships can we find between states u and w ? 2
Dependency Analysis Variable x depends on Y if changing the initial values u ( y ) , y ∈ Y changes the set of possible values for w ( x ) 3
Dependency Analysis Variable x depends on Y if changing the initial values u ( y ) , y ∈ Y changes the set of possible values for w ( x ) Ideally, we want to minimize Y , but consider: ? P ; x := y ∪ x := z Aim: syntactic, compositional analysis of α for a “small” Y 3
Definition For each set X , D α ( X ) is a set of variables that X might depend on: � FV ( e ) if x = y � D y := e ( X ) = { x } otherwise x ∈ X D α ; β ( X ) = D α ( D β ( X )) D α ∪ β ( X ) = D α ( X ) ∪ D β ( X ) 4
Definition (tests) Tests are slightly weird: D ? Q ( X ) = X ∪ FV ( Q ) Compare to its semantics: ( u , u ) ∈ � ? Q � ⇐ ⇒ u ∈ � Q � 5
Definition (tests) Tests are slightly weird: D ? Q ( X ) = X ∪ FV ( Q ) Compare to its semantics: ( u , u ) ∈ � ? Q � ⇐ ⇒ u ∈ � Q � What does x depend on? ? k = 1; x := y ∪ x := z 5
Definition (loops) Semantics of loops ( α ∗ ): α 0 ∪ α 1 ∪ α 2 ∪ · · · α n ≡ α ; ... ; α � �� � n times Loops can be unfolded: � D i D α ∗ ( X ) = α ( X ) i ∈ N D 0 α ( S ) = S D i +1 ( S ) = D α ( D i α ( S )) α 6
Definition (ODEs) x ′ = � ODEs in vector form ( � e ), first attempt: � X if X ∩ � x = ∅ D � e ( X ) = x ′ = � x ∪ � X ∪ � e FV ( e ) otherwise e ∈ � 7
Definition (ODEs) x ′ = � ODEs in vector form ( � e ), first attempt: � X if X ∩ � x = ∅ D � e ( X ) = x ′ = � x ∪ � X ∪ � e FV ( e ) otherwise e ∈ � Extension to handle evolution domain constraints: D � e & Q ( X ) = D � e ( X ) ∪ FV ( Q ) x ′ = � x ′ = � 7
Definition (ODEs) This badly over-approximates the dependencies, e.g.: x ′ = 1 , y ′ = 1 Has solution: x = x 0 + t , y = y 0 + t But analysis says x , y are interdependent 8
Definition (ODEs) Not easy to get right, consider: x ′ = 1 , y ′ = y 2 If y 0 = 0, x = x 0 + t , y = 0 is the solution If y 0 > 0, t < 1 y 0 , so x ∈ [ x 0 , x 0 + 1 y 0 ) 9
Global solutions x ′ = � Assume � e has a global solution for all time, then we can instead use: D � e ( X ) = T x ′ = � where T is the smallest set satisfying X ⊆ T and � x i ∈ T → FV ( � e i ) ∈ T , i.e. the transitive closure of all variables mentioned in X across the system. 10
Global solutions x ′ = � Assume � e has a global solution for all time, then we can instead use: D � e ( X ) = T x ′ = � where T is the smallest set satisfying X ⊆ T and � x i ∈ T → FV ( � e i ) ∈ T , i.e. the transitive closure of all variables mentioned in X across the system. When do global solutions exist? 10
Linearity x ′ = A � x , then e tA � If ODE is linear, i.e. � x 0 is a global solution. Simple to check if ODE is linear, e.g.: x ′ = v , v ′ = a & v ≥ 0 x depends on { x , v , a } and v depends on { v , a } 11
Linearity, revisited Consider the non-linear system: x ′ = 1 , y ′ = xy Solution: x = x 0 + t , y = y 0 e x 0 t + t 2 2 , but analysis says x depends on { x , y } 12
Linearity, revisited Consider the non-linear system: x ′ = 1 , y ′ = xy Solution: x = x 0 + t , y = y 0 e x 0 t + t 2 2 , but analysis says x depends on { x , y } x ∩ T C being linear. Relax requirement that whole ODE is linear, to just � 12
Linearity, revisited Consider the non-linear system: x ′ = 1 , y ′ = xy Solution: x = x 0 + t , y = y 0 e x 0 t + t 2 2 , but analysis says x depends on { x , y } x ∩ T C being linear. Relax requirement that whole ODE is linear, to just � This works even if there is no solution for all time: x ′ = x 2 , y ′ = xy 12
Correctness Proposition (Coincidence for terms and formulas) If u , v agree on FV ( e ) , then u � e � = v � e � , and if u , v agree on FV ( Q ) , then u ∈ � Q � ⇐ ⇒ v ∈ � Q � . 13
Correctness Proposition (Coincidence for terms and formulas) If u , v agree on FV ( e ) , then u � e � = v � e � , and if u , v agree on FV ( Q ) , then u ∈ � Q � ⇐ ⇒ v ∈ � Q � . Theorem (Restricted coincidence) If u , v agree on D α ( X ) and ( u , u ′ ) ∈ � α � , there exists ( v , v ′ ) ∈ � α � such that u ′ , v ′ agree on X. Proof. By induction on α . 13
Correctness Corollary If P → [ α ] Q, then there is a precondition R such that P → R, R → [ α ] Q, where FV ( R ) ⊆ D α ( FV ( Q )) . Proof. Let R ≡ ∃ � xP , then for u ∈ � R � there exists v ∈ � P � . For any ( u , u ′ ) ∈ � α � , previous theorem gives ( v , v ′ ) ∈ � α � , and u ′ , v ′ agree on FV ( Q ). By assumption, v ′ ∈ � Q � , so u ′ ∈ � Q � by the coincidence lemma. 14
Application: Invariants for free! Task: find possible invariants for: x ′ = − y , y ′ = x 15
Application: Invariants for free! Task: find possible invariants for: x ′ = − y , y ′ = x Parametric invariant candidate p over V = { x , y } : p = ax 2 + bxy + cy 2 + dx + ey + f Set Lie derivative p ′ = 0: p ′ = 2 axx ′ + b ( x ′ y + y ′ x ) + 2 cyy ′ + dx ′ + ey ′ = − 2 axy + b ( x 2 − y 2 ) + 2 cxy − dy + ex = 0 15
Application: Differential Invariant Generation Comparing coefficients: a = c , b = 0 , d = 0 , e = 0 Therefore, ax 2 + ay 2 + f = 0 is an invariant, for any constant a , f 16
Application: Differential Invariant Generation How did we choose p (or equivalently V )? Recall corollary: can always find P → [ α ] Q , FV ( P ) ⊆ D α ( FV ( Q )) Only search for invariants φ → [ α ] φ , where φ is closed under D α . 17
Application: Differential Invariant Generation Dependency also allows us to search in order, e.g.: 2 = ω d 1 , t ′ = 1 α ≡ x ′ 1 = d 1 , x ′ 2 = d 2 , d ′ 1 = − ω d 2 , d ′ D α ( d 1 ) = { ω, d 1 , d 2 } D α ( d 2 ) = { ω, d 1 , d 2 } D α ( x 1 ) = { ω, d 2 , d 1 , x 1 } D α ( x 2 ) = { ω, d 2 , d 1 , x 2 } D α ( t ) = { t } , D α ( ω ) = { ω } Search for invariants in sets: { t } , { d 1 , d 2 } , { d 1 , d 2 , x 1 , x 2 } . 18
Results ODE System Invariants Generated v ′ = aw , w ′ = − v f 0 + f 1 ( v 2 + aw 2 ) = 0 x ′ = v , v ′ = a , t ′ = 1 f 0 + f 1 ( − at + v ) = 0 x ′ = x , t ′ = 1 f 0 + t ≥ 0 , f 1 + x 2 ≥ 0 f 0 + f 1 ( d 2 1 + d 2 α (prev. slide) 2 ) = 0 , f 2 + f 3 ( d 2 − ω x 1 ) + f 4 ( d 1 + ω x 2 ) = 0 , f 5 + t ≥ 0 19
Results Parametric invariant for motion equation: f 0 + f 1 ( − at + v ) = 0 Set f 1 = 1 , f 0 = − v 0 : v = v 0 + a ∗ t 20
Results Parametric invariant for motion equation: f 0 + f 1 ( − at + v ) = 0 Set f 1 = 1 , f 0 = − v 0 : v = v 0 + a ∗ t Another invariant: f 0 + a 2 f 1 t 2 + 1 2 at ( − 2 f 2 + f 3 t − 4 f 1 v ) + v ( f 2 − f 3 t + f 1 v ) + f 3 x = 0 Set f 2 = f 1 = 0 , f 3 = 1 , f 0 = − x 0 : x = x 0 + vt − 1 2 at 2 Substituting previous equation: x = x 0 + v 0 t + 1 2 at 2 20
Conclusion X B Y C A W D Z 21
Conclusion Invariants Generated X f 0 + f 1 ( v 2 + aw 2 ) = 0 B f 0 + f 1 ( − at + v ) = 0 Y f 0 + t ≥ 0 , f 1 + x 2 ≥ 0 C f 0 + f 1 ( d 2 1 + d 2 2 ) = 0 , A f 2 + f 3 ( d 2 − ω x 1 ) + f 4 ( d 1 + ω x 2 ) = 0 , W f 5 + t ≥ 0 D Z 21
Conclusion Invariants Generated X f 0 + f 1 ( v 2 + aw 2 ) = 0 B f 0 + f 1 ( − at + v ) = 0 Y f 0 + t ≥ 0 , f 1 + x 2 ≥ 0 C f 0 + f 1 ( d 2 1 + d 2 2 ) = 0 , A f 2 + f 3 ( d 2 − ω x 1 ) + f 4 ( d 1 + ω x 2 ) = 0 , W f 5 + t ≥ 0 D Z Questions? 21
Recommend
More recommend