CS 641 Lecture -*- Outline -*- * Cartesian Closed Categories category theory helps in guiding discovery of concepts, structures, theorems presentation better set of basic tools than set thery, because it's "typed" focus on the operations (arrows) of the types involved not the representation cartesian closed categories formlize the notions of application and abstraction ** Binary products *** examples **** sets A x B = {(a,b) | a in A, b in B} y in A x B is uniquely determined by fst(y), snd(y): y = (fst(y), snd(y)) **** product of posets (P,<=p) x (Q,<=q) = (PxQ,<=) where (x,y) <= (x',y') iff x <=p x' and y <=q y' *** definition let C be a category, let A,B be objects of C. A product of A and B consists of *an object of C*, A x B and a pair of arrows (of C), fst: AxB -> A and snd: AxB -> B with the universal property that for all objects D and arrows f: D->A, g:D->B, there is a unique arrow :D->AxB such that fst o = f and snd o = g *draw the diagram with A <-fst- AxB -snd-> B on the bottom* Products are not unique (so don't say "the product") only defined up to unique isomorphism *** product arrows Can use the unique arrow guaranteed the product to define the product of two arrows f: A->B and f':A'->B' fxf':AxA' -> BxB' *draw the diagram with B <-fst- BxB' -snd-> B' on the bottom* is the unique arrow ** finite products *** terminal objects A terminal object in a category C is an object 1 s.t., for each object A, there is a unique arrow !_A: A -> 1. e.g., in Set, a singleton set is terminal *draw the diagram to show that 1 and 1' must be isomorphic* dual notion: initial objects, also important *** points in a category with terminal objects p: 1->A is a point of A has to be a constant function so applying f to a, where a in A is the same as the point f o p, where p:1->A is such that p(x) = a. *** category with finite products = category with products and terminal object 1 x A =~= A x 1 inductive def of finite products: x() = 1 x(A1,...,An) = (x(A1,...An-1)) x An for n>0 pi_i^n: x(A1,...,An) -> Ai ** exponentials Let CC be a category with products An exponential of objects B and C in CC is an object C^B = [B->C] and an arrow apply: C^B x B -> C = [B->C]xB -> C with the following universal property: for all objects A and arrows f: AxB->C in CC there is a unique arrow (curry(f) x id_B) such that apply o (curry(f) x id_B) = f lemma: if h: A -> (B -> C) then h = curry(apply o (h x id_B)). ** ccc = category with finite products and exponentials *** example: Set *** example: posets *** property: Hom(CxA,B) isomorphic to Hom(C,A->B) given by curry as follows g:(CxA)->B) |--> curry(g):(C->(A->B)) exercise (don't do in class): prove this ** lambda calculus with products *** Syntax add type constants (basic types) and term constants (e.g., 1, 2) Sigma_t is set of type constants (e.g., Bool, Nat, ...) Sigma_e is set of term constants (e.g., (1,Nat), (true,Bool)) of form (c,s), where s is a type expression over Sigma_t add product types tupling expressions, fst, and snd ---------------- t ::= C | t->t | t x t | (t) e ::= c | \x:t.e | e e | (e,e) | fst(e) | snd(e) | (e) ---------------- raw terms with signature Sigma = (Sigma_t, Sigma_e) *** Typing rules add the following to those of simply typed lambda calculus --------------------- [constant] H |- c:s if (c,s) in Sigma_e [pairing] H |- e1:s, H |- e2:t ==> H |- (e1,e2) : s x t [first] H |- e : s x t ==> H |- fst(e) : s [second] H |- e : s x t ==> H |- snd(e) : t --------------------- *** Equational rules add the following to those of simply typed lambda calculus ---------------------- {Pair} H |- (fst(e), snd(e)) = e : s x t {First} H |- fst(e1,e2) = e1 : s {Second} H |- snd(e1,e2) = e2 : t {Congruence} H|-e1=e1':s, H|-e2=e2':t ==> H|-(e1,e2)=(e1',e2'):sxt ---------------------- ** Ccc models ----------------------- A ccc model of a \-calculus with signature Sigma is a ccc (CC, 1, x, ->) and a maping CC[[.]]: Sigma_t -> objects of CC, i.e., if T is a type constant, then CC[[T]] is a object of CC s.t. CC[[s -> t]] = [ CC[[s]] -> CC[[t]] ] and CC[[s x t]] = CC[[s]] x CC[[t]]. a mapping CC[[.]]: Sigma_e -> points of CC i.e., if (c,s) is a term constant, then CC[[c]]: 1 -> CC[[s]] is an arrow of CC ----------------------- write [[.]] for CC[[.]] below *** meaning function on terms ---------------- [[H |> e :s]] : x([[s1]],...,[[sn]]) -> [[s]] where H = x1:s1, ..., xn:sn ---------------- i.e., takes an environment and gives an element of s ---------------------- let A = x([[s1]],...,[[sn]]) -constants: [[H |> c:s]] = [[c]] o !_A -projection: [[H |> xi:si]] = pi_i^n -abstraction: [[H |> \x:u.e':u->v]] = curry([[H,x:u |> e':v]]) -application: [[H |> (e0 e1):s]] = apply o <[[H |> e0:t->s]], [[H |> e1:t]]> -pair: [[H |> (e1,e2):s x t]] = <[[H |> e1:s]], [[H |> e2:t]]> -first: [[H |> fst(e):s]] = fst o [[H |> e : s x t]] ---------------------- work example: [[ |> (\x:s . \f:s->t . f(x)): s -> (s->t) -> t]] or [[ H |> \x:s . e(x) : s -> t ]] *** soundness lemma (eta-rule soundness): if x is not in Fv(e), then [[H, x:s |> e:t]] = [[H |> e:t]] o fst. Pf: induction on structure of e. lemma (substitution): Let f = [[H, x:s |> e:t]] : A x B -> C and g = [[H |> e':s]] : A -> B. Then [[H |> [e'/x]e : t]] = f o : A-> C. Pf: induction on structure of e. ** Type frames in a ccc relation between cccs a type frames as models? cccs are more general frames use functions to interpret terms of higher type, cccs interpret them using points substitution (induction) vs. diagram property (of exponentials?) *** set-like ccc's (concrete categories) 1. objects a in C are sets 2. arrows of ccc are set functions, apply of the ccc is the same as function application 3. exponential in CCC is a set of functions *** generated type frame pick X in the category as interpretation of type o use for D^{s->t} the set of all arrows D^s -> D^t in the ccc e.g., over the ccc Set, get full type frame over a chosen set claim: A[[H |> e:t]]r = C[[H |> e:t]](r(x1), ..., r(xn))