Fixed Point Semantics and Partial Recursion in Coq Yves Bertot, Vladimir Komendantsky

Fixed Point Semantics and Partial Recursion in Coq Yves Bertot, Vladimir Komendantsky

Fixed point semantics and partial recursion in Coq Yves Bertot, Vladimir Komendantsky To cite this version: Yves Bertot, Vladimir Komendantsky. Fixed point semantics and partial recursion in Coq. MPC 2008, Jul 2008, Marseille, France. inria-00190975v4 HAL Id: inria-00190975 https://hal.inria.fr/inria-00190975v4 Submitted on 24 Jan 2008 (v4), last revised 24 Jul 2008 (v11) HAL is a multi-disciplinary open access L’archive ouverte pluridisciplinaire HAL, est archive for the deposit and dissemination of sci- destinée au dépôt et à la diffusion de documents entific research documents, whether they are pub- scientifiques de niveau recherche, publiés ou non, lished or not. The documents may come from émanant des établissements d’enseignement et de teaching and research institutions in France or recherche français ou étrangers, des laboratoires abroad, or from public or private research centers. publics ou privés. Fixed point semantics and partial recursion in Coq Yves Bertot and Vladimir Komendantsky⋆ INRIA Sophia Antipolis Abstract. We propose to use Knaster–Tarski least fixed point theorem as a basis to define recursive functions in the Calculus of Inductive Con- structions. This widens the class of functions that can be modeled in type-theory based theorem proving tools to potentially non-terminating functions. This is only possible if we extend the logical framework by adding some axioms of classical logic. We claim that the extended frame- work makes it possible to reason about terminating or non-terminating computations and we show that extraction can also be extended to han- dle the new functions. 1 Introduction For theoretical computer scientists, Knaster–Tarski least fixed point theorem, as well as its application – the so-called first fixed point theorem of Kleene [27], is a firm theoretical ground to assert the existence of objects defined by recur- sive equations. These objects can be inductive types or recursive functions as in [15,14]. We consider the following generalized statement of Knaster–Tarski theorem [1]: Theorem 1 (complete partial order version of Knaster–Tarski). Given a monotone function f on a chain-complete partial order, consider the following transfinite sequence: xo = ⊥ xα+1 = f(xα) xβ = the least upper bound of the chain {f(xα)}α<β if β is a limit ordinal. The function f has a least fixed point. Moreover, if f is continuous then the least fixed point is obtained in at most ω iterations. To use this theorem, one should be able to express that the domain of interest has the required completeness property and that the function being considered is continuous. If the goal is to define a partial recursive function then this requires using axioms of classical logic, and for this reason the step is seldom made in the user community of type-theory based theorem proving. However, the construc- tive prejudice is not a necessity: adding classical logic axioms to the constructive ⋆ inria-00190975, version 4 - 24 Jan 2008 This work was partially supported by the French ANR Project CompCert logic of type theory can often be done safely to retain the consistency of the whole system. In this paper, we work in classical logic to reason about potentially non- terminating recursive functions. No inconsistency is introduced in the process, because potentially non-terminating functions of type A → B are actually mod- eled as functions of type A → B⊥: the fact that a function may not terminate is recorded in its type, non-terminating computations are given the value ⊥ which is distinguished from all the regular values, and one can reason classically about the fact that a function terminates or not. This is obviously non-constructive but does not introduce any inconsistency. One of the advantages of type-theory based theorem proving is that ac- tual programs can be derived from formal models, with guarantees that these programs satisfy properties that are predicted in formally verified proofs. This derivation process, known as extraction [24,17], performs a cleaning operation so that all parts of the formal models that correspond to compile-time verifications are removed. The extracted programs are often reasonably efficient. In this pa- per, we also show that extraction can accommodate the new class of potentially non-terminating functions. When axioms are added to the logical framework, three cases may occur: first, the new axioms may make the system inconsistent; second, the new axioms may be used only in the part of the models that is cleaned away by the extraction process; third, the axioms may be used in the part that becomes included into the derived programs. We don’t really need to discuss the first case that should be avoided at all costs. In the second case, the extraction process still produces a consistent program, with the same guarantee of termination even if this guar- antee relies on classical logic reasoning steps. In the third case, the added axiom needs to be linked to a computation process that implements the behavior pre- dicted by the axiom. We claim that this can be done safely if Knaster–Tarski least fixed point theorem is given a sensible computational content. Kleene’s least fixed point theorem can be used to justify the existence of recursive functions, because these functions can be described as the least fixed point of the functional that arises in their recursive equation. However, it is necessary to ensure that the function space has the properties of a complete partial order and that the functional is continuous. These facts can be motivated using a simple development of basic domain theory. With the help of the axiom of definite description, this theorem can be used to produce a function, which we shall call fixp, that takes as argument a continuous function and returns the least fixed point of this function. When the argument of fixp is a functional, the least fixed point is a recursive function, which can then be combined with other functions to build larger software models. With respect to extraction, we also suggest a few improvements to the ex- traction process that should help making sure that fairly efficient code can be obtained automatically from the formal models studied inside our extension of the Calculus of Inductive Constructions. From the formal proof point of view, Knaster–Tarski least fixed point theorem provides us with two important properties of the function it produces. The first property is that the obtained function satisfies the fixed point equation. The importance of fixed point equations is straightforward and was already described in [3]. This fixed point equation is useful when we want to prove properties of the function, for instance, that under some conditions it is guaranteed to terminate. The second property is that the least fixed point is obtained in at most ω iterations. As a result, we can reason by induction on the length of computations, thus providing a poor man’s approximation of what is called fixed point induction in [27]. This possibility allows to prove properties of the function result when it exists, and can also be used to prove that under some conditions a function fails to terminate. In this paper, we recapitulate our basic formalization of domain theory. Then, we show how this theory can be used in the definition of simple recursive func- tions. In particular, we give an example that contains proofs about recursive function as a support to discuss the techniques that are available. Next, we dis- cuss matters concerned with extraction and execution of the recursive programs that are obtained in this way. Related work and opportunities for further exten- sions are reviewed at the end of the paper. All the experiments described in this paper were done with Coq [11,5] and can be found on the Internet from the first author’s web page [6]. 2 Basic notions In this section, we follow the lines of our Coq development on domain theory. We pursue the approach proposed in [23] to define various types of records for classes of functions with given properties. 2.1 Building complete preorders of continuous functions We define a preorder O to be a record containing a carrier element A : Type and a reflexive and transitive relation on A, denoted ≤O. All preorders form a type ord. For any preorder O, the derived equality is the relation, denoted ==O, such that, for any x y : O, x ==O y whenever x ≤O y and y ≤O x. For A a type and O a preorder, we define the pointwise order relation ≤A→O on functions A → O to be such that, f ≤A→O g whenever, for all x : A, f x ≤O g x. This relation can be proven to be a preorder. Hence we construct a o preorder (a function space) on the type A → O. We denote this space by A → O. As an instance of the ord type, we construct the ordered lifting of the standard type nat of natural numbers in Coq with respect to the standard relation ≤ on nat. We call this lifting nat ord. For O1 and O2 preorders, we define the type of monotonic functions from f : O1 to O2 as the type of records containing a function and a proof that f is monotonic. The pointwise preorder on functions can be lifted to monotonic functions, so that we can construct a preorder of monotonic functions. This m preorder is denoted O1 → O2. Now we can use convenient notation to define a chain on a preorder O as an m element of nat ord → O. Chains play an important role in the implementation of complete preorders below. In many cases it is helpful to have notation for partial evaluation of a function m m depending on more than one arguments.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    18 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us