Download presentation
Presentation is loading. Please wait.
Published byLeon Potter Modified over 8 years ago
1
Lecture 3: Object Concepts as Categories Nick Rossiter, Computing Science, Newcastle University, England B.N.Rossiter@newcastle.ac.uk http://www.cs.ncl.ac.uk/people/b.n.rossiter/
2
Introduction Look at use of categories for application: –Modelling of object information systems Introduce further categorical constructions: –Functors –Cartesian Closed Categories –Natural Transformations
3
Classes as Categories Classes have –identifiers: represented by a categorical object –attributes: represented by an arrow from the identifier (as source) to each attribute (as target) arrows of type assignment arrows can be monic or epic
4
Classes as Categories -- Methods –methods: represented by arrows from one or more attributes to another attribute. arrows of type function We define the Category Class in the universal category Set to have the above constructions.
5
Example Class Category Studentd ependency function StudentIdStudentName {Module Module Title Mark} AverageMark Will structure some of this later as pullback (N:M)
6
Example Class - Observations StudentId is initial object of category Identifiers/keys are usually initial objects No terminal object as it stands StudentId StudentName is not monic nor epic Module ModuleTitle is monic (1:1)
7
Example Class - Types The class category Student forms one type for use elsewhere in the system Arrows are also typed e.g. –Module ModuleTitle is monic –StudentId is in the domain available for student identifiers in the discrete category S: s: SStudentId (or s:1 S StudentId) There must be a mapping for the instance s from the discrete category S to StudentId
8
Constraints: Example of Keys Constraints such as normalization tests can be applied e.g. Boyce-Codd Normal Form (BCNF) For a relation, say R(a,b,c,d), can determine the candidate keys from the given (non- trivial) functional dependencies. Can then test whether every determinant (source of non-trivial functional dependency) is a candidate key
9
Procedure for Normalization Test 1 Take category CLASS Transform CLASS to POS where: –the objects are the powerset of those in CLASS –the arrows are the orderings by projection (trivial functional dependencies) Create a category DEP holding the non- trivial functional dependencies. Embed POS and DEP in a category PRJ
10
Procedure for Normalization Test 2 Determine limit of singleton attributes in PRJ (greatest lower bound) if it exists If no limit, determine maximal lower bounds. Assign limit or maximal lower bounds to candidate key.
11
Example of Normalization Test 1 CLASS: objects a,b,c, arrow a b identity arrows for each object POS: objects powerset of a,b,c (2 3 ) arrows trivial dependencies as projections
12
Example of Normalization Test 2 PRJ: as POS but with addition of non- trivial dependency ab empty {a} {b}{c} {a,b}{a,c}{b,c} trivial {a,b,c} non-trivial
13
Example of Normalization Test 3 Let Y = {{a}, {b}, {c}} (singleton attributes) Limit Y = {a,c} (greatest lower bound) Candidate key = {a,c} Determinant = {a} So not BCNF as not every determinant is a candidate key.
14
Further Category Constructions: The Functor Categories are mapped from one to another by a higher-order function called a Functor. A functor F maps from category A to B by: –assigning each F(a) to B –assigning each F(f) to B where a is an object in A and f is an arrow in A
15
Functors Preserve Composition F(f 1 ) o F(f 2 ) = F(f 1 o f 2 ) F c= F(c) fhF(f)F(h) ba F(b)F(a) g F(g)
16
Functors Preserve Identities Functors preserve identities: F(1 a ) = 1 F(a) That is: F (1 a : a a) = 1 F(a) : F(a) F(a)
17
Functors are Arrows They are composable F : A B G: BC CH = G o F G H BA F
18
Functors are Associative Their evaluation is associative. The order of evaluation of three or more composed functors does not matter
19
Scope of Functors Can preserve source category structure in target category: F: A B Full and faithful functor: A,B same structure
20
Free Functors Can assign additional structures For example assign to each set its powerset (all combinations): POWER: CLASSPOS assigns the powerset of the set, say Y, in CLASS to POS. Free functor
21
Forgetful Functors Can forget structure For example forget set functions in a Set category. REMOVE_FUNCTIONS: Set Discrete Underlying (Forgetful) functor Returns elements only
22
Functors for Embedding The functors EMBED1: POSPRJ EMBED2: DEPPRJ embed the arrows of POS and DEP in PRJ. Inclusion functor
23
Identity Functor Can identify a category 1 A : AA 1 A is identity functor for category A
24
Relationships between Classes Association: by pullback Student pi l f Student x mark ExamMark pi r g Exam
25
Semantics of Pullbacks Gives constraints of entity-relationship modelling of relationships: –cardinality of 1:1, 1:N, N:M –mandatory or optional participation –can paste together pullbacks to give n-ary relationships –colimit of diagram includes the link object, the name of which appears as the product suffix
26
Inheritance Through coproducts: as cone Manager+Employee ManagerEmployee
27
Inheritance as Commuting Diagram More detailed representation as commuting diagram fManager i l UManager+ gi r Employee Employee Gives unqualified union (U is universal object)i l o f = i r o g
28
Cartesian Closed Categories Widespread use in computing science A Cartesian closed category has: –a terminal object –products –exponentials (connectivity - no discrete objects)
29
Examples Cartesian Closed The diagrams for products, coproducts, pullbacks and pushouts are examples of Cartesian closed categories Further example: A A X B X C Bemptyset C has products, terminal object (empty set) and connectivity (no discrete objects)
30
Object Instantiation The Extension -- the category OBJECT representing the objects associated with each category Functors relate intension to extension: Data: CLASSOBJECT and extension to intension: Name: OBJECT CLASS
31
Constraints with Functors The functors preserve types, composition, identities and limits of the intension in the extension. P o E = ITYPE E = Name P I CLASSOBJECT E
32
Information System Queries D : CLASS OBJECT D is database with CLASS as intension and OBJECT as extension Query q on D returns subset of database DS with intension CLASSDS and extesnion OBJECTDS: DS : CLASSDS OBJECTDS
33
Query DS Query is: q: DS D DS is subset of D Both DS and D are functors
34
Natural Transformation q is natural transformation as it maps from one functor to another Functors must be of similar type Assigns underlying categorical objects and arrows of one functor to another
35
Simple View D CLASS OBJECT q CLASSDSOBJECTDS DS
36
Details of Natural Transformation DS(source(f)) q a D(source(f)) DS(f)D(f) DS(target(f))q b D(target(f)) For each f in CLASSDS, the equation: D(f) o q a = q b o DS(f)must hold
37
Further Reading Categories for the Working Mathematician Mac Lane, Saunders 2nd edition Springer-Verlag (1998). Prototyping a Categorical Database in P/FDM, Nelson, D A, & Rossiter, B N, Proc. 2nd Int. Workshop Advances in Databases and Information Systems (ADBIS'95), Moscow, 27-30 June 1995, Springer-Verlag Workshops in Computing, ISBN 3-540-76014-8, 432--456 (1996).
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.