• No results found

Isabelle Tutorial. 1 August 2015 CADE-25

N/A
N/A
Protected

Academic year: 2021

Share "Isabelle Tutorial. 1 August 2015 CADE-25"

Copied!
58
0
0

Loading.... (view fulltext now)

Full text

(1)

Isabelle Tutorial

Christian Sternagel

Makarius Wenzel

1 August 2015

CADE-25

(2)

Isabelle Tutorial

History

(3)

Isabelle Tutorial History

Dana Scott:

Logic for Computable Functions

1969

Robin Milner: Stanford LCF

1972

ML: Meta Language

1973

Edinburgh LCF

1977

Larry Paulson: Cambridge LCF

1985

Isabelle

1986

Tobias Nipkow: Isabelle/HOL

1993

1969

1993

(4)

Isabelle Tutorial History

Dana Scott:

Logic for Computable Functions

1969

Robin Milner: Stanford LCF

1972

ML: Meta Language

1973

Edinburgh LCF

1977

Larry Paulson: Cambridge LCF

1985

Isabelle

1986

Tobias Nipkow: Isabelle/HOL

1993

1969

1993

(5)

Isabelle Tutorial History

Dana Scott:

Logic for Computable Functions

1969

Robin Milner: Stanford LCF

1972

ML: Meta Language

1973

Edinburgh LCF

1977

Larry Paulson: Cambridge LCF

1985

Isabelle

1986

Tobias Nipkow: Isabelle/HOL

1993

1969

1993

(6)

Isabelle Tutorial History

Dana Scott:

Logic for Computable Functions

1969

Robin Milner: Stanford LCF

1972

ML: Meta Language

1973

Edinburgh LCF

1977

Larry Paulson: Cambridge LCF

1985

Isabelle

1986

Tobias Nipkow: Isabelle/HOL

1993

1969

1993

(7)

Isabelle Tutorial History

Dana Scott:

Logic for Computable Functions

1969

Robin Milner: Stanford LCF

1972

ML: Meta Language

1973

Edinburgh LCF

1977

Larry Paulson: Cambridge LCF

1985

Isabelle

1986

Tobias Nipkow: Isabelle/HOL

1993

1969

1993

(8)

Isabelle Tutorial History

Dana Scott:

Logic for Computable Functions

1969

Robin Milner: Stanford LCF

1972

ML: Meta Language

1973

Edinburgh LCF

1977

Larry Paulson: Cambridge LCF

1985

Isabelle

1986

Tobias Nipkow: Isabelle/HOL

1993

1969

1993

(9)

Isabelle Tutorial History

Dana Scott:

Logic for Computable Functions

1969

Robin Milner: Stanford LCF

1972

ML: Meta Language

1973

Edinburgh LCF

1977

Larry Paulson: Cambridge LCF

1985

1986

Tobias Nipkow: Isabelle/HOL

1993

1969

1993

(10)

Isabelle Tutorial History

TTY interaction (1979)

(Wikipedia: K. Thompson and D. Ritchie at PDP-11)

(11)

Isabelle Tutorial History

(12)

Isabelle Tutorial History

Document-oriented Prover IDE: Isabelle/jEdit (2015)

(13)

Isabelle Tutorial History

(14)

Isabelle Tutorial

Functional programming

in Isabelle/HOL

(15)

Isabelle Tutorial Functional programming in Isabelle/HOL

Example: Insertion Sort

4

2

2

7

7

5

5

3

3

6

6

6

6

3

3

3

3

6

6

5

5

5

5

6

6

7

7

7

7

2

2

2

2

7

7

2

2

6

6

7

7

2

2

5

5

6

6

7

7

2

2

3

3

5

5

6

6

7

7

4

4

4

4

7

7

4

4

6

6

7

7

4

4

5

5

6

6

7

7

(16)

Isabelle Tutorial Functional programming in Isabelle/HOL

Example: Insertion Sort

4

4

2

2

7

7

5

5

3

3

6

6

6

6

3

3

3

3

6

6

5

5

5

5

6

6

7

7

7

7

2

2

2

2

7

7

2

2

6

6

7

7

2

2

5

5

6

6

7

7

2

2

3

3

5

5

6

6

7

7

4

4

4

4

7

7

4

4

6

6

7

7

4

4

5

5

6

6

7

7

(17)

Isabelle Tutorial Functional programming in Isabelle/HOL

Example: Insertion Sort

4

2

2

7

7

5

5

3

3

6

6

6

6

3

3

3

3

6

6

5

5

5

5

6

6

7

7

7

7

2

2

2

2

7

7

2

2

6

6

7

7

2

2

5

5

6

6

7

7

2

2

3

3

5

5

6

6

7

7

4

4

4

4

7

7

4

4

6

6

7

7

4

4

5

5

6

6

7

7

(18)

Isabelle Tutorial Functional programming in Isabelle/HOL

Example: Insertion Sort

4

4

2

2

7

7

5

5

3

3

6

6

6

6

3

3

3

3

6

6

5

5

5

5

6

6

7

7

7

7

2

2

2

2

7

7

2

2

6

6

7

7

2

2

5

5

6

6

7

7

2

2

3

3

5

5

6

6

7

7

4

4

4

4

7

7

4

4

6

6

7

7

4

4

5

5

6

6

7

7

(19)

Isabelle Tutorial Functional programming in Isabelle/HOL

Example: Insertion Sort

4

2

2

7

7

5

5

3

3

6

6

6

6

3

3

3

3

6

5

5

5

5

6

6

7

7

7

7

2

2

2

2

7

7

2

2

6

6

7

7

2

2

5

5

6

6

7

7

2

2

3

3

5

5

6

6

7

7

4

4

4

4

7

7

4

4

6

6

7

7

4

4

5

5

6

6

7

7

(20)

Isabelle Tutorial Functional programming in Isabelle/HOL

Example: Insertion Sort

4

4

2

2

7

7

5

5

3

3

6

6

6

6

3

3

3

3

6

6

5

5

5

5

6

6

7

7

7

7

2

2

2

2

7

7

2

2

6

6

7

7

2

2

5

5

6

6

7

7

2

2

3

3

5

5

6

6

7

7

4

4

4

4

7

7

4

4

6

6

7

7

4

4

5

5

6

6

7

7

(21)

Isabelle Tutorial Functional programming in Isabelle/HOL

Example: Insertion Sort

4

2

2

7

7

5

5

3

3

6

6

6

6

3

3

3

3

6

5

5

5

6

7

7

7

7

2

2

2

2

7

7

2

2

6

6

7

7

2

2

5

5

6

6

7

7

2

2

3

3

5

5

6

6

7

7

4

4

4

4

7

7

4

4

6

6

7

7

4

4

5

5

6

6

7

7

(22)

Isabelle Tutorial Functional programming in Isabelle/HOL

Example: Insertion Sort

4

4

2

2

7

7

5

5

3

3

6

6

6

6

3

3

3

3

6

6

5

5

5

5

6

6

7

7

7

7

2

2

2

2

7

7

2

2

6

6

7

7

2

2

5

5

6

6

7

7

2

2

3

3

5

5

6

6

7

7

4

4

4

4

7

7

4

4

6

6

7

7

4

4

5

5

6

6

7

7

(23)

Isabelle Tutorial Functional programming in Isabelle/HOL

Example: Insertion Sort

4

2

2

7

7

5

5

3

3

6

6

6

6

3

3

3

3

6

5

5

5

6

7

7

7

2

2

2

7

7

2

2

6

6

7

7

2

2

5

5

6

6

7

7

2

2

3

3

5

5

6

6

7

7

4

4

4

4

7

7

4

4

6

6

7

7

4

4

5

5

6

6

7

7

(24)

Isabelle Tutorial Functional programming in Isabelle/HOL

Example: Insertion Sort

4

4

2

2

7

7

5

5

3

3

6

6

6

6

3

3

3

3

6

6

5

5

5

5

6

6

7

7

7

7

2

2

2

2

7

7

2

2

6

6

7

7

2

2

5

5

6

6

7

7

2

2

3

3

5

5

6

6

7

7

4

4

4

4

7

7

4

4

6

6

7

7

4

4

5

5

6

6

7

7

(25)

Isabelle Tutorial Functional programming in Isabelle/HOL

Example: Insertion Sort

4

2

2

7

7

5

5

3

3

6

6

6

6

3

3

3

3

6

5

5

5

6

6

7

7

7

7

2

2

2

2

7

2

2

6

7

2

2

5

5

6

6

7

7

2

2

3

3

5

5

6

6

7

7

4

4

4

4

7

7

4

4

6

6

7

7

4

4

5

5

6

6

7

7

(26)

Isabelle Tutorial Functional programming in Isabelle/HOL

Example: Insertion Sort

4

4

2

2

7

7

5

5

3

3

6

6

6

6

3

3

3

3

6

6

5

5

5

5

6

6

7

7

7

7

2

2

2

2

7

7

2

2

6

6

7

7

2

2

5

5

6

6

7

7

2

2

3

3

5

5

6

6

7

7

4

4

4

4

7

7

4

4

6

6

7

7

4

4

5

5

6

6

7

7

(27)

Isabelle Tutorial Functional programming in Isabelle/HOL

Example: Insertion Sort

4

2

2

7

7

5

5

3

3

6

6

6

6

3

3

3

3

6

6

5

5

5

5

6

6

7

7

7

7

2

2

2

2

7

2

2

6

7

2

2

5

6

7

2

2

3

5

6

7

4

4

4

4

7

7

4

4

6

6

7

7

4

4

5

5

6

6

7

7

(28)

Isabelle Tutorial Functional programming in Isabelle/HOL

Example: Insertion Sort

4

4

2

2

7

7

5

5

3

3

6

6

6

6

3

3

3

3

6

6

5

5

5

5

6

6

7

7

7

7

2

2

2

2

7

7

2

2

6

6

7

7

2

2

5

5

6

6

7

7

2

2

3

3

5

5

6

6

7

7

4

4

4

4

7

7

4

4

6

6

7

7

4

4

5

5

6

6

7

7

(29)

Isabelle Tutorial Functional programming in Isabelle/HOL

Example: Insertion Sort

4

4

2

2

7

7

5

5

3

3

6

6

6

6

3

3

3

3

6

6

5

5

5

5

6

6

7

7

7

7

2

2

2

2

7

2

2

6

7

2

2

5

6

7

2

2

3

5

6

7

7

4

4

4

7

4

4

6

6

7

7

4

4

5

5

6

6

7

7

(30)

Isabelle Tutorial Functional programming in Isabelle/HOL

Example: Insertion Sort

4

4

2

2

7

7

5

5

3

3

6

6

6

6

3

3

3

3

6

6

5

5

5

5

6

6

7

7

7

7

2

2

2

2

7

7

2

2

6

6

7

7

2

2

5

5

6

6

7

7

2

2

3

3

5

5

6

6

7

7

4

4

4

4

7

7

4

4

6

6

7

7

4

4

5

5

6

6

7

7

(31)

Isabelle Tutorial Functional programming in Isabelle/HOL

Example: Insertion Sort

4

4

2

2

7

7

5

5

3

3

6

6

6

6

3

3

3

3

6

6

5

5

5

5

6

6

7

7

7

7

2

2

2

2

7

2

2

6

7

2

2

5

6

7

2

2

3

5

6

6

7

7

4

4

4

4

7

4

4

6

7

4

5

6

7

(32)

Isabelle Tutorial Functional programming in Isabelle/HOL

A Functional Implementation

inserting an element into a sorted list

insert

::

a

-> [

a

] -> [

a

]

insert x

[]

=

[

x

]

insert x

(

y

:

ys

)

=

if

x

y

then

x

:

y

:

ys

else

y

:

insert x ys

sorting by repeatedly inserting elements into the empty list

insertionSort

:: [

a

] -> [

a

]

insertionSort xs

= foldr

insert

[]

xs

where

foldr

f b

[

x1

,

x2

,

. . .

,

xn

]

=

f x1

(f x2

(

. . .

(f xn

b)

. . .

))

How to prove correctness?

=

Isabelle/HOL

(33)

Isabelle Tutorial Functional programming in Isabelle/HOL

A Functional Implementation

inserting an element into a sorted list

insert

::

a

-> [

a

] -> [

a

]

insert x

[]

=

[

x

]

insert x

(

y

:

ys

)

=

if

x

y

then

x

:

y

:

ys

else

y

:

insert x ys

sorting by repeatedly inserting elements into the empty list

insertionSort

:: [

a

] -> [

a

]

insertionSort xs

= foldr

insert

[]

xs

where

foldr

f b

[

x1

,

x2

,

. . .

,

xn

]

=

f x1

(f x2

(

. . .

(f xn

b)

. . .

))

How to prove correctness?

(34)

Isabelle Tutorial Functional programming in Isabelle/HOL

A Functional Implementation

inserting an element into a sorted list

insert

::

a

-> [

a

] -> [

a

]

insert x

[]

=

[

x

]

insert x

(

y

:

ys

)

=

if

x

y

then

x

:

y

:

ys

else

y

:

insert x ys

sorting by repeatedly inserting elements into the empty list

insertionSort

:: [

a

] -> [

a

]

insertionSort xs

= foldr

insert

[]

xs

where

foldr

f b

[

x1

,

x2

,

. . .

,

xn

]

=

f x1

(f x2

(

. . .

(f xn

b)

. . .

))

How to prove correctness?

=

Isabelle/HOL

(35)

Isabelle Tutorial Functional programming in Isabelle/HOL

A Functional Implementation

inserting an element into a sorted list

insert

::

a

-> [

a

] -> [

a

]

insert x

[]

=

[

x

]

insert x

(

y

:

ys

)

=

if

x

y

then

x

:

y

:

ys

else

y

:

insert x ys

sorting by repeatedly inserting elements into the empty list

insertionSort

:: [

a

] -> [

a

]

insertionSort xs

= foldr

insert

[]

xs

where

(36)

Isabelle Tutorial

Isabelle/HOL proof tools

(37)

Isabelle Tutorial Isabelle/HOL proof tools

Sledgehammer

heavy external ATPs / SMTs for

proof search

light internal ATP (Metis) for

proof reconstruction

(38)

Isabelle Tutorial Isabelle/HOL proof tools

Automated disprovers — counter examples

nitpick

based on

relational model finder

quickcheck

based on

random functional evaluation

(39)

Isabelle Tutorial Isabelle/HOL proof tools

Isabelle/HOL proof methods

rule: generic Natural Deduction (with HO unification)

cases: elimination, syntactic representation of datatypes,

inversion of inductive sets and predicates

induct

and

coinduct: induction and coinduction of types, sets,

predicates

simp: equational reasoning by the Simplifier (HO rewriting),

with possibilities for add-on tools

fast

and

blast: classical reasoning (tableau)

auto

and

force: combined simplification and classical reasoning

arith,

presburger: specific theories

(40)

Isabelle Tutorial

Theory specifications

(41)

Isabelle Tutorial Theory specifications

Types

augmented version of

Simple Theory of Types

(Church 1940)

schematic

polymorphism

(weaker than ML let-polymorphism)

basic types:

bool,

nat,

0

a

0

b

(full function space)

Type specifications:

typedef

semantic subtype of existing type

quotient_type

wrt. equivalence relation or PER

record

extensible records (glorified tuples)

datatype

and

codatatype

(Bounded Natural Functors)

datatype

0

a list

=

Nil

|

Cons

(

hd

:

0

a

) (

tl

:

0

a list

)

(42)

Isabelle Tutorial Theory specifications

Functions and constants

abbreviation

:

abstract syntax

definitions

abbreviation

(

input

)

double

::

nat

nat

where

double n

2

n

definition

: simple

non-recursive

definitions

definition

square

::

nat

nat

where

square n

=

n

n

fun

and

function

/

termination

:

general recursion

with

implicit or explicit termination proof

fun

fibonacci

::

nat

nat

where

fibonacci 0

=

0

|

fibonacci

(

Suc 0

) =

1

|

fibonacci

(

Suc

(

Suc n

)) =

fibonacci n

+

fibonacci

(

Suc n

)

(43)

Isabelle Tutorial Theory specifications

Inductive predicates and sets

inductive

and

coinductive

: Knaster-Tarski fixed-points over

predicates or sets

inductive_set

star

(

_

?

[

100

]

100

)

for

R

:: (

0

a

×

0

a

)

set

where

base

: (

x

,

x

)

R

?

|

step

: (

x

,

y

)

R

=

(

y

,

z

)

R

?

=

(

x

,

z

)

R

?

This means

R

?

is the least relation (set of pairs) that is closed under the

introduction rules

above. The following

induction rule

is provided:

(

x1

,

x2

)

R

?

=

(

V

(44)

Isabelle Tutorial Theory specifications

Type classes

Predicate over

constant signature

with

single type-variable

Integrated into type-system:

order-sorted algebra

of

constraints

Class intersections are called

sorts

Class inclusion

hierarchy: by definition or proof

Class instantiation by

concrete types

class

zero

=

fixes

zero

::

0

a

(

0

)

class

one

=

fixes

one

::

0

a

(

1

)

class

times

=

fixes

times

::

0

a

0

a

0

a

(infixl

70

)

class

group

=

times

+

one

+

inverse

+

assumes

group_assoc

: (

x

y

)

z

=

x

(

y

z

)

and

group_left_one

:

1

x

=

x

and

group_left_inverse

:

inverse x

x

=

1

(45)

Isabelle Tutorial Theory specifications

Example: class hierarchy

(46)

Isabelle Tutorial

Code generation

(47)

Isabelle Tutorial Code generation

HOL (with type classes)

Mini-Haskell

Standard ML

Haskell

. . .

source language

intermediate language

target language

sound, provided target language has

rewriting semantics

(i.e. evaluation [s

]

[t] implies

s

=

t

in HOL)

representation of HOL term

s

in target language

(48)

Isabelle Tutorial Code generation

HOL (with type classes)

Mini-Haskell

Standard ML

Haskell

. . .

source language

intermediate language

target language

sound, provided target language has

rewriting semantics

(i.e. evaluation [s

]

[t] implies

s

=

t

in HOL)

representation of HOL term

s

in target language

only partial correctness (generated functions might diverge)

(49)

Isabelle Tutorial Code generation

HOL (with type classes)

Mini-Haskell

Standard ML

Haskell

. . .

source language

intermediate language

target language

sound, provided target language has

rewriting semantics

(i.e. evaluation [s

]

[t] implies

s

=

t

in HOL)

(50)

Isabelle Tutorial Code generation

Code equations

specify how to “interpret” constants in generated code

registered and modified via attribute

code

provided automatically by many commands:

definition

,

fun

,

function

etc.

Triggering code generation

specify

where

and in what

target language

code

should be generated for given

constants

export_code

Example

export_code

rev

in

SML (*file "/tmp/rev.ML"*)

(51)

Isabelle Tutorial Code generation

Code equations

specify how to “interpret” constants in generated code

registered and modified via attribute

code

provided automatically by many commands:

definition

,

fun

,

function

etc.

Triggering code generation

specify

where

and in what

target language

code

should be generated for given

constants

export_code

(52)

Isabelle Tutorial

Structured proofs:

Isabelle/Isar

(53)

Isabelle Tutorial Structured proofs: Isabelle/Isar

Atomic proofs

Skipped proofs:

sorry

Single-step proofs:

by

fact

by

this

.

by

rule

..

Automated proofs:

by

auto

by

simp

(54)

Isabelle Tutorial Structured proofs: Isabelle/Isar

Goal refinement

Canonical double-step:

have

prop

by

(initial_method) (terminal_method)

or:

have

prop

proof

(initial_method)

qed

(terminal_method)

Structured proof body:

have

prop

have

prop

proof

(initial_method)

proof

(initial_method)

fix

vars

case

(case_name vars)

assume

props

show

prop

h

proof

i

show

prop

h

proof

i

qed

(terminal_method)

qed

(terminal_method)

(55)

Isabelle Tutorial Structured proofs: Isabelle/Isar

Using facts

Goal statement with facts:

from

facts

1

have

prop

using

facts

2

proof

(initial_method)

body

qed

(terminal_method)

initial_method

sees

facts

1

facts

2

as primary argument

actual use of facts depends on proof method,

e.g.

rule,

cases,

induct,

auto

Abbreviations and synonyms:

(56)

Isabelle Tutorial Structured proofs: Isabelle/Isar

Example

notepad

begin

fix

A B

::

bool

have

A

B

−→

B

A

proof

(

rule impI

)

assume

:

A

B

show

B

A

proof

(

rule conjI

)

from

show

B

by

(

rule conjunct2

)

from

show

A

by

(

rule conjunct1

)

qed

qed

end

(57)

Isabelle Tutorial Structured proofs: Isabelle/Isar

Context elements

Universal context:

fix

and

assume

{

fix

x

have

B x

sorry

}

have

V

x

.

B x

by

fact

{

assume

A

have

B

sorry

}

have

A

=

B

by

fact

Existential context:

obtain

{

obtain

a

where

B a

sorry

have

C

sorry

(58)

Isabelle Tutorial Structured proofs: Isabelle/Isar

Structured statements

prefix of

context elements:

fixes

,

assumes

, . . .

regular

conclusion

shows

dual conclusion

obtains

— “may assume that . . . ”

theorem

intro

:

fixes

a

::

0

a

and

B

::

0

a

bool

assumes

B a

shows

x

.

B x

theorem

elim

:

fixes

B

::

0

a

bool

assumes

x

.

B x

obtains

a

::

0

a

where

B a

useful diagnostic command:

print_statement

References

Related documents

During this visit, the expert group interviewed a large number of relevant people, including children and parents who experienced the practices first hand, but

In the event that subscribing shareholders are corporate shareholders, and if the monetary amount to be received via this Tender Offer exceeds the portion of the tender

Most IAD concepts share a number of common elements: inflatable elements (e.g., toroids, cylinders, and/or spheres), gores (e.g., front cover), and radial straps.

Timothy (2020)Evaluation of Wearable Electronics for Epilepsy: A

The parameters of clients into Clients of special category (as given below) may be classified as higher risk.. and higher degree of due diligence and regular update of KYC

The FEDERAL REGISTER (ISSN 0097–6326) is published daily, Monday through Friday, except official holidays, by the Office of the Federal Register, National Archives and

on behalf of Debtor TriVascular Sales LLC [email protected] [email protected];[email protected] Andrew Ball Zollinger.. on behalf of

The two main aims of this study were to present a tumor-specific, national real-world data cohort (as opposed to clinical trials data) of children and adolescents