Programs are Proofs
Each time you write a program, you are writing a proof!
Proof of what?
Each program proves its type
For each Int
there exists an Int
:
idInt :: Int -> Int
idInt x = x
Each program proves its type
For each a
there exists an a
:
id :: a -> a
id x = x
Each program proves its type
But, for each Int
there exists an a
:
idErr :: Int -> a
idErr x = error "Define me?"
Programs (as proofs) should be well-formed ...
... that is terminating and total.
Each program proves its type
Known as Curry–Howard correspondence
independently developed by Curry (1934) and Howard (1969).
Known as Propositions as Types & Proofs as Programs
by Phil Wadler (2014).
Propositions as Refinement Types
Q: Can you read the following type as a theorem?
f :: x:Int -> y:Int -> {v:() | x + y = y + x}
Q: How would you prove this theorem?
e.g. Parallelized Function Equivalent to Original
A. Farmer et al: Reasoning with the HERMIT
Propositions as Refinement Types
Refined Types are theorems
and
Haskell Functions are proofs.
Make the theorems pretty!
ProofCombinators
comes with Liquid Haskell and allows for pretty proofs!
Make the theorems even prettier!
ProofCombinators
comes with Liquid Haskell and allows for pretty proofs!
Use more SMT knowledge
ProofCombinators
comes with Liquid Haskell and allows for pretty proofs!
Theorems about Haskell functions
Express & Prove Theorems in Haskell ...
... for Haskell functions.
Define (terminating) fib
in the logic!
Reflect fib
in the logic.
(Need to prove fib
terminates...)
Structuring Proofs
Using combinators from ProofCombinators
!
Reusing Proofs: The "because" operator
Using combinators from ProofCombinators
!
Paper & Pencil style Proofs
fib
is increasing
Another "Paper & Pencil" Proof
Exercise: Lets fix the proof that fib
is monotonic?
Exercise: Can you replace trivial
to fix the monotonicity proof?
Generalizing monotonicity proof
Exercise: Generalize the implementation of fMono
proof below to any increasing function f
.
Reusing Theorems by Application
fib
is monotonic!
Recap
Refinements: | Types + Predicates |
Specification: | Refined Input/Output Types |
Verification: | SMT-based Predicate Subtyping |
Measures: | Specify Properties of Data |
Termination: | Well-founded Metrics |
Programs as Proofs: | Theorem Proving in Haskell |
Next: Structural Induction: Program Properties about data types!