• Aucun résultat trouvé

Automated Software Verification

N/A
N/A
Protected

Academic year: 2022

Partager "Automated Software Verification"

Copied!
75
0
0

Texte intégral

(1)

Automated Software Verification

Ahmed Bouajjani

Université Paris Diderot

(2)

Development of our modern life

<==>

Increasing need of automated services

Introduction

(3)

Development of our modern life

<==>

Increasing need of automated services

==>

Computers systems are ubiquitous, handling critical tasks

Introduction

(4)

Development of our modern life

<==>

Increasing need of automated services

==>

Computers systems are ubiquitous, handling critical tasks

==>

Complex systems, hard to get right

==>

Misbehaviors have inacceptable consequences

Introduction

(5)

Development of our modern life

<==>

Increasing need of automated services

==>

Computers systems are ubiquitous, handling critical tasks

==>

Complex systems, hard to get right

==>

Misbehaviors have inacceptable consequences

==>

Need of principled methods of their design and verification

Introduction

(6)

Development of our modern life

<==>

Increasing need of automated services

==>

Computers systems are ubiquitous, handling critical tasks

==>

Complex systems, hard to get right

==>

Misbehaviors have inacceptable consequences

==>

Need of principled methods of their design and verification

==>

- Formal methods for modeling and specification - Automated verification methods and techniques

Introduction

(7)

Development of our modern life

<==>

Increasing need of automated services

==>

Computers systems are ubiquitous, handling critical tasks

==>

Complex systems, hard to get right

==>

Misbehaviors have inacceptable consequences

==>

Need of principled methods of their design and verification

==>

- Formal methods for modeling and specification - Automated verification methods and techniques Widely used in industry:

- Transportation, energy: safety critical systems

- (hard/soft)ware ind. (Intel, IBM, ARM, Microsoft, Facebook, Amazone WS,

Introduction

(8)

Formal Modeling and Specification

• Languages with precise semantics.

• Allow precise communication between

– the user and the designer(s)

– the designer(s) and the developper(s)

• Allow rigorous reasoning and behaviors

– Precise meaning of behaviors

– Precise meaning of equivalence/refinement

– Precise meaning of correctness

(9)

Abstraction/Refinement

• The design starts at a high level of abstraction using formal models and specifications.

• Refinement steps are needed until reaching a concrete, optimized, executable code.

• Each step must be validated.

• Early detection of design errors is important!

(Their repair at late stages is hard and

expansive)

(10)

Systems and their Properties

• Various formalisms depending on the abstraction level, the class of systems, and their desired

properties.

• Classes of programs:

– Functional programs

– Sequential imperative programs

– Reactive/parallel/concurrent programs

• Properties:

– Partial correctness (correct when it terminates) – Termination

– Safety/liveness properties

(11)

Models and Specification languages

• Transformation of data:

– Model: Function of a data domain.

– Specification: Input-output relation.

• Transformation of memory states

– Model: State machine.

– Specification: Assertions on initial-final states.

• Interaction between concurrent processes

– Model: Parallel state machines.

– Specification: Assertions about sequences of states.

(12)

Several approaches

• Testing

– Applicable to the executable code

– Cannot ensure exploration of all behaviors – Sometimes, the only applicable approach

• Automated theorem proving

– Uses general logic-based framework and proof systems – Requires ingenuity from the user (the verifier)

– Allows to reason at different levels of abstraction

• Algorithmic verification (model checking)

– Use abstract operational models and decision procedures

– Less generality than Theorem Proving but more automation

– Useful in many practical cases

(13)

Goal of this course

• Introduce to abstract reasoning about program behaviors.

• We care in this course more about program semantics and correctness than about program complexity

(performances).

• Notion of formal specification, implementation, proof of correctness of an implementation w.r.t. a specification.

• Verification approaches for basic classes of programs

and properties.

(14)

Contents

• Data Manipulating Programs

• Reactive Systems

- Abstract data types

- Functional programs, recursion

- Imperative programs, pre/post-condition reasoning

- Communication, concurrency - Model-checking

- Abstract analysis

(15)

Theme 1: Abstract Reasoning

Lecture 1: Abstract Data Types & Recursive Functions

Ahmed Bouajjani

Paris Diderot University – Paris 7

January 2014

(16)

Data manipulation

Programs transform data

They implement functions between inputs and outputs

Examples of data domains: Booleans, Characters, Integers, Reals, Strings, Lists, Trees, etc.

A function has a type (domain and co-domain): f :D1⇥· · ·⇥Dn!D Examples:

^ : Boolean⇥Boolean!Boolean + : Nat ⇥Nat !Nat

Sort : List[Nat]!List[Nat]

Types must be given precisely. This avoids many errors.

(17)

Data manipulation

Programs transform data

They implement functions between inputs and outputs

Examples of data domains: Booleans, Characters, Integers, Reals, Strings, Lists, Trees, etc.

A function has a type (domain and co-domain):

f :D1⇥· · ·⇥Dn !D Examples:

^ : Boolean⇥Boolean!Boolean + : Nat ⇥Nat !Nat

Sort : List[Nat]!List[Nat]

Types must be given precisely. This avoids many errors.

(18)

Data manipulation

Programs transform data

They implement functions between inputs and outputs

Examples of data domains: Booleans, Characters, Integers, Reals, Strings, Lists, Trees, etc.

A function has a type (domain and co-domain):

f :D1⇥· · ·⇥Dn !D Examples:

^ : Boolean⇥Boolean!Boolean + : Nat ⇥Nat !Nat

Sort : List[Nat]!List[Nat]

Types must be given precisely. This avoids many errors.

(19)

Defining Functions

Finite data domains: Enumeration of its values Example:

0^0 = 0 0^1 = 0 1^0 = 0 1^1 = 1

Not always practical, but possible in theory

A more compact definition using a conditional construct: x^y = (ifx= 0then0elsey)

How to write functions over infinite domains ? We need more powerful constructs

We need to give a structure to infinite data domains

(20)

Defining Functions

Finite data domains: Enumeration of its values Example:

0^0 = 0 0^1 = 0 1^0 = 0 1^1 = 1 Not always practical, but possible in theory

A more compact definition using a conditional construct:

x^y = (ifx= 0then0elsey)

How to write functions over infinite domains ? We need more powerful constructs

We need to give a structure to infinite data domains

(21)

Defining Functions

Finite data domains: Enumeration of its values Example:

0^0 = 0 0^1 = 0 1^0 = 0 1^1 = 1 Not always practical, but possible in theory

A more compact definition using a conditional construct:

x^y = (ifx= 0then0elsey)

How to write functions over infinite domains ?

We need more powerful constructs

We need to give a structure to infinite data domains

(22)

Defining Functions

Finite data domains: Enumeration of its values Example:

0^0 = 0 0^1 = 0 1^0 = 0 1^1 = 1 Not always practical, but possible in theory

A more compact definition using a conditional construct:

x^y = (ifx= 0then0elsey)

How to write functions over infinite domains ? We need more powerful constructs

We need to give a structure to infinite data domains

(23)

Inductive Definition of (Potentially Infinite) Sets

An element (object) is either basic or constructed from other objects.

A set is defined by a set of constants and a set of constructors Example: The set Nat of natural numbers

I Constant:

0 :Nat

I Constructor:

s:Nat!Nat

Example of elements ofNat:

0,s(0),s(s(0)),s(s(s(0))), ... Notation: n abbreviates sn(0)

(24)

Inductive Definition of (Potentially Infinite) Sets

An element (object) is either basic or constructed from other objects.

A set is defined by a set of constants and a set of constructors Example: The set Nat of natural numbers

I Constant:

0 :Nat

I Constructor:

s:Nat!Nat

Example of elements ofNat:

0,s(0),s(s(0)),s(s(s(0))), ... Notation: n abbreviates sn(0)

(25)

Inductive Definition of (Potentially Infinite) Sets

An element (object) is either basic or constructed from other objects.

A set is defined by a set of constants and a set of constructors Example: The set Nat of natural numbers

I Constant:

0 :Nat

I Constructor:

s:Nat!Nat

Example of elements ofNat:

0,s(0),s(s(0)),s(s(s(0))), ...

Notation: n abbreviates sn(0)

(26)

The General Schema

Given a set of constants C ={c1,· · ·,cm},

Given a set of constructors of the form↵:Dn⇥A!D The set of element ofD is the smallest set such that:

I CD

I For every constructor:DnA!D, for everyd1, . . . ,dn2D, and everya2A,↵(d1, . . . ,dn,a)2D

(27)

The Domain of Lists

Examples of lists:

I [2; 5; 8; 5] list of natural numbers

I [p;a;r;i;s] list of characters

I [[0; 2]; [2; 5; 2; 0]] list of lists of natural numbers

The domain List[?] parametrized by a domain?:

I Constant:

[] :List[?]

I Left-concatenation:

· : ?List[?]!List[?] Examples:

I 0·[] = [0]

I 2·(5·(8·(5·[]))) = 2·5·8·5·[] = [2; 5; 8; 5]

I (0·[])·[] = [[0]]

I []·[] = [[]]6= []

I (0·[])·((2·[])·[]) = [[0]; [2]]

(28)

The Domain of Lists

Examples of lists:

I [2; 5; 8; 5] list of natural numbers

I [p;a;r;i;s] list of characters

I [[0; 2]; [2; 5; 2; 0]] list of lists of natural numbers The domain List[?] parametrized by a domain?:

I Constant:

[] :List[?]

I Left-concatenation:

· : ?List[?]!List[?]

Examples:

I 0·[] = [0]

I 2·(5·(8·(5·[]))) = 2·5·8·5·[] = [2; 5; 8; 5]

I (0·[])·[] = [[0]]

I []·[] = [[]]6= []

I (0·[])·((2·[])·[]) = [[0]; [2]]

(29)

The Domain of Lists

Examples of lists:

I [2; 5; 8; 5] list of natural numbers

I [p;a;r;i;s] list of characters

I [[0; 2]; [2; 5; 2; 0]] list of lists of natural numbers The domain List[?] parametrized by a domain?:

I Constant:

[] :List[?]

I Left-concatenation:

· : ?List[?]!List[?]

Examples:

I 0·[] = [0]

I 2·(5·(8·(5·[]))) = 2·5·8·5·[] = [2; 5; 8; 5]

(30)

Defining functions over inductively defined sets

Let f :Nat !D. Define f(x), for every x2Nat.

Case spitting using the structure of the elements

I f(0) = ?

I f(s(x)) = ?

Inductive definition (Recursion)

Define f(s(x))assuming that we know how to compute f(x) Similar to proofs using structural induction

Prove P(0), and prove that P(s(x))holds assuming P(x).

(31)

Defining functions over inductively defined sets

Let f :Nat !D. Define f(x), for every x2Nat.

Case spitting using the structure of the elements

I f(0) = ?

I f(s(x)) = ?

Inductive definition (Recursion)

Define f(s(x))assuming that we know how to compute f(x)

Similar to proofs using structural induction

Prove P(0), and prove that P(s(x))holds assuming P(x).

(32)

Defining functions over inductively defined sets

Let f :Nat !D. Define f(x), for every x2Nat.

Case spitting using the structure of the elements

I f(0) = ?

I f(s(x)) = ?

Inductive definition (Recursion)

Define f(s(x))assuming that we know how to compute f(x) Similar to proofs using structural induction

Prove P(0), and prove that P(s(x))holds assuming P(x).

(33)

Recursion: An Example

Addition + :Nat⇥Nat !Nat

Recursive definition

0 +x = x

s(x1) +x2 = s(x1+x2) Computation

s(s(0)) +s(0) = s(s(0) +s(0))

= s(s(0 +s(0)))

= s(s(s(0)))

(34)

Recursion: An Example

Addition + :Nat⇥Nat !Nat Recursive definition

0 +x = x

s(x1) +x2 = s(x1+x2)

Computation

s(s(0)) +s(0) = s(s(0) +s(0))

= s(s(0 +s(0)))

= s(s(s(0)))

(35)

Recursion: An Example

Addition + :Nat⇥Nat !Nat Recursive definition

0 +x = x

s(x1) +x2 = s(x1+x2) Computation

s(s(0)) +s(0) = s(s(0) +s(0))

= s(s(0 +s(0)))

= s(s(s(0)))

(36)

Recursion: Another Example

Append function @ :List[?]⇥List[?]!List[?]

Example: [2; 5; 7]@[1; 5] = [2; 5; 7; 1; 5]

Recursive definition

[]@` =

`

(a·`1)@`2 =

a·(`1@`2)

Computation:

(2·5·7·[])@(1·5·[]) = 2·((5·7·[])@(1·5·[]))

= 2·5·((7·[])@(1·5·[]))

= 2·5·7·([]@(1·5·[]))

= 2·5·7·1·5·[]

(37)

Recursion: Another Example

Append function @ :List[?]⇥List[?]!List[?]

Example: [2; 5; 7]@[1; 5] = [2; 5; 7; 1; 5]

Recursive definition

[]@` =

`

(a·`1)@`2 =

a·(`1@`2) Computation:

(2·5·7·[])@(1·5·[]) = 2·((5·7·[])@(1·5·[]))

= 2·5·((7·[])@(1·5·[]))

= 2·5·7·([]@(1·5·[]))

= 2·5·7·1·5·[]

(38)

Recursion: Another Example

Append function @ :List[?]⇥List[?]!List[?]

Example: [2; 5; 7]@[1; 5] = [2; 5; 7; 1; 5]

Recursive definition

[]@` = ` (a·`1)@`2 =

a·(`1@`2) Computation:

(2·5·7·[])@(1·5·[]) = 2·((5·7·[])@(1·5·[]))

= 2·5·((7·[])@(1·5·[]))

= 2·5·7·([]@(1·5·[]))

= 2·5·7·1·5·[]

(39)

Recursion: Another Example

Append function @ :List[?]⇥List[?]!List[?]

Example: [2; 5; 7]@[1; 5] = [2; 5; 7; 1; 5]

Recursive definition

[]@` = `

(a·`1)@`2 = a·(`1@`2)

Computation:

(2·5·7·[])@(1·5·[]) = 2·((5·7·[])@(1·5·[]))

= 2·5·((7·[])@(1·5·[]))

= 2·5·7·([]@(1·5·[]))

= 2·5·7·1·5·[]

(40)

Recursion: Another Example

Append function @ :List[?]⇥List[?]!List[?]

Example: [2; 5; 7]@[1; 5] = [2; 5; 7; 1; 5]

Recursive definition

[]@` = `

(a·`1)@`2 = a·(`1@`2) Computation:

(2·5·7·[])@(1·5·[]) = 2·((5·7·[])@(1·5·[]))

= 2·5·((7·[])@(1·5·[]))

= 2·5·7·([]@(1·5·[]))

= 2·5·7·1·5·[]

(41)

Composition: Functions can call other functions

Multiplication ⇤:Nat⇥Nat !Nat

Recursive definition

0⇤x =

0

s(x1)⇤x2 =

(x1⇤x2) +x2

Computation

s2(0)⇤s3(0) = (s(0)⇤s3(0)) +s3(0)

= ((0⇤s3(0)) +s3(0)) +s3(0)

= (0 +s3(0)) +s3(0)

= s3(0) +s3(0) =s(s2(0)) +s3(0)

= s(s2(0) +s3(0))

= s(s(s(0) +s3(0)))

= s(s(s(0 +s3(0))))

= s(s(s(s3(0)))) =s6(0)

(42)

Composition: Functions can call other functions

Multiplication ⇤:Nat⇥Nat !Nat Recursive definition

0⇤x =

0

s(x1)⇤x2 =

(x1⇤x2) +x2

Computation

s2(0)⇤s3(0) = (s(0)⇤s3(0)) +s3(0)

= ((0⇤s3(0)) +s3(0)) +s3(0)

= (0 +s3(0)) +s3(0)

= s3(0) +s3(0) =s(s2(0)) +s3(0)

= s(s2(0) +s3(0))

= s(s(s(0) +s3(0)))

= s(s(s(0 +s3(0))))

= s(s(s(s3(0)))) =s6(0)

(43)

Composition: Functions can call other functions

Multiplication ⇤:Nat⇥Nat !Nat Recursive definition

0⇤x = 0 s(x1)⇤x2 =

(x1⇤x2) +x2

Computation

s2(0)⇤s3(0) = (s(0)⇤s3(0)) +s3(0)

= ((0⇤s3(0)) +s3(0)) +s3(0)

= (0 +s3(0)) +s3(0)

= s3(0) +s3(0) =s(s2(0)) +s3(0)

= s(s2(0) +s3(0))

= s(s(s(0) +s3(0)))

= s(s(s(0 +s3(0))))

= s(s(s(s3(0)))) =s6(0)

(44)

Composition: Functions can call other functions

Multiplication ⇤:Nat⇥Nat !Nat Recursive definition

0⇤x = 0

s(x1)⇤x2 = (x1⇤x2) +x2

Computation

s2(0)⇤s3(0) = (s(0)⇤s3(0)) +s3(0)

= ((0⇤s3(0)) +s3(0)) +s3(0)

= (0 +s3(0)) +s3(0)

= s3(0) +s3(0) =s(s2(0)) +s3(0)

= s(s2(0) +s3(0))

= s(s(s(0) +s3(0)))

= s(s(s(0 +s3(0))))

= s(s(s(s3(0)))) =s6(0)

(45)

Composition: Functions can call other functions

Multiplication ⇤:Nat⇥Nat !Nat Recursive definition

0⇤x = 0

s(x1)⇤x2 = (x1⇤x2) +x2

Computation

s2(0)⇤s3(0) = (s(0)⇤s3(0)) +s3(0)

= ((0⇤s3(0)) +s3(0)) +s3(0)

= (0 +s3(0)) +s3(0)

= s3(0) +s3(0) =s(s2(0)) +s3(0)

= s(s2(0) +s3(0))

= s(s(s(0) +s3(0)))

(46)

Composition: Another Example

Factorial function fact:Nat !Nat

Recursive definition

fact(0) =

s(0)

fact(s(x)) =

s(x)⇤fact(x)

Computation

fact(s(s(0))) = s(s(0))⇤fact(s(0))

= s(s(0))⇤(s(0)⇤fact(0))

= s(s(0))⇤(s(0)⇤s(0))

= s(0)⇤(s(0)⇤s(0)) +s(0)⇤s(0)

= 0⇤(s(0)⇤s(0)) +s(0)⇤s(0) +s(0)⇤s(0)

= ...

(47)

Composition: Another Example

Factorial function fact:Nat !Nat Recursive definition

fact(0) =

s(0)

fact(s(x)) =

s(x)⇤fact(x) Computation

fact(s(s(0))) = s(s(0))⇤fact(s(0))

= s(s(0))⇤(s(0)⇤fact(0))

= s(s(0))⇤(s(0)⇤s(0))

= s(0)⇤(s(0)⇤s(0)) +s(0)⇤s(0)

= 0⇤(s(0)⇤s(0)) +s(0)⇤s(0) +s(0)⇤s(0)

= ...

(48)

Composition: Another Example

Factorial function fact:Nat !Nat Recursive definition

fact(0) = s(0) fact(s(x)) =

s(x)⇤fact(x) Computation

fact(s(s(0))) = s(s(0))⇤fact(s(0))

= s(s(0))⇤(s(0)⇤fact(0))

= s(s(0))⇤(s(0)⇤s(0))

= s(0)⇤(s(0)⇤s(0)) +s(0)⇤s(0)

= 0⇤(s(0)⇤s(0)) +s(0)⇤s(0) +s(0)⇤s(0)

= ...

(49)

Composition: Another Example

Factorial function fact:Nat !Nat Recursive definition

fact(0) = s(0)

fact(s(x)) = s(x)⇤fact(x)

Computation

fact(s(s(0))) = s(s(0))⇤fact(s(0))

= s(s(0))⇤(s(0)⇤fact(0))

= s(s(0))⇤(s(0)⇤s(0))

= s(0)⇤(s(0)⇤s(0)) +s(0)⇤s(0)

= 0⇤(s(0)⇤s(0)) +s(0)⇤s(0) +s(0)⇤s(0)

= ...

(50)

Composition: Another Example

Factorial function fact:Nat !Nat Recursive definition

fact(0) = s(0)

fact(s(x)) = s(x)⇤fact(x) Computation

fact(s(s(0))) = s(s(0))⇤fact(s(0))

= s(s(0))⇤(s(0)⇤fact(0))

= s(s(0))⇤(s(0)⇤s(0))

= s(0)⇤(s(0)⇤s(0)) +s(0)⇤s(0)

= 0⇤(s(0)⇤s(0)) +s(0)⇤s(0) +s(0)⇤s(0)

= ...

(51)

Composition: Yet Another Example

Reverse function Rev :List[?]!List[?]

Example: Rev([2; 5; 2; 1]) = [1; 2; 5; 2]

Recursive definition:

Rev([]) =

[]

Rev(a·`) =

Rev(`)@[a]

Computation

Rev([2; 5; 1]) = Rev([5; 1])@[2]

= (Rev([1])@[5])@[2]

= ((Rev([])@[1])@[5])@[2]

= ([1]@[5])@[2]

= [1; 5]@[2] ...

= [1; 5; 2]

(52)

Composition: Yet Another Example

Reverse function Rev :List[?]!List[?]

Example: Rev([2; 5; 2; 1]) = [1; 2; 5; 2]

Recursive definition:

Rev([]) =

[]

Rev(a·`) =

Rev(`)@[a] Computation

Rev([2; 5; 1]) = Rev([5; 1])@[2]

= (Rev([1])@[5])@[2]

= ((Rev([])@[1])@[5])@[2]

= ([1]@[5])@[2]

= [1; 5]@[2] ...

= [1; 5; 2]

(53)

Composition: Yet Another Example

Reverse function Rev :List[?]!List[?]

Example: Rev([2; 5; 2; 1]) = [1; 2; 5; 2]

Recursive definition:

Rev([]) = []

Rev(a·`) =

Rev(`)@[a] Computation

Rev([2; 5; 1]) = Rev([5; 1])@[2]

= (Rev([1])@[5])@[2]

= ((Rev([])@[1])@[5])@[2]

= ([1]@[5])@[2]

= [1; 5]@[2] ...

= [1; 5; 2]

(54)

Composition: Yet Another Example

Reverse function Rev :List[?]!List[?]

Example: Rev([2; 5; 2; 1]) = [1; 2; 5; 2]

Recursive definition:

Rev([]) = []

Rev(a·`) = Rev(`)@[a]

Computation

Rev([2; 5; 1]) = Rev([5; 1])@[2]

= (Rev([1])@[5])@[2]

= ((Rev([])@[1])@[5])@[2]

= ([1]@[5])@[2]

= [1; 5]@[2] ...

= [1; 5; 2]

(55)

Composition: Yet Another Example

Reverse function Rev :List[?]!List[?]

Example: Rev([2; 5; 2; 1]) = [1; 2; 5; 2]

Recursive definition:

Rev([]) = []

Rev(a·`) = Rev(`)@[a]

Computation

Rev([2; 5; 1]) = Rev([5; 1])@[2]

= (Rev([1])@[5])@[2]

= ((Rev([])@[1])@[5])@[2]

= ([1]@[5])@[2]

= [1; 5]@[2]

(56)

Functions between di↵erent domains

The Length function | · | : List[?]!Nat

|[]| = 0

|a·`| = s(|`|)

Sum of the elements ⌃ : List[Nat]!Nat

⌃([]) = 0

⌃(n·`) = n+⌃(`)

(57)

Functions between di↵erent domains

The Length function | · | : List[?]!Nat

|[]| = 0

|a·`| = s(|`|)

Sum of the elements ⌃ : List[Nat]!Nat

⌃([]) = 0

⌃(n·`) = n+⌃(`)

(58)

Functions between di↵erent domains

The Length function | · | : List[?]!Nat

|[]| = 0

|a·`| = s(|`|)

Sum of the elements ⌃ : List[Nat]!Nat

⌃([]) = 0

⌃(n·`) = n+⌃(`)

(59)

Functions between di↵erent domains

The Length function | · | : List[?]!Nat

|[]| = 0

|a·`| = s(|`|)

Sum of the elements ⌃ : List[Nat]!Nat

⌃([]) = 0

⌃(n·`) = n+⌃(`)

(60)

Inductive definition of functions: A General Schema

Let f :D⇥E !F.

For every constantc 2D and every e 2E, define f(c,e) (as an element ofF)

For every constructor ↵:Dn⇥A!D, for everye 2E, define f(↵(x1,· · ·,xn,a),e) using aandf(x1,e),· · · ,f(xn,e).

(61)

Proving facts about functions

Neutral element:

8x 2Nat.x⇤s(0) =s(0)⇤x=x Commutativity:

8x,y 2Nat.x+y =y+x Associativity:

8x,y,z 2Nat.x+ (y+z) = (x+y) +z Distributivity:

8x,y,z 2Nat.x⇤(y+z) = (x⇤y) + (x⇤z) Idempotence:

8`2List[?].Rev(Rev(`)) =`

(62)

Structural Induction

Let c1, . . . ,cm be the constants, and let↵1, . . . ,↵n be the constructors.

P(c1) . . .

P(cm)

K1

^

i=1

P(xi) )P(↵1(x1,· · ·xK1)) . . .

Kn

^

i=1

P(xi) )P(↵n(x1,· · ·xKn)) 8x.P(x)

(63)

Proving Neutrality of 1 for ⇤

8x 2Nat.x⇤s(0) =s(0)⇤x =x

Casex = 0.

I 0s(0) = 0

I s(0)0 = 00 + 0 = 0 + 0 = 0

Casex =s(x0). Induction Hypothesis: x0⇤s(0) =s(0)⇤x0 =x0

I s(x0)s(0) = (x0s(0))+s(0) =x0+s(0) =s(0)+x0=s(0+x0) =s(x0) (uses commutativity of +)

I s(0)s(x0) = (0s(x0)) +s(x0) = 0 +s(x0) =s(x0)

(64)

Proving Neutrality of 1 for ⇤

8x 2Nat.x⇤s(0) =s(0)⇤x =x

Casex = 0.

I 0s(0) = 0

I s(0)0 = 00 + 0 = 0 + 0 = 0

Casex =s(x0). Induction Hypothesis: x0⇤s(0) =s(0)⇤x0 =x0

I s(x0)s(0) = (x0s(0))+s(0) =x0+s(0) =s(0)+x0=s(0+x0) =s(x0) (uses commutativity of +)

I s(0)s(x0) = (0s(x0)) +s(x0) = 0 +s(x0) =s(x0)

(65)

Proving Neutrality of 1 for ⇤

8x 2Nat.x⇤s(0) =s(0)⇤x =x

Casex = 0.

I 0s(0) = 0

I s(0)0 = 00 + 0 = 0 + 0 = 0

Casex =s(x0). Induction Hypothesis: x0⇤s(0) =s(0)⇤x0=x0

I s(x0)s(0) = (x0s(0))+s(0) =x0+s(0) =s(0)+x0=s(0+x0) =s(x0) (uses commutativity of +)

I s(0)s(x0) = (0s(x0)) +s(x0) = 0 +s(x0) =s(x0)

(66)

Proving Neutrality of 1 for ⇤

8x 2Nat.x⇤s(0) =s(0)⇤x =x

Casex = 0.

I 0s(0) = 0

I s(0)0 = 00 + 0 = 0 + 0 = 0

Casex =s(x0). Induction Hypothesis: x0⇤s(0) =s(0)⇤x0=x0

I s(x0)s(0) = (x0s(0))+s(0) =x0+s(0) =s(0)+x0=s(0+x0) =s(x0) (uses commutativity of +)

I s(0)s(x0) = (0s(x0)) +s(x0) = 0 +s(x0) =s(x0)

(67)

Proving Neutrality of 1 for ⇤

8x 2Nat.x⇤s(0) =s(0)⇤x =x

Casex = 0.

I 0s(0) = 0

I s(0)0 = 00 + 0 = 0 + 0 = 0

Casex =s(x0). Induction Hypothesis: x0⇤s(0) =s(0)⇤x0=x0

I s(x0)s(0) = (x0s(0))+s(0) =x0+s(0) =s(0)+x0=s(0+x0) =s(x0) (uses commutativity of +)

I s(0)s(x0) = (0s(x0)) +s(x0) = 0 +s(x0) =s(x0)

(68)

Proving Commutativity of +

8x,y 2Nat.x+y =y+x

Casex = 0. ) x+y = 0 +y =y 8y 2Nat.y =y+ 0 ?

I Casey = 0: y+ 0 = 0 + 0 = 0

I Casey =s(y0):

F Induction hypothesis: y0=y0+ 0

F y+ 0 =s(y0) + 0 =s(y0+ 0) =s(y0) =y

Casex =s(x0). Induction Hypothesis: 8z 2Nat.x0+z =z+x0 8y 2Nat.s(x0) +y=y+s(x0) ?

I Casey = 0: s(x0) + 0 =s(x0+ 0) =s(0 +x0) =s(x0) = 0 +s(x0)

I Casey =s(y0):

F Induction hypothesis: s(x0) +y0=y0+s(x0)

F s(x0) +s(y0) =s(x0+s(y0)) =s(s(y0) +x0) =s(s(y0+x0))

F s(y0) +s(x0) =s(y0+s(x0)) =s(s(x0) +y0) =s(s(x0+y0))

F s(s(x0+y0)) =s(s(y0+x0))

(69)

Proving Commutativity of +

8x,y 2Nat.x+y =y+x

Casex = 0. ) x+y = 0 +y =y 8y 2Nat.y =y+ 0 ?

I Casey = 0: y+ 0 = 0 + 0 = 0

I Casey =s(y0):

F Induction hypothesis: y0=y0+ 0

F y+ 0 =s(y0) + 0 =s(y0+ 0) =s(y0) =y

Casex =s(x0). Induction Hypothesis: 8z 2Nat.x0+z =z+x0 8y 2Nat.s(x0) +y=y+s(x0) ?

I Casey = 0: s(x0) + 0 =s(x0+ 0) =s(0 +x0) =s(x0) = 0 +s(x0)

I Casey =s(y0):

F Induction hypothesis: s(x0) +y0=y0+s(x0)

F s(x0) +s(y0) =s(x0+s(y0)) =s(s(y0) +x0) =s(s(y0+x0))

F s(y0) +s(x0) =s(y0+s(x0)) =s(s(x0) +y0) =s(s(x0+y0))

F s(s(x0+y0)) =s(s(y0+x0))

(70)

Proving Commutativity of +

8x,y 2Nat.x+y =y+x

Casex = 0. ) x+y = 0 +y =y 8y 2Nat.y =y+ 0 ?

I Casey = 0: y+ 0 = 0 + 0 = 0

I Casey =s(y0):

F Induction hypothesis: y0=y0+ 0

F y+ 0 =s(y0) + 0 =s(y0+ 0) =s(y0) =y

Casex =s(x0). Induction Hypothesis: 8z 2Nat.x0+z =z+x0 8y 2Nat.s(x0) +y=y+s(x0) ?

I Casey = 0: s(x0) + 0 =s(x0+ 0) =s(0 +x0) =s(x0) = 0 +s(x0)

I Casey =s(y0):

F Induction hypothesis: s(x0) +y0=y0+s(x0)

F s(x0) +s(y0) =s(x0+s(y0)) =s(s(y0) +x0) =s(s(y0+x0))

F s(y0) +s(x0) =s(y0+s(x0)) =s(s(x0) +y0) =s(s(x0+y0))

F s(s(x0+y0)) =s(s(y0+x0))

(71)

Proving Commutativity of +

8x,y 2Nat.x+y =y+x

Casex = 0. ) x+y = 0 +y =y 8y 2Nat.y =y+ 0 ?

I Casey = 0: y+ 0 = 0 + 0 = 0

I Casey =s(y0):

F Induction hypothesis: y0=y0+ 0

F y+ 0 =s(y0) + 0 =s(y0+ 0) =s(y0) =y

Casex =s(x0). Induction Hypothesis: 8z 2Nat.x0+z =z+x0 8y 2Nat.s(x0) +y=y+s(x0) ?

I Casey = 0: s(x0) + 0 =s(x0+ 0) =s(0 +x0) =s(x0) = 0 +s(x0)

I Casey =s(y0):

F Induction hypothesis: s(x0) +y0=y0+s(x0)

F s(x0) +s(y0) =s(x0+s(y0)) =s(s(y0) +x0) =s(s(y0+x0))

F s(y0) +s(x0) =s(y0+s(x0)) =s(s(x0) +y0) =s(s(x0+y0))

F s(s(x0+y0)) =s(s(y0+x0))

(72)

Proving Commutativity of +

8x,y 2Nat.x+y =y+x

Casex = 0. ) x+y = 0 +y =y 8y 2Nat.y =y+ 0 ?

I Casey = 0: y+ 0 = 0 + 0 = 0

I Casey =s(y0):

F Induction hypothesis: y0=y0+ 0

F y+ 0 =s(y0) + 0 =s(y0+ 0) =s(y0) =y

Casex =s(x0). Induction Hypothesis: 8z 2Nat.x0+z =z+x0 8y 2Nat.s(x0) +y=y+s(x0) ?

I Casey = 0: s(x0) + 0 =s(x0+ 0) =s(0 +x0) =s(x0) = 0 +s(x0)

I Casey =s(y0):

F Induction hypothesis: s(x0) +y0=y0+s(x0)

F s(x0) +s(y0) =s(x0+s(y0)) =s(s(y0) +x0) =s(s(y0+x0))

F s(y0) +s(x0) =s(y0+s(x0)) =s(s(x0) +y0) =s(s(x0+y0))

F s(s(x0+y0)) =s(s(y0+x0))

(73)

Proving Commutativity of +

8x,y 2Nat.x+y =y+x

Casex = 0. ) x+y = 0 +y =y 8y 2Nat.y =y+ 0 ?

I Casey = 0: y+ 0 = 0 + 0 = 0

I Casey =s(y0):

F Induction hypothesis: y0=y0+ 0

F y+ 0 =s(y0) + 0 =s(y0+ 0) =s(y0) =y

Casex =s(x0). Induction Hypothesis: 8z 2Nat.x0+z =z+x0 8y 2Nat.s(x0) +y=y+s(x0) ?

I Casey = 0: s(x0) + 0 =s(x0+ 0) =s(0 +x0) =s(x0) = 0 +s(x0)

I Casey =s(y0):

F Induction hypothesis: s(x0) +y0=y0+s(x0)

F s(x0) +s(y0) =s(x0+s(y0)) =s(s(y0) +x0) =s(s(y0+x0))

F s(y0) +s(x0) =s(y0+s(x0)) =s(s(x0) +y0) =s(s(x0+y0))

F s(s(x0+y0)) =s(s(y0+x0))

(74)

Proving Commutativity of +

8x,y 2Nat.x+y =y+x

Casex = 0. ) x+y = 0 +y =y 8y 2Nat.y =y+ 0 ?

I Casey = 0: y+ 0 = 0 + 0 = 0

I Casey =s(y0):

F Induction hypothesis: y0=y0+ 0

F y+ 0 =s(y0) + 0 =s(y0+ 0) =s(y0) =y

Casex =s(x0). Induction Hypothesis: 8z 2Nat.x0+z =z+x0 8y 2Nat.s(x0) +y=y+s(x0) ?

I Casey = 0: s(x0) + 0 =s(x0+ 0) =s(0 +x0) =s(x0) = 0 +s(x0)

I Casey =s(y0):

F Induction hypothesis: s(x0) +y0=y0+s(x0)

F s(x0) +s(y0) =s(x0+s(y0)) =s(s(y0) +x0) =s(s(y0+x0))

F s(y0) +s(x0) =s(y0+s(x0)) =s(s(x0) +y0) =s(s(x0+y0))

F s(s(x0+y0)) =s(s(y0+x0))

(75)

Summary

The first step in defining a function is to define its type (its domain and its co-domain).

Infinite data domain can be defined inductively (set of constants and a set of constructors).

Functions over infinite data domains by reasoning on the inductive structure of the data domains.

Facts about recursive functions can be proved by reasoning on the inductive structure of the data domains.

Références

Documents relatifs

S’il est probable que les algorithmes intéresseront prochainement les juridictions pénales et les praticiens du droit et s’immisceront à court ou moyen terme dans les bureaux

L’évolution de la technologie permettra demain des actions impossibles aujourd’hui : de la vidéo plein écran de parfaite qualité, des formats de bannières toujours plus

Kocher selbst bezeichnete ihn als eine Weiterent- wicklung des Langenbeck-Zugangs, ohne zu ahnen, dass ein Standardzugang zur Hüfte auch noch mehr als 100 Jahre spä- ter mit

Par ailleurs, l’application du système HACCP est durablement installée seulement comme complément indispensable aux bonnes pratiques d’hygiène (BPH) et

Smith (1988) also conceived predicting as the core of reading comprehension because it was central to the top-down model of the reading process as it orientated any reading

Le tableau VI.4 montre les résultats du taux d’identification en utilisant tous les paramètres BSIF, avec le niveau 3 de la division pyramidale spatiale et deux images dans

Leur conception du vivre ensemble est celle de la villégiature (Candau, Nougarèdes, 2008), le voisinage étant réduit à un cadre paysager (Forrest, 2007).. La réalisation des

Plasmacytoid dendritic cells deficient in IFNα production promote the amplification of FOXP3+regulatory T cells and are associated with poor prognosis in breast cancer