5. Verifying Functions 5.0
Chapter 5
Verifying Functions
©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 248
5. Verifying Functions 5.0
Overview of Chapter
5. Verifying Functions 5.1 Introduction
5.2 Case study: Greatest common devisor 5.3 Well-definedness of recursive functions 5.4 Case study: Quicksort
©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 249
5. Verifying Functions 5.1 Introduction
Section 5.1
Introduction
©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 250
5. Verifying Functions 5.1 Introduction
Motivation
Verifying properties of functions
Verifying properties of functions is a fundamental task in theorem proving and software engineering:
• Functions allow to express recursive algorithms
• Functions can be used to model systems (e.g., a compiler is essentially a function)
• Functions are used to specify input/output behavior of procedures, so calledIO-properties
• Verifying recursive functions is related to terminiation proofs
©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 251
5. Verifying Functions 5.1 Introduction
Specification
Kinds of specifications:
• specification = model + properties
=⇒ verify that model has the properties or
• specification = model1+ model2+ relationship
=⇒ verify that models are in the relationship
Here:
specification = function definition + property of function
©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 252
5. Verifying Functions 5.1 Introduction
Basic proof techniques
Verify:
• well-definedness of function by:
I structural induction according to parameter types
I more general: well-founded ordering on parameter space:
“show that parameters get smaller”
• property of defined function:
I structural induction according to parameter types
I in general, proof technique depends on properties
©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 253
5. Verifying Functions 5.1 Introduction
Discussion
Verification
• checks for consistency of models and properties
I models may not reflect what designer/programmer had in mind
I properties may not reflect what designer/programmer had in mind
• works for the full parameter space (in contrast to testing)
• discovers also “pathological” problems
• uses redundancy to find errors
• helps to improve the descriptions
Formalverification avoids misunderstanding, allows using tools, and avoids errors in proofs.
©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 254
5. Verifying Functions 5.2 Case study: Greatest common devisor
Section 5.2
Case study: Greatest common devisor
©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 255