html5-img
1 / 29

Gilmore Logic as a Basis for Programming Languages

Gilmore Logic as a Basis for Programming Languages. Jamie Andrews Dept. of Computer Science Univ. of Western Ontario Visiting SITE Sep-Dec 2003. Styles of Programming Languages. Imperative: tell computer what to do Examples: Fortran, C, Java Functional: define functions

isra
Télécharger la présentation

Gilmore Logic as a Basis for Programming Languages

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Gilmore Logic as a Basis for Programming Languages Jamie Andrews Dept. of Computer Science Univ. of Western Ontario Visiting SITE Sep-Dec 2003

  2. Styles of Programming Languages • Imperative: tell computer what to do • Examples: Fortran, C, Java • Functional: define functions • Examples: Lisp, ML, Haskell • Logic: define relations • Examples: Prolog, Mercury • Object-Oriented: objects contain both data and functions • Examples: Smalltalk, C++, Java

  3. Functions Are Relations • A function f:(S -> T) can be seen as a set of pairs {(x,y) | f(x) = y} • A relation r on (S x T) can be seen as a set of pairs {(x,y) | r(x,y)} • Thus a function is a relation • Thus functional programming can be based on logic (relational) programming • Right?

  4. The Vision

  5. Benefits • All styles of programming languages given semantics wrt base logic programming language • Logical specifications -> proofs of properties of base logic programs • No need to define logics for individual programming languages • Connection to field of logic

  6. The Problem • Functional languages use rich type systems • Rich type systems needed to describe (e.g.) object-oriented features • Rich type systems cause inconsistencies in most higher order logics

  7. Example: Universal Types • Functional programs use lists a lot • Need lists of integers, lists of strings, etc. • Want nil (the empty list) to be of type (forall (T:type) (list T)) • i.e. for all types T, nil is of type (list T)

  8. Example: Fixpoint Types • Say we want employee objects to be of type Employee • Want to be able to say • Employee e1; • Employee e2; • … • if (e1.equals(e2)) {…}

  9. Fixpoint Types cont’d • Thus we want • Type Employee defined-as {… equals:(Employee -> boolean) …} • Employee type to be self-referential • To be precise, want • Type Employee defined-as fixpoint T{… equals:(T -> boolean) …}

  10. Higher Order Logic • Phrase used to refer to logic with arbitrary lambda-abstraction and quantification • Needed if we want to interpret modern functional programming languages in logic

  11. The Y Combinator • Y is a term such that (YM) = M(YM) for all terms M • Useful for describing recursive functions • Can appear in untyped lambda calculi • Y causes inconsistencies in most higher order logics • Y is typable in any type system with universal and fixpoint types (forall (T:type) ((T -> T) -> T)) • Oops!

  12. The Vision (remember?)

  13. Curry’s Paradox • One reason why Y is not in most HOL • Works in any logic with l, Y and => • Let M be (lx.(x => A)) for arbitrary A • Then (YM) = (M(YM)) = ((YM) => A) • Assume (YM) |- (YM) • Thus (YM) |- ((YM) => A) • So by modus ponens (YM) |- A, and so 2 things: • (1) ((YM) => A) |- A • (2) |- ((YM) => A)) • So from (1) and (2) we have…. |- A

  14. Other Solutions • Scrap the vision • Don’t base programming languages on logic • Restrict programming languages to use type systems consistent with HOL • Confuses two uses of type systems • Restricts expressivity of programming languages

  15. Gilmore Logic • Most higher order logics gain consistency from type systems • Russell, Church, Curry, Scott, Milner, Plotkin, Coquand…….. • Gilmore logics gain consistency by distinguishing between use and mention

  16. Terms of Gilmore Logic • Constants, predicate names and variables • Lambda-abstractions and applications • Propositional connectives • Quantifiers • See TPHOLs 2002 work in progress track paper

  17. Use and Mention • Two flavours of variables: use and mention • Use variable ~= property • Mention variable ~= name of a property • Mention term is any term without a free use variable • Use term can be: • Predicate name • Use variable • Use term applied to mention term

  18. Examples of Use Terms • p • X where X is a use variable • (p a) • (X a) • (p a q) • (X a b y p q) where y is a mention variable • But not (X a b Y) • And not (p X)

  19. Examples of Mention Terms • a • p • (p a) • (p q r y) • ly.lw.(forall X ((y X) => (X w))) • Let’s call this term “inter” • Describes intersection of sets with property y

  20. A Use for inter • Let z be the term lu.((u 0) & forall x ((u x) => (u (s x))) • Property of being a zero-successor set • Thus (inter z) is • The intersection of all zero-successor sets • The set of natural numbers • Let’s call it n

  21. Rules of Gilmore Logic • Propositional and quantifier rules from standard sequent calculus (e.g. Gentzen’s LK) • Witness term flavours must agree with quantified var • Lambda rules: e.g. • Axiom: where N =ab M • But only for use terms M, N G, M[x/N] |- D ----------------------- G, ((lx.M) N) |- D ----------------------- G, M |- D, N

  22. Effect of Definitions and Rules • Remember n? (intersection of all zero-successor sets) • Proving |- forall x ((n x) => (M x)) reduces to proving two sequents: • |- (M 0) • (M x) |- (M (s x)) • Built-in induction

  23. Consistency • Consistent model theory exists • Model assigns: • Mention terms to mention variables • Relations on mention terms to predicates and use variables • Model M |= A if either • A is a use term true under assignment of truth • A is built up from use terms by connectives • Cut-elimination may be possible

  24. The Y Combinator • Curry’s paradox does not bite • (Y M) is fine as a term • However it is not a use term • Therefore (Y M) |- (Y M) not an axiom • Recursive sets (relations) can be defined using Y as well • (Y (ln.lx.(x=0 \/ exists y (x=(s y) & (n y))))) • But with this, cannot prove properties by induction

  25. Functions to Relations • Function definition, e.g. (f x) defined-as (g x (h x)) can be seen as relation definition (fr x y) defined-as exists z ((hr x z) & (gr x z y)) • Strict/lazy distinction

  26. Procedures to Relations • Procedure definition, e.g. p(x) defined-as x := x+2; x := x*3 can be seen as relation definition (pr x y) defined-as exists z (z = x+2 & y = z*3)

  27. Gilmore Logic and Types • Use/mention distinction orthogonal to types • Different type systems can be layered on top of Gilmore logic • Restrict terms and formulas considered • e.g. with universal and fixpoint types

  28. Questions • What is the best way to define recursive relations? • Are there theories that can be defined in (e.g.) Coq that cannot be defined in Gilmore logic? • Vice versa? • Relationship between intersection and Y combinator form of recursive relations?

  29. Conclusions • Gilmore logic offers promising base logic on which to build programming languages • Weak inherent type system => expressivity • Use variables => possibility of proving theorems • Many questions for further study

More Related