Logic and Objects Language, Application and Implementation

Logic and Objects Language, Application and Implementation

Logic and Objects Language, application and implementation Francis Gregory McCabe A thesis submitted to the University of London for the degree of Doctor of Philosophy Mon, 17 Apr, 1989 Department of computing Imperial College of Science and technology 180 Queens Gate London SW7 2BZ © 1988 F.G. MCCabe F ot Mary Ann and Jessica Abstract In this thesis we investigate a number of extensions to logic programming. In particular we look at the incorporation of concepts from functional and object oriented programming into logic programming. This is done by extending the regular syntax of logic programming to include notations for functions and classes. The object oriented extension — class template programming — allows us to see how we might compose logic programs into larger programs. Furthermore, it gives a sound basis for understanding what a program module might be in the context of logic programming. The various features commonly found in object oriented programming languages such as message passing and inheritance are given an interpretation in this framework. As a typical example of the power of class template programming we look at the representation of graphics in a logic programming context. This denotational graphics formalism shows how the relationship between terms and numbers can be used to construct an analogous relationship between terms and pictures. This allows us to describe pictures with terms. Furthermore, we can describe relations over pictures — such as a picture generator or the relation of ‘being inside a picture’ — as relations over those terms. Class templates are used as the programming formalism in which these relations can be expressed. The semantics of our extensions are carefully examined, and in particular we prove that class templates are a conservative extension of logic programming. This gives us a sound basis for our class template language and also allows us to inherit theorems and programming techniques from logic programming itself. We show a preprocessor which translates class template programs into efficient Prolog programs. We also investigate how a Prolog compiler might be modified to handle class tempaltes and give even better performance than that of native Prolog. Table of contents 5 Table of Contents Introduction 9 0.1 What is logic programming? 10 0.2 Structure of the chapters 16 0.3 Acknowledgements 17 1. Logic and equational programming 19 1.0 Introduction and motivation 19 1.0. 1 Intended interpretations are not always neutral 19 1.0. 2 Prolog programs may not be reversible 20 1.0. 3 The proliferation of intermediate variables 22 1.0. 4 Higher order functions and relations 22 1.0. 5 Incompleteness of functional programming 24 1.1 Conditional equalities 25 1.1.1 Mixed relational and functional styles 27 1.1.2 Do equations describe functions? 28 1.1.3 Quoted expressions 29 1.2 Higher order functions and relations 30 1.2.1 ^-expressions and function values 31 1.2.2 Set abstractions 35 1.2.3 Loop-free programming with map 37 1.2.4 Using the reduce function 38 1.2.5 The set abstraction interpretation of logic programs 39 1.3 Summary of equational programming 40 2. Logic and objects — the class template language 41 2.0 Introduction and motivation 41 2 .0 . 1 Large programs and modules 43 2.0. 1.1 Name based modules 43 2.0. 1.2 Predicate based modules 44 2.0. 1.3 Higher order modules 45 2.0. 2 What is object oriented programming? 45 2.1 What is an object? (from 1st principles) 46 2.1.1 Is an object a term or a set of assertions? 47 2.1.2 The theory of objects 48 2.1.3 Methods in a class template 49 2.1.4 Messages and deduction 50 6 Table of contents 2.2 Class template notation 51 2.2.1 Variable labels 53 2.3 Class templates and modules 54 2.3.1 More complex orderings 57 2.3.2 Variable labels and object search 58 2.4 Data driven programming 59 2.5 The structure of classes — inclusion 63 2.5.1 Broadcast messages 65 2.6 The structure of classes — specialization 68 2.6.1 Class rules and inheritance 68 2.6.2 Computing with class rules 70 2.6.3 Multiple inheritance 72 2.6.4 Overriding inheritance 73 2.6.5 s e l f reference 74 2.6.6 Error trapping and s e l f reference 78 2.6.7 The importance of being atomic 79 2.6.8 super reference 82 2.7 Mutable objects 83 2.7.1 assert, retract and class template programs 84 2.8 Related work 85 2.8.1 T he‘isa’ interpretation 85 2.8.2 Hayes'Logic of Frames 87 2.8.3 The POL system 88 2.8.4 Zaniolo's objects 92 2.8.5 LOGIN — logic with inheritance 93 2.8.6 Logical objects 95 2.8.7 Objects as intensions 98 2.8.8 Concurrent logic programming and objects 99 2.8.9 Metalogical objects 101 3 . Denotational graphics 103 3.0 Introduction 103 3.0.1 Objects versus command sequences 104 3.1 Denoting pictures by terms 105 3.1.1 Simple pictures 105 3.1.2 Computing with pictures 106 3.1.2.1 A simple graphics display processor 106 3.1.2.2 Drawing a simple picture 107 3.2 More complex pictures 111 Table of contents 7 3.2.1 Aggregate pictures 112 3.2.2 Using complex pictures 113 3.2.3 Drawing complex pictures 118 3.2.3.1 Pointwise inclusion in an aggregate picture 118 3.2.4 Drawing modified pictures 120 3.3 Graphics and applications 123 3.3.1 The link between an application and its tools 126 3.3.1.1 Drawing an selecting tool icons 127 3.3.2 Displaying graphic edit windows 129 3.4 Related work 131 3.4.1 Helm and Marriot 131 3.5 Summary 132 4. Semantics of equations 133 4.1 The logic of functions 133 4.1.1 Functions, terms and canonical forms 135 4.1.2 A simple evaluator for canon 139 4.1.3 The effect of evaluation order 140 4.1.4 Compiling expressions 141 4.1.5 Quoted expressions and evaluation 143 4.2 The logic of X's and set abstractions 144 4.2.1 Applying predicates to tuples 145 4.2.2 Giving away names 147 4.2.3 Set abstractions with free variables 148 4.2.4 Union set abstractions 149 4.2.5 Equality of relations 150 5. Semantics of class template programs 153 5.0 Introduction 153 5 .0 . 1 The fundamental intuition 15 3 5.0. 2 The approach to understanding 154 5.0 . 3 Class template programs 15 5 5.1 A proof theory for class template programs 156 5.1.1 The distribution of labels 157 5.1.2 Class body inference rules 158 5.1.3 Class rule inference rules 159 5.1.4 The logical connective inference rules 160 5.2 Mapping class template programs into clausal form 161 8 Table of contents 5.2.1 Equations and class templates 166 5.3 The soundness of class template inference 167 5.3.1 Soundness of label distribution 168 5.3.2 The soundness of the class body inference rules 169 5.3.3 The soundness of class rule inference 170 5.4 The completeness of class template inference 173 5.5 Conventional logic programs within class template programs 178 5.6 Class template programs and higher order functionals 180 6. Implementing class templates 185 6.1 A preprocessor for translating class templates into Prolog 185 6.1.1 Class bodies 186 6.1.2 Label variables 188 6.1.3 Labelled calls and class bodies 189 6.1.4 Class rules 191 6.1.5 Equations and expressions 195 6.1.6 Named functions 199 6.1.7 Object search 200 6.1.8 Representing class template programs 202 6.1.9 A comparison of class template programs with Prolog programs 204 6.2 Compiling class template programs 206 6.2.1 Choice point and call record structures 209 6.2.2 Class rules 211 6.2.3 Dynamically asserted clauses 213 6.3 Summary 213 Conclusion and future work 215 Appendix A. Syntax of class template programs 219 Appendix B. The class template preprocessor 223 Appendix C. Example class template programs 243 Glossary 249 Bibliography 255 Introduction 9 Introduction There are a number of reasons why logic programming is important in the field of computing. Principal amongst them is that logic programming offers the basis of a theory of computing as it might be. By this we mean that logic offers an expressive language in which we can build programs and yet which is mathematically tractable. One of the great successes of logic programming is undoubtedly the Prolog programming language, yet paradoxically Prolog is also a great failure. Prolog strives at an ideal but does not reach it. Much of the criticism directed at Prolog has been concentrated on the so-called ‘dirty’ features of Prolog, condemning the cut, the use of dynamically self-modifying programs1 and so forth. However one could rightly argue that a lot of Prolog's programming power (as a practical programming language) comes from these same features. In fact Prolog fails the ideal in many respects, not least of which is the fact that the simple flat structure of Horn clauses makes it difficult to construct large programs. In general one can argue that the more structural deficiencies such as the lack of properly constructed ‘higher order’ or ‘meta order’ aspects forced the early designers to make essentially ad-hoc decisions when these requirements arose.

View Full Text

Details

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