Dec 2014 Isabelle/FOL Proof Assistant In a glance Mohamed Abouelwafa
University Of Ottawa OCICS Supervised by Professor: Amy Felty Prepared by Mohamed Abouelwafa Mabou069@uottawa.ca 1
Abstract This tutorial is meant to discuss the basic features and capabilities of Isabelle proof assistant (Isabelle2014) with some applications on First-Order formalism without going into deep details. We will do the demonstrations and cases using only First-order logic examples with simple types and constants. The tutorial shows the main features of JEdit user interface and the main instructions of Isar proof language. This tutorial is for beginners and those who want to start learning Isabelle and then the rest of bibliographies at the end of the tutorial can be used for gaining more knowledge and deeper experience. 2
Table of Contents List of Figures... 4 Introduction... 5 Terminology... 5 Isabelle/jEdit... 7 Basics of Isabelle... 9 Formalizing syntax... 9 Syntax representation... 9 Reasoning in Isabelle... 9 Proofs and theorems in Isabelle...10 Theories...10 Commands and syntax...11 Natural deduction rules...12 Introduction Rules...12 Elimination Rules...13 Some useful commands...13 Application Examples...14 Example 1:...14 Example 2:...14 Example 3:...15 Example 4:...15 Example 5:...15 Example 6:...16 Example 7:...16 Example 8:...17 Example 9:...17 Example 10:...18 Example 11:...19 Example 12:...19 Bibliography...20 3
List of Figures Figure 1: Isabelle/jEdit IDE... 6 Figure 2: Colored code in Isabelle/jEdit... 7 Figure 3: Completion in Isabelle/jEdit... 7 Figure 4: list of some symbols in Isabelle/jEdit with abbreviations... 8 Figure 5: "Examples.thy" file contents...10 Figure 6: Example Proof...11 4
Introduction Isabelle 2014 is a proof assistant package, which is used to represent mathematical formulas using a formal structured proof language called Isar. It provides tools for proving these formulas in a logical calculus. 1 Isabelle deals with different kinds of logics, the current research and development in Isabelle is concentrating on dealing with Higher Order Logic (HOL) formulas. The first distributable version of Isabelle was released in 1986 dealing with First Order Logic (FOL) then the beginning of dealing with Higher Order Logic (HOL) capabilities were introduced in 1987. The Prover system consists of two main components, the Prover IDE and the Editor. The editor is responsible for interacting with the system user, where the users can formulate their problem in a logical form then the Prover checks the formulas and provides feedback for the end user. An important feature of Isabelle proof assistant is that, the formal language is easily read by humans which makes it more convenient to enter the formulas and later to be easy to debug and find errors and bugs in the code. Isabelle with jedit provides the user with a big library of mathematical and logical symbols that makes it easy for the user to formalize the situation in hand. Terminology Isabelle/Isar Isabelle is a generic logical framework for higher-order natural deduction/ Implemented using an intelligent semi-automated reasoning language for providing an interpreted language environment of its own 2, Which has been specifically tailored for the needs of theory and proof development. Isabelle/Scala It is the system programming language of Isabelle. It extends the pure logical environment of Isabelle/ML ow rd r wor d of graphical user interfaces, text editors, IDE frameworks, web services etc. 3 Isabelle/ML is the implementation and extension language of Isabelle. It is integrated into the logical context of Isabelle/Isar and allows manipulating logical entities directly. Arbitrary add-on tools may be implemented for object-logics such as Isabelle/HOL. 4 Simply, the group of commands, tactics and rules are used to represent the system in hand. 1 Isabelle2014 official webpage, http://isabelle.in.tum.de/ 2 Makarius Wenzel, The Isabelle/Isar Reference Manual 3 Makarius Wenzel, Isabelle/jEdit 4 Makarius Wenzel, Isabelle/jEdit 5
PIDE It is a general framework for Prover IDEs based on Isabelle/Scala. It is built around a concept of parallel and asynchronous document processing, which is supported natively by the parallel proof engine that is implemented in Isabelle/ML. 5 Isabelle/jEdit It is the main example application of the PIDE framework and the default user-interface for Isabelle. It targets both beginners and experts. Technically, Isabelle/jEdit combines a slightly modified version of the jedit code base with a special plugin for Isabelle, integrated as standalone application for the main operating system platforms: Linux, Windows, Mac OS X 6 Figure 1: Isabelle/jEdit IDE 5 Makarius Wenzel, Isabelle/jEdit 6 Makarius Wenzel, Isabelle/jEdit 6
Isabelle/jEdit The Isabelle/jEdit is a very powerful Prover IDE with the jedit editor which comes with a lot of features, for example: - Colored code o Each word in the proof syntax has its own color depending on its type. For example, om r b u comm d r r d ory i co ro word r gr Figure 2: Colored code in Isabelle/jEdit - Copy/Paste o User can Copy/Paste the written code in Isabelle/jEdit for faster duplication of the constructs. o User can even use Copy/Past with the Unicode syntax produced by the editor, not only within Isabelle/jEdit, but also between the editor and other programs such as Microsoft Word. o User can use Copy/Paste to copy the code from the console rendered output for further usage or presentation purposes. - Completion o One of the most powerful features is the completion option (sometimes, they call it Sm r Comp io, which helps greatly in speeding up the formalization process and reliefs the user from memorizing all the commands, tactics and symbols control characters. o User can enter symbols by entering their canonical name. Canonical names take the form of \<and> this will result in the symbol or the name preceded by a backslash \and, again, this will result in the symbol. o User can enter symbols by entering their abbreviation. For example, entering an & symbol will result in jedit to convert it to. Entering an symbol will result in jedit to convert it to. o Completions option can be configured in the menu (Plugins Plugin options / Isabelle / General / Completion. Figure 3: Completion in Isabelle/jEdit 7
Symbol Name with backslash Abbreviation \<and> & \<or> \<not> ~ \<longrightarrow> ==> \<longrightarrow> --> \<forall>! \<exists>? \<lbrakk> [ \<rbrakk> ] Figure 4: list of some symbols in Isabelle/jEdit with abbreviations - Spell checking o Where the editor may underline some wrong semantics or unknown words to the system for further review or action that may be required by the user. 8
Basics of Isabelle Isabelle uses a special format for formalizing the Propositional Logic and hence Natural deduction, where some times braces are redundant. Also, Isabelle binds to the right if braces are absent. Formalizing syntax - P x stand for P(x) - P xy stand for P(x,y) - x. P stands for x P(x) which is a quantified sentence. - x. P stands for x P(x) which is a quantified sentence. Syntax representation - A 1 ; A 2 ; ; n G where o A 1 ; A 2 ; ; n are the set of premises meaning A 1 and A 2 and and A n o means then o G is the goal of the formula - Binary connectives are written in place, so we write P Q R instead of P Q R Reasoning in Isabelle There are two types of reasoning (proving mechanisms) - Forward reasoning: o If we have A and we have B then we can conclude A B. o We start from the premises and assumptions then we continue our deduction till we reach the goal - Backward reasoning: o To prove A B we have to prove A is true and B is true. o We start from the goal, divide the goal into a set of subgoals, then we work with these subgoals one by one till we match the premises and assumptions. Throughout this tutorial, we will be using Backward reasoning for explanations and example proofs. 9
Proofs and theorems in Isabelle Proofs in Isabelle go through certain standard steps as follows: 1. Define a theorem. 2. Define the set of premises and assumptions. 3. Define the goal. 4. Design the proof steps till you match the goal with the premises and you have no more subgoals are left. Theories Isabelle is a theorem Prover where each file is considered to be a separate theorem. So, for Isabelle to be able to decode the proof that we are going to represent, we need to declare a theory and save the file also, with the same name of the theory with ex io.thy Also, a very important point, each theory in Isabelle is built upon an existing theory which insures that new theories are built upon stable older theories resulting in maintaining consistency. Figure 5: "Examples.thy" file contents From figure 5 we can see the co o i Examples.thy containing the general skeleton for a theory where we can start building up our proofs. The file starts with theory k yword which tells the engine that this file wi co i ory m d Examples. T imports dir c iv Prover gi m o b ory FOL curr ory Examples i bui upo. T dir c iv begin i i i r o o proo can be contained inside the current theory. d o ory i w i d dir c iv end w ic rov r gi w r o op processing the theory file. No : m io d r i r ori r bui upo xi i g ori. So i v ry important to make sure that the imported theory file exists and reachable by the Prover engine ( FOL.thy in our example). 10
Commands and syntax Comments Comments in Isabelle are ASCII/Unicode string c o d i (* d *). (* This is a comment *) Premises and Goal definition Goal is defined using a lemma directive. The lemma name can be used for reusing the proved lemma r i ory o rwi i op io. lemma <lemma_name> : premises_list separated by ; G Applying Natural Deduction rules The directive apply is used to apply the natural deduction rules and tactics during the proof steps. Apply (rule/tactic/method Theorem_name) Apply assumption Apply assumption+ Ending the proof The directive done is used to end the proof. done Figure 6: Example Proof We can see from Figure 6 the construction of an example simple proof. The proof starts with defining the premises and the goal, then applying the proper rules and methods to finally match the goal with the pr mi w r goi g o w i goi g roug proo p d p ou pu p by p. 11
Natural deduction rules Isabelle uses natural deduction techniques to propagate through the proof using two type of natural deduction rules: - Introduction rules: where we infer connectives. - Elimination rules: where we deduce the connectives consequences. Isabelle depends on schematic variables that can be substituted for, for example?p;?q?p?q conji We can see the formula having two variables P and Q having a question mark in front of each of them; it means that that rule applies for these variables that can be substituted for. Introduction Rules Rule Isabelle goal representation Isabelle rule A ; B A B apply (rule conji) A A B apply (rule disji1) B A B apply (rule disji2) A B A B apply (rule impi) A False A apply (rule noti) 12
Elimination Rules Rule Isabelle goal representation Isabelle rule A B A apply (rule conjunct1) A B B apply (rule conjunct2) C apply (rule conje) C apply (rule disje) A; A apply (rule impe) apply (rule mp) apply (rule note) Some useful commands - oops o To abandon the current proof sequence and go to another proof. In other words, it tells the Prover engine to stop processing the current proof sequence without considering it not completed yet. - sorry o To abandon the current proof but still can use the declared lemma. - defer o Move the first subgoal to the last position - Prefer n o Move subgoal n to first position - auto o Automatically apply the automatic tactics to prove the goal. 13
Application Examples Example 1: lemma " A A" 1. A A done lemma?a?a Here i straightforward proof where we compared the goal to the premises. Example 2: lemma IEx1:" A; B A B" apply (rule conji) 1. A B A B goal (2 subgoals): 1. A B A 2. A B B 1. A B B done lemma IEx1:?A?B?A?B In this example, we started by the goal, where it can be inferred by a conjunction introduction tactic. Then, by comparing to the premises, we get the proof. 14
Example 3: lemma IEx2: " A A B" 1. A A B apply (rule disji1) 1. A A done lemma IEx2:?A?A?B Example 4: lemma Iex3: " A B A B" apply (rule impi) 1. (A B) A B 1. (A B) A B done lemma Iex3: (?A?B)?A?B Example 5: lemma IEx4: " A False A" apply (rule noti) 1. (A False) A 1. (A False) A False done lemma IEx4: (?A False)?A 15
Example 6: lemma EEx1: " A B A" apply (rule conjunct1) 1. A B A 1. A B A?Q done lemma EEx1:?A?B?A Example 7: lemma EEx2: " A B B A" apply (rule disje) apply (rule disji2) 1. A B B A goal (3 subgoals): 1. A B?P?Q 2. A B?P B A 3. A B?Q B A goal (2 subgoals): 1. A B A B A 2. A B B B A goal (2 subgoals): 1. A B A A 2. A B B B A 1. A B B B A apply (rule disji1) 1. A B B B done lemma EEx2:?A?B?B?A 16
Example 8: lemma EEx3: " A; A B B" apply (rule impe) + 1. A A B B goal (3 subgoals): 1. A A B?P?Q 2. A A B?P 3. A A B?Q B done lemma EEx3:?A?A?B?B Example 9: lemma Ex2: " P Q; R Q R " apply (rule conji) defer apply (rule conjunct2) 1. P Q R Q R goal (2 subgoals): 1. P Q R Q 2. P Q R R goal (2 subgoals): 1. P Q R R 2. P Q R Q 1. P Q R Q 1. P Q R?P3 Q done lemma Ex2:?P?Q?R?Q?R T comm d d r i u d o mov ir ubgo o po i io. 17
Example 10: lemma Ex1: " P (Q R) P Q R" 1. P Q R P Q R apply (rule impi) apply (rule conje) apply (rule mp) apply (rule mp) 1. P Q R P Q R goal (2 subgoals): 1. P Q R P Q?P2?Q2 2. P Q R P Q?P2?Q2 R 1. P Q R P Q P Q R goal (2 subgoals): 1. P Q R P Q P Q?P5 R 2. P Q R P Q P Q?P5 goal (3 subgoals): 1. P Q R P Q P Q?P8?P5 R 2. P Q R P Q P Q?P8 3. P Q R P Q P Q?P5 goal (2 subgoals): 1. P Q R P Q P Q P 2. P Q R P Q P Q Q 1. P Q R P Q P Q Q done lemma Ex1:?P?Q?R?P?Q?R The theorem mp i Modu o w ic i qu o imp ic io i roduc io. 18
Example 11: lemma Ex3: " x. P(x) x. P(x)" apply (rule exi) apply (rule spec) done 1. x. P(x) x. P(x) 1. x. P(x) P(?x) 1. x. P(x) x. P(?x3(x)) lemma Ex3: x.?p(x) x.?p(x) T or m p c r i u d o g o ubgo rom pr mi (used as a forward reasoning tactic). Example 12: lemma Ex4: " x y. F u v. F" apply (rule alli) apply (rule alli) apply (rule spec) apply (rule spec) 1. x y. F u v. F 1. u. x y. F v. F 1. u v. x y. F F 1. u v. x y. F x. F 1. u v. x y. F x xa. F done lemma Ex4: x y.?f u v.?f 19
Bibliography - Isabelle homepage - http://isabelle.in.tum.de/ - Makarius Wenzel, Isabelle / jedit, August 27, 2014 - http://www.cl.cam.ac.uk/research/hvg/isabelle/dist/doc/jedit.pdf - Lawrence C. Paulson, Old Introduction to Isabelle, With Contributions by Tobias Nipkow and Markus Wenzel, August 27, 2014 - http://isabelle.in.tum.de/dist/isabelle2014/doc/intro.pdf - Tobias Nipkow, Programming and Proving in Isabelle/HOL, August 27, 2014 - http://isabelle.in.tum.de/dist/isabelle2014/doc/prog-prove.pdf - Lawrence C. Paulson, Isabelle s Logics: FOL and ZF, With Contributions by Tobias Nipkow and Markus Wenzel, August 27, 2014 - http://isabelle.in.tum.de/dist/isabelle2014/doc/logics-zf.pdf - http://www.wikipedia.org/ - Clemens Ballarin, Introduction to Isabelle, Session one http://www21.in.tum.de/~ballarin/belgrade08-tut/session01/session01.pdf - Clemens Ballarin, Introduction to Isabelle, Session two http://www21.in.tum.de/~ballarin/belgrade08-tut/session02/session02.pdf - Jacques Fleuriot, Introduction to Isabelle/HOL - http://www.inf.ed.ac.uk/teaching/courses/ar/2004-05/slides/small-isabelle-hol-8-9.pdf - Joaqu ın AGuado, Natural Deduction ISABELLE Single- step proofs based on Sequent Notation - http://www.gdi.uni-bamberg.de/personnel/aguado/talks/isabelle.pdf 20