• Keine Ergebnisse gefunden

Extension: IMP plus arrays

N/A
N/A
Protected

Academic year: 2022

Aktie "Extension: IMP plus arrays"

Copied!
4
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

8. Program Verification 8.4 Program verification with Isabelle/HOL

Extension: IMP plus arrays

Case study:

To illustrate a more realistic example, we

• extend IMP by arrays

• extend the Hoare logic appropriately

• verify the splitting step according to the program and specification given in the introduction

See » HoareIMParray.thy

©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 476

8. Program Verification 8.5 Software verification tools

Section 8.5

Software verification tools

©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 477

8. Program Verification 8.5 Software verification tools

Overview

Considered techniques and tools:

• Embedding programming into HO interactive theorem proving (e.g., theory Simpl.thy written in Isabelle/HOL)

• Tools for interactive software verification (e.g., KeY, Why)

• Extended static checking (e.g., Spec#, Chalice, VeriFast)

• Specification and refinement (e.g., Event B, KIV)

• Automated theorem proving, in particular:

I

Superposition provers (e.g., SPASS, E)

I

SMT solvers and model checkers (e.g., Z3, SPIN)

©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 478

8. Program Verification 8.5 Software verification tools

Subsection 8.5.1

Embedding programming into HO interactive theorem proving

©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 479

(2)

8. Program Verification 8.5 Software verification tools

General approach

• Specify programming language syntax and semantics in an interactive theorem prover for HOL

• Use HOL as specification language for program properties

• Use the HOL proof system for verification

©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 480

8. Program Verification 8.5 Software verification tools

Example: Verifying Simpl programs

Simpl (by N. Schirmer [Archives of formal proofs]):

A sequential imperative programming language:

• mutually recursive procedures

• abrupt termination and exceptions

• runtime faults

• local and global variables

• pointers and heaps

• expressions with side-effects

• pointers to procedures

• partial application and closures

• dynamic method invocation

• unbounded nondeterminism

©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 481

8. Program Verification 8.5 Software verification tools

Example program: Quicksort on heap lists

Illustrating:

• Handling of programming language aspects:

I

recursive procedures

I

local and global variables

I

pointers and heaps

• Handling of specification aspects:

I

heap-manipulation using abstraction

I

frame properties

• Problems of embedding

©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 482

8. Program Verification 8.5 Software verification tools

Modeling of a program specific state

Heap for singly-linked lists (sll-heaps):

record globals_heap = next_ ’ :: "ref ⇒ ref"

cont_ ’ :: "ref ⇒ nat"

A predicate to abstract sll-heaps:

primrec List :: ref ⇒ ( ref ⇒ ref ) ⇒ ref list ⇒ bool where

List x h [] = (x = Null) |

List x h (p #ps ) = (x = p ∧ x , Null ∧ List (h x) h ps)

©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 483

(3)

8. Program Verification 8.5 Software verification tools

Modeling of a program specific state (2)

The variables for procedures append and quickSort record ’g vars = "’g state " +

p_’ :: "ref "

q_’ :: "ref "

le_ ’ :: "ref "

gt_ ’ :: "ref "

hd_ ’ :: "ref "

tl_ ’ :: "ref "

©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 484

8. Program Verification 8.5 Software verification tools

Implementation and specification of procedure append

procedures append(p ,q |p) =

"IF ´p= Null THEN ´p :== ´q

ELSE ´p → ´next :== CALL append ( ´p → ´next , ´q) FI"

append_spec :

" ∀ σ Ps Qs. Γ `

{ σ. List ´p ´next Ps ∧ List ´q ´next Qs ∧ set Ps ∩ set Qs = {} }

´p :== PROC append ( ´p, ´q) { List ´p ´next (Ps@ Qs) ∧

( ∀ x. x < set Ps −→ ´next x =

σ

next x) }"

append_modifies :

" ∀ σ. Γ `

{ σ } ´p :== PROC append ( ´ p, ´q)

{ t. t may_only_modify_globals σ in [next] }"

©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 485

8. Program Verification 8.5 Software verification tools

Implementation of procedure quickSort

procedures quickSort (p| p) =

"IF ´p= Null THEN SKIP

ELSE ´tl :== ´p → ´next ;; ´le :== Null ;; ´gt :== Null ;;

WHILE ´tl,Null DO

´hd :== ´tl;; ´tl :== ´tl → ´next ;;

IF ´hd → ´cont ≤ ´p → ´cont

THEN ´hd → ´next :== ´le;; ´le :== ´hd ELSE ´hd → ´next :== ´gt;; ´gt :== ´hd FI

OD;;

´le :== CALL quickSort ( ´le);;

´gt :== CALL quickSort ( ´gt);;

´p → ´next :== ´gt;;

´le :== CALL append ( ´le , ´p);;

´p :== ´le FI"

©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 486

8. Program Verification 8.5 Software verification tools

Specification of procedure quickSort

quickSort_spec:

" ∀ σ Ps. Γ `

{ σ. List ´p ´next Ps }

´p :== PROC quickSort ( ´p)

{ ( ∃ sortedPs . List ´p ´next sortedPs ∧ sorted (op ≤ ) (map

σ

cont sortedPs ) ∧ Ps <~~> sortedPs ) ∧

( ∀ x. x < set Ps −→ ´next x =

σ

next x) }"

quickSort_modifies:

" ∀ σ. Γ ` { σ }

´p :== PROC quickSort ( ´p)

{ t. t may_only_modify_globals σ in [next] }"

©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 487

(4)

8. Program Verification 8.5 Software verification tools

Discussion of embedding approach

• Advantages:

I

powerful specification language and reasoning support

I

flexible for experimenting with languages

I

meta-logical aspects can be handled

• Disadvantages:

I

handling (realistic) programs can be a bit cumbersome

I

realizing convenient IDEs expensive

©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 488

8. Program Verification 8.5 Software verification tools

Subsection 8.5.2

Tools for interactive software verification

©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 489

8. Program Verification 8.5 Software verification tools

General approach

• Programming-language-specific front end/development environment

• Programming-language-specific specification language

• Verification condition generator (VCG)

• Possibly several provers to discharge the VCs (automated and/or interactive)

©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 490

8. Program Verification 8.5 Software verification tools

Example systems

• KeY: http://www.key-project.org/

I

programming language: JavaCard; specifications in JML

I

based on an interactive prover for dynamic logic

I

makes extensive use of symbolic evaluation

• Why, Why3: http://why.lri.fr/

I

programming languages: Java subset, C subset

I

specific specification languages

I

general-purpose verification condition generator

I

uses many interactive and automated provers

©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 491

Referenzen

ÄHNLICHE DOKUMENTE

3 If an integer literal cannot be represented by any type in its list and an extended integer type (3.9.1) can represent its value, it may have that extended integer type. If all of

If a function template declaration in namespace scope has the same name, parameter-type-list, return type, and template parameter list as a function template introduced by

If a function template declaration in namespace scope has the same name, parameter-type-list, return type, and template parameter list as a function template introduced by

3 If an integer literal cannot be represented by any type in its list and an extended integer type (3.9.1) can represent its value, it may have that extended integer type. If all of

Schneide die Zweige schräg an, lass dir von einem Erwachsenen helfen. Überflüssige

Modern language learning courses are no longer exclusively based on books or face-to-face lectures. More and more lessons make use of multimedia and personalized learning methods.

The challenge of specifying a visual programming language on diverging mobile platforms truly demands new and different approaches. Using Cucumber to com- pose

All these data sets give us images paired with natural language expressions; in most of them, the relation between image and expression is annotated more fine-grainedly by