SlideShare une entreprise Scribd logo
1  sur  23
Formal Methods in
Software
Lecture 7. Category Theory
Vlad Patryshev
SCU
2014
In This Lecture
• database example
• terminal object, initial object;
• products, unions
• equalizers
• pullbacks
Database Example
create type rels as enum (‘spouse’, ‘child’, ‘partner’);
create type jobs as enum (‘ceo’, ‘cto’, ‘eng’, ‘sales’);
create table Person (id bigint, name varchar(80), primary key (id));
create table Company (id bigint, name varchar(80), primary key (id));
create table Rel (from bigint, to bigint, kind rels,
constraint p1_fk foreign key (from references Person(id),
constraint p2_fk foreign key (yo references Person(id)
);
create table Job (company bigint, employee bigint, position jobs,
constraint c_fk foreign key (comp references Company(id),
constraint p_fk foreign key (pers references Person(id)
);
“Conceptual Model”
Person
id
name
Company
id
name
Job
position
company
employee
Relationship
kind
from
to
rels
{spouse,
child,
partner}
jobs
{ceo, cto,
eng, sales}
“More Conceptual Model”
Person
name
Company
name
Job
Relationship
rels
{spouse,
child,
partner}
jobs
{ceo, cto,
eng, sales}
“More Conceptual Model”
Person
name
Company
name
Job
Relationship
rels
{spouse,
child,
partner}
jobs
{ceo, cto,
eng, sales}
It’s a category!
Pet Database
create type kind as enum (‘cat’, ‘dog’, ‘fly’, ‘hamster’, ‘e.coli’);
create table Person (id bigint, name varchar(80), pet bigint,
primary key (id),
constraint pet_fk foreign key (pet references Animal(id));
create table Animal (id bigint, kind kind, name varchar(80), owner
bigint,
primary key (id),
constraint owner_pk foreign key owner references Person(id));
“More Conceptual Model”
Person
name
Animal
kind
{cat, dog,
fly, hamster,
e.coli}
Where’s composition?
kind(pet(owner(pet(“John”)))
select kind from Animal a where a.owner
in (select id from Person where pet in
(select id from Animal where owner in
(select id from person where
name=’John’)));
Initial Object in a Category
Definition. Given a category C, Initial Object is such an object 0 that there is
a unique function iX:0 → X for any given X. (this is its “universal property”)
Note that if we take X=0, we see that there is just one function 0 → 0. Can
you name a set (or two) with only one function S→S?
And what if there’s more than one such an object? Say 01 and 02, both have
this interesting feature. Then, for 01, we have a unique a:01 → 02; and
similarly we have a unique b:02 → 01. Composing a and b either way, we
get an identity; so they are isomorphisms.
Initial object is unique up to an isomorphism.
Examples of Initial Objects
• Sets: ∅, and it is unique (by sets axioms)
• Monoids: {0} - all “such monoids” are isomorphic
• Categories: empty category (whether there’s a plurality of them…)
• In this category of three objects we see no initial object:
• In this category c is initial object:
• How about more than one
initial object?
They are
isomorphic!
Terminal Object in a Category
Definition. Given a category C, Terminal Object is such an object 1 that
there is a unique function uX:X → 1 for any given X. (this is its “universal
property”)
Note that if we take X=1, we see that there is just one function 1 → 1, same
as with 0.
And what if there’s more than one such an object? Say 11 and 12, both have
this interesting feature. Then, for 11, we have a unique a:11 → 12; and
similarly we have a unique b:12 → 11. Composing a and b either way, we
get an identity; so they are isomorphisms.
Terminal object, like initial one, is unique up to an isomorphism.
Examples of Terminal Objects
• Sets: any singleton {x} is terminal. They are not equal, but are isomorphic.
• Monoids: {0} - all “such monoids” are isomorphic
• Categories: empty category (whether there’s a plurality of them…)
• In this category of three objects we see no terminal object:
• In this category c is terminal object:
Initial and Terminal Object in our DB
terminal
Cartesian Product
Definition. Given a category C, and two objects in it, X and Y, their Cartesian
Product is such an object Z=X×Y, together with two functions, pX:Z→X and
pY:Z→Y, that for any pair f:A→X and g:A→Y, f=pX∘h and g=pY∘h for some
unique h. (this is its “universal property”)
Cartesian product is unique up to an isomorphism. (proof?)
Examples of Cartesian Products
• Sets: AxB = {(a,b)|a∈A,b∈B}, and it is unique (by sets axioms)
• Databases: select * from A,B;
• Good programming languages, e.g. Scala: (A,B)
val intWithString: (Int, String) = (42, “Hello 42”)
• In a monoid? We have just one object!
• In a poset? It’s min(a,b)
Disjoint Union (dual to Product)
Definition. Given a category C, and two objects in it, X and Y, their Disjoint
Union is such an object Z=X+Y, together with two functions, iX:X→Z and
iY:Y→Z, that for any pair f:X→A and g:Y→A, f=h∘iX and g=h∘iY for some
unique h. (this is its “universal property”)
Disjoint union is unique up to an isomorphism. (proof?)
Examples of Disjoint Unions
• Sets: A+B = A∪B, and it is unique (by sets axioms)
• Databases: select * from A union B;
• Good programming languages, e.g. Scala: Either[A,B]
val intOrString: Either[Int, String] = Left(42)// Right(“Hello 42”)
• In a poset? It’s max(a,b)
Equalizers
Definition. Given a category C, two objects in it, X and Y, and two functions,
f,g:X→Y, their Equalizer is such an object E=Eq(f,g), together with a
function eq:E→X, such that that f∘eq=g∘eq for any m:O→X, m=eq∘u for
some unique u. (this is its “universal property”)
An equalizer is unique up to an isomorphism. (proof?)
Pullbacks
Definition. Given a category C, objects, X, Y and Z, and two functions,
f:X→Z and g:X→Z, their Pullback is such an object X×ZY, together with
functions pX:X×ZY→X and pY:X×ZY→Y, such that g∘pY = f∘pX, and for any
pair x:U→X, y:U→Y, x=pX∘h and y=pY∘h for some unique h. (this is its
“universal property”)
A pullback is unique up to an isomorphism. (proof?)
Examples of Pullbacks
• Sets: {(x,y)|x∈X,y∈Y,f(x)=g(y)}
• Databases: select * from A, B where A.f=B.g;
e.g. select * from Person A, Person B where A.pet=B.pet;
• In a poset? Same as min.
• Cartesian products are pullbacks.
References
http://www.amazon.com/Category-Computer-Scientists-Foundations-Computing/dp/0262660717
Wikipedia
Formal methods   7 - category theory

Contenu connexe

Tendances

Programming haskell chapter10
Programming haskell chapter10Programming haskell chapter10
Programming haskell chapter10Kousuke Ruichi
 
Scala categorytheory
Scala categorytheoryScala categorytheory
Scala categorytheoryKnoldus Inc.
 
Functional and Algebraic Domain Modeling
Functional and Algebraic Domain ModelingFunctional and Algebraic Domain Modeling
Functional and Algebraic Domain ModelingDebasish Ghosh
 
Bayesian Methods for Machine Learning
Bayesian Methods for Machine LearningBayesian Methods for Machine Learning
Bayesian Methods for Machine Learningbutest
 
Architectural Patterns in Building Modular Domain Models
Architectural Patterns in Building Modular Domain ModelsArchitectural Patterns in Building Modular Domain Models
Architectural Patterns in Building Modular Domain ModelsDebasish Ghosh
 
Application of ordinal logistic to pregnancy outcomes
Application of ordinal logistic to pregnancy outcomesApplication of ordinal logistic to pregnancy outcomes
Application of ordinal logistic to pregnancy outcomesAlexander Decker
 
كتيب ملخصات دروس للرياضيات السنة الثانية ثانوي 2
كتيب   ملخصات دروس للرياضيات السنة الثانية ثانوي 2كتيب   ملخصات دروس للرياضيات السنة الثانية ثانوي 2
كتيب ملخصات دروس للرياضيات السنة الثانية ثانوي 2math44
 

Tendances (11)

Programming haskell chapter10
Programming haskell chapter10Programming haskell chapter10
Programming haskell chapter10
 
5
55
5
 
Scala categorytheory
Scala categorytheoryScala categorytheory
Scala categorytheory
 
An introduction to scala
An introduction to scalaAn introduction to scala
An introduction to scala
 
Functional and Algebraic Domain Modeling
Functional and Algebraic Domain ModelingFunctional and Algebraic Domain Modeling
Functional and Algebraic Domain Modeling
 
Nested loop
Nested loopNested loop
Nested loop
 
Bayesian Methods for Machine Learning
Bayesian Methods for Machine LearningBayesian Methods for Machine Learning
Bayesian Methods for Machine Learning
 
Architectural Patterns in Building Modular Domain Models
Architectural Patterns in Building Modular Domain ModelsArchitectural Patterns in Building Modular Domain Models
Architectural Patterns in Building Modular Domain Models
 
Application of ordinal logistic to pregnancy outcomes
Application of ordinal logistic to pregnancy outcomesApplication of ordinal logistic to pregnancy outcomes
Application of ordinal logistic to pregnancy outcomes
 
Cats in Scala
Cats in ScalaCats in Scala
Cats in Scala
 
كتيب ملخصات دروس للرياضيات السنة الثانية ثانوي 2
كتيب   ملخصات دروس للرياضيات السنة الثانية ثانوي 2كتيب   ملخصات دروس للرياضيات السنة الثانية ثانوي 2
كتيب ملخصات دروس للرياضيات السنة الثانية ثانوي 2
 

En vedette

Introduction to formal methods
Introduction to formal methodsIntroduction to formal methods
Introduction to formal methodsInzemamul Haque
 
Formal methods 4 - Z notation
Formal methods   4 - Z notationFormal methods   4 - Z notation
Formal methods 4 - Z notationVlad Patryshev
 
Agile Software Development Overview
Agile Software Development OverviewAgile Software Development Overview
Agile Software Development OverviewDUONG Trong Tan
 
Formal Verification Techniques
Formal Verification TechniquesFormal Verification Techniques
Formal Verification TechniquesDVClub
 
Formal Methods lecture 01
Formal Methods lecture 01Formal Methods lecture 01
Formal Methods lecture 01Sidra Ashraf
 
#1 formal methods – introduction for software engineering
#1 formal methods – introduction for software engineering#1 formal methods – introduction for software engineering
#1 formal methods – introduction for software engineeringSharif Omar Salem
 

En vedette (9)

Introduction to formal methods
Introduction to formal methodsIntroduction to formal methods
Introduction to formal methods
 
Formal methods 4 - Z notation
Formal methods   4 - Z notationFormal methods   4 - Z notation
Formal methods 4 - Z notation
 
Agile Software Development Overview
Agile Software Development OverviewAgile Software Development Overview
Agile Software Development Overview
 
Z specification
Z specificationZ specification
Z specification
 
Formal Verification Techniques
Formal Verification TechniquesFormal Verification Techniques
Formal Verification Techniques
 
Formal Methods lecture 01
Formal Methods lecture 01Formal Methods lecture 01
Formal Methods lecture 01
 
Formal Methods
Formal MethodsFormal Methods
Formal Methods
 
#1 formal methods – introduction for software engineering
#1 formal methods – introduction for software engineering#1 formal methods – introduction for software engineering
#1 formal methods – introduction for software engineering
 
Formal verification
Formal verificationFormal verification
Formal verification
 

Similaire à Formal methods 7 - category theory

Intoduction to Homotopy Type Therory
Intoduction to Homotopy Type TheroryIntoduction to Homotopy Type Therory
Intoduction to Homotopy Type TheroryJack Fox
 
It Is Possible to Do Object-Oriented Programming in Java
It Is Possible to Do Object-Oriented Programming in JavaIt Is Possible to Do Object-Oriented Programming in Java
It Is Possible to Do Object-Oriented Programming in JavaKevlin Henney
 
What can scala puzzlers teach us
What can scala puzzlers teach usWhat can scala puzzlers teach us
What can scala puzzlers teach usDaniel Sobral
 
Absolute and Relative Clustering
Absolute and Relative ClusteringAbsolute and Relative Clustering
Absolute and Relative ClusteringToshihiro Kamishima
 
Real World Haskell: Lecture 4
Real World Haskell: Lecture 4Real World Haskell: Lecture 4
Real World Haskell: Lecture 4Bryan O'Sullivan
 
Build a compiler using C#, Irony and RunSharp.
Build a compiler using C#, Irony and RunSharp.Build a compiler using C#, Irony and RunSharp.
Build a compiler using C#, Irony and RunSharp.James Curran
 
Monads and Monoids by Oleksiy Dyagilev
Monads and Monoids by Oleksiy DyagilevMonads and Monoids by Oleksiy Dyagilev
Monads and Monoids by Oleksiy DyagilevJavaDayUA
 
Category Theory in 10 Minutes
Category Theory in 10 MinutesCategory Theory in 10 Minutes
Category Theory in 10 MinutesJordan Parmer
 
Scala categorytheory
Scala categorytheoryScala categorytheory
Scala categorytheoryMeetu Maltiar
 
Dm2021 binary operations
Dm2021 binary operationsDm2021 binary operations
Dm2021 binary operationsRobert Geofroy
 
Power of functions in a typed world
Power of functions in a typed worldPower of functions in a typed world
Power of functions in a typed worldDebasish Ghosh
 
Database Design and Normalization Techniques
Database Design and Normalization TechniquesDatabase Design and Normalization Techniques
Database Design and Normalization TechniquesNishant Munjal
 

Similaire à Formal methods 7 - category theory (20)

ECMA 入门
ECMA 入门ECMA 入门
ECMA 入门
 
Intoduction to Homotopy Type Therory
Intoduction to Homotopy Type TheroryIntoduction to Homotopy Type Therory
Intoduction to Homotopy Type Therory
 
It Is Possible to Do Object-Oriented Programming in Java
It Is Possible to Do Object-Oriented Programming in JavaIt Is Possible to Do Object-Oriented Programming in Java
It Is Possible to Do Object-Oriented Programming in Java
 
What can scala puzzlers teach us
What can scala puzzlers teach usWhat can scala puzzlers teach us
What can scala puzzlers teach us
 
Elements of functional programming
Elements of functional programmingElements of functional programming
Elements of functional programming
 
Sets, functions and groups
Sets, functions and groupsSets, functions and groups
Sets, functions and groups
 
Absolute and Relative Clustering
Absolute and Relative ClusteringAbsolute and Relative Clustering
Absolute and Relative Clustering
 
Real World Haskell: Lecture 4
Real World Haskell: Lecture 4Real World Haskell: Lecture 4
Real World Haskell: Lecture 4
 
Prolog2 (1)
Prolog2 (1)Prolog2 (1)
Prolog2 (1)
 
Build a compiler using C#, Irony and RunSharp.
Build a compiler using C#, Irony and RunSharp.Build a compiler using C#, Irony and RunSharp.
Build a compiler using C#, Irony and RunSharp.
 
Monads and Monoids by Oleksiy Dyagilev
Monads and Monoids by Oleksiy DyagilevMonads and Monoids by Oleksiy Dyagilev
Monads and Monoids by Oleksiy Dyagilev
 
Propositional Logic and Pridicate logic
Propositional Logic and Pridicate logicPropositional Logic and Pridicate logic
Propositional Logic and Pridicate logic
 
Python speleology
Python speleologyPython speleology
Python speleology
 
Category Theory in 10 Minutes
Category Theory in 10 MinutesCategory Theory in 10 Minutes
Category Theory in 10 Minutes
 
Scala categorytheory
Scala categorytheoryScala categorytheory
Scala categorytheory
 
Scala jargon cheatsheet
Scala jargon cheatsheetScala jargon cheatsheet
Scala jargon cheatsheet
 
Java Day-4
Java Day-4Java Day-4
Java Day-4
 
Dm2021 binary operations
Dm2021 binary operationsDm2021 binary operations
Dm2021 binary operations
 
Power of functions in a typed world
Power of functions in a typed worldPower of functions in a typed world
Power of functions in a typed world
 
Database Design and Normalization Techniques
Database Design and Normalization TechniquesDatabase Design and Normalization Techniques
Database Design and Normalization Techniques
 

Plus de Vlad Patryshev

Formal methods 8 - category theory (last one)
Formal methods   8 - category theory (last one)Formal methods   8 - category theory (last one)
Formal methods 8 - category theory (last one)Vlad Patryshev
 
Formal methods 5 - Pi calculus
Formal methods   5 - Pi calculusFormal methods   5 - Pi calculus
Formal methods 5 - Pi calculusVlad Patryshev
 
Formal methods 3 - languages and machines
Formal methods   3 - languages and machinesFormal methods   3 - languages and machines
Formal methods 3 - languages and machinesVlad Patryshev
 
Formal methods 2 - languages and machines
Formal methods   2 - languages and machinesFormal methods   2 - languages and machines
Formal methods 2 - languages and machinesVlad Patryshev
 
Formal methods 1 - introduction
Formal methods   1 - introductionFormal methods   1 - introduction
Formal methods 1 - introductionVlad Patryshev
 
Truth, deduction, computation lecture i (last one)
Truth, deduction, computation   lecture i (last one)Truth, deduction, computation   lecture i (last one)
Truth, deduction, computation lecture i (last one)Vlad Patryshev
 
Truth, deduction, computation lecture h
Truth, deduction, computation   lecture hTruth, deduction, computation   lecture h
Truth, deduction, computation lecture hVlad Patryshev
 
Truth, deduction, computation lecture g
Truth, deduction, computation   lecture gTruth, deduction, computation   lecture g
Truth, deduction, computation lecture gVlad Patryshev
 
Truth, deduction, computation lecture f
Truth, deduction, computation   lecture fTruth, deduction, computation   lecture f
Truth, deduction, computation lecture fVlad Patryshev
 
Truth, deduction, computation lecture e
Truth, deduction, computation   lecture eTruth, deduction, computation   lecture e
Truth, deduction, computation lecture eVlad Patryshev
 
Truth, deduction, computation lecture d
Truth, deduction, computation   lecture dTruth, deduction, computation   lecture d
Truth, deduction, computation lecture dVlad Patryshev
 
Truth, deduction, computation lecture c
Truth, deduction, computation   lecture cTruth, deduction, computation   lecture c
Truth, deduction, computation lecture cVlad Patryshev
 
Truth, deduction, computation lecture b
Truth, deduction, computation   lecture bTruth, deduction, computation   lecture b
Truth, deduction, computation lecture bVlad Patryshev
 
Truth, deduction, computation lecture a
Truth, deduction, computation   lecture aTruth, deduction, computation   lecture a
Truth, deduction, computation lecture aVlad Patryshev
 
Truth, deduction, computation lecture 9
Truth, deduction, computation   lecture 9Truth, deduction, computation   lecture 9
Truth, deduction, computation lecture 9Vlad Patryshev
 
Truth, deduction, computation lecture 8
Truth, deduction, computation   lecture 8Truth, deduction, computation   lecture 8
Truth, deduction, computation lecture 8Vlad Patryshev
 
Truth, deduction, computation lecture 7
Truth, deduction, computation   lecture 7Truth, deduction, computation   lecture 7
Truth, deduction, computation lecture 7Vlad Patryshev
 
Truth, deduction, computation lecture 6
Truth, deduction, computation   lecture 6Truth, deduction, computation   lecture 6
Truth, deduction, computation lecture 6Vlad Patryshev
 
Truth, deduction, computation; lecture 5
Truth, deduction, computation;  lecture 5Truth, deduction, computation;  lecture 5
Truth, deduction, computation; lecture 5Vlad Patryshev
 
Truth, deduction, computation; lecture 4
Truth, deduction, computation;  lecture 4Truth, deduction, computation;  lecture 4
Truth, deduction, computation; lecture 4Vlad Patryshev
 

Plus de Vlad Patryshev (20)

Formal methods 8 - category theory (last one)
Formal methods   8 - category theory (last one)Formal methods   8 - category theory (last one)
Formal methods 8 - category theory (last one)
 
Formal methods 5 - Pi calculus
Formal methods   5 - Pi calculusFormal methods   5 - Pi calculus
Formal methods 5 - Pi calculus
 
Formal methods 3 - languages and machines
Formal methods   3 - languages and machinesFormal methods   3 - languages and machines
Formal methods 3 - languages and machines
 
Formal methods 2 - languages and machines
Formal methods   2 - languages and machinesFormal methods   2 - languages and machines
Formal methods 2 - languages and machines
 
Formal methods 1 - introduction
Formal methods   1 - introductionFormal methods   1 - introduction
Formal methods 1 - introduction
 
Truth, deduction, computation lecture i (last one)
Truth, deduction, computation   lecture i (last one)Truth, deduction, computation   lecture i (last one)
Truth, deduction, computation lecture i (last one)
 
Truth, deduction, computation lecture h
Truth, deduction, computation   lecture hTruth, deduction, computation   lecture h
Truth, deduction, computation lecture h
 
Truth, deduction, computation lecture g
Truth, deduction, computation   lecture gTruth, deduction, computation   lecture g
Truth, deduction, computation lecture g
 
Truth, deduction, computation lecture f
Truth, deduction, computation   lecture fTruth, deduction, computation   lecture f
Truth, deduction, computation lecture f
 
Truth, deduction, computation lecture e
Truth, deduction, computation   lecture eTruth, deduction, computation   lecture e
Truth, deduction, computation lecture e
 
Truth, deduction, computation lecture d
Truth, deduction, computation   lecture dTruth, deduction, computation   lecture d
Truth, deduction, computation lecture d
 
Truth, deduction, computation lecture c
Truth, deduction, computation   lecture cTruth, deduction, computation   lecture c
Truth, deduction, computation lecture c
 
Truth, deduction, computation lecture b
Truth, deduction, computation   lecture bTruth, deduction, computation   lecture b
Truth, deduction, computation lecture b
 
Truth, deduction, computation lecture a
Truth, deduction, computation   lecture aTruth, deduction, computation   lecture a
Truth, deduction, computation lecture a
 
Truth, deduction, computation lecture 9
Truth, deduction, computation   lecture 9Truth, deduction, computation   lecture 9
Truth, deduction, computation lecture 9
 
Truth, deduction, computation lecture 8
Truth, deduction, computation   lecture 8Truth, deduction, computation   lecture 8
Truth, deduction, computation lecture 8
 
Truth, deduction, computation lecture 7
Truth, deduction, computation   lecture 7Truth, deduction, computation   lecture 7
Truth, deduction, computation lecture 7
 
Truth, deduction, computation lecture 6
Truth, deduction, computation   lecture 6Truth, deduction, computation   lecture 6
Truth, deduction, computation lecture 6
 
Truth, deduction, computation; lecture 5
Truth, deduction, computation;  lecture 5Truth, deduction, computation;  lecture 5
Truth, deduction, computation; lecture 5
 
Truth, deduction, computation; lecture 4
Truth, deduction, computation;  lecture 4Truth, deduction, computation;  lecture 4
Truth, deduction, computation; lecture 4
 

Dernier

COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsNbelano25
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationNeilDeclaro1
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 

Dernier (20)

COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health Education
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 

Formal methods 7 - category theory

  • 1. Formal Methods in Software Lecture 7. Category Theory Vlad Patryshev SCU 2014
  • 2. In This Lecture • database example • terminal object, initial object; • products, unions • equalizers • pullbacks
  • 3. Database Example create type rels as enum (‘spouse’, ‘child’, ‘partner’); create type jobs as enum (‘ceo’, ‘cto’, ‘eng’, ‘sales’); create table Person (id bigint, name varchar(80), primary key (id)); create table Company (id bigint, name varchar(80), primary key (id)); create table Rel (from bigint, to bigint, kind rels, constraint p1_fk foreign key (from references Person(id), constraint p2_fk foreign key (yo references Person(id) ); create table Job (company bigint, employee bigint, position jobs, constraint c_fk foreign key (comp references Company(id), constraint p_fk foreign key (pers references Person(id) );
  • 7. Pet Database create type kind as enum (‘cat’, ‘dog’, ‘fly’, ‘hamster’, ‘e.coli’); create table Person (id bigint, name varchar(80), pet bigint, primary key (id), constraint pet_fk foreign key (pet references Animal(id)); create table Animal (id bigint, kind kind, name varchar(80), owner bigint, primary key (id), constraint owner_pk foreign key owner references Person(id));
  • 8. “More Conceptual Model” Person name Animal kind {cat, dog, fly, hamster, e.coli} Where’s composition? kind(pet(owner(pet(“John”))) select kind from Animal a where a.owner in (select id from Person where pet in (select id from Animal where owner in (select id from person where name=’John’)));
  • 9. Initial Object in a Category Definition. Given a category C, Initial Object is such an object 0 that there is a unique function iX:0 → X for any given X. (this is its “universal property”) Note that if we take X=0, we see that there is just one function 0 → 0. Can you name a set (or two) with only one function S→S? And what if there’s more than one such an object? Say 01 and 02, both have this interesting feature. Then, for 01, we have a unique a:01 → 02; and similarly we have a unique b:02 → 01. Composing a and b either way, we get an identity; so they are isomorphisms. Initial object is unique up to an isomorphism.
  • 10. Examples of Initial Objects • Sets: ∅, and it is unique (by sets axioms) • Monoids: {0} - all “such monoids” are isomorphic • Categories: empty category (whether there’s a plurality of them…) • In this category of three objects we see no initial object: • In this category c is initial object: • How about more than one initial object? They are isomorphic!
  • 11. Terminal Object in a Category Definition. Given a category C, Terminal Object is such an object 1 that there is a unique function uX:X → 1 for any given X. (this is its “universal property”) Note that if we take X=1, we see that there is just one function 1 → 1, same as with 0. And what if there’s more than one such an object? Say 11 and 12, both have this interesting feature. Then, for 11, we have a unique a:11 → 12; and similarly we have a unique b:12 → 11. Composing a and b either way, we get an identity; so they are isomorphisms. Terminal object, like initial one, is unique up to an isomorphism.
  • 12. Examples of Terminal Objects • Sets: any singleton {x} is terminal. They are not equal, but are isomorphic. • Monoids: {0} - all “such monoids” are isomorphic • Categories: empty category (whether there’s a plurality of them…) • In this category of three objects we see no terminal object: • In this category c is terminal object:
  • 13. Initial and Terminal Object in our DB terminal
  • 14. Cartesian Product Definition. Given a category C, and two objects in it, X and Y, their Cartesian Product is such an object Z=X×Y, together with two functions, pX:Z→X and pY:Z→Y, that for any pair f:A→X and g:A→Y, f=pX∘h and g=pY∘h for some unique h. (this is its “universal property”) Cartesian product is unique up to an isomorphism. (proof?)
  • 15. Examples of Cartesian Products • Sets: AxB = {(a,b)|a∈A,b∈B}, and it is unique (by sets axioms) • Databases: select * from A,B; • Good programming languages, e.g. Scala: (A,B) val intWithString: (Int, String) = (42, “Hello 42”) • In a monoid? We have just one object! • In a poset? It’s min(a,b)
  • 16.
  • 17. Disjoint Union (dual to Product) Definition. Given a category C, and two objects in it, X and Y, their Disjoint Union is such an object Z=X+Y, together with two functions, iX:X→Z and iY:Y→Z, that for any pair f:X→A and g:Y→A, f=h∘iX and g=h∘iY for some unique h. (this is its “universal property”) Disjoint union is unique up to an isomorphism. (proof?)
  • 18. Examples of Disjoint Unions • Sets: A+B = A∪B, and it is unique (by sets axioms) • Databases: select * from A union B; • Good programming languages, e.g. Scala: Either[A,B] val intOrString: Either[Int, String] = Left(42)// Right(“Hello 42”) • In a poset? It’s max(a,b)
  • 19. Equalizers Definition. Given a category C, two objects in it, X and Y, and two functions, f,g:X→Y, their Equalizer is such an object E=Eq(f,g), together with a function eq:E→X, such that that f∘eq=g∘eq for any m:O→X, m=eq∘u for some unique u. (this is its “universal property”) An equalizer is unique up to an isomorphism. (proof?)
  • 20. Pullbacks Definition. Given a category C, objects, X, Y and Z, and two functions, f:X→Z and g:X→Z, their Pullback is such an object X×ZY, together with functions pX:X×ZY→X and pY:X×ZY→Y, such that g∘pY = f∘pX, and for any pair x:U→X, y:U→Y, x=pX∘h and y=pY∘h for some unique h. (this is its “universal property”) A pullback is unique up to an isomorphism. (proof?)
  • 21. Examples of Pullbacks • Sets: {(x,y)|x∈X,y∈Y,f(x)=g(y)} • Databases: select * from A, B where A.f=B.g; e.g. select * from Person A, Person B where A.pet=B.pet; • In a poset? Same as min. • Cartesian products are pullbacks.