Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction...

32
Introduction Refactoring Refactoring Operations Conclusion Refactoring, Refinement, and Reasoning A Logical Characterization for Hybrid Systems Stefan Mitsch 1,2 Jan-David Quesel 1 Andr´ e Platzer 1 1 Computer Science Department, Carnegie Mellon University 2 Cooperative Information Systems, Johannes Kepler University May 14, 2014 Stefan Mitsch, Jan-David Quesel, Andr´ e Platzer CMU,JKU Refactoring, Refinement, and Reasoning 1 of 14

Transcript of Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction...

Page 1: Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction Refactoring Refactoring Operations Conclusion Refactoring, Re nement, and Reasoning A Logical

Introduction Refactoring Refactoring Operations Conclusion

Refactoring, Refinement, and ReasoningA Logical Characterization for Hybrid Systems

Stefan Mitsch1,2 Jan-David Quesel1 Andre Platzer1

1Computer Science Department, Carnegie Mellon University

2Cooperative Information Systems, Johannes Kepler University

May 14, 2014

Stefan Mitsch, Jan-David Quesel, Andre Platzer CMU,JKU

Refactoring, Refinement, and Reasoning 1 of 14

Page 2: Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction Refactoring Refactoring Operations Conclusion Refactoring, Re nement, and Reasoning A Logical

Introduction Refactoring Refactoring Operations Conclusion

Hybrid Systems

Hybrid Systems are Challenging

I Computation + Physical behavior

I Sensor uncertainty

I Disturbance

I Computation delay

I Many components

0 1 2 3 4 5 60.0

0.5

1.0

1.5

2.0

2.5

3.0

3.5

2 4 6 8 10t

-0.8

-0.6

-0.4

-0.2

0.2

a

2 4 6 8 10t

0.2

0.4

0.6

0.8

1.0

v

2 4 6 8 10t

2

4

6

8

p

px

py

Stefan Mitsch, Jan-David Quesel, Andre Platzer CMU,JKU

Refactoring, Refinement, and Reasoning 2 of 14

Page 3: Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction Refactoring Refactoring Operations Conclusion Refactoring, Re nement, and Reasoning A Logical

Introduction Refactoring Refactoring Operations Conclusion

Hybrid Systems

Hybrid Systems are Challenging

I Computation + Physical behavior

I Sensor uncertainty

I Disturbance

I Computation delay

I Many components

0 1 2 3 4 5 60.0

0.5

1.0

1.5

2.0

2.5

3.0

3.5

2 4 6 8 10t

-0.8

-0.6

-0.4

-0.2

0.2

a

2 4 6 8 10t

0.2

0.4

0.6

0.8

1.0

v

2 4 6 8 10t

2

4

6

8

p

px

py

Challenge

Hybrid systems are almost impossible to get rightwithout proper analysis Formal verification

Stefan Mitsch, Jan-David Quesel, Andre Platzer CMU,JKU

Refactoring, Refinement, and Reasoning 2 of 14

Page 4: Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction Refactoring Refactoring Operations Conclusion Refactoring, Re nement, and Reasoning A Logical

Introduction Refactoring Refactoring Operations Conclusion

Formal Verification

Hybrid System Theorem Proving

I Symbolic execution of model

I Model structure reflected in proof

I Correctness properties

Safety Always stay safeLiveness Ultimately complete

a task

Our Tools

KeYmaera Hybrid systems theorem prover

Sϕnx Hybrid systems modeling

proof

α

β

modelα β

proof

α

β

γ

β

modelα βγ

Stefan Mitsch, Jan-David Quesel, Andre Platzer CMU,JKU

Refactoring, Refinement, and Reasoning 3 of 14

Page 5: Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction Refactoring Refactoring Operations Conclusion Refactoring, Re nement, and Reasoning A Logical

Introduction Refactoring Refactoring Operations Conclusion

Iterative Development

Hybrid Systems Theorem Proving is Challenging

I Differential equations

I Complicated arithmetic

Manage complexity

I Start simple — verify

I Improve — verify — repeat

proof

α

β

modelα β

proof

α

β

γ

β

modelα βγ

Stefan Mitsch, Jan-David Quesel, Andre Platzer CMU,JKU

Refactoring, Refinement, and Reasoning 4 of 14

Page 6: Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction Refactoring Refactoring Operations Conclusion Refactoring, Re nement, and Reasoning A Logical

Introduction Refactoring Refactoring Operations Conclusion

Iterative Development

Hybrid Systems Theorem Proving is Challenging

I Differential equations

I Complicated arithmetic

Manage complexity

I Start simple — verify

I Improve — verify — repeat

proof

α

β

modelα β

proof

α

β

γ

β

modelα βγ

Stefan Mitsch, Jan-David Quesel, Andre Platzer CMU,JKU

Refactoring, Refinement, and Reasoning 4 of 14

Page 7: Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction Refactoring Refactoring Operations Conclusion Refactoring, Re nement, and Reasoning A Logical

Introduction Refactoring Refactoring Operations Conclusion

Iterative Development

Hybrid Systems Theorem Proving is Challenging

I Differential equations

I Complicated arithmetic

Manage complexity

I Start simple — verify

I Improve — verify — repeat

proof

α

β

modelα β

proof

α

β

γ

β

modelα βγ

Stefan Mitsch, Jan-David Quesel, Andre Platzer CMU,JKU

Refactoring, Refinement, and Reasoning 4 of 14

Page 8: Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction Refactoring Refactoring Operations Conclusion Refactoring, Re nement, and Reasoning A Logical

Introduction Refactoring Refactoring Operations Conclusion

Iterative Development

Hybrid Systems Theorem Proving is Challenging

I Differential equations

I Complicated arithmetic

Manage complexity

I Start simple — verify

I Improve — verify — repeat

proof

α

β

modelα β

proof

α

β

γ

β

modelα βγ

Challenge

Proof-aware refactoringinstead of reverification on every change

(retain soundness without redoing the proof)

Stefan Mitsch, Jan-David Quesel, Andre Platzer CMU,JKU

Refactoring, Refinement, and Reasoning 4 of 14

Page 9: Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction Refactoring Refactoring Operations Conclusion Refactoring, Re nement, and Reasoning A Logical

Introduction Refactoring Refactoring Operations Conclusion

Proof-aware Refactoring

Refactoring Operation

I Transforms a source model into a refactored model

I Syntactic rewriting rule

For example

conditions

α;β (α ∪ γ);β

source

α βrefactoredα βγ

Stefan Mitsch, Jan-David Quesel, Andre Platzer CMU,JKU

Refactoring, Refinement, and Reasoning 5 of 14

Page 10: Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction Refactoring Refactoring Operations Conclusion Refactoring, Re nement, and Reasoning A Logical

Introduction Refactoring Refactoring Operations Conclusion

How to Retain Soundness

Structural Refactoring

Always retains soundness

proof

α

β

γ

β

modelα

γ

β

β

≡proof

α

β

γ

β

modelα βγ

Behavioral Refactoring

Proof patch retains soundness

proof

α

β

modelα β

patchproof

α

β

γ

β

modelα βγ

Stefan Mitsch, Jan-David Quesel, Andre Platzer CMU,JKU

Refactoring, Refinement, and Reasoning 6 of 14

Page 11: Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction Refactoring Refactoring Operations Conclusion Refactoring, Re nement, and Reasoning A Logical

Introduction Refactoring Refactoring Operations Conclusion

How to Retain Soundness

Structural Refactoring

Always retains soundness

proof

α

β

γ

β

modelα

γ

β

β

≡proof

α

β

γ

β

modelα βγ

Behavioral Refactoring

Proof patch retains soundness

proof

α

β

modelα β

patchproof

α

β

γ

β

modelα βγ

Stefan Mitsch, Jan-David Quesel, Andre Platzer CMU,JKU

Refactoring, Refinement, and Reasoning 6 of 14

Page 12: Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction Refactoring Refactoring Operations Conclusion Refactoring, Re nement, and Reasoning A Logical

Introduction Refactoring Refactoring Operations Conclusion

Patching Necessity by Correctness Property

Add Behavior

Remove Behavior

liveness

safety

modelα β

reuse

patch

vV

liveness

safety

modelα βγ

liveness

safety

modelα β

patch

reuse

wV

liveness

safety

modelα βγ

Stefan Mitsch, Jan-David Quesel, Andre Platzer CMU,JKU

Refactoring, Refinement, and Reasoning 7 of 14

Page 13: Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction Refactoring Refactoring Operations Conclusion Refactoring, Re nement, and Reasoning A Logical

Introduction Refactoring Refactoring Operations Conclusion

Patching Necessity by Correctness Property

Add Behavior Remove Behavior

liveness

safety

modelα β

reuse

patch

vV

liveness

safety

modelα βγ

liveness

safety

modelα β

patch

reuse

wV

liveness

safety

modelα βγ

Stefan Mitsch, Jan-David Quesel, Andre Platzer CMU,JKU

Refactoring, Refinement, and Reasoning 7 of 14

Page 14: Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction Refactoring Refactoring Operations Conclusion Refactoring, Re nement, and Reasoning A Logical

Introduction Refactoring Refactoring Operations Conclusion

Patching Necessity by Correctness Property

Add Behavior Remove Behavior

liveness

safety

modelα β

reuse

patch

vV

liveness

safety

modelα βγ

liveness

safety

modelα β

patch

reuse

wV

liveness

safety

modelα βγ

Projective Relational Refinement

α vV γ iff ρ(α)|V ⊆ ρ(γ)|Vρ(α) reachability relation of α

α, γ hybrid systems models

V ⊆ Σ relevant set of variables

|V projection of relations or states to thevariables in V

Stefan Mitsch, Jan-David Quesel, Andre Platzer CMU,JKU

Refactoring, Refinement, and Reasoning 7 of 14

Page 15: Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction Refactoring Refactoring Operations Conclusion Refactoring, Re nement, and Reasoning A Logical

Introduction Refactoring Refactoring Operations Conclusion

Sound Refactoring Catalog

Structural Refactorings

I Extract Common Program

I Extract ContinuousDynamics

I Drop Implied EvolutionDomain Constraint

Behavioral Refactorings

I Introduce Control Path

I Introduce ComplementaryContinuous Dynamics

I Event- to Time-TriggeredArchitecture

Stefan Mitsch, Jan-David Quesel, Andre Platzer CMU,JKU

Refactoring, Refinement, and Reasoning 8 of 14

Page 16: Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction Refactoring Refactoring Operations Conclusion Refactoring, Re nement, and Reasoning A Logical

Introduction Refactoring Refactoring Operations Conclusion

Extract Common Program

Motivation Reduce model duplication

Mechanics (R1) (α; γ) ∪ (β; γ) (α ∪ β); γ

α

β

γ

γ

extract (R1)α

β

γ

Variation Inline program (R2) (α ∪ β); γ (α; γ) ∪ (β; γ)

Proof patch

Safety None

Liveness None

Stefan Mitsch, Jan-David Quesel, Andre Platzer CMU,JKU

Refactoring, Refinement, and Reasoning 9 of 14

Page 17: Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction Refactoring Refactoring Operations Conclusion Refactoring, Re nement, and Reasoning A Logical

Introduction Refactoring Refactoring Operations Conclusion

Introduce Control Path

Motivation Add control decisions

Mechanics (R3) α;β (α ∪ γ);β

α β introduce (R3)αγ

β

Variation Remove Control Path (R4) (α ∪ γ);β α;β

Proof patch

Safety Prove safety of the added branch

Liveness None

Stefan Mitsch, Jan-David Quesel, Andre Platzer CMU,JKU

Refactoring, Refinement, and Reasoning 10 of 14

Page 18: Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction Refactoring Refactoring Operations Conclusion Refactoring, Re nement, and Reasoning A Logical

Event

Clock

Introduction Refactoring Refactoring Operations Conclusion

Event- to Time-Triggered Architecture

Motivation Derive a time-triggered controller

Mechanics (R5) α; (x ′ = θ&F ∧ ψ) (?[α; c := 0; η]ψ;α); c := 0; η

α γ ≡ (x ′1 = θ1, . . . , x′n = θn & F ∧ ψ)

β ∗

event- to time-triggered (R5)

?([α; c := 0; η]ψ

?([β; c := 0; η]ψ

c := 0η ≡ (x ′1 = θ1, . . . , x

′n = θn,

c ′ = 1 & F ∧ c ≤ ε)

Proof Patch

Safety Composes several refactorings + prove safety ofderived tests

Stefan Mitsch, Jan-David Quesel, Andre Platzer CMU,JKU

Refactoring, Refinement, and Reasoning 11 of 14

Page 19: Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction Refactoring Refactoring Operations Conclusion Refactoring, Re nement, and Reasoning A Logical

Introduction Refactoring Refactoring Operations Conclusion

Summary

Benefits of Proof-aware Refactorings

I easier to evolve correct systems

I easier to get simple systems correct

I still want to handle complex systems, but not pay the price ofreverification

I co-evolve model and proof

Stefan Mitsch, Jan-David Quesel, Andre Platzer CMU,JKU

Refactoring, Refinement, and Reasoning 12 of 14

Page 20: Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction Refactoring Refactoring Operations Conclusion Refactoring, Re nement, and Reasoning A Logical

Introduction Refactoring Refactoring Operations Conclusion

Future Work

Refactoring Catalog

I Pull and merge tests

I Weaken/strengthen test

I Switch sequence

I Introduce computation delay

I Introduce uncertainty

I Introduce disturbance

I Change norm (2/∞ norm)

I . . .

Theory

I Liveness proof patches

I Distance measurement

I Refinement based on games

Implementation

I Sϕnx and KeYmaera

I Background proving

Stefan Mitsch, Jan-David Quesel, Andre Platzer CMU,JKU

Refactoring, Refinement, and Reasoning 13 of 14

Page 21: Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction Refactoring Refactoring Operations Conclusion Refactoring, Re nement, and Reasoning A Logical

Introduction Refactoring Refactoring Operations Conclusion

Thank you!

Stefan [email protected]

http://www.cs.cmu.edu/∼smitsch

Stefan Mitsch, Jan-David Quesel, Andre Platzer CMU,JKU

Refactoring, Refinement, and Reasoning 14 of 14

Page 22: Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction Refactoring Refactoring Operations Conclusion Refactoring, Re nement, and Reasoning A Logical

Proofs Examples

Extract Continuous Dynamics

(R6)∀v ∈ V (θ) ∪

⋃i∈I V (ϑi ). v 6∈ BV (D(θ)) ∪

⋃i∈I BV (D(ϑi ))⋃

i∈I(αi ; (v ′ = θ,w ′ = ϑi )

)

(⋃i∈I (αi ; x := ϑi )

); (v ′ = θ,w ′ = x)

)(R7)

(⋃i∈I (αi ; x := ϑi )

); (v ′ = θ,w ′ = x)

)

⋃i∈I(αi ; (v

′ = θ,w ′ = ϑi ))

α v ′ = θ,w ′ = ϑ1

β v ′ = θ,w ′ = ϑ2

extract (R6)

inline (R7)

α x := ϑ1

β x := ϑ2

v ′ = θ,w ′ = x

Proof obligations

None, because the original program and the refactored program areobservationally equivalent.

Stefan Mitsch, Jan-David Quesel, Andre Platzer CMU,JKU

Refactoring, Refinement, and Reasoning 1 of 6

Page 23: Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction Refactoring Refactoring Operations Conclusion Refactoring, Re nement, and Reasoning A Logical

Proofs Examples

Drop Implied Evolution Domain Constraint

(R8)F → H F → [x ′ = θ&G ]H

?F ; x ′ = θ&G ∧ H ?F ; x ′ = θ&G(R9)

?F ; x ′ = θ&G ?F ; x ′ = θ&G ∧ H

(R10)?F ; x ′ = θ&G ∧ H

?F ; x ′ = θ&G(R11)

F → H F → [x ′ = θ&G ]H

?F ; x ′ = θ&G ?F ; x ′ = θ&G ∧ H

?Fx ′ = θ

& G ∧ H

|= F → H θ preserves H

drop (R8)/(R10)introduce (R9)/(R11) ?F

x ′ = θ& G

Proof obligations

Liveness None, because projective partial refinement, i. e.,(?F ; x ′ = θ&G ∧ H

)vV

F

(?F ; x ′ = θ&G

)holds.

Safety Show that H is a differential invariant

Stefan Mitsch, Jan-David Quesel, Andre Platzer CMU,JKU

Refactoring, Refinement, and Reasoning 2 of 6

Page 24: Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction Refactoring Refactoring Operations Conclusion Refactoring, Re nement, and Reasoning A Logical

Proofs Examples

Introduce Complementary Continuous Dynamics

(R12) α; x ′ = θ&F α; (x ′ = θ&F ∪ x ′ = θ&∼F )

α x ′ = θ & F compl. (R12)α x ′ = θ & F

x ′ = θ & ∼F

Proof obligations

Liveness None

Safety Show that the controller with subsequentcomplementary dynamics only reaches states that arealready reachable with the original dynamics, i. e.,show

(〈α; x ′ = θ&∼F 〉ΥV

)→(〈α; x ′ = θ&F 〉ΥV

)

Stefan Mitsch, Jan-David Quesel, Andre Platzer CMU,JKU

Refactoring, Refinement, and Reasoning 3 of 6

Page 25: Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction Refactoring Refactoring Operations Conclusion Refactoring, Re nement, and Reasoning A Logical

Proofs Examples

Example: Introduce Moderate Braking

ctrl

?Safe a := Amax

?v = 0 a := 0a :=−Bmax

t := 0x ′ = v , v ′ = a, t ′ = 1

& v ≥ 0 ∧ t ≤ ε

introduce control path

ctrl . . .

?x + v2

Bmax≤ S a :=−Bmax

2

t := 0x ′ = v , v ′ = a, t ′ = 1

& v ≥ 0 ∧ t ≤ ε

Stefan Mitsch, Jan-David Quesel, Andre Platzer CMU,JKU

Refactoring, Refinement, and Reasoning 4 of 6

Page 26: Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction Refactoring Refactoring Operations Conclusion Refactoring, Re nement, and Reasoning A Logical

Proofs Examples

Introduce Moderate Braking: Auxiliary Safety Proof

∗axφ, [A ∪ C ∪ B][P]φ ` [A ∪ C ∪ B][P]φ

prove new branchφ ` [Br ][P]φ

Wlφ, [A ∪ C ∪ B][P]φ ` [Br ][P]φ∧r φ, [A ∪ C ∪ B][P]φ ` [A ∪ C ∪ B][P]φ ∧ [Br ][P]φ[;] φ, [(A ∪ C ∪ B); P]φ ` [A ∪ C ∪ B][P]φ ∧ [Br ][P]φ∀l,∀l φ, ∀x∀v (φ→ [(A ∪ C ∪ B); P]φ) ` [A ∪ C ∪ B][P]φ ∧ [Br ][P]φ[;],[∪] φ, ∀x∀v (φ→ [(A ∪ C ∪ B); P]φ) ` [(A ∪ C ∪ B ∪ Br ); P]φexpand φ, ∀x∀v (φ→ [car]φ) ` [car]φ

. . .∗

axφ, ∀x∀v(φ→ [car]φ) ` φ ∧ ∀x∀v(φ→ [car]φ)[] gen φ,∀x∀v(φ→ [car]φ) ` [car](φ ∧ ∀x∀v(φ→ [car]φ))∧l φ ∧ ∀x∀v(φ→ [car]φ) ` [car](φ ∧ ∀x∀v(φ→ [car]φ))

expand I(φ) ` [car]I(φ)

∗axI(φ) ` I(φ) . . .

∗φ ` ψ

∧l,Wlφ ∧ ∀x∀v (φ→ [car]φ) ` ψexpand I(φ) ` ψ

[∗] I(φ) ` [car∗]ψ

Base case

Stefan Mitsch, Jan-David Quesel, Andre Platzer CMU,JKU

Refactoring, Refinement, and Reasoning 5 of 6

Page 27: Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction Refactoring Refactoring Operations Conclusion Refactoring, Re nement, and Reasoning A Logical

Proofs Examples

Introduce Moderate Braking: Auxiliary Safety Proof

∗axφ, [A ∪ C ∪ B][P]φ ` [A ∪ C ∪ B][P]φ

prove new branchφ ` [Br ][P]φ

Wlφ, [A ∪ C ∪ B][P]φ ` [Br ][P]φ∧r φ, [A ∪ C ∪ B][P]φ ` [A ∪ C ∪ B][P]φ ∧ [Br ][P]φ[;] φ, [(A ∪ C ∪ B); P]φ ` [A ∪ C ∪ B][P]φ ∧ [Br ][P]φ∀l,∀l φ, ∀x∀v (φ→ [(A ∪ C ∪ B); P]φ) ` [A ∪ C ∪ B][P]φ ∧ [Br ][P]φ[;],[∪] φ, ∀x∀v (φ→ [(A ∪ C ∪ B); P]φ) ` [(A ∪ C ∪ B ∪ Br ); P]φexpand φ, ∀x∀v (φ→ [car]φ) ` [car]φ

. . .∗

axφ, ∀x∀v(φ→ [car]φ) ` φ ∧ ∀x∀v(φ→ [car]φ)[] gen φ,∀x∀v(φ→ [car]φ) ` [car](φ ∧ ∀x∀v(φ→ [car]φ))∧l φ ∧ ∀x∀v(φ→ [car]φ) ` [car](φ ∧ ∀x∀v(φ→ [car]φ))

expand I(φ) ` [car]I(φ)

∗axI(φ) ` I(φ) . . .

∗φ ` ψ

∧l,Wlφ ∧ ∀x∀v (φ→ [car]φ) ` ψexpand I(φ) ` ψ

[∗] I(φ) ` [car∗]ψ

Hypothesisstrong enough

Stefan Mitsch, Jan-David Quesel, Andre Platzer CMU,JKU

Refactoring, Refinement, and Reasoning 5 of 6

Page 28: Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction Refactoring Refactoring Operations Conclusion Refactoring, Re nement, and Reasoning A Logical

Proofs Examples

Introduce Moderate Braking: Auxiliary Safety Proof

∗axφ, [A ∪ C ∪ B][P]φ ` [A ∪ C ∪ B][P]φ

prove new branchφ ` [Br ][P]φ

Wlφ, [A ∪ C ∪ B][P]φ ` [Br ][P]φ∧r φ, [A ∪ C ∪ B][P]φ ` [A ∪ C ∪ B][P]φ ∧ [Br ][P]φ[;] φ, [(A ∪ C ∪ B); P]φ ` [A ∪ C ∪ B][P]φ ∧ [Br ][P]φ∀l,∀l φ, ∀x∀v (φ→ [(A ∪ C ∪ B); P]φ) ` [A ∪ C ∪ B][P]φ ∧ [Br ][P]φ[;],[∪] φ, ∀x∀v (φ→ [(A ∪ C ∪ B); P]φ) ` [(A ∪ C ∪ B ∪ Br ); P]φexpand φ, ∀x∀v (φ→ [car]φ) ` [car]φ

. . .∗

axφ, ∀x∀v(φ→ [car]φ) ` φ ∧ ∀x∀v(φ→ [car]φ)[] gen φ,∀x∀v(φ→ [car]φ) ` [car](φ ∧ ∀x∀v(φ→ [car]φ))∧l φ ∧ ∀x∀v(φ→ [car]φ) ` [car](φ ∧ ∀x∀v(φ→ [car]φ))

expand I(φ) ` [car]I(φ)

∗axI(φ) ` I(φ) . . .

∗φ ` ψ

∧l,Wlφ ∧ ∀x∀v (φ→ [car]φ) ` ψexpand I(φ) ` ψ

[∗] I(φ) ` [car∗]ψ

Induction step

Stefan Mitsch, Jan-David Quesel, Andre Platzer CMU,JKU

Refactoring, Refinement, and Reasoning 5 of 6

Page 29: Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction Refactoring Refactoring Operations Conclusion Refactoring, Re nement, and Reasoning A Logical

Proofs Examples

Introduce Moderate Braking: Auxiliary Safety Proof

∗axφ, [A ∪ C ∪ B][P]φ ` [A ∪ C ∪ B][P]φ

prove new branchφ ` [Br ][P]φ

Wlφ, [A ∪ C ∪ B][P]φ ` [Br ][P]φ∧r φ, [A ∪ C ∪ B][P]φ ` [A ∪ C ∪ B][P]φ ∧ [Br ][P]φ[;] φ, [(A ∪ C ∪ B); P]φ ` [A ∪ C ∪ B][P]φ ∧ [Br ][P]φ∀l,∀l φ, ∀x∀v (φ→ [(A ∪ C ∪ B); P]φ) ` [A ∪ C ∪ B][P]φ ∧ [Br ][P]φ[;],[∪] φ, ∀x∀v (φ→ [(A ∪ C ∪ B); P]φ) ` [(A ∪ C ∪ B ∪ Br ); P]φexpand φ, ∀x∀v (φ→ [car]φ) ` [car]φ

. . .∗

axφ, ∀x∀v(φ→ [car]φ) ` φ ∧ ∀x∀v(φ→ [car]φ)[] gen φ,∀x∀v(φ→ [car]φ) ` [car](φ ∧ ∀x∀v(φ→ [car]φ))∧l φ ∧ ∀x∀v(φ→ [car]φ) ` [car](φ ∧ ∀x∀v(φ→ [car]φ))

expand I(φ) ` [car]I(φ)

∗axI(φ) ` I(φ) . . .

∗φ ` ψ

∧l,Wlφ ∧ ∀x∀v (φ→ [car]φ) ` ψexpand I(φ) ` ψ

[∗] I(φ) ` [car∗]ψ

GeneralizeI(φ) ` [car ]I(φ)

toI(φ) ` [car ]φ

Stefan Mitsch, Jan-David Quesel, Andre Platzer CMU,JKU

Refactoring, Refinement, and Reasoning 5 of 6

Page 30: Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction Refactoring Refactoring Operations Conclusion Refactoring, Re nement, and Reasoning A Logical

Proofs Examples

Introduce Moderate Braking: Auxiliary Safety Proof

∗axφ, [A ∪ C ∪ B][P]φ ` [A ∪ C ∪ B][P]φ

prove new branchφ ` [Br ][P]φ

Wlφ, [A ∪ C ∪ B][P]φ ` [Br ][P]φ∧r φ, [A ∪ C ∪ B][P]φ ` [A ∪ C ∪ B][P]φ ∧ [Br ][P]φ[;] φ, [(A ∪ C ∪ B); P]φ ` [A ∪ C ∪ B][P]φ ∧ [Br ][P]φ∀l,∀l φ, ∀x∀v (φ→ [(A ∪ C ∪ B); P]φ) ` [A ∪ C ∪ B][P]φ ∧ [Br ][P]φ[;],[∪] φ, ∀x∀v (φ→ [(A ∪ C ∪ B); P]φ) ` [(A ∪ C ∪ B ∪ Br ); P]φexpand φ, ∀x∀v (φ→ [car]φ) ` [car]φ

. . .∗

axφ, ∀x∀v(φ→ [car]φ) ` φ ∧ ∀x∀v(φ→ [car]φ)[] gen φ, ∀x∀v(φ→ [car]φ) ` [car](φ ∧ ∀x∀v(φ→ [car]φ))∧l φ ∧ ∀x∀v(φ→ [car]φ) ` [car](φ ∧ ∀x∀v(φ→ [car]φ))

expand I(φ) ` [car]I(φ)

∗axI(φ) ` I(φ) . . .

∗φ ` ψ

∧l,Wlφ ∧ ∀x∀v (φ→ [car]φ) ` ψexpand I(φ) ` ψ

[∗] I(φ) ` [car∗]ψ

Standard rulesfor programs ∪ and ;

Stefan Mitsch, Jan-David Quesel, Andre Platzer CMU,JKU

Refactoring, Refinement, and Reasoning 6 of 6

Page 31: Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction Refactoring Refactoring Operations Conclusion Refactoring, Re nement, and Reasoning A Logical

Proofs Examples

Introduce Moderate Braking: Auxiliary Safety Proof

∗axφ, [A ∪ C ∪ B][P]φ ` [A ∪ C ∪ B][P]φ

prove new branchφ ` [Br ][P]φ

Wlφ, [A ∪ C ∪ B][P]φ ` [Br ][P]φ∧r φ, [A ∪ C ∪ B][P]φ ` [A ∪ C ∪ B][P]φ ∧ [Br ][P]φ[;] φ, [(A ∪ C ∪ B); P]φ ` [A ∪ C ∪ B][P]φ ∧ [Br ][P]φ∀l,∀l φ, ∀x∀v (φ→ [(A ∪ C ∪ B); P]φ) ` [A ∪ C ∪ B][P]φ ∧ [Br ][P]φ[;],[∪] φ, ∀x∀v (φ→ [(A ∪ C ∪ B); P]φ) ` [(A ∪ C ∪ B ∪ Br ); P]φexpand φ, ∀x∀v (φ→ [car]φ) ` [car]φ

. . .∗

axφ, ∀x∀v(φ→ [car]φ) ` φ ∧ ∀x∀v(φ→ [car]φ)[] gen φ, ∀x∀v(φ→ [car]φ) ` [car](φ ∧ ∀x∀v(φ→ [car]φ))∧l φ ∧ ∀x∀v(φ→ [car]φ) ` [car](φ ∧ ∀x∀v(φ→ [car]φ))

expand I(φ) ` [car]I(φ)

∗axI(φ) ` I(φ) . . .

∗φ ` ψ

∧l,Wlφ ∧ ∀x∀v (φ→ [car]φ) ` ψexpand I(φ) ` ψ

[∗] I(φ) ` [car∗]ψ

Exploit φ→ [car]φalready proven

Stefan Mitsch, Jan-David Quesel, Andre Platzer CMU,JKU

Refactoring, Refinement, and Reasoning 6 of 6

Page 32: Refactoring, Re nement, and Reasoningaplatzer/pub/refactoring-slides.pdf · Introduction Refactoring Refactoring Operations Conclusion Refactoring, Re nement, and Reasoning A Logical

Proofs Examples

Introduce Moderate Braking: Auxiliary Safety Proof

∗axφ, [A ∪ C ∪ B][P]φ ` [A ∪ C ∪ B][P]φ

prove new branchφ ` [Br ][P]φ

Wlφ, [A ∪ C ∪ B][P]φ ` [Br ][P]φ∧r φ, [A ∪ C ∪ B][P]φ ` [A ∪ C ∪ B][P]φ ∧ [Br ][P]φ[;] φ, [(A ∪ C ∪ B); P]φ ` [A ∪ C ∪ B][P]φ ∧ [Br ][P]φ∀l,∀l φ, ∀x∀v (φ→ [(A ∪ C ∪ B); P]φ) ` [A ∪ C ∪ B][P]φ ∧ [Br ][P]φ[;],[∪] φ, ∀x∀v (φ→ [(A ∪ C ∪ B); P]φ) ` [(A ∪ C ∪ B ∪ Br ); P]φexpand φ, ∀x∀v (φ→ [car]φ) ` [car]φ

. . .∗

axφ, ∀x∀v(φ→ [car]φ) ` φ ∧ ∀x∀v(φ→ [car]φ)[] gen φ, ∀x∀v(φ→ [car]φ) ` [car](φ ∧ ∀x∀v(φ→ [car]φ))∧l φ ∧ ∀x∀v(φ→ [car]φ) ` [car](φ ∧ ∀x∀v(φ→ [car]φ))

expand I(φ) ` [car]I(φ)

∗axI(φ) ` I(φ) . . .

∗φ ` ψ

∧l,Wlφ ∧ ∀x∀v (φ→ [car]φ) ` ψexpand I(φ) ` ψ

[∗] I(φ) ` [car∗]ψ

Prove new branch

Stefan Mitsch, Jan-David Quesel, Andre Platzer CMU,JKU

Refactoring, Refinement, and Reasoning 6 of 6