introduction to automated theorem provingcs3234/cs3234-lec02b.pdfautomated theorem provers •...
TRANSCRIPT
Introduction to Automated Theorem Proving
CS3234
Lecture 2
Martin Henz and Aquinas Hobor
OutlineOutline
• What is an automated theorem prover?p
• Advantages and disadvantages
• Introduction to Coq
2
Automated Theorem ProversAutomated Theorem Provers
• Computer program that can generate and checkComputer program that can generate and check mathematical theorems
• Theorems are expressed in some mathematical l i h i i l l i dilogic, such as propositional logic, predicate logic, first‐order logic, …
• Many different theorem provers out there: y pIsabelle/HOL, TWELF, Coq, Metamath, Nuprl, …
3
Theorem Prover Overview
Math (in some logic)Provided by user(not to scale) g(not to scale)
Provided by Theorem Proverdeveloper
(not to scale)
4
Differences Between ProversDifferences Between Provers
• The logic the prover uses– Isabelle/HOL : Higher Order Logic (HOL)– TWELF : Logical Framework (LF)– Coq : Calculus of (Co‐)Inductive Constructions (CiC)Coq : Calculus of (Co )Inductive Constructions (CiC)– etc.
• Some logics are more powerful (can express and prove more theorems) than others, e.g.,– Propositional Logic is usually the weakestp g y– CiC is more powerful than HOL
M f l l i b h d t• More powerful logics can be harder to use
5
Differences Between ProversDifferences Between Provers• The task a prover handles
– All provers can check theorems in their logic– Automated proof generation is much harder
• Different provers have different trade‐offs b t d f t ti d thbetween degree of automation and the power of the logic they handle
The more powerful the logic the less automatic– The more powerful the logic, the less automatic generation of proofs
– Many automated theorem provers are really moreMany automated theorem provers are really more automated theorem checkers
6
Proof Checking vs. Proof GenerationR ll th t f l f i li t f f l h f• Recall that a formal proof is a list of formulas each of which is justified by an axiom or an inference rule applied to earlier formulas
Formulas JustificationF1 AxiomF2 Rule 3 and F1… …Theorem …
• Formal proofs are very easy to check mechanically– Just make sure the justifications are applied correctlyJust make sure the justifications are applied correctly
• However, proof generation is harder – have to generate a list of formulas, each of which has valid justification, and where the last formula is the desired theorem. 7
Differences Between ProversDifferences Between Provers
• Practical differences– Or, “Oh, yeah – it’s a piece of software!”
• Some provers have:• Some provers have:– More support if there is trouble (mailing lists)– Bigger user base– More frequent new versions– Tool support– Better library support (e.g. built‐in definitions of the realBetter library support (e.g. built in definitions of the real numbers, etc.)
• It’s possible to have bugs! Which are more trustworthy?• It’s possible to have bugs! Which are more trustworthy?
8
What does the user provide?What does the user provide?
• Depends on which prover!p p
• All provers: statement of theorem expressed in the logic of the system
F thi i h ll d i i• For some provers, this is enough – all you do is give the desired theorem and push “Go”
• Fully automatic provers can’t prove nearly as many theorems as “semiautomatic” provers
9
What does the user provide?What does the user provide?
• So the user must provide some kind of hintsSo the user must provide some kind of hints that help the prover (often provided in the same file)same file)
L f l hi “A f i h• Least useful hint: “A proof exists – search forever until you find it”
• Most useful hint: “Here is the proof: …” p
10
Intermediate Hints• Most provers take a middle path and require hints between the two extremes– Statement of key lemmas (useful intermediate results)– Proof outline (how the lemmas connect)– Key idea in proof (“prove by induction on n”)– Proof script (list of medium‐sized steps in the proof)
• One advantage of providing hints is that if the theorem is not provable the prover can providetheorem is not provable, the prover can provide better error reporting as to why the proof failed.– Most error reporting is still pretty difficult (worse than aMost error reporting is still pretty difficult (worse than a typical compiler error report)
11
Theorem Prover Overview
Statement of Theorem
Hi tProvided by user(not to scale) Hints(not to scale)
Provided by Theorem Proverdeveloper
(not to scale)
12
LibraryLibraryMany theorems share commonly used definitionsd land lemmas
• Natural numbers• Natural numbers– Definition (zero & successor)– Facts about naturals (a + b = b + a) and their proofs( ) p
• Integers– Definition (naturals & negative naturals & zero)– Facts about integers (e.g., a + (‐a) = 0) and their proofs
• etc.13
Theorem Prover Overview
Statement of Theorem
Hi tProvided by user(not to scale) Hints(not to scale)
TheoremProvided by Theorem Theorem Prover
developer(not to scale)
TheoremLibrary
14
OutlineOutline
• What is an automated theorem prover?p
• Advantages and disadvantages
• Introduction to Coq
15
Why are theorem provers used?
• Very high assurance due to mechanical checking
• When possible, automatic proof generation can significantly improve program development– Earlier detection of bugs
– Better code/design coverage than testing
– Frequently tools can locate errors faster than debugging
16
High assurance• In general, highest assurance that there are no mistakes in proofmistakes in proof– Checkers are very thorough: don’t get tired, don’t get bored, don’t make mistakes
– If anything, the problem is the opposite – trying to convince a checker that a true thing is true can be frustratingfrustrating.
U d i h t i iti l• Used in areas where correctness is critical– AerospaceD f– Defense
– etc. 17
Right tool for the job…Right tool for the job…
Better at some kinds of tasks than othersBetter at some kinds of tasks than others
• Best: proving behavior of real programs• Best: proving behavior of real programs
B d• Bad: – Cryptography: often we rely on guesses (P = NP ?)P th T l d lib i t ti l t– Pure math: Tools and libraries are not practical yet
– Design: How to prove one user interface better than another?than another?
18
Uses for proof generationFor problems that are simpler, proof generationis very useful as wellis very useful as well
• T pe inference & checkers (e ML Ja a C#)• Type inference & checkers (e.g., ML, Java, C#)
• Safety of web applications (e.g., Java)
• Static analysis tools– Buffer overrun analysis– Safety property analysis
19
Disadvantages of d hAutomated Theorem Proving
For proof generation:For proof generation:
• Only useful for certain kinds of “simple” problems• Only useful for certain kinds of simple problems
T l f tl diffi lt t d l• Tools are frequently very difficult to develop
f h b d• Often can have very bad worst‐case running time– e.g., Hindley‐Milner type inference is O(22
n)
– Sometimes the average running time is much better
20
Disadvantages of Automated Theorem ProvingAutomated Theorem Proving
For proof checking:
• Developing the hints / proof by hand can be veryl b i t ilabor‐intensive
I b diffi l f li• It can be very difficult to formalize correctness– “correct” operating system?“correct” web browser?– correct web browser?
– “correct” compiler?
• Learning curve to use systems can be steep21
One more advantage… they are fun to use!
• A bit like writing software in a scripting language
they are fun to use!
A bit like writing software in a scripting language
“Building such scripts is surprisingly addictiveBuilding such scripts is surprisingly addictive, in a videogame kind of way…”
‐ Xavier Leroy‐ Xavier Leroy
• The advantage of never having to worry about bugs• The advantage of never having to worry about bugs in the finished product
• Can work on math at 3 AM without fear22
OutlineOutline
• What is an automated theorem prover?p
• Advantages and disadvantages
• Introduction to Coq
23
CoqCoq• Theorem prover developed in France
– Name is the French word for rooster(The French have a distressing lack of regard for the way their words sound i h l )in other languages.)
– Lots of library & tool support– Large user baseLarge user base
• Calculus of (Co‐)Inductive Constructions (CiC)– We will just use a small portion
// /• Available on the web at http://coq.inria.fr/– Windows, MacOS, Linux/UNIX 24
Tactic‐based systemTactic based system
• CiC is quite powerful so automatic proofCiC is quite powerful, so automatic proof generation is quite limited
• Instead, a user provides hints in the form of f iproof scripts
• Proof scripts are lists of tactics, which guide Coq in generating the proofq g g p
25
CoqIDE
26
CoqIDE
Current GoalProof Script
Current GoalProof Script
Error Reporting
27
DemonstrationDemonstration
hi i ll h i filNote: this presentation as well as the script file we
will go over now will be available to you online.
28
Homework, due next week
A file has been added to the online course workbin.
Hints:
St t l• Start early. I am very unlikely to help with installation problems the night before the homework is due Also the learning curve for Coq can be steepdue. Also, the learning curve for Coq can be steep.
• I am available for help most afternoons. Feel free to knock pon my door or write me email if you have questions.
d h i did i l• You are encouraged to go over the script we did in class before starting the homework.
29
Homework, due next week
A file has been added to the online course workbin.
Hints:
St t l
If I could make it flash bright orange I would.
• Start early. I am very unlikely to help with installation problems the night before the homework is due Also the learning curve for Coq can be steepdue. Also, the learning curve for Coq can be steep.
• I am available for help most afternoons. Feel free to knock pon my door or write me email if you have questions.
d h i did i l• You are encouraged to go over the script we did in class before starting the homework.
30
Individual Work OnlyyBecause of the nature of the machine checked partBecause of the nature of the machine‐checked part
of this assignment, you should not collaborate with
any of your classmates. The handwritten part of the
assignment can be discussed with your classmates.
Do the machine‐checked part on your ownDo the machine‐checked part on your own.
If you have questions about this, please email me.31
HintsHints
1 Start Early1. Start Early
2. We have a local copy of the downloads (much faster!) on the websitefaster!) on the website
3. Email Aquinas with questions if you get stuck
4. Tutorials:1. http://coq.inria.fr/V8.1/files/doc/Tutorial.pdf
2. http://cel.archives‐ouvertes.fr/docs/00/33/44/28/PDF/coq‐hurry.pdf
32