Primitive recursive functions and fixpoints
Posted by helmutbrandl in Uncategorized on April 29, 2013
Introduction Recursion and fixpoint equations The mathematical content of the definition of a recursive function is a fixpoint equation. Let us demonstrate this statement with a simple example. The textbook example of a recursive function is the factorial function. In our programming language it looks like factorial(n:NATURAL): NATURAL ensure Result = if n=0 then 1 […]
Endofunctions, closures, cycles and chains
Posted by helmutbrandl in Uncategorized on March 18, 2013
Introduction Motivation Endofunctions are functions f of type A->A where A can be any type. Since all functions are partial functions we can use endofunctions to model linked structures. E.g. if we have an object which has an optional reference to an object of the same type the optional reference can be viewed as a […]
Mutable structures: Arrays
Posted by helmutbrandl in Uncategorized on February 4, 2013
Introduction Nearly all languages with imperative elements have some kind of an array. In C an array is just a typed pointer to a memory region. You can address the different elements by giving an offset to the start of the memory region. The compiler multiplies the offset with the size of the objects contained […]
Introduction to processes
Posted by helmutbrandl in Uncategorized on December 3, 2012
Basics A function is a computation object which calculates a result given its arguments. A procedure is a computation object which establishes a postcondition provided that its precondition is satisfied. Functions and procedures do not interact with their environment during their lifetime. They just have an entry point and an exit point. What happens between […]
Closures and fixpoints
Posted by helmutbrandl in Uncategorized on November 28, 2012
Introduction Recursive definitions of functions (and processes as we well see later) are fixpoint equations. The simple example of the recursive definiton of the factorial function can be used to illustrate this fact. fact(n:NATURAL): NATURAL ensure Result = if n=0 then 1 else n*fact(n-1) end end This definition is equivalent to the following assertion. fact_all: […]
Functions and Complete Partial Orders
Posted by helmutbrandl in Uncategorized on November 19, 2012
Motivation Why study complete partial orders? Let us look at some simple examples. Everybody knows the recursive definition of the factorial function. In our programming language the definition looks like: factorial(n:NATURAL): NATURAL ensure Result = if n=0 then 1 else n*factorial(n-1) end end But this is not a classical definition. A classical definition of a […]
Binary Relations, Endorelations and Transitive Closures
Posted by helmutbrandl in Uncategorized on October 18, 2012
Introduction Relations are an important vehicle to write specifications. In this article we study some properties of binary relations. First we start from binary relations in general with domain, range, composition, images etc. In the second part we study endorelations i.e. binary relations where the type of the domain and the range are the same. […]
Complete lattices and closure systems
Posted by helmutbrandl in Uncategorized on September 16, 2012
Introduction Complete lattices are important because of their connection to closure systems. Closure systems arise in many cases. Some examples: 1. Graphs: If we have a graph we often use the phrase “All the nodes reachable from a specific node”. A set of nodes of a graph which contains all reachable nodes is a closed […]
Predicates as sets
Posted by helmutbrandl in Uncategorized on August 19, 2012
Mathematical sets Sets abound in mathematics. If a mathematician wants to treat a collection of objects which satisfy a certain property as an entity, he defines a set. Sets are a very powerful tool in specifications. In order to obtain good readability we introduce a set like notation. Set expressions The expression {1,2,3} is the […]
Boolean lattices
Posted by helmutbrandl in Uncategorized on August 19, 2012
Introduction This article is dedicated to boolean lattices. A boolean lattice is another name for a boolean algebra. A boolean lattice is an algebraic structure with two binary operators “*” and “+” which represent “and” and “or”, a unary operator “-” which represents negation. The binary operators are commutative, associative and distributive. Furthermore there are […]
The heap sort algorithm
Posted by helmutbrandl in Uncategorized on July 23, 2012
Introduction The heapsort algorithm is a sorting algorithm which has time complexity O(n log n) and does not need additional space. Merge sort has the same time complexity but usually needs additional space. As opposed to merge sort, the heap sort algorithm is not stable i.e. it might reverse the order of equal elements. The […]
Lattices — Partial order with supremum and infimum
Posted by helmutbrandl in Uncategorized on July 16, 2012
Introduction Types which satisfy the concept of a partial order (i.e. which are descendants of the type PARTIAL_ORDER) have a binary relation “<=” which is reflexive, transitive and antisymmetric, i.e. for every three objects “a”, “b”, and “c” the following conditions are satisfied: reflexive: a<=a transitive: a<=b => b=>c => a=>c antisymmetric: a<=b => b=>a […]
The insertion sort algorithm
Posted by helmutbrandl in Uncategorized on July 1, 2012
Introduction Insertion sort is one of the simplest sorting algorithms. It is quite efficient for small arrays. Its runtime increases with the square of the number of elements to be sorted. Therefore it should not be used with large data sets. For large data sets algorithms like merge sort or heap sort are far more […]
The implementation side of framing
Posted by helmutbrandl in Uncategorized on June 17, 2012
The specification In the previous article the specification of a buffer of elements of a certain type has been described. Let us repeat here shortly the essence of the specification. class BUFFER[G] feature capacity: NATURAL content: ghost LIST[G] count: NATURAL ensure Result = content.count end [] (i:NATURAL): G require i < count ensure Result ~ […]
Abstraction wins: An approach to framing and mutability
Posted by helmutbrandl in Uncategorized on June 3, 2012
Basics Modern Eiffel has immutable and mutable types. An object of immutable type cannot be modified, an object of mutable type can be modified. Therefore we say that an object is mutable or immutable depending on its type. Immutable objects don’t have an own identity. The identity of an immutable object is completely determined by […]
Order structures: An excercise in abstraction and multiple inheritance
Posted by helmutbrandl in Uncategorized on May 29, 2012
Introduction Order structures seem to be abstract concepts of theoretical mathematics with minor practical importance. But this is just at first glance. A closer look reveals that many data types have order structure. – The basic types NATURAL, INTEGER, FLOAT etc. have a total order – The type SET[T] has a partial order with “is_subset” […]
Predicates, ghost predicates and higher order predicates
Posted by helmutbrandl in Uncategorized on May 17, 2012
Motivation Predicates play an important role in specifying functions and procedures. Since predicates are mainly used within assertions (i.e. within contracts) it is often not necessary that predicates are computable. We often use predicates to express not computable properties and give them a concise name instead of repeating a long and clumsy boolean expression over […]
Proofs made easy with proof procedures
Posted by helmutbrandl in Uncategorized on May 8, 2012
Introduction The Modern Eiffel project has two major goals: Design and implement a language which (a) allows formal verification and (b) is usuable by programmers. The second goal has not yet been fully met, because the interface to the proof engine is not easy to grasp for prgrammers coming from object oriented languages like C++, […]
Functions, ghost functions and higher order functions
Posted by helmutbrandl in Uncategorized on April 30, 2012
Ghost functions Boolean expressions of the form all(x:X) p(a,x) — x is a bound variable, a is free within the expression some(x:X) p(a,x) are not computable in general, even if the boolean valued function “p” is computable. I.e. the following constructs are illegal in executable code. — Illegal if expression!!! if all(x:X) p(a,x) then exp1 […]
Tuples and functions
Posted by helmutbrandl in Uncategorized on April 29, 2012
Introduction Tuples are very versatile in Modern Eiffel. This is due to the possibility that tuples and sequences of expressions can be freely mixed as long as the corresponding types match. In the following tuples and the possible use of tuples in expressions and functions is shown. Tuples Tuples are product types. If you have […]