isabelle/fol proof assistantafelty/courses/isabelletutorialabouelwafam.pdf · isabelle/fol proof...

21
Dec 2014 Isabelle/FOL Proof Assistant In a glance Mohamed Abouelwafa

Upload: others

Post on 24-Mar-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Dec 2014

Isabelle/FOL Proof Assistant In a glance

Mohamed Abouelwafa

Isabelle/FOL Proof Assistant 2014

1

University Of Ottawa

OCICS

Supervised by

Professor: Amy Felty

Prepared by

Mohamed Abouelwafa

[email protected]

Isabelle/FOL Proof Assistant 2014

2

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.

Isabelle/FOL Proof Assistant 2014

3

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

Isabelle/FOL Proof Assistant 2014

4

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

Isabelle/FOL Proof Assistant 2014

5

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

own2, 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

Isabelle/FOL Proof Assistant 2014

6

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

Isabelle/FOL Proof Assistant 2014

7

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

Isabelle/FOL Proof Assistant 2014

8

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.

Isabelle/FOL Proof Assistant 2014

9

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

- ⟦ A1; A2; ………… ; n ⟧ ⟹ G where

o A1; A2; ………… ; n are the set of premises meaning A1 and A2 and ………… and An

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.

Isabelle/FOL Proof Assistant 2014

10

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).

Isabelle/FOL Proof Assistant 2014

11

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.

Isabelle/FOL Proof Assistant 2014

12

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)

Isabelle/FOL Proof Assistant 2014

13

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.

Isabelle/FOL Proof Assistant 2014

14

Application Examples

Example 1:

Isabelle syntax Prover engine output

lemma "⟦A⟧ ⟹ A" goal (1 subgoal): 1. A ⟹ A

apply assumption goal: No subgoals!

done lemma ?A ⟹ ?A

Here i ’ straightforward proof where we compared the goal to the premises.

Example 2:

Isabelle syntax Prover engine output

lemma IEx1:"⟦ A; B ⟧ ⟹ A B" goal (1 subgoal): 1. A ⟹ B ⟹ A B

apply (rule conjI) goal (2 subgoals): 1. A ⟹ B ⟹ A 2. A ⟹ B ⟹ B

apply assumption goal (1 subgoal): 1. A ⟹ B ⟹ B

apply assumption goal: No subgoals!

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.

Isabelle/FOL Proof Assistant 2014

15

Example 3:

Isabelle syntax Prover engine output

lemma IEx2: "⟦ A ⟧ ⟹ A B"

goal (1 subgoal): 1. A ⟹ A B

apply (rule disjI1) goal (1 subgoal): 1. A ⟹ A

apply assumption goal: No subgoals!

done lemma IEx2: ?A ⟹ ?A ?B

Example 4:

Isabelle syntax Prover engine output

lemma Iex3: "⟦ A ⟹ B ⟧ ⟹ A B" goal (1 subgoal): 1. (A ⟹ B) ⟹ A B

apply (rule impI) goal (1 subgoal): 1. (A ⟹ B) ⟹ A ⟹ B

apply assumption goal: No subgoals!

done lemma Iex3: (?A ⟹ ?B) ⟹ ?A ?B

Example 5:

Isabelle syntax Prover engine output

lemma IEx4: "⟦ A ⟹ False ⟧ ⟹ ¬A" goal (1 subgoal): 1. (A ⟹ False) ⟹ ¬ A

apply (rule notI) goal (1 subgoal): 1. (A ⟹ False) ⟹ A ⟹ False

apply assumption goal: No subgoals!

done lemma IEx4: (?A ⟹ False) ⟹ ¬ ?A

Isabelle/FOL Proof Assistant 2014

16

Example 6:

Isabelle syntax Prover engine output

lemma EEx1: "⟦ A B ⟧ ⟹ A" goal (1 subgoal): 1. A B ⟹ A

apply (rule conjunct1) goal (1 subgoal): 1. A B ⟹ A ?Q

apply assumption goal: No subgoals!

done lemma EEx1: ?A ?B ⟹ ?A

Example 7:

Isabelle syntax Prover engine output

lemma EEx2: "⟦ A B ⟧ ⟹ B A" goal (1 subgoal): 1. A B ⟹ B A

apply (rule disjE)

goal (3 subgoals): 1. A B ⟹ ?P ?Q 2. A B ⟹ ?P ⟹ B A 3. A B ⟹ ?Q ⟹ B A

apply assumption goal (2 subgoals): 1. A B ⟹ A ⟹ B A 2. A B ⟹ B ⟹ B A

apply (rule disjI2) goal (2 subgoals): 1. A B ⟹ A ⟹ A 2. A B ⟹ B ⟹ B A

apply assumption goal (1 subgoal): 1. A B ⟹ B ⟹ B A

apply (rule disjI1) goal (1 subgoal): 1. A B ⟹ B ⟹ B

apply assumption goal: No subgoals!

done lemma EEx2: ?A ?B ⟹ ?B ?A

Isabelle/FOL Proof Assistant 2014

17

Example 8:

Isabelle syntax Prover engine output

lemma EEx3: "⟦ A; A B ⟧ ⟹ B" goal (1 subgoal): 1. A ⟹ A B ⟹ B

apply (rule impE)

goal (3 subgoals): 1. A ⟹ A B ⟹ ?P ?Q 2. A ⟹ A B ⟹ ?P 3. A ⟹ A B ⟹ ?Q ⟹ B

apply assumption+ goal: No subgoals!

done lemma EEx3: ?A ⟹ ?A ?B ⟹ ?B

Example 9:

Isabelle syntax Prover engine output

lemma Ex2: "⟦ P Q; R ⟧⟹ Q R " goal (1 subgoal): 1. P Q ⟹ R ⟹ Q R

apply (rule conjI) goal (2 subgoals): 1. P Q ⟹ R ⟹ Q 2. P Q ⟹ R ⟹ R

defer goal (2 subgoals): 1. P Q ⟹ R ⟹ R 2. P Q ⟹ R ⟹ Q

apply assumption goal (1 subgoal): 1. P Q ⟹ R ⟹ Q

apply (rule conjunct2) goal (1 subgoal): 1. P Q ⟹ R ⟹ ?P3 Q

apply assumption goal: No subgoals!

done lemma Ex2: ?P ?Q ⟹ ?R ⟹ ?Q ?R

T comm d “d r” i u d o mov ir ubgo o po i io .

Isabelle/FOL Proof Assistant 2014

18

Example 10:

Isabelle syntax Prover engine output

lemma Ex1: "⟦ P (Q R) ⟧ ⟹ P Q R"

goal (1 subgoal): 1. P Q R ⟹ P Q R

apply (rule impI) goal (1 subgoal): 1. P Q R ⟹ P Q ⟹ R

apply (rule conjE)

goal (2 subgoals): 1. P Q R ⟹ P Q ⟹ ?P2 ?Q2 2. P Q R ⟹ P Q ⟹ ?P2 ⟹ ?Q2 ⟹ R

apply assumption goal (1 subgoal): 1. P Q R ⟹ P Q ⟹ P ⟹ Q ⟹ R

apply (rule mp)

goal (2 subgoals): 1. P Q R ⟹ P Q ⟹ P ⟹ Q ⟹ ?P5 R 2. P Q R ⟹ P Q ⟹ P ⟹ Q ⟹ ?P5

apply (rule mp)

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

apply assumption

goal (2 subgoals): 1. P Q R ⟹ P Q ⟹ P ⟹ Q ⟹ P 2. P Q R ⟹ P Q ⟹ P ⟹ Q ⟹ Q

apply assumption goal (1 subgoal): 1. P Q R ⟹ P Q ⟹ P ⟹ Q ⟹ Q

apply assumption goal: No subgoals!

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 .

Isabelle/FOL Proof Assistant 2014

19

Example 11:

Isabelle syntax Prover engine output

lemma Ex3: "⟦ x. P(x)⟧ ⟹ x. P(x)" goal (1 subgoal): 1. x. P(x) ⟹ x. P(x)

apply (rule exI) goal (1 subgoal): 1. x. P(x) ⟹ P(?x)

apply (rule spec) goal (1 subgoal): 1. x. P(x) ⟹ x. P(?x3(x))

apply assumption goal: No subgoals!

done 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:

Isabelle syntax Prover engine output

lemma Ex4: "⟦ x y. F⟧ ⟹ u v. F"

goal (1 subgoal): 1. x y. F ⟹ u v. F

apply (rule allI)

goal (1 subgoal): 1. ⋀u. x y. F ⟹ v. F

apply (rule allI)

goal (1 subgoal): 1. ⋀u v. x y. F ⟹ F

apply (rule spec)

goal (1 subgoal): 1. ⋀u v. x y. F ⟹ x. F

apply (rule spec)

goal (1 subgoal): 1. ⋀u v. x y. F ⟹ x xa. F

apply assumption goal: No subgoals!

done lemma Ex4: x y. ?F ⟹ u v. ?F

Isabelle/FOL Proof Assistant 2014

20

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