COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161...

110
COMP 4161 Data61 Advanced Course Advanced Topics in Software Verification Gerwin Klein, June Andronick, Christine Rizkallah, Miki Tanaka 1 | COMP4161 | c Data61, CSIRO: provided under Creative Commons Attribution License

Transcript of COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161...

Page 1: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

COMP 4161

Data61 Advanced Course

Advanced Topics in Software Verification

Gerwin Klein, June Andronick, Christine Rizkallah, Miki Tanaka

1 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 2: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Binary Search(java.util.Arrays)

1: public static int binarySearch(int[] a, int key) {

2: int low = 0;

3: int high = a.length - 1;

4:

5: while (low <= high) {

6: int mid = (low + high) / 2;

7: int midVal = a[mid];

8:

9: if (midVal < key)

10: low = mid + 1

11: else if (midVal > key)

12: high = mid - 1;

13: else

14: return mid; // key found

15: }

16: return -(low + 1); // key not found.

17: }

2 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 3: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Binary Search(java.util.Arrays)

1: public static int binarySearch(int[] a, int key) {

2: int low = 0;

3: int high = a.length - 1;

4:

5: while (low <= high) {

6: int mid = (low + high) / 2;

7: int midVal = a[mid];

8:

9: if (midVal < key)

10: low = mid + 1

11: else if (midVal > key)

12: high = mid - 1;

13: else

14: return mid; // key found

15: }

16: return -(low + 1); // key not found.

17: }

6: int mid = (low + high) / 2;

http://googleresearch.blogspot.com/2006/06/

extra-extra-read-all-about-it-nearly.html

2 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 4: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Organisatorials

When Tue 9:00 – 10:30Fri 10:30 – 12:00

Where Ainsworth 201 (K-J17-201)

http://www.cse.unsw.edu.au/~cs4161/

3 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 5: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

About us

The trustworthy systems verification team

Ü Functional correctness and security of the seL4 microkernelSecurity↔ Isabelle/HOL model ↔ Haskell model ↔C code ↔Binary

4 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 6: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

About us

The trustworthy systems verification team

Ü Functional correctness and security of the seL4 microkernelSecurity↔ Isabelle/HOL model ↔ Haskell model ↔C code ↔Binary

Ü 10 000 LOC / 500 000 lines of proof; about 25 person years of effort

4 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 7: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

About us

The trustworthy systems verification team

Ü Functional correctness and security of the seL4 microkernelSecurity↔ Isabelle/HOL model ↔ Haskell model ↔C code ↔Binary

Ü 10 000 LOC / 500 000 lines of proof; about 25 person years of effort

Ü Cogent code/proof co-generation; CakeML verified compiler; etc.

4 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 8: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

About us

The trustworthy systems verification team

Ü Functional correctness and security of the seL4 microkernelSecurity↔ Isabelle/HOL model ↔ Haskell model ↔C code ↔Binary

Ü 10 000 LOC / 500 000 lines of proof; about 25 person years of effort

Ü Cogent code/proof co-generation; CakeML verified compiler; etc.

Open Sourcehttp://sel4.systems

https://ts.data61.csiro.au/projects/TS/cogent.pml

https://cakeml.org

4 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 9: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

About us

The trustworthy systems verification team

Ü Functional correctness and security of the seL4 microkernelSecurity↔ Isabelle/HOL model ↔ Haskell model ↔C code ↔Binary

Ü 10 000 LOC / 500 000 lines of proof; about 25 person years of effort

Ü Cogent code/proof co-generation; CakeML verified compiler; etc.

Open Sourcehttp://sel4.systems

https://ts.data61.csiro.au/projects/TS/cogent.pml

https://cakeml.org

We are always embarking on exciting new projects.We offer

Ü summer student scholarship projects

Ü honours and PhD theses

Ü research assistant and verification engineer positions

4 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 10: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

What you will learn

Ü how to use a theorem prover

5 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 11: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

What you will learn

Ü how to use a theorem prover

Ü background, how it works

5 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 12: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

What you will learn

Ü how to use a theorem prover

Ü background, how it works

Ü how to prove and specify

5 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 13: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

What you will learn

Ü how to use a theorem prover

Ü background, how it works

Ü how to prove and specify

Ü how to reason about programs

5 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 14: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

What you will learn

Ü how to use a theorem prover

Ü background, how it works

Ü how to prove and specify

Ü how to reason about programs

Health Warning

Theorem Proving is addictive

5 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 15: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Prerequisites

This is an advanced course. It assumes knowledge in

Ü Functional programming

Ü First-order formal logic

The following program should make sense to you:

map f [] = []map f (x:xs) = f x : map f xs

You should be able to read and understand this formula:

∃x . (P(x) −→ ∀x . P(x))

6 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 16: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Prerequisites

This is an advanced course. It assumes knowledge in

Ü Functional programming

Ü First-order formal logic

The following program should make sense to you:

map f [] = []map f (x:xs) = f x : map f xs

You should be able to read and understand this formula:

∃x . (P(x) −→ ∀x . P(x))

6 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 17: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Prerequisites

This is an advanced course. It assumes knowledge in

Ü Functional programming

Ü First-order formal logic

The following program should make sense to you:

map f [] = []map f (x:xs) = f x : map f xs

You should be able to read and understand this formula:

∃x . (P(x) −→ ∀x . P(x))

6 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 18: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Content — Using TheoremProvers

Rough timeline

Ü Intro & motivation, getting started

[today]

Ü Foundations & Principles

• Lambda Calculus, natural deduction [1,2]• Higher Order Logic [3a]• Term rewriting [4]

Ü Proof & Specification Techniques

• Inductively defined sets, rule induction [5]• Datatypes, recursion, induction [6, 7]• Hoare logic, proofs about programs, C verification [8b,9]• (mid-semester break)• Writing Automated Proof Methods [10]• Isar, codegen, typeclasses, locales [11c ,12]

aa1 due; ba2 due; ca3 due

7 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 19: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Content — Using TheoremProvers

Rough timeline

Ü Intro & motivation, getting started

[today]

Ü Foundations & Principles

• Lambda Calculus, natural deduction

[1,2]

• Higher Order Logic

[3a]

• Term rewriting

[4]

Ü Proof & Specification Techniques

• Inductively defined sets, rule induction [5]• Datatypes, recursion, induction [6, 7]• Hoare logic, proofs about programs, C verification [8b,9]• (mid-semester break)• Writing Automated Proof Methods [10]• Isar, codegen, typeclasses, locales [11c ,12]

aa1 due; ba2 due; ca3 due

7 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 20: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Content — Using TheoremProvers

Rough timeline

Ü Intro & motivation, getting started

[today]

Ü Foundations & Principles

• Lambda Calculus, natural deduction

[1,2]

• Higher Order Logic

[3a]

• Term rewriting

[4]

Ü Proof & Specification Techniques

• Inductively defined sets, rule induction

[5]

• Datatypes, recursion, induction

[6, 7]

• Hoare logic, proofs about programs, C verification

[8b,9]• (mid-semester break)

• Writing Automated Proof Methods

[10]

• Isar, codegen, typeclasses, locales

[11c ,12]

aa1 due; ba2 due; ca3 due

7 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 21: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Content — Using TheoremProvers

Rough timeline

Ü Intro & motivation, getting started [today]

Ü Foundations & Principles

• Lambda Calculus, natural deduction [1,2]• Higher Order Logic [3a]• Term rewriting [4]

Ü Proof & Specification Techniques

• Inductively defined sets, rule induction [5]• Datatypes, recursion, induction [6, 7]• Hoare logic, proofs about programs, C verification [8b,9]• (mid-semester break)• Writing Automated Proof Methods [10]• Isar, codegen, typeclasses, locales [11c ,12]

aa1 due; ba2 due; ca3 due

7 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 22: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

What you should do to have achance at succeeding

Ü attend lectures

Ü try Isabelle early

Ü redo all the demos alone

Ü try the exercises/homework we give, when we do give some

Ü DO NOT CHEAT

• Assignments and exams are take-home. This does NOT mean youcan work in groups. Each submission is personal.

• For more info, see Plagiarism Policya

a https://student.unsw.edu.au/plagiarism

8 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 23: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

What you should do to have achance at succeeding

Ü attend lectures

Ü try Isabelle early

Ü redo all the demos alone

Ü try the exercises/homework we give, when we do give some

Ü DO NOT CHEAT

• Assignments and exams are take-home. This does NOT mean youcan work in groups. Each submission is personal.

• For more info, see Plagiarism Policya

a https://student.unsw.edu.au/plagiarism

8 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 24: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

What you should do to have achance at succeeding

Ü attend lectures

Ü try Isabelle early

Ü redo all the demos alone

Ü try the exercises/homework we give, when we do give some

Ü DO NOT CHEAT

• Assignments and exams are take-home. This does NOT mean youcan work in groups. Each submission is personal.

• For more info, see Plagiarism Policya

a https://student.unsw.edu.au/plagiarism

8 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 25: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

What you should do to have achance at succeeding

Ü attend lectures

Ü try Isabelle early

Ü redo all the demos alone

Ü try the exercises/homework we give, when we do give some

Ü DO NOT CHEAT

• Assignments and exams are take-home. This does NOT mean youcan work in groups. Each submission is personal.

• For more info, see Plagiarism Policya

a https://student.unsw.edu.au/plagiarism

8 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 26: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

What you should do to have achance at succeeding

Ü attend lectures

Ü try Isabelle early

Ü redo all the demos alone

Ü try the exercises/homework we give, when we do give some

Ü DO NOT CHEAT

• Assignments and exams are take-home. This does NOT mean youcan work in groups. Each submission is personal.

• For more info, see Plagiarism Policya

a https://student.unsw.edu.au/plagiarism

8 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 27: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

What you should do to have achance at succeeding

Ü attend lectures

Ü try Isabelle early

Ü redo all the demos alone

Ü try the exercises/homework we give, when we do give some

Ü DO NOT CHEAT

• Assignments and exams are take-home. This does NOT mean youcan work in groups. Each submission is personal.

• For more info, see Plagiarism Policya

a https://student.unsw.edu.au/plagiarism

8 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 28: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Credits

some material (in using-theorem-provers part) shamelessly stolen from

Tobias Nipkow, Larry Paulson, Markus Wenzel

David Basin, Burkhardt Wolff

Don’t blame them, errors are ours

9 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 29: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

What is a proof?

to prove

Ü from Latin probare (test, approve, prove)

Ü to learn or find out by experience (archaic)

Ü to establish the existence, truth, or validity of(by evidence or logic)prove a theorem, the charges were never proved in court

10 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 30: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

What is a proof?

to prove (Merriam-Webster)

Ü from Latin probare (test, approve, prove)

Ü to learn or find out by experience (archaic)

Ü to establish the existence, truth, or validity of(by evidence or logic)prove a theorem, the charges were never proved in court

10 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 31: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

What is a proof?

to prove (Merriam-Webster)

Ü from Latin probare (test, approve, prove)

Ü to learn or find out by experience (archaic)

Ü to establish the existence, truth, or validity of(by evidence or logic)prove a theorem, the charges were never proved in court

10 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 32: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

What is a proof?

to prove (Merriam-Webster)

Ü from Latin probare (test, approve, prove)

Ü to learn or find out by experience (archaic)

Ü to establish the existence, truth, or validity of(by evidence or logic)prove a theorem, the charges were never proved in court

10 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 33: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

What is a proof?

to prove (Merriam-Webster)

Ü from Latin probare (test, approve, prove)

Ü to learn or find out by experience (archaic)

Ü to establish the existence, truth, or validity of(by evidence or logic)prove a theorem, the charges were never proved in court

pops up everywhere

Ü politics (weapons of mass destruction)

Ü courts (beyond reasonable doubt)

Ü religion (god exists)

Ü science (cold fusion works)

10 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 34: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

What is a mathematical proof?

In mathematics, a proof is a demonstration that, given certainaxioms, some statement of interest is necessarily true. (Wikipedia)

Example:√

2 is not rational.

Proof:

11 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 35: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

What is a mathematical proof?

In mathematics, a proof is a demonstration that, given certainaxioms, some statement of interest is necessarily true. (Wikipedia)

Example:√

2 is not rational.

Proof: assume there is r ∈ Q such that r2 = 2.Hence there are mutually prime p and q with r = p

q .

Thus 2q2 = p2, i.e. p2 is divisible by 2.2 is prime, hence it also divides p, i.e. p = 2s.Substituting this into 2q2 = p2 and dividing by 2 gives q2 = 2s2. Hence,q is also divisible by 2. Contradiction. Qed.

11 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 36: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Nice, but..

Ü still not rigorous enough for some

• what are the rules?• what are the axioms?• how big can the steps be?• what is obvious or trivial?

Ü informal language, easy to get wrong

Ü easy to miss something, easy to cheat

12 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 37: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Nice, but..

Ü still not rigorous enough for some

• what are the rules?• what are the axioms?• how big can the steps be?• what is obvious or trivial?

Ü informal language, easy to get wrong

Ü easy to miss something, easy to cheat

Theorem. A cat has nine tails.Proof. No cat has eight tails. Since one cat has one more tail than nocat, it must have nine tails.

12 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 38: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

What is a formal proof?

A derivation in a formal calculus

13 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 39: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

What is a formal proof?

A derivation in a formal calculus

Example: A ∧ B −→ B ∧ A derivable in the following system

Rules:X ∈ SS ` X

(assumption)S ∪ {X} ` Y

S ` X −→ Y(impI)

S ` X S ` YS ` X ∧ Y

(conjI)S ∪ {X ,Y } ` Z

S ∪ {X ∧ Y } ` Z(conjE)

13 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 40: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

What is a formal proof?

A derivation in a formal calculus

Example: A ∧ B −→ B ∧ A derivable in the following system

Rules:X ∈ SS ` X

(assumption)S ∪ {X} ` Y

S ` X −→ Y(impI)

S ` X S ` YS ` X ∧ Y

(conjI)S ∪ {X ,Y } ` Z

S ∪ {X ∧ Y } ` Z(conjE)

Proof:1. {A,B} ` B (by assumption)2. {A,B} ` A (by assumption)3. {A,B} ` B ∧ A (by conjI with 1 and 2)4. {A ∧ B} ` B ∧ A (by conjE with 3)5. {} ` A ∧ B −→ B ∧ A (by impI with 4)

13 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 41: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

What is a theorem prover?

Implementation of a formal logic on a computer.

Ü fully automated (propositional logic)

Ü automated, but not necessarily terminating (first order logic)

Ü with automation, but mainly interactive (higher order logic)

14 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 42: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

What is a theorem prover?

Implementation of a formal logic on a computer.

Ü fully automated (propositional logic)

Ü automated, but not necessarily terminating (first order logic)

Ü with automation, but mainly interactive (higher order logic)

Ü based on rules and axioms

Ü can deliver proofs

14 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 43: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

What is a theorem prover?

Implementation of a formal logic on a computer.

Ü fully automated (propositional logic)

Ü automated, but not necessarily terminating (first order logic)

Ü with automation, but mainly interactive (higher order logic)

Ü based on rules and axioms

Ü can deliver proofs

There are other (algorithmic) verification tools:

Ü model checking, static analysis, ...

Ü usually do not deliver proofs

Ü See COMP3153: Algorithmic Verification

14 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 44: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Why theorem proving?

Ü Analysing systems/programs thoroughly

Ü Finding design and specification errors early

Ü High assurance (mathematical, machine checked proof)

Ü it’s not always easy

Ü it’s fun

15 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 45: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Why theorem proving?

Ü Analysing systems/programs thoroughly

Ü Finding design and specification errors early

Ü High assurance (mathematical, machine checked proof)

Ü it’s not always easy

Ü it’s fun

15 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 46: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Why theorem proving?

Ü Analysing systems/programs thoroughly

Ü Finding design and specification errors early

Ü High assurance (mathematical, machine checked proof)

Ü it’s not always easy

Ü it’s fun

15 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 47: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Why theorem proving?

Ü Analysing systems/programs thoroughly

Ü Finding design and specification errors early

Ü High assurance (mathematical, machine checked proof)

Ü it’s not always easy

Ü it’s fun

15 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 48: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Main theorem proving system forthis course

λ→

∀=Is

abelle

β

α

Isabelle

Ü used here for applications, learning how to prove

16 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 49: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

What is Isabelle?

A generic interactive proof assistant

Ü generic:not specialised to one particular logic(two large developments: HOL and ZF, will mainly use HOL)

Ü interactive:more than just yes/no, you can interactively guide the system

Ü proof assistant:helps to explore, find, and maintain proofs

17 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 50: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

What is Isabelle?

A generic interactive proof assistant

Ü generic:not specialised to one particular logic(two large developments: HOL and ZF, will mainly use HOL)

Ü interactive:more than just yes/no, you can interactively guide the system

Ü proof assistant:helps to explore, find, and maintain proofs

17 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 51: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

What is Isabelle?

A generic interactive proof assistant

Ü generic:not specialised to one particular logic(two large developments: HOL and ZF, will mainly use HOL)

Ü interactive:more than just yes/no, you can interactively guide the system

Ü proof assistant:helps to explore, find, and maintain proofs

17 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 52: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

What is Isabelle?

A generic interactive proof assistant

Ü generic:not specialised to one particular logic(two large developments: HOL and ZF, will mainly use HOL)

Ü interactive:more than just yes/no, you can interactively guide the system

Ü proof assistant:helps to explore, find, and maintain proofs

17 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 53: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Why Isabelle?

Ü free

Ü widely used systems

Ü active development

Ü high expressiveness and automation

Ü reasonably easy to use

Ü (and because we know it best ;-))

18 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 54: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Why Isabelle?

Ü free

Ü widely used systems

Ü active development

Ü high expressiveness and automation

Ü reasonably easy to use

Ü (and because we know it best ;-))

18 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 55: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

If I prove it on the computer, it is correct, right?

19 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 56: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

If I prove it on the computer, it iscorrect, right?

No, because:

À hardware could be faulty

Á operating system could be faulty

 implementation runtime system could be faulty

à compiler could be faulty

Ä implementation could be faulty

Å logic could be inconsistent

Æ theorem could mean something else

20 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 57: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

If I prove it on the computer, it iscorrect, right?

No, because:

À hardware could be faulty

Á operating system could be faulty

 implementation runtime system could be faulty

à compiler could be faulty

Ä implementation could be faulty

Å logic could be inconsistent

Æ theorem could mean something else

20 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 58: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

If I prove it on the computer, it iscorrect, right?

No, because:

À hardware could be faulty

Á operating system could be faulty

 implementation runtime system could be faulty

à compiler could be faulty

Ä implementation could be faulty

Å logic could be inconsistent

Æ theorem could mean something else

20 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 59: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

If I prove it on the computer, it iscorrect, right?

No, because:

À hardware could be faulty

Á operating system could be faulty

 implementation runtime system could be faulty

à compiler could be faulty

Ä implementation could be faulty

Å logic could be inconsistent

Æ theorem could mean something else

20 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 60: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

If I prove it on the computer, it iscorrect, right?

No, because:

À hardware could be faulty

Á operating system could be faulty

 implementation runtime system could be faulty

à compiler could be faulty

Ä implementation could be faulty

Å logic could be inconsistent

Æ theorem could mean something else

20 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 61: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

If I prove it on the computer, it iscorrect, right?

No, because:

À hardware could be faulty

Á operating system could be faulty

 implementation runtime system could be faulty

à compiler could be faulty

Ä implementation could be faulty

Å logic could be inconsistent

Æ theorem could mean something else

20 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 62: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

If I prove it on the computer, it iscorrect, right?

No, because:

À hardware could be faulty

Á operating system could be faulty

 implementation runtime system could be faulty

à compiler could be faulty

Ä implementation could be faulty

Å logic could be inconsistent

Æ theorem could mean something else

20 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 63: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

If I prove it on the computer, it iscorrect, right?

No, because:

À hardware could be faulty

Á operating system could be faulty

 implementation runtime system could be faulty

à compiler could be faulty

Ä implementation could be faulty

Å logic could be inconsistent

Æ theorem could mean something else

20 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 64: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

If I prove it on the computer, it iscorrect, right?

No, but:

probability for

Ü OS and H/W issues reduced by using different systems

Ü runtime/compiler bugs reduced by using different compilers

Ü faulty implementation reduced by having the right prover architecture

Ü inconsistent logic reduced by implementing and analysing it

Ü wrong theorem reduced by expressive/intuitive logics

No guarantees, but assurance immensly higher than manual proof

21 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 65: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

If I prove it on the computer, it iscorrect, right?

No, but:probability for

Ü OS and H/W issues reduced by using different systems

Ü runtime/compiler bugs reduced by using different compilers

Ü faulty implementation reduced by having the right prover architecture

Ü inconsistent logic reduced by implementing and analysing it

Ü wrong theorem reduced by expressive/intuitive logics

No guarantees, but assurance immensly higher than manual proof

21 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 66: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

If I prove it on the computer, it iscorrect, right?

No, but:probability for

Ü OS and H/W issues reduced by using different systems

Ü runtime/compiler bugs reduced by using different compilers

Ü faulty implementation reduced by having the right prover architecture

Ü inconsistent logic reduced by implementing and analysing it

Ü wrong theorem reduced by expressive/intuitive logics

No guarantees, but assurance immensly higher than manual proof

21 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 67: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

If I prove it on the computer, it iscorrect, right?

No, but:probability for

Ü OS and H/W issues reduced by using different systems

Ü runtime/compiler bugs reduced by using different compilers

Ü faulty implementation reduced by having the right prover architecture

Ü inconsistent logic reduced by implementing and analysing it

Ü wrong theorem reduced by expressive/intuitive logics

No guarantees, but assurance immensly higher than manual proof

21 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 68: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

If I prove it on the computer, it iscorrect, right?

No, but:probability for

Ü OS and H/W issues reduced by using different systems

Ü runtime/compiler bugs reduced by using different compilers

Ü faulty implementation reduced by having the right prover architecture

Ü inconsistent logic reduced by implementing and analysing it

Ü wrong theorem reduced by expressive/intuitive logics

No guarantees, but assurance immensly higher than manual proof

21 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 69: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

If I prove it on the computer, it iscorrect, right?

No, but:probability for

Ü OS and H/W issues reduced by using different systems

Ü runtime/compiler bugs reduced by using different compilers

Ü faulty implementation reduced by having the right prover architecture

Ü inconsistent logic reduced by implementing and analysing it

Ü wrong theorem reduced by expressive/intuitive logics

No guarantees, but assurance immensly higher than manual proof

21 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 70: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

If I prove it on the computer, it iscorrect, right?

No, but:probability for

Ü OS and H/W issues reduced by using different systems

Ü runtime/compiler bugs reduced by using different compilers

Ü faulty implementation reduced by having the right prover architecture

Ü inconsistent logic reduced by implementing and analysing it

Ü wrong theorem reduced by expressive/intuitive logics

No guarantees, but assurance immensly higher than manual proof

21 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 71: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

If I prove it on the computer, it iscorrect, right?

Soundness architecturescareful implementation PVS

LCF approach, small proof kernel HOL4Isabelle

explicit proofs + proof checker CoqTwelfIsabelleHOL4

22 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 72: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

If I prove it on the computer, it iscorrect, right?

Soundness architecturescareful implementation PVS

LCF approach, small proof kernel HOL4Isabelle

explicit proofs + proof checker CoqTwelfIsabelleHOL4

22 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 73: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

If I prove it on the computer, it iscorrect, right?

Soundness architecturescareful implementation PVS

LCF approach, small proof kernel HOL4Isabelle

explicit proofs + proof checker CoqTwelfIsabelleHOL4

22 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 74: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Meta Logic

Meta language:The language used to talk about another language.

Examples:English in a Spanish class, English in an English class

Meta logic:The logic used to formalize another logic

Example:Mathematics used to formalize derivations in formal logic

23 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 75: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Meta Logic

Meta language:The language used to talk about another language.

Examples:English in a Spanish class, English in an English class

Meta logic:The logic used to formalize another logic

Example:Mathematics used to formalize derivations in formal logic

23 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 76: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Meta Logic

Meta language:The language used to talk about another language.

Examples:English in a Spanish class, English in an English class

Meta logic:The logic used to formalize another logic

Example:Mathematics used to formalize derivations in formal logic

23 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 77: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Meta Logic – Example

Syntax:

Formulae: F ::= V | F −→ F | F ∧ F | FalseV ::= [A− Z ]

Derivable: S ` X X a formula, S a set of formulae

24 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 78: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Meta Logic – Example

Syntax:

Formulae: F ::= V | F −→ F | F ∧ F | FalseV ::= [A− Z ]

Derivable: S ` X X a formula, S a set of formulae

logic / meta logic

X ∈ SS ` X

S ∪ {X} ` Y

S ` X −→ Y

S ` X S ` YS ` X ∧ Y

S ∪ {X ,Y } ` Z

S ∪ {X ∧ Y } ` Z

24 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 79: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Isabelle’s Meta Logic

∧=⇒ λ

25 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 80: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

∧Syntax:

∧x . F (F another meta level formula)

in ASCII: !!x. F

26 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 81: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

∧Syntax:

∧x . F (F another meta level formula)

in ASCII: !!x. F

Ü universal quantifier on the meta level

Ü used to denote parameters

Ü example and more later

26 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 82: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

=⇒

Syntax: A =⇒ B (A,B other meta level formulae)in ASCII: A ==> B

27 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 83: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

=⇒

Syntax: A =⇒ B (A,B other meta level formulae)in ASCII: A ==> B

Binds to the right:

A =⇒ B =⇒ C = A =⇒ (B =⇒ C )

Abbreviation:

[[A;B]] =⇒ C = A =⇒ B =⇒ C

Ü read: A and B implies C

Ü used to write down rules, theorems, and proof states

27 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 84: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Example: a theorem

mathematics: if x < 0 and y < 0, then x + y < 0

formal logic: ` x < 0 ∧ y < 0 −→ x + y < 0variation: x < 0; y < 0 ` x + y < 0

Isabelle: lemma ”x < 0 ∧ y < 0 −→ x + y < 0”variation: lemma ”[[x < 0; y < 0]] =⇒ x + y < 0”variation: lemma

assumes ”x < 0” and ”y < 0” shows ”x + y < 0”

28 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 85: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Example: a theorem

mathematics: if x < 0 and y < 0, then x + y < 0

formal logic: ` x < 0 ∧ y < 0 −→ x + y < 0variation: x < 0; y < 0 ` x + y < 0

Isabelle: lemma ”x < 0 ∧ y < 0 −→ x + y < 0”variation: lemma ”[[x < 0; y < 0]] =⇒ x + y < 0”variation: lemma

assumes ”x < 0” and ”y < 0” shows ”x + y < 0”

28 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 86: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Example: a theorem

mathematics: if x < 0 and y < 0, then x + y < 0

formal logic: ` x < 0 ∧ y < 0 −→ x + y < 0variation: x < 0; y < 0 ` x + y < 0

Isabelle: lemma ”x < 0 ∧ y < 0 −→ x + y < 0”variation: lemma ”[[x < 0; y < 0]] =⇒ x + y < 0”

variation: lemmaassumes ”x < 0” and ”y < 0” shows ”x + y < 0”

28 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 87: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Example: a theorem

mathematics: if x < 0 and y < 0, then x + y < 0

formal logic: ` x < 0 ∧ y < 0 −→ x + y < 0variation: x < 0; y < 0 ` x + y < 0

Isabelle: lemma ”x < 0 ∧ y < 0 −→ x + y < 0”variation: lemma ”[[x < 0; y < 0]] =⇒ x + y < 0”variation: lemma

assumes ”x < 0” and ”y < 0” shows ”x + y < 0”

28 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 88: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Example: a rule

logic:X YX ∧ Y

variation:S ` X S ` YS ` X ∧ Y

Isabelle: [[X ;Y ]] =⇒ X ∧ Y

29 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 89: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Example: a rule

logic:X YX ∧ Y

variation:S ` X S ` YS ` X ∧ Y

Isabelle: [[X ;Y ]] =⇒ X ∧ Y

29 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 90: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Example: a rule

logic:X YX ∧ Y

variation:S ` X S ` YS ` X ∧ Y

Isabelle: [[X ;Y ]] =⇒ X ∧ Y

29 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 91: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Example: a rule with nestedimplication

logic:X ∨ Y

X....Z

Y....Z

Z

variation:

S ∪ {X} ` Z S ∪ {Y } ` Z

S ∪ {X ∨ Y } ` Z

Isabelle: [[X ∨ Y ;X =⇒ Z ;Y =⇒ Z ]] =⇒ Z

30 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 92: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Example: a rule with nestedimplication

logic:X ∨ Y

X....Z

Y....Z

Z

variation:

S ∪ {X} ` Z S ∪ {Y } ` Z

S ∪ {X ∨ Y } ` Z

Isabelle: [[X ∨ Y ;X =⇒ Z ;Y =⇒ Z ]] =⇒ Z

30 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 93: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Example: a rule with nestedimplication

logic:X ∨ Y

X....Z

Y....Z

Z

variation:

S ∪ {X} ` Z S ∪ {Y } ` Z

S ∪ {X ∨ Y } ` Z

Isabelle: [[X ∨ Y ;X =⇒ Z ;Y =⇒ Z ]] =⇒ Z

30 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 94: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

λ

Syntax: λx . F (F another meta level formula)in ASCII: %x. F

31 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 95: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

λ

Syntax: λx . F (F another meta level formula)in ASCII: %x. F

Ü lambda abstraction

Ü used for functions in object logics

Ü used to encode bound variables in object logics

Ü more about this in the next lecture

31 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 96: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Enough Theory!

Getting started with Isabelle

Page 97: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

System Architecture

Prover IDE (jEdit) – user interface

HOL, ZF – object-logics

Isabelle – generic, interactive theorem prover

Standard ML – logic implemented as ADT

User can access all layers!

33 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 98: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

System Architecture

Prover IDE (jEdit) – user interface

HOL, ZF – object-logics

Isabelle – generic, interactive theorem prover

Standard ML – logic implemented as ADT

User can access all layers!

33 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 99: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

System Architecture

Prover IDE (jEdit) – user interface

HOL, ZF – object-logics

Isabelle – generic, interactive theorem prover

Standard ML – logic implemented as ADT

User can access all layers!

33 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 100: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

System Architecture

Prover IDE (jEdit) – user interface

HOL, ZF – object-logics

Isabelle – generic, interactive theorem prover

Standard ML – logic implemented as ADT

User can access all layers!

33 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 101: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

System Architecture

Prover IDE (jEdit) – user interface

HOL, ZF – object-logics

Isabelle – generic, interactive theorem prover

Standard ML – logic implemented as ADT

User can access all layers!

33 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 102: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

System Requirements

Ü Linux, Windows, or MacOS X (10.8 +)

Ü Standard ML (PolyML implementation)

Ü Java (for jEdit)

Premade packages for Linux, Mac, and Windows + info on:http://mirror.cse.unsw.edu.au/pub/isabelle/

34 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 103: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Documentation

Available from http://isabelle.in.tum.de

Ü Learning Isabelle

• Concrete Semantics Book• Tutorial on Isabelle/HOL (LNCS 2283)• Tutorial on Isar• Tutorial on Locales

Ü Reference Manuals

• Isabelle/Isar Reference Manual• Isabelle Reference Manual• Isabelle System Manual

Ü Reference Manuals for Object-Logics

35 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 104: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

jEdit/PIDE

36 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 105: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

jEdit/PIDE

Theory File

Isabelle Output37 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 106: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

jEdit/PIDE

LaTeX Comment

Commands

logic terms go in quotes: Òx + 2Ó

38 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 107: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

jEdit/PIDE

Command + hover for popup info

Command click jumps to deÞnition

39 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 108: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

jEdit/PIDE

error

processed

unprocessed

40 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License

Page 109: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Demo

Page 110: COMP 4161 Data61 Advanced Course Advanced Topics in ...cs4161/18s2/week01A_anim.pdf · COMP 4161 Data61 Advanced Course Advanced Topics in Software Veri cation Gerwin Klein, June

Exercises

Ü Download and install Isabelle fromhttp://mirror.cse.unsw.edu.au/pub/isabelle/

Ü Step through the demo files from the lecture web page

Ü Write your own theory file, look at some theorems in the library, try’find theorems’

Ü How many theorems can help you if you need to prove somethingcontaining the term “Suc(Suc x)”?

Ü What is the name of the theorem for associativity of addition of naturalnumbers in the library?

42 | COMP4161 | c© Data61, CSIRO: provided under Creative Commons Attribution License