A Meta-Programming Approach to Realizing Dependently Typed Logic Programming

A Meta-Programming Approach to Realizing Dependently Typed Logic Programming

A Meta-Programming Approach to Realizing Dependently Typed Logic Programming Zach Snow David Baelde Gopalan Nadathur Computer Science and Eng. Computer Science and Eng. Computer Science and Eng. University of Minnesota University of Minnesota University of Minnesota [email protected] [email protected] [email protected] ABSTRACT in an elegant way through type dependencies, and they for- Dependently typed lambda calculi such as the Logical Frame- malize the authentication of proofs through type-checking. work (LF) can encode relationships between terms in types Such calculi can also be assigned a logic programming in- and can naturally capture correspondences between formu- terpretation by exploiting the well-known isomorphism be- las and their proofs. Such calculi can also be given a logic tween formulas and types [12]. The Twelf system [17] that programming interpretation: the Twelf system is based on we consider in this paper exploits this possibility relative such an interpretation of LF. We consider here whether a to LF. As such, it has been used successfully in specifying conventional logic programming language can provide the and prototyping varied formal systems and mechanisms have benefits of a Twelf-like system for encoding type and proof- also been built into it to reason about these specifications. and-formula dependencies. In particular, we present a sim- Predicate logics provide the basis for logic programming ple mapping from LF specifications to a set of formulas in languages that are also capable of encoding rule-based spec- the higher-order hereditary Harrop (hohh) language, that ifications. Within this framework, the logic of higher-order relates derivations and proof-search between the two frame- hereditary Harrop (hohh) formulas [13] that underlies the works. We then show that this encoding can be improved by language λProlog [15] provides a builtin ability to treat bind- exploiting knowledge of the well-formedness of the original ing notions in syntax and thus has particular usefulness in LF specifications to elide much redundant type-checking in- representing formal systems. However, unlike LF, this logic formation. The resulting logic program has a structure that cannot reflect dependencies between objects into types and closely resembles the original specification, thereby allow- also does not directly represent the relationship between for- ing LF specifications to be viewed as hohh meta-programs. mulas and their proofs. While such correspondences can Using the Teyjus implementation of λProlog, we show that always be encoded in auxiliary predicate definitions, it is our translation provides an efficient means for executing LF of interest to understand if a more systematic treatment is specifications, complementing the ability that the Twelf sys- possible. A specific form to this question is if Twelf speci- tem provides for reasoning about them. fications can be viewed as λProlog \meta-programs." There are benefits to such a possibility: the convenience of writing specifications using dependent types can be combined with Keywords the ability to execute them via an efficient λProlog imple- logical frameworks, dependently typed lambda calculi, higher- mentation as well as perhaps to reason about them using order logic programming, translation logics and systems meant for analyzing hohh descriptions [2, 7, 10, 14]. A partial answer to the question raised above has been 1. INTRODUCTION provided by Felty, who described a translation of LF speci- There is a significant, and growing interest in mechanisms fications to hohh formulas and then showed that LF deriva- for specifying, prototyping and reasoning about formal sys- tions correspond exactly to hohh derivations of the trans- tems that are described by syntax-directed rules. Depen- lated LF judgment [5, 6]. The focus on matching derivations dently typed lambda calculi such as the Logical Framework allows Felty to assume the existence of a complete LF judg- (LF) [11] provide many conveniences from a specification ment, and, in particular, of an LF object in her translation. perspective in this context: such calculi facilitate the use of a However, this assumption is inappropriate in our context, higher-order approach to describing the syntax of formal ob- given that we are interested in constructing proof terms that jects, they allow relationships between terms to be captured show particular types are inhabited, i.e., in proof search that plays a fundamental role in the logic programming setting. We therefore refine the earlier mapping to remove this as- sumption and show that the resulting translation preserves Permission to make digital or hard copies of all or part of this work for derivability in a sense relevant to the logic programming in- personal or classroom use is granted without fee provided that copies are terpretation; an important part of our proof is showing how not made or distributed for profit or commercial advantage and that copies to extract an LF object satisfying a type from a derivation bear this notice and the full citation on the first page. To copy otherwise, to constructed using the hohh version of the specification. Our republish, to post on servers or to redistribute to lists, requires prior specific first encoding may include redundant type-checking judg- permission and/or a fee. PPDP 2010 ments which obscure the translated specification and can Copyright 20XX ACM X-XXXXX-XX-X/XX/XX ...$10.00. result in poor execution behavior. We design conditions for ized by two collections of terms called G- and D-formulas eliminating some of these judgments, resulting in an im- that are defined mutually recursively by the following syntax proved translation that corresponds closely to the intention rules: of the orginal LF specification. This part of our work relies on an analysis of the structure of LF expressions and also G := > j A j D ⊃ G j 8x:G has relevance, for example, to providing compact represen- D := A j G ⊃ D j 8x:D tations of proof terms. Finally, we demonstrate that the A specification or logic program is a finite collection of closed execution of the translated form by means of the Teyjus im- D-formulas that are also called program clauses and a goal plementation [9] of λProlog [15] provides an effective means or a query is a closed G-formula. for animating Twelf programs. Computation corresponds to searching for a derivation of In the next two sections, we describe a relevant fragment a sequent of the form Σ; Γ −! G where Σ is the initial of the hohh logic and the Twelf specification language. Sec- (language) signature, Γ is a logic program and G is a goal. tion 4 then presents our first translation; a full proof of its Figure 1 presents the rules for constructing such a derivation. correctness appears in Appendix A. In the following sec- Read in a proof search direction, the 8R rule leads to an tion, we describe and exploit a property of LF expressions expansion of the signature in the sequent whose derivation and type-checking to refine the earlier translation to pro- is sought and the ⊃ R rule similarly causes an addition to duce a more efficient and transparent version. Section 6 the logic program. The expression \t is a Σ-term" in the 8L provides experimental data towards supporting the use of rule means that t is a closed term all of whose nonlogical this translation as a means for executing Twelf programs. constants are contained in Σ. The derivation rules manifest We conclude the paper with a discussion of related work a goal-directed character: to find a derivation for Σ; Γ −! and possible future directions. G, we simplify G based on its logical structure and then use the decide rule to select a formula from the logic program 2. A HIGHER-ORDER PREDICATE LOGIC for solving an atomic goal. Notice also that the decide rule FOR DESCRIBING COMPUTATIONS initiates the consideration of a focused sequence of rules that is similar to backchaining.2 In particular, if the formula The logic of hohh formulas is based on an intuitionistic selected from Γ has the structure version of Church's simple theory of types [4]. Both log- 0 ics are built over a typed form of the λ-calculus. The types (8x1:F1 ⊃ ::: ⊃ 8xn:(Fn ⊃ A ) :::) are constructed using !, the infix, right associative function type constructor, starting from a finite collection of atomic then this sequence is equivalent to the rule types that includes o, the type of propositions, and at least 0 0 1 Σ; Γ −! F1 ::: Σ; Γ −! Fn one other type. We assume that we are given sets of vari- backchain ables and constants, each with an associated type. The full Σ; Γ −! A collection of (typed) terms is generated from these by the which has the proviso that for some Σ-terms t1; : : : ; tn that usual abstraction and (left associative) application opera- have the same types as x1; : : : ; xn, respectively, it is the case tors. Terms that differ only in the names of their bound 0 0 that A is equal to A [t1=x1; : : : tn=xn] and, for 1 ≤ i ≤ n, Fi variables are not distinguished. We further assume a no- is equal to Fi[t1=x1; : : : ; ti=xi]. tion of equality between terms that is generated by β- and The logic that we have described has been given an effi- η-reduction. It is well-known that every term has a unique cient implementation in the Teyjus system [9]. It is possi- normal form under these reduction operations in this simply- ble also to reason in sophisticated ways about specifications typed setting. All terms are to be converted into such a that are constructed using it. To begin with, the logic has form prior to their consideration in any context.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    12 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