Abstract
In this chapter, a number of fairly elementary algorithms are developed. They are, namely: linear search; finding the maximal element in an array; a version of binary search; a simple pattern matching algorithm; raising a number to a specific integer power; and finding the integer approximation of a logarithm to the base 2.
This is a preview of subscription content, log in via an institution.
Buying options
Tax calculation will be finalised at checkout
Purchases are for personal use only
Learn about institutional subscriptionsNotes
- 1.
One can easily prove this assertion rigourously by referring to the definitions for existential and/or universal quantification in Sect. 2.1.2 in the context of the predicate formula version of app(A, x, A. len, A. len).
- 2.
Recall that we noted at the start of this discussion, in Sect. 3.1.1, that app(A, x, 0, A. len) holds invariantly throughout—i.e. x was assumed to appear somewhere in A.
- 3.
These variables are not mentioned in the pre- and postconditions, and are, in this sense, local to the inner workings of the code to be constructed “between” the pre- and postconditions, as it were. Morgan has a refinement rule that regards the introduction of local variables into the frame as a refinement.
- 4.
Here, the part relating to the variant has been omitted, since it will be true under the substitution.
- 5.
As suggested later, if N is closer to 2ℓ + 1 than it is to 2ℓ, then (ℓ + 1) would be a better approximation of log 2(N) than ℓ would be. However, this can only be established by explicitly computing 2ℓ and 2ℓ + 1—something which we wish to avoid in the algorithm to be derived.
Author information
Authors and Affiliations
Rights and permissions
Copyright information
© 2012 Springer-Verlag Berlin Heidelberg
About this chapter
Cite this chapter
Kourie, D.G., Watson, B.W. (2012). Simple Examples. In: The Correctness-by-Construction Approach to Programming. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-27919-5_3
Download citation
DOI: https://doi.org/10.1007/978-3-642-27919-5_3
Published:
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-642-27918-8
Online ISBN: 978-3-642-27919-5
eBook Packages: Computer ScienceComputer Science (R0)