1 / 37

Lecture 3: Object Concepts as Categories

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/. Introduction. Look at use of categories for application: Modelling of object information systems

bjay
Download Presentation

Lecture 3: Object Concepts as Categories

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. 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 Student dependency function StudentId StudentName {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:1S 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 (23) arrows trivial dependencies as projections

  12. Example of Normalization Test 2 • PRJ: as POS but with addition of non-trivial dependency a b 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(f1) o F(f2) =F(f1 o f2) F c = F(c) f h F(f) F(h) b a F(b) F(a) g F(g)

  16. Functors Preserve Identities • Functors preserve identities: F(1a) = 1F(a) • That is: F (1a : a a) = 1F(a) : F(a) F(a)

  17. Functors are Arrows • They are composable F : A B G: B C C H = G o F G H B A 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 1A : AA 1A is identity functor for category A

  24. Relationships between Classes • Association: by pullback Student pil f Student xmark Exam Mark pir 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 Manager Employee

  27. Inheritance as Commuting Diagram • More detailed representation as commuting diagram f Manager il U Manager+ g ir Employee Employee • Gives unqualified union (U is universal object) il o f = ir 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 B emptyset 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: CLASS OBJECT • 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 = I TYPE E = Name P I CLASS OBJECT E

  32. Information System Queries • D : CLASSOBJECT 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 CLASSDS OBJECTDS DS

  36. Details of Natural Transformation DS(source(f)) qa D(source(f)) DS(f) D(f) DS(target(f)) qb D(target(f)) For each f in CLASSDS, the equation: D(f) o qa = qb 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).

More Related