Refinement Reflection
 
 Allow terminating Haskell functions in refinements!
Theorems about Haskell functions
e.g. Parallelized Function Equivalent to Original
forall xs. sum xs == parallelSum xs
A. Farmer et al: Reasoning with the HERMIT 
 
Theorems about Haskell functions
 
 
 Can we express the above theorems in Liquid Haskell? 
 
Express & Prove Theorems in Haskell ...
... for Haskell functions.
Types As Theorems
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
 
 
 Can we express the above theorems in Liquid Haskell? 
 
Express & Prove Theorems in Haskell ...
... for Haskell functions.
Refinement Reflection
Reflect fib in the logic.
(Need to prove fib terminates...)
fib is an uninterpreted function
 For which logic only knows the congruence axiom... 
... and nothing else
Reflect Function into Output Type
 The type of fib connects logic & Haskell implementation 
fib :: i:Nat
    -> {v:Nat |  v == fib i
              && v == if i == 0 then 0 else
                      if i == 1 then 1 else
                      fib (i-1) + fib (i-2)
       }
Calling fib i reveals its implementation in the logic!
Reflection at Result Type
Exercise: Lets prove that fib 2 == 1.
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? 
Note: Totality checker should be on for valid proofs
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 | 
| Reflection: | Haskell functions in Logic | 
Next: Structural Induction: Program Properties about data types!