static analysis and interactive theorem proving a match
play

Static Analysis and Interactive Theorem Proving - A Match Made in - PowerPoint PPT Presentation

Introduction Static Analysis by Example Interactive Theorem Proving in Coq Bliss? - Not Quite Yet... Static Analysis and Interactive Theorem Proving - A Match Made in Heaven ? Jael E. Kriener University of Kent, Canterbury November 18, 2011


  1. Introduction Static Analysis by Example Interactive Theorem Proving in Coq Bliss? - Not Quite Yet... Static Analysis and Interactive Theorem Proving - A Match Made in Heaven ? Jael E. Kriener University of Kent, Canterbury November 18, 2011

  2. Introduction Static Analysis by Example Interactive Theorem Proving in Coq Bliss? - Not Quite Yet... The Point of this ... • ... to express amazement and gratitude for logic(ians) in the old century • ... to express hopes and dreams for the new century

  3. Introduction Static Analysis by Example Interactive Theorem Proving in Coq Bliss? - Not Quite Yet... Overview Introduction Static Analysis by Example Interactive Theorem Proving in Coq Bliss? - Not Quite Yet...

  4. Introduction Static Analysis by Example Interactive Theorem Proving in Coq Bliss? - Not Quite Yet... Static Analysis Sometimes one wants to know that a program will behave in a certain way before running it.

  5. Introduction Static Analysis by Example Interactive Theorem Proving in Coq Bliss? - Not Quite Yet... Static Analysis A Static Analyser is a program, that • takes as input a program, and • returns information about its behaviour.

  6. Introduction Static Analysis by Example Interactive Theorem Proving in Coq Bliss? - Not Quite Yet... (Non-) Determinacy in Prolog Relational Prolog is relational (as opposed to functional). Predicates A Prolog program defines a sets of predicates in Horn clauses ( P ( � x ) ← B ). Modes Computationally these predicates can be used differently, depending on which arguments are given and which are expected back. Determinism The same predicate may behave deterministically in some modes and non-deterministically in others.

  7. Introduction Static Analysis by Example Interactive Theorem Proving in Coq Bliss? - Not Quite Yet... ... for example: Example (append) append( [], Y, Y). append( [A | X], Y, [A | Z]) :- append( X, Y, Z). demo

  8. Introduction Static Analysis by Example Interactive Theorem Proving in Coq Bliss? - Not Quite Yet... ... for example: Example (append) append( [], Y, Y). append( [A | X], Y, [A | Z]) :- append( X, Y, Z). deterministic in: x ∨ ( y ∧ z )

  9. Introduction Static Analysis by Example Interactive Theorem Proving in Coq Bliss? - Not Quite Yet... How does it work? 1.1. Define a formal syntax for your language: Program ::= ǫ | Predicate . Program Predicate ::= Head ← Goal ; Goal , ! , Goal ; Goal Head ::= p ( � x ) Goal ::= post( θ ) | Head | Goal , Goal where � x is a vector of distinct variables and θ is some constraint over some � y

  10. Introduction Static Analysis by Example Interactive Theorem Proving in Coq Bliss? - Not Quite Yet... How does it work? 1.2. Define a semantics over that syntax: For a given stratified program P , its semantics - µ P - is defined as a fixpoint of F P : F P :: Program → Env → Env F P � ǫ � µ = µ F P � P . Ps � µ = F P � Ps � ( µ [ p ( � y ) �→ ( F H � P � µ )( p ( � y ))]) where P = p ( � y ) ← B F H :: Predicate → Env → Env y ) �→ λ� y ( F G � G 1 � µ� Θ : � F H � p ( � y ) ← B � µ = µ [ p ( � Θ . ↓ ∃ � Ψ)] � if F G � G 2 � µ� Θ = Φ : � F G � G 3 � µ [Φ] Φ where � Ψ = F G � G 4 � µ� Θ otherwise B = G 1 ; G 2 , ! , G 3 ; G 4 and Goal → Env → Con ↓ seq → Con ↓ F G :: seq F G � G � µ [] = [] F G � post( φ ) � µ (Θ : � { φ } ∩ Θ : F G � post( φ ) � µ� Θ) = trim ( ↓ Θ) x ) � µ (Θ : � x ) � µ� F G � p ( � Θ) = ( ↓ ρ � x ( µ p ( � y ) ( ↓ ρ y ([Θ])))) ∩ Θ : F G � p ( � Θ y , � � x ,� where p ( � y ) ∈ dom ( µ ) x ) ∩ vars ( � y ) = ∅ and vars ( � F G � G 1 , G 2 � µ (Θ : � F G � G 2 � µ ( F G � G 1 � µ (Θ : � Θ) = Θ))

  11. Introduction Static Analysis by Example Interactive Theorem Proving in Coq Bliss? - Not Quite Yet... How does it work? 2. Define a map from your syntax to deterministic modes: The determinacy semantics - δ P - of a program P is the greatest fixpoint of D P � P � : D P Program → DEnv → DEnv :: D P � ǫ � δ = δ D P � P . Ps � δ = D P � Ps � ( δ [ p ( � y ) �→ ( D H � P � δ )( p ( � y ))]) where P = p ( � y ) ← B D H :: Predicate → DEnv → DEnv D H � p ( � y ) ← B � δ = δ [ p ( � y ) �→↓ ∀ � y ( D G � G 1 � δ ∩ ( S G � G 2 � → D G � G 3 � δ ) ∩ D G � G 4 � δ ∩ Θ 1 ∩ Θ 2 )] where Θ 1 = mux ( S G � G 1 � , S G � G 4 � ) Θ 2 = mux ( S G � G 1 � , S G � G 2 , G 3 � ) and p ( � y ) ← G 1 ; G 2 , ! , G 3 ; G 4 ∈ P and Goal → DEnv → Con ↓ D G :: D G � post( φ ) � δ = ↓ { true } D G � p ( � x ) � δ = ↓ ρ � x ∀ � y ( δ ( p ( � y ))) y , � y ) ∈ dom ( δ ) where p ( � D G � G 1 , G 2 � δ ( S G � G 2 � → D G � G 1 � δ ) ∩ ( S G � G 1 � → D G � G 2 � δ ) =

  12. Introduction Static Analysis by Example Interactive Theorem Proving in Coq Bliss? - Not Quite Yet... How does it work? 3. Implement that to get your analyser !

  13. Introduction Static Analysis by Example Interactive Theorem Proving in Coq Bliss? - Not Quite Yet... Let’s think about the dialectic here... Problem: Say you have a program P , and say you care very much that P behaves in a certain way. Solution: You use my analyser A . You will want some sort of guarantee that A is correct ...

  14. Introduction Static Analysis by Example Interactive Theorem Proving in Coq Bliss? - Not Quite Yet... Let’s think about the dialectic here... Q: “Why should I trust A to be correct?” A: “Because D is correct, and A implements D .”

  15. Introduction Static Analysis by Example Interactive Theorem Proving in Coq Bliss? - Not Quite Yet... Let’s think about the dialectic here... Q1: “How do I know D is correct?” Q2: “How do I know A implements D ?”

  16. Introduction Static Analysis by Example Interactive Theorem Proving in Coq Bliss? - Not Quite Yet... Let’s think about the dialectic here... Q1: “How do I know D is correct?” A1: “Because I proved Theorem 2:” Theorem ( D G is correct w.r.t. F G ) If Θ ⊆ D G � G � δ P then |F G � G � µ P [Θ] | ≤ 1 for stratified P. That’s not really an answer...

  17. Introduction Static Analysis by Example Interactive Theorem Proving in Coq Bliss? - Not Quite Yet... Let’s think about the dialectic here... Q2: “How do I know A implements D ?” A2: “???”

  18. Introduction Static Analysis by Example Interactive Theorem Proving in Coq Bliss? - Not Quite Yet... It would be great... ... if I could do my analysis, such that at this point, you have these two guarantees, and you don’t have to trust me on either one, and you don’t understand where they come from either.

  19. Introduction Static Analysis by Example Interactive Theorem Proving in Coq Bliss? - Not Quite Yet... This is what Coq can do for us: I can: • write (and maintain ) proofs, and • give them to you. You can believe it’s a proof without: • understanding it, or • trusting me on it.

  20. Introduction Static Analysis by Example Interactive Theorem Proving in Coq Bliss? - Not Quite Yet... Ideally Coq should do this, too: I can: • write these formal proofs over these semantics, and • get out an implementation of these semantics, • plus a guarantee that the implementation does the right thing. They are working on it ...

  21. Introduction Static Analysis by Example Interactive Theorem Proving in Coq Bliss? - Not Quite Yet... Awesome ! This is Curry-Howard come true! And it means, I can be “a logician, not a hacker” (RD) and still be programming!

  22. Introduction Static Analysis by Example Interactive Theorem Proving in Coq Bliss? - Not Quite Yet... Bliss? - Not Quite Yet... This is programming “Principia-style”... ... and the pain is still great!

  23. Introduction Static Analysis by Example Interactive Theorem Proving in Coq Bliss? - Not Quite Yet... Some of the pain: Dependent types are painful... !

  24. Introduction Static Analysis by Example Interactive Theorem Proving in Coq Bliss? - Not Quite Yet... Some of the pain: Coq’s strict termination requirement is painful... !

  25. Introduction Static Analysis by Example Interactive Theorem Proving in Coq Bliss? - Not Quite Yet... But we’re getting there, so Thank You!

Recommend


More recommend