Computational Semantics, Type Theory, and Functional Programming


 Christopher McDonald
 1 years ago
 Views:
Transcription
1 Computational Semantics, Type Theory, and Functional Programming I Converting Montague Grammarians into Programmers Jan van Eijck CWI and ILLC, Amsterdam, UilOTS, Utrecht LOLA7 Tutorial, Pecs August 2002
2 Summary Functional Expressions and Types Type Theory, Type Polymorphism [Hin97] Functional Programming Representing Semantic Knowledge in Type Theory Building a Montague Fragment [Mon73] Datastructures for Syntax Semantic Interpretation
3 Functional Expressions and Types According to Frege, the meaning of John arrived can be represented by a function argument expression Aj where A denotes a function and j an argument to that function. The expression A does not reveal that it is supposed to combine with an individual term to form a formula (an expression denoting a truth value). One way to make this explicit is by means of lambda notation. The function expression of this example is then written as (λx.ax). It is also possible to be even more explicit, and write λx.(ax) :: e t to indicate the type of the expression, or even: (λx e.a e t x) e t.
4 Definition of Types The set of types over e, t is given by the following BNF rule: T ::= e t (T T ). The basic type e is the type of expressions denoting individual objects (or entities). The basic type t is the type of formulas (of expressions which denote truth values). Complex types are the types of functions. For example, (e t) or e t is the type of functions from entities to truth values. In general: T 1 T 2 is the type of expressions denoting functions from denotations of T 1 expressions to denotations of T 2 expressions.
5 Picturing a Type Hierarchy The types e and t are given. Individual objects or entities are objects taken from some domain of discussion D, so e type expressions denote objects in D. The truth values are {0, 1}, so type t expression denotes values in {0, 1}. For complex types we use recursion. This gives: D e = D, D t = {0, 1}, D A B = D B D A. Here D B D A denotes the set of all functions from D A to D B.
6 A function with range {0, 1} is called a characteristic function, because it characterizes a set (namely, the set of those things which get mapped to 1). If T is some arbitrary type, then any member of D T t is a characteristic function. The members of D e t, for instance, characterize subsets of the domain of individuals D e. As another example, consider D (e t) t. According to the type definition this is the domain of functions D t D e t, i.e., the functions in {0, 1} D e t. These functions characterize sets of subsets of the domain of individuals D e.
7 Types of Relations As a next example, consider the domain D e (e t). Assume for simplicity that D e is the set {a, b, c}. Then we have: D e (e t) = D e t D e = (D D e t ) De = ({0, 1} {a,b,c} ) {a,b,c}. Example element of D e (e t) : a b c a 1 b 0 c 0 a 0 b 1 c 1 a 0 b 0 c 1
8 The elements of D e (e t) can in fact be regarded as functional encodings of twoplaced relations R on D e, for a function in D e (e t) maps every element d of D e to (the characteristic function of) the set of those elements of D e that are Rrelated to d.
9 Types for Propositional Functions Note that D t t has precisely four members, namely: identity negation constant 1 constant The elements of D t (t t) are functions from the set of truth values to the functions in D t t, i.e., to the set of four functions pictured above. As an example, here is the function which maps 1 to the constant 1 function, and 0 to the identity: ( ) ( )
10 We can view this as a two step version of the semantic operation of taking a disjunction. If the truth value of its first argument is 1, then the disjunction becomes true, and the truth value of the second argument does not matter (hence the constant 1 function). 1 ( If the truth value of the first argument is 0, then the truth value of the disjunction as a whole is determined by the truth value of the second argument (hence the identity function). 0 ( ) )
11 Types in Haskell In this section we take a brief look at how types appear in the functional programming language Haskell [HFP96, JH + 99, Bir98, DvE02]. For Haskell, see: The text inside the boxes is literal Haskell code. For convenience we collect the code of this tuturial in a module. The present module is called LOLA1. module LOLA1 where import Domain import Model
12 In Haskell, the type for truthvalues is called Bool. Thus, the type for the constant function that maps all truth values to 1 is Bool > Bool. The truth value 1 appears in Haskell as True, the truth value 0 as False. The definitions of the constant True and the constant False function in Haskell run as follows: c1 :: Bool > Bool c1 _ = True c0 :: Bool > Bool c0 _ = False The definitions consist of a type declaration and a value specification. Whatever argument you feed c1, the result will be True. Whatever argument you give c0, the result will be False. The underscore is used for any value whatsoever.
13 An equivalent specification of these functions runs as follows: c1 :: Bool > Bool c1 = \ p > True c0 :: Bool > Bool c0 = \ p > False The function in Bool > Bool that swaps the two truth values is predefined in Haskell as not. The identity function is predefined in Haskell as id. This function has the peculiarity that it has polymorphic type: it can be used as the identity for any type for which individuation makes sense.
14 In Haskell, the disjunction function will have type Bool > Bool > Bool This type is read as Bool > (Bool > Bool). Implementation of disj, in terms of c1 and id: disj :: Bool > Bool > Bool disj True = c1 disj False = id Alternative: disj :: Bool > Bool > Bool disj = \ p > if p then c1 else id
15 Type Polymorphism The id function: id :: a > a id x = x A function for arity reduction: self :: (a > a > b) > a > b self f x = f x x This gives: LOLA1> self (<=) 3 True
16 Properties, Relations The polymorphic type of a property is a > Bool. Examples: (>= 0), (<> x), even. The polymorphic type of a relation is a > b > Bool. The polymorphic type of a relation over a single type is a > a > Bool. Examples: (<), (<=), (==).
17 List Types Examples of list types: [Int] is the type of lists of integers, [Char] is the type of lists of characters, or strings, [Bool] is the type of lists of Booleans, and so on. If a is a type, [a] is the type of lists over a. Note that [a] is a polymorphic type. [] is the empty list (of any type). (x:xs) is the prototypical nonempty list. The head of (x:xs) is x, the tail is xs.
18 List Comprehension List comprehension is the list counterpart of set comprehension: {x x A, P (x)} LOLA1> [ n n < [0..20], n mod 7 == 1 ] [1,8,15] LOLA1> [ 2^n n < [0..10] ] [1,2,4,8,16,32,64,128,256,512,1024] LOLA1> [ w ++ w w < ["ab","cd","eef"] ] ["abab","cdcd","eefeef"]
19 The map Function The function map takes a function and a list and returns a list containing the results of applying the function to the individual list members. If f is a function of type a > b and xs is a list of type [a], then map f xs will return a list of type [b]. map :: (a > b) > [a] > [b] map f [] = [] map f (x:xs) = (f x) : map f xs E.g., map (^2) [1..9] will produce the list of squares: [1, 4, 9, 16, 25, 36, 49, 64, 81]
20 The filter Function The filter function takes a property and a list, and returns the sublist of all list elements satisfying the property. filter :: (a > Bool) > [a] > [a] filter p [] = [] filter p (x:xs) p x = x : filter p xs otherwise = filter p xs LOLA1> filter even [1..10] [2,4,6,8,10]
21 Function Composition For the composition f. g to make sense, the result type of g should equal the argument type of f, i.e., if f :: a > b then g :: c > a. Under this typing, the type of f. g is c > b. Thus, the operator (.) that composes two functions has the following type and definition: (.) :: (a > b) > (c > a) > c > b (f. g) x = f (g x)
22 A Domain of Entities To illustrate the type e, we construct a small example domain of entities consisting of individuals A,..., M, by declaring a datatype Entity. module Domain where data Entity = A B C D E F G H I J K L M deriving (Eq,Bounded,Enum,Show) The stuff about deriving (Eq,Bounded,Enum,Show) is there to enable us to do equality tests on entities (Eq), to refer to A as the minimum element and M as the maximum element (Bounded), to enumerate the elements (Enum), and to display the elements on the screen (Show).
23 Because Entity is a bounded and enumerable type, we can put all of its elements in a finite list: entities :: [Entity] entities = [minbound..maxbound] This gives: CompSem1> entities [A,B,C,D,E,F,G,H,I,J,K,L,M]
24 r :: Entity > Entity > Bool r A A = True r A _ = False r B B = True r B C = True r B _ = False r C C = True r = False
25 This gives: LOLA1> r A B False LOLA1> r A A True
26 Using lambda abstraction, we can select sublists of a list that satisfy some property we are interested in. Suppose we are interested in the property of being related by r to the element B. This property can be expressed using λ abstraction as λx.(rb)x. In Haskell, this same property is expressed as (\ x > r B x). Using a property to create a sublist is done by means of the filter operation. Here is how we use filter to find the list of entities satisfying the property: LOLA1> filter (\ x > r B x) entities [B,C] With negation, we can express the complement of this property. This gives: LOLA1> filter (\ x > not (r B x)) entities [A,D,E,F,G,H,I,J,K,L,M]
27 Here is how disj is used to express the property of being either related to a or to b: LOLA1> filter (\ x > disj (r A x) (r B x)) entities [A,B,C] Haskell has a predefined infix operator that serves the same purpose as disj. Instead of the above, we could have used the following: LOLA1> filter (\ x > (r A x) (r B x)) entities [A,B,C] Similarly, Haskell has a predefined infix operator && for conjunction.
28 The Language of Typed Logic and Its Semantics Assume that we have constants and variables available for all types in the type hierarchy. Then the language of typed logic over these is defined as follows. type ::= e t (type type) expression ::= constanttype variabletype (λ variabletype 1.expressiontype 2 )type 1 type 2 (expressiontype 1 type 2 expressiontype 1 )type 2 For an expression of the form (E 1 E 2 ) to be welltyped the types have to match. The type of the resulting expression is fully determined by the types of the components. Similarly, the type of a lambda expression (λv.e) is fully determined by the types of v and E.
29 Often we leave out the type information. The definition of the language then looks like this: expression ::= constant variable (λ variable.expression) (expression expression)
30 Models for Typed Logic A model M for a typed logic over e, t consists of a domain dom (M) = D e together with an interpretation function int (M) = I which maps every constant of the language to a function of the appropriate type in the domain hierarchy based on D e. A variable assignment s for typed logic maps every variable of the language to a function of the appropriate type in the domain hierarchy. The semantics for the language is given by defining a function [.] M s which maps every expression of the language to a function of the appropriate type.
31 [constant] M s = I(constant). [variable] M s = s(variable). [(λv T1.E T2 )] M s = h where h is the function given by h : d D T1 [E ] M s(v d) D T 2. [(E 1 E 2 )] M s = [E 1 ] M s ([E 2 ] M s ).
32 Assume that (((Gc)b)a) expresses that a gives b to c. What do the following expressions say: 1. (λx.(((gc)b)x)). giving b to c 2. (λx.(((gc)x)a)). being a present of a to c 3. (λx.(((gx)b)a)). receiving b from a 4. (λx.(((gx)b)x)). giving b to oneself.
33 Assume that (((Gc)b)a) expresses that a gives b to c. What do the following expressions say: 1. (λx.(λy.(((gx)b)y))). giving b 2. (λx.(λy.(((gy)b)x))). receiving b.
34 Logical Constants of Predicate Logic The logical constants of predicate logic can be viewed as constants of typed logic, as follows. is a constant of type t t with the following interpretation. [ ] = h, where h is the function in {0, 1} {0,1} which maps 0 to 1 and vice versa. and are constants of type t t t with the following interpretations. [ ] = h, where h is the function in ({0, 1} {0,1} ) {0,1} which maps 1 to {(1, 1), (0, 0)} and 0 to {(1, 0), (0, 0)}. [ ] = h, where h is the function in ({0, 1} {0,1} ) {0,1} which maps 1 to {(1, 1), (0, 1)} and 0 to {(1, 1), (0, 0)}.
35 not not True not False :: Bool > Bool = False = True (&&) :: Bool > Bool > Bool False && x = False True && x = x ( ) :: Bool > Bool > Bool False x = x True x = True
36 Quantifiers of Predicate Logic The quantifiers and are constants of type (e t) t, with the following interpretations. [ ] = h, where h is the function in {0, 1} D e t which maps the function that characterizes D e to 1 and every other characteristic function to 0. [ ] = h, where h is the function in {0, 1} D e t which maps the function that characterizes to 0 and every other characteristic function to 1.
37 Second Order and Polymorphic Quantification It is possible to add constants for quantification over different types. E.g., to express second order quantification (i.e., quantification over properties of things), one would need quantifier constants of type ((e t) t) t. The general (polymorphic) type of quantification is (T t) t.
38 Haskell implementation of quantification: any, all :: (a > Bool) > [a] > Bool any p = or. map p all p = and. map p Definition of forall and exists for bounded enumerable domains, in terms of these: forall, exists :: (Enum a, Bounded a) => (a > Bool) > Bool forall = \ p > all p [minbound..maxbound] exists = \ p > any p [minbound..maxbound]
39 What is the type of binary generalized quantifiers such as Q (λx.p x)(λx.qx) Q (λx.p x)(λx.qx) Q M (λx.p x)(λx.qx) ( all P are Q ) ( some P are Q ) ( most P are Q ) (e t) (e t) t.
40 Implementation of binary generalized quantifiers: every, some, no :: (Entity > Bool) > (Entity > Bool) > Bool every = \ p q > all q (filter p entities) some = \ p q > any q (filter p entities) no = \ p q > not (some p q)
41 most :: (Entity > Bool) > (Entity > Bool) > Bool most = \ p q > length (filter (\ x > p x && q x) entities) > length (filter (\ x > p x && not (q x)) entities)
42 The P is Q is true just in case 1. there is exactly one P, 2. that P is Q.
43 singleton :: [a] > Bool singleton [x] = True singleton _ = False the :: (Entity > Bool) > (Entity > Bool) > Bool the = \ p q > singleton (filter p entities) && q (head (filter p entities))
44 Typed Logic and Predicate Logic With the constants,,,, added, the language of typed logic contains ordinary predicate logic as a proper fragment. Here are some example expressions of typed logic, with their predicate logical counterparts: ( (P x)) (( (P x))(qy)) ( (λx.p x)) ( (λx.( (λy.((ry)x))))) P x P x Qy xp x x yrxy Note the order of the arguments in ((Ry)x) versus Rxy.
45 Curry and Uncurry The conversion of a function of type (a,b) > c to one of type a > b > c is called currying (named after Haskell Curry). curry is predefined in Haskell: curry :: ((a,b) > c) > (a > b > c) curry f x y = f (x,y) The conversion of a function of type a > b > c to one of type (a,b) > c is called uncurrying, uncurry :: (a > b > c) > ((a,b) > c) uncurry f p = f (fst p) (snd p)
46 LOLA1> r B C True LOLA1> (uncurry r) (B,C) True As we also want the arguments in the other order, what we need is: 1. first flip the arguments, 2. next uncurry the function. inv2 :: (a > b > c) > ((b,a) > c) inv2 = uncurry. flip LOLA1> inv2 r (C,B) True
47 For the converse operation, we combine curry with flip, as follows: flip. curry. LOLA1> (flip. curry. inv2) r B C True
48 Conversion for Three Placed Relations For threeplaced relations, we need to convert from and too triples, and for that appropriate definitions are needed for selecting the first, second or third element from a triple. e1 e1 (x,y,z) e2 e2 (x,y,z) e3 e3 (x,y,z) :: (a,b,c) > a = x :: (a,b,c) > b = y :: (a,b,c) > c = z inv3 :: (a > b > c > d) > ((c,b,a) > d) inv3 f t = f (e3 t) (e2 t) (e1 t)
49 Here is a definition of a threeplaced relation in Haskell: g :: Entity > Entity > Entity > Bool g D x y = r x y g E x y = not (r x y) g _ = False This gives: LOLA1> g E B C False LOLA1> g E C B True LOLA1> inv3 g (B,C,E) True LOLA1>
50 Assume R is a typed logical constant of type e (e t) which is interpreted as the twoplaced relation of respect between individuals. Then ((Rb)a) expresses that a respects b. In abbreviated notation this becomes R(a, b). Now λx. yr(x, y) is abbreviated notation for respecting someone, and λx. yr(x, y) for being respected by someone. If G(a, b, c) is shorthand for a gives b to c, then λx. y zg(x, y, z) expresses giving something to someone, and λx. yg(x, b, y) expresses giving b to someone. Finally, λx. yg(y, b, x) expresses receiving b from someone. Assume G(x, y, z), which is short for (((Gz)y)x), means that x gives y to z. Use this to find a typed logic expression for receiving something from someone. λx. y zg(y, z, x).
51 Suppose we want to translate Anne gave Claire the book, which has syntactic structure [ S [ NP Anne ][ V P [ T V [ DT V gave][ NP Claire ]][ NP the book ]]] in a compositional way, using λzyx.g(x, y, z) as translation for give. Translating all the combinations of phrases as function argument combination, we arrive at the following translation of the sentence. 1 (((λzyx.g(x, y, z)c)b)a). This does indeed express what we want, but in a rather roundabout way. We would like to reduce this expression to G(a, b, c).
52 Reducing Expressions of Typed Logic To reduce expression (1) to its simplest form, three steps of socalled β conversion are needed. During β conversion of an expression consisting of a functor expression λv.e followed by an argument expression A, basically the following happens: The prefix λv. is removed, the argument expression A is removed, and finally the argument expression A is substituted in E for all free occurrences of v. The free occurrences of v in E are precisely the occurrences which were bound by λv in λv.e. Here is the proviso. In some cases, the substitution process described above cannot be applied without further ado, because it will result in unintended capturing of variables within the argument expression A.
53 Consider expression (2): 2 ((λx.(λy.((ry)x)))y). In this expression, y is bound in the functional part (λx.(λy.((ry)x))) but free in the argument part y. Reducing (2) by β conversion according to the recipe given above would result in (λy.((ry)y)), with capture of the argument y at the place where it is substituted for x. This problem can be avoided by performing β conversion on an alphabetic variant of the original expression, say on (3). 3 ((λx.(λz.((rz)x)))y).
54 Another example where α conversion (i.e., switching to an alphabetic variant) is necessary before β conversion to prevent unintended capture of free variables is the expression (4). 4 ((λp. x((ax) p))(bx)). In (4), p is a variable of type t, and x one of type e. Variable x is bound inside the functional part (λp. x((ax) p)) but free in the argument part (Bx). Substituting (Bx) for p in the function expression would cause x to be captured, with failure to preserve the original meaning. Again, the problem is avoided if β conversion is performed on an alphabetic variant of the original expression, say on (5). 5 ((λp. z((az) p))(bx)). Performing β reduction on (5) yields z.((ax) (Bx)), with the argument of B still free, as it should be.
55 Freedom, Bondage, Substitution Variable v is free in expression E if the following holds (we use for the relation of being syntactically identical, i.e. for being the same expression): v E, E (E 1 E 2 ), and v is free in E 1 or v is free in E 2, E (λx.e 1 ), and v x, and v is free in E 1. Examples of free occurrences of x: (λx.(p x)), ((λx.(p x))x), (λx.((rx)x)), ((λx.((rx)x))x), ((λy.((rx)y))x).
56 Which occurrences of x are free in ((λy. x((rx)y))x)? Bear in mind that x((rx)y) is shorthand for ( (λx.((rx)y))). ((λy. x((rx)y))x).
57 Substitution of y for x in (λy.(p x)): (λy.(p x))[x := y]. The function (λy.(p x)) is the function yielding (P x) for any argument, i.e., the constant (P x) function. It is easy to get this substitution wrong: (λy.(p x))[x := y] (λy.(p x)[x := y]) (λy.(p y)). This is a completely different function, namely the function that assigns to argument a the result of applying P to a. By doing an appropriate renaming, we get the correct result: (λy.(p x))[x := y] (λz.(p x)[y := z][x := y]) (λz.(p x)[x := y]) (λz.(p y)).
58 Substitution of s for free occurrences of v in E, with notation E[v := s]. If E v then E[v := s] s, if E x v (i.e., E is a variable different from v), then E[x := s] x, if E c (i.e., E is a constant), then E[x := s] c, if E (E 1 E 2 ) then E[v := s] (E 1 [v := s] E 2 [v := s]), if E (λx.e 1 ), then if v x then E[v := s] E, if v x then there are two cases: 1. if x is not free in s or v is not free in E then E[v := s] (λx.e 1 [v := s]), 2. if x is free in s and v is free in E then E[v := s] (λy.e 1 [x := y][v := s]), for some y which is not free in s and not free in E 1.
59 Reduction Reduction comes in three flavours: β reduction, α reduction and η β α reduction, with corresponding arrows, and. η Beta reduction: ((λv.e)s) β E[v := s]. Condition: v and s are of the same type (otherwise the expression to be reduced is not welltyped). Alpha reduction: (λv.e) α (λx.e[v := x]). Conditions: v and x are of the same type, and x is not free in E. Eta reduction: ((λv.e)v) η E.
60 The real work takes place during β reduction. The α reduction rule serves only to state in an explicit fashion that λ calculations are insensitive to switches to alphabetic variants. Whether one uses λx to bind occurrences of x or λy to bind occurrences of y is immaterial, just like it is immaterial in the case of predicate logic whether one writes xp x or yp y. The η reduction rule makes a principle explicit that we have used implicitly all the time: if (P j) expresses that John is present, then both P and (λx.(p x)) express the property of being present. This is so η because ((λx.(p x))x) (P x), so P and (λx.(p x)) give the same result when applied to argument x, i.e., they express the same function.
61 Applying β reduction to (((λzyx.g(x, y, z)c)b)a), or in unabbreviated notation ((((λz.(λy.(λx.(((gz)y)x))))c)b)a), gives: ((((λz.(λy.(λx.(((gz)y)x))))c)b)a) β (((λy.(λx.(((gc)y)x)))b)a) β ((λx.(((gc)b)x))a) β (((Gc)b)a).
62 To be fully precise we have to state explicitly that expressions can be reduced in context. The following principles express this: β E E β (F E) (F E ) β E E β (λv.e) (λv.e ) Here F is assumed to have the appropriate type. β E E β (EF ) (E F ) These principles allow β reductions at arbitrary depth within expressions.
63 Reduce the following expressions to their simplest forms: 1. ((λy.(λx.(y x)))p ). λx.(p x). 2. (((λy.(λx.(y x)))p )y). (P y). 3. ((λp.(λq. x(p x Qx)))A). (λq. x(ax Qx)). 4. (((λp.(λq. x(p x Qx)))A)B). x(ax Bx). 5. ((λp.(λq. x(p x Qx)))(λy.((λx.((Ry)x))j))). (λq. x((λz.((rj)z)x) Qx)) (λq. x(((rj)x) Qx)).
64 Confluence Property In the statement of the following property, we write E E for E reduces in a number of α, β, η steps to E. Confluence property (or: ChurchRosser property): For all expressions E, E 1, E 2 of typed logic: if E E 1 and E E 2 then there is an expression F with E 1 F and E 2 F.
65 Normal Form Property An expression of the form ((λv.e)s) is called a βredex (for: β reducible expression). E[v := s] is called the contractum of ((λv.e)s). An expression that does not contain any redexes is called a normal form. Normal form property: Every expression of typed logic can be reduced to a normal form. Combining the confluence property and the normal form property we get that the normal forms of an expression E are identical modulo α conversion. That is to say, all normal forms of E are alphabetic variants of one another.
66 The normal form property holds thanks to the restrictions imposed by the typing discipline. Untyped lambda calculus lacks this property. In untyped lambda calculus it is allowed to apply expressions to themselves. In typed lambda calculus this is forbidden, because (xx) cannot be consistently typed. In untyped lambda calculus, expressions like (λx.(xx)) are wellformed. It is easy to see that does not have a normal form. ((λx.(xx))(λx.(xx)))
67 Misleading Form and Logical Form The metamorphosis of β conversion is relevant for an enlightened view on the historical misleading form thesis for natural language. The predicate logical translations of natural language sentences with quantified expressions did not seem to follow the linguistic structure. In the logical translations, the quantified expressions seemed to have disappeared. Using expressions of typed logic it is quite simple to analyse John smiled and Noone smiled along the same lines: The subject NPs get the translations: λp.p j and λp. x.((person x) (P x)).
68 Representing a Model for Predicate Logic in Haskell All we need to specify a first order model in Haskell is a domain of entities and suitable interpretations of proper names and predicates. The domain of entities was given above as Entity. module Model where import Domain
69 Interpretation for proper names: ann, mary, bill, johnny :: Entity ann = A mary = M bill = B johnny = J
70 man,boy,woman,person,thing,house :: Entity > Bool man x = x == B x == D x == J woman x = x == A x == C x == M boy x = x == J person x = man x woman x thing x = not (person x) house x = x == H cat x = x == K mouse x = x == I
71 laugh,cry,curse,smile,old,young :: Entity > Bool laugh x = x == M x == C x == B x == D x == J cry x = x == B x == D curse x = x == J x == A smile x = x == M x == B x == I x == K young x = x == J old x = x == B x == D
72 Meanings for twoplaced predicates, represented as (Entity,Entity) > Bool. love,respect,hate,own :: (Entity,Entity) > Bool love (x,y) = (x == B && (y == M y == A)) (woman x && (y == J y == B)) respect (x,y) = person x && person y x == F x == I hate (x,y) = ((x == B x == J) && thing y) (x == I && y == K) own (x,y) = (x ==A && y == E) (x == M && (y == K y == H))
73 Montague Grammar: Datastructures for Syntax data S = S NP VP deriving (Eq,Show) data NP = Ann Mary Bill Johnny NP1 DET CN NP2 DET RCN deriving (Eq,Show) data DET = Every Some No The Most deriving (Eq,Show) data CN = Man Woman Boy Person Thing House Cat Mouse deriving (Eq,Show)
74 data RCN = CN1 CN VP CN2 CN NP TV deriving (Eq,Show) data VP = Laughed Smiled VP1 TV NP deriving (Eq,Show) data TV = Loved Respected Hated Owned deriving (Eq,Show)
75 Semantic Interpretation We define for every syntactic category an interpretation function of the appropriate type. Sentences: ints :: S > Bool ints (S np vp) = (intnp np) (intvp vp)
76 Noun Phrases: intnp :: NP > (Entity > Bool) > Bool intnp Ann = \ p > p ann intnp Mary = \ p > p mary intnp Bill = \ p > p bill intnp Johnny = \ p > p johnny intnp (NP1 det cn) = (intdet det) (intcn cn) intnp (NP2 det rcn) = (intdet det) (intrcn rcn)
77 For the interpretation of verb phrases we invoke the information encoded in our first order model. intvp :: VP > Entity > Bool intvp Laughed = laugh intvp Smiled = smile For the interpretation of complex VPs, we have to find a way to make reference to the property of standing into the TV relation to the subject of the sentence. intvp (VP1 tv np) = \ subj > intnp np (\ obj > inttv tv obj subj)
78 TVs: link up with model information. inttv :: TV > Entity > Entity > Bool inttv Loved = (flip. curry) love inttv Respected = (flip. curry) respect inttv Hated = (flip. curry) hate inttv Owned = (flip. curry) own
79 The interpreation of CNs is similar to that of VPs. intcn :: CN > Entity > Bool intcn Man = man intcn Boy = boy intcn Woman = woman intcn Person = person intcn Thing = thing intcn House = house
80 Determiners: use the logical constants defined above. intdet :: DET > (Entity > Bool) > (Entity > Bool) > Bool intdet Every = every intdet Some = some intdet No = no intdet The = the
81 Interpretation of relativised common nouns of the form That CN VP: check whether an entity has both the CN and the VP property: intrcn :: RCN > Entity > Bool intrcn (CN1 cn vp) = \ e > ((intcn cn e) && (intvp vp e)) Interpretation of relativised common nouns of the form That CN NP TV : check whether an entity has both the CN property as the property of being the object of NP TV. intrcn (CN2 cn np tv) = \e > ((intcn cn e) && (intnp np (inttv tv e)))
82 Testing it Out LOLA1> ints (S (NP1 The Boy) Smiled) False LOLA1> ints (S (NP1 The Boy) Laughed) True LOLA1> ints (S (NP1 Some Man) Laughed) True LOLA1> ints (S (NP1 No Man) Laughed) False LOLA1> ints (S (NP1 Some Man) (VP1 Loved (NP1 Some Woman))) True
83 Further Issues Syntax: if there is time. Quantifyingin: application of NP denotations to PROabstractions. Intensionality: add a type w for worlds, and build the type hierarchy over t, e, w. Flexible typing Anaphoric linking: classical variable binding is not enough... Next Lecture: The Dynamic Turn
84 References [Bir98] R. Bird. Introduction to Functional Programming Using Haskell. Prentice Hall, [DvE02] K. Doets and J. van Eijck. Reasoning, computation and representation using Haskell. Draft Textbook. Available from [HFP96] P. Hudak, J. Fasel, and J. Peterson. A gentle introduction to Haskell. Technical report, Yale University, Available from the Haskell homepage: [Hin97] J. Roger Hindley. Basic Simple Type Theory. Cambridge University Press, [JH + 99] S. Peyton Jones, J. Hughes, et al. Report on the programming
85 language Haskell 98. Available from the Haskell homepage: [Mon73] R. Montague. The proper treatment of quantification in ordinary English. In J. Hintikka e.a., editor, Approaches to Natural Language, pages Reidel, 1973.
Introduction to Type Theory
Introduction to Type Theory Herman Geuvers Radboud University Nijmegen, The Netherlands Technical University Eindhoven, The Netherlands 1 Overview These notes comprise the lecture Introduction to Type
More informationDependent Types at Work
Dependent Types at Work Ana Bove and Peter Dybjer Chalmers University of Technology, Göteborg, Sweden {bove,peterd}@chalmers.se Abstract. In these lecture notes we give an introduction to functional programming
More informationSwitching Algebra and Logic Gates
Chapter 2 Switching Algebra and Logic Gates The word algebra in the title of this chapter should alert you that more mathematics is coming. No doubt, some of you are itching to get on with digital design
More informationType Theory & Functional Programming
Type Theory & Functional Programming Simon Thompson Computing Laboratory, University of Kent March 1999 c Simon Thompson, 1999 Not to be reproduced i ii To my parents Preface Constructive Type theory has
More informationLogical Constants Across Varying Types
Notre Dame Journal of Formal Logic Volume 30, Number 3, Summer 1989 315 Logical Constants Across Varying Types JOHAN van BENTHEM Abstract We investigate the notion of "logicality" for arbitrary categories
More informationMonads for functional programming
Monads for functional programming Philip Wadler, University of Glasgow Department of Computing Science, University of Glasgow, G12 8QQ, Scotland (wadler@dcs.glasgow.ac.uk) Abstract. The use of monads to
More informationSettheoretic Foundation of Parametric Polymorphism and Subtyping
Settheoretic Foundation of Parametric Polymorphism and Subtyping Giuseppe Castagna 1 Zhiwu Xu 1,2 1 CNRS, Laboratoire Preuves, Programmes et Systèmes, Univ Paris Diderot, Sorbonne Paris Cité, Paris, France.
More informationBlame for All. Jeremy G. Siek. Amal Ahmed. Robert Bruce Findler. Philip Wadler. Abstract. 1. Introduction
Blame for All Amal Ahmed Indiana University amal@cs.indiana.edu Robert Bruce Findler Northwestern University robby@eecs.northwestern.edu Jeremy G. Siek University of Colorado at Boulder jeremy.siek@colorado.edu
More informationUNBOUND ANAPHORIC PRONOUNS: ETYPE, DYNAMIC, AND STRUCTUREDPROPOSITIONS APPROACHES
FRIEDERIKE MOLTMANN UNBOUND ANAPHORIC PRONOUNS: ETYPE, DYNAMIC, AND STRUCTUREDPROPOSITIONS APPROACHES ABSTRACT. Unbound anaphoric pronouns or Etype pronouns have presented notorious problems for semantic
More informationThe Set Data Model CHAPTER 7. 7.1 What This Chapter Is About
CHAPTER 7 The Set Data Model The set is the most fundamental data model of mathematics. Every concept in mathematics, from trees to real numbers, is expressible as a special kind of set. In this book,
More information10 The Essence of ML Type Inference
10 The Essence of ML Type Inference François Pottier and Didier Rémy 10.1 What Is ML? The name ML appeared during the late seventies. It then referred to a generalpurpose programming language that was
More informationTop Quality Type Error Messages
Top Quality Type Error Messages Top Kwaliteit Typeringsfoutmeldingen (met een samenvatting in het Nederlands) Proefschrift ter verkrijging van de graad van doctor aan de Universiteit Utrecht op gezag van
More informationPROOFS AND TYPES JEANYVES GIRARD PAUL TAYLOR YVES LAFONT. CAMBRIDGE UNIVERSITY PRESS Cambridge. Translated and with appendices by
PROOFS AND TYPES JEANYVES GIRARD Translated and with appendices by PAUL TAYLOR YVES LAFONT CAMBRIDGE UNIVERSITY PRESS Cambridge New York Melbourne New Rochelle Sydney ii Published by the Press Syndicate
More informationType Theory and Lexical Decomposition
Type Theory and Lexical Decomposition James Pustejovsky Department of Computer Science Brandeis University, Waltham, MA 02454 jamesp@cs.brandeis.edu Abstract In this paper, I explore the relation between
More informationA Semantical Perspective on Verification of Knowledge
A Semantical Perspective on Verification of Knowledge Paul Leemans, Jan Treur, Mark Willems Vrije Universiteit Amsterdam, Department of Artificial Intelligence De Boelelaan 1081a, 1081 HV Amsterdam The
More informationDenotational design with type class morphisms (extended version)
LambdaPix technical report 200901, March 2009 (minor revisions February 15, 2011) 1 Denotational design with type class morphisms (extended version) Conal Elliott LambdaPix conal@conal.net Abstract Type
More informationCategorial Type Logics
Categorial Type Logics Michael Moortgat Utrecht Institute of Linguistics, OTS Excerpt from Chapter Two in J. van Benthem and A. ter Meulen (eds.) Handbook of Logic and Language. Elsevier, 1997. Contents
More informationHoare Type Theory, Polymorphism and Separation
Under consideration for publication in J. Functional Programming 1 Hoare Type Theory, Polymorphism and Separation ALEKSANDAR NANEVSKI and GREG MORRISETT Harvard University {aleks,greg}@eecs.harvard.edu
More informationType and Effect Systems
Type and Effect Systems Flemming Nielson & Hanne Riis Nielson Department of Computer Science, Aarhus University, Denmark. Abstract. The design and implementation of a correct system can benefit from employing
More informationInnovations in Computational Type Theory using Nuprl
Innovations in Computational Type Theory using Nuprl S. F. Allen, M. Bickford, R. L. Constable, R. Eaton, C. Kreitz, L. Lorigo, E. Moran Department of Computer Science, CornellUniversity, Ithaca, NY 148537501
More informationGoogle s MapReduce Programming Model Revisited
Google s MapReduce Programming Model Revisited Ralf Lämmel Data Programmability Team Microsoft Corp. Redmond, WA, USA Abstract Google s MapReduce programming model serves for processing large data sets
More informationIntuitionistic Type Theory. Per MartinLöf
Intuitionistic Type Theory Per MartinLöf Notes by Giovanni Sambin of a series of lectures given in Padua, June 1980 Contents Introductory remarks............................ 1 Propositions and judgements.......................
More informationDependently Typed Programming in Agda
Dependently Typed Programming in Agda Ulf Norell 1 and James Chapman 2 1 Chalmers University, Gothenburg ulfn@chalmers.se 2 Institute of Cybernetics, Tallinn james@cs.ioc.ee 1 Introduction In HindleyMilner
More informationType Systems. Luca Cardelli. Digital Equipment Corporation Systems Research Center
Type Systems 1 Introduction Luca Cardelli Digital Equipment Corporation Systems Research Center The fundamental purpose of a type system is to prevent the occurrence of execution errors during the running
More informationWelltyped programs can t be blamed
Welltyped programs can t be blamed Philip Wadler University of Edinburgh Robert Bruce Findler University of Chicago Abstract We introduce the blame calculus, which adds the notion of blame from Findler
More informationOn Understanding Types, Data Abstraction, and Polymorphism
On Understanding Types, Data Abstraction, and Polymorphism LUCA CARDELLI AT&T Bell Laboratories, Murray Hill, N. J. 07974 PETER WEGNER Department of Computer Science, Brown University, Providence, R. I.
More informationEmbedding effect systems in Haskell
Embedding effect systems in Haskell Dominic Orchard Tomas Petricek Computer Laboratory, University of Cambridge firstname.lastname@cl.cam.ac.uk Abstract Monads are now an everyday tool in functional programming
More informationType Systems. Luca Cardelli. Microsoft Research
Type Systems Luca Cardelli Microsoft Research 1 Introduction The fundamental purpose of a type system is to prevent the occurrence of execution errors during the running of a program. This informal statement
More informationWeyl s Predicative Classical Mathematics as a LogicEnriched Type Theory
Weyl s Predicative Classical Mathematics as a LogicEnriched Type Theory ROBIN ADAMS and ZHAOHUI LUO Dept of Computer Science, Royal Holloway, Univ of London We construct a logicenriched type theory LTT
More informationOn Understanding Types, Data Abstraction, and Polymorphism
1 Computing Surveys, Vol 17 n. 4, pp 471522, December 1985 On Understanding Types, Data Abstraction, and Polymorphism Luca Cardelli AT&T Bell Laboratories, Murray Hill, NJ 07974 (current address: DEC
More information