SlideShare a Scribd company logo
Formal Methods in
Software
Lecture 6. Elements of Algebra
Vlad Patryshev
SCU
2014
In This Lecture
● monoid
● group
● groupoid
● category
Monoid
An object X (e.g. a set, a type in programming language),
binary operation Op,
nullary operation Zero;
Laws:
● Op is associative
● Zero is neutral re: Op
Monoid: examples
● Real numbers ℝ and multiplication; 1. is neutral element
● Natural numbers ℕ, max, 0
● Sets and union; ∅ is neutral
● Lists, concatenation, empty list
● Predicates, conjunction, TRUE
● Given an X, functions: X → X, their composition, idX
as neutral
Mappings of Monoids
Given monoids (A,opa
,za
) and (B,opb
,zb
), define a mapping f that
preserves structure:
● f: A → B - that is, defined on elements of A, mapping them to B
● f(x opa
y) = f(x) opb
f(y)
● f(za
) = zb
E.g.
● exp: (ℝ,+,0) → (ℝ,*,1)
● sum: List[Int] → (Int,+,0)
Monoid of Endomorphisms
Definition. Endomorphism is a function f:X → X
Endomorphisms form a monoid, ({f:X → X}, ∘, idx
)
If X is a finite set, the size is |X||X|
, so we denote this monoid XX
.
Example: id ā b̄ swap
a a a b b
b b a b a
Group
Group is a monoid (A,op,0) where each element has an inverse:
∀x∈A ∃y∈A ((x op y) = 0) ∧ ((y op x) = 0)
Notation: y = x-1
, or y = inv(x)
E.g.
● (ℤ,+,0); inv(x) = -x
Group of Isomorphisms
In monoid ({f:X → X}, ∘, idx
)
take only such functions that have an inverse
they are called isomorphisms.
f is an isomorphism if ∃g:X→X (f∘g = idx
) ∧ (g∘f = idx
)
It is also known a bijection in the case when X is a set.
Examples:
(_+7):ℝ→ℝ; (-3.4*_):ℝ→ℝ
Group of Permutations
Take a set of n elements, {0,1,2,...,n}, and its isomorphic
endomorphisms
They are called permutations.
The group of all permutations on n elements is called An
.
|An
| = n!
Sorting n elements amounts to finding the right one out of n! elements.
With no extra knowledge, binary search gives an estimate
O(log(n!))=O(n log(n))
0 1 2
po
p1
p2
(p0
,p1
,p2
)
What if there’s more than one X?
Have a bunch of objects, (X1
,X2
,...,Xn
)
take all isomorphisms between them:
invertible functions of kind f:Xi
→Xj
It is not a group, and not a monoid:
1. composition is only allowed between f:Xi
→Xj
and g:Xj
→Xk
2. no common neutral element, but idi
:Xi
→Xi
Still, have associativity, neutrality, inverses.
It is called Groupoid
Examples of Groupoids
● a group is a groupoid
● X and Y are objects. Iso(X,X) ∪ Iso(Y,Y) is a
groupoid
●
● Set A, and an identity on each element - this makes a
discrete groupoid
What If Not Only Isomorphisms
Have a bunch of objects, (X1
,X2
,...,Xn
)
take functions between them, so that:
1. idi
:Xi
→Xi
included, for each i;
2. if f:Xi
→Xj
and g:Xj
→Xk
are present, so is g∘f:Xi
→Xk
Have associativity, have neutrality; inverses optional.
It is called Category
Examples of Categories
● Every monoid is a category (with just one object)
● Every groupoid is a category (all functions invertible)
● Category of all sets and their functions
● Category of all monoids and their functions
● Tiny things, like
○ Category 1 =
○ Category 1+1 =
○ Category 2 =
○ Category 3 =
Java as a Category
Objects (Xi
): all types and classes (Integer, String, java.util.Date, Map<X,Y>)
Functions: all imaginable static functions, plus methods, plus identities
E.g.
toString: Integer → String
It is not an isomorphism: some strings are not results of toString.
But it is an injection; injection is called monomorphism in Category Theory.
Integer.parseInt: String → Integer - not even a function.
Either have to restrict to representations of integers, or redefine “function”.
References
https://docs.google.com/presentation/d/1M0ozs06eLh9GWvi-
RhPvah6YBzQ2lclqbPGUADpg0H4/edit?usp=sharing
http://www.amazon.com/Category-Computer-Scientists-Foundations-Computing/dp/0262660717
Wikipedia
Formal methods   6 - elements of algebra

More Related Content

PPTX
Formal methods 7 - category theory
PDF
Functional Programming in C++
PPTX
Unary and binary set operations
PPTX
Typeclasses
PDF
Category Theory made easy with (ugly) pictures
PDF
Collections In Java
PDF
Tele3113 wk1wed
KEY
Programming haskell chapter10
Formal methods 7 - category theory
Functional Programming in C++
Unary and binary set operations
Typeclasses
Category Theory made easy with (ugly) pictures
Collections In Java
Tele3113 wk1wed
Programming haskell chapter10

What's hot (10)

PDF
Scala Bootcamp 1
PPT
Nested loop
PDF
Bayesian Methods for Machine Learning
PDF
Functional and Algebraic Domain Modeling
PPT
An introduction to scala
PDF
Scala categorytheory
PDF
Application of ordinal logistic to pregnancy outcomes
PDF
Architectural Patterns in Building Modular Domain Models
PDF
Introduction to Category Theory for software engineers
Scala Bootcamp 1
Nested loop
Bayesian Methods for Machine Learning
Functional and Algebraic Domain Modeling
An introduction to scala
Scala categorytheory
Application of ordinal logistic to pregnancy outcomes
Architectural Patterns in Building Modular Domain Models
Introduction to Category Theory for software engineers
Ad

Viewers also liked (20)

PPT
Formal meth
PPTX
Hypervisors
PPTX
Formal methods 5 - Pi calculus
PPTX
Formal methods 3 - languages and machines
PPTX
#7 formal methods – loop proof examples
PPTX
Formal methods 2 - languages and machines
PPTX
Introduction to formal methods
PPTX
#2 formal methods – principles of logic
PPTX
Software Quality Assurance(Intro)
PPTX
Formal methods 1 - introduction
PPTX
#8 formal methods – pro logic
PPTX
Virtualization support by intel
PDF
Formal methods 8 - category theory (last one)
PPTX
#5 formal methods – hoare logic
PPTX
#6 formal methods – loop proof using induction method
PPT
Slides chapters 28-32
PDF
Truth, deduction, computation lecture 7
PPTX
Formal Methods lecture 01
PPTX
PhD Presentation (Doctorate)
PPT
Slides chapters 26-27
Formal meth
Hypervisors
Formal methods 5 - Pi calculus
Formal methods 3 - languages and machines
#7 formal methods – loop proof examples
Formal methods 2 - languages and machines
Introduction to formal methods
#2 formal methods – principles of logic
Software Quality Assurance(Intro)
Formal methods 1 - introduction
#8 formal methods – pro logic
Virtualization support by intel
Formal methods 8 - category theory (last one)
#5 formal methods – hoare logic
#6 formal methods – loop proof using induction method
Slides chapters 28-32
Truth, deduction, computation lecture 7
Formal Methods lecture 01
PhD Presentation (Doctorate)
Slides chapters 26-27
Ad

Similar to Formal methods 6 - elements of algebra (16)

PDF
Probabilistic Machine Learning - Continuous Variables
PDF
UMAP - Mathematics and implementational details
PPT
Discrete mathematics Ch1 sets Theory_Dr.Khaled.Bakro د. خالد بكرو
PPTX
Sets, functions and groups
PDF
Group Theory and Its Application: Beamer Presentation (PPT)
PDF
5.3 Basic functions. A handout.
PDF
Presentation-Alex-20150421
PDF
Truth, deduction, computation lecture f
PDF
Numerical solution of boundary value problems by piecewise analysis method
PPTX
Introduction of predicate logics
PDF
PaperNo10-KaramiHabibiSafariZarrabi-IJCMS
PDF
A Coq Library for the Theory of Relational Calculus
PDF
Function and Recursively defined function
PDF
S. Duplij, Polyadic integer numbers and finite (m,n)-fields (Journal version,...
PDF
5.3 Basic functions. Dynamic slides.
PDF
Rouviere
Probabilistic Machine Learning - Continuous Variables
UMAP - Mathematics and implementational details
Discrete mathematics Ch1 sets Theory_Dr.Khaled.Bakro د. خالد بكرو
Sets, functions and groups
Group Theory and Its Application: Beamer Presentation (PPT)
5.3 Basic functions. A handout.
Presentation-Alex-20150421
Truth, deduction, computation lecture f
Numerical solution of boundary value problems by piecewise analysis method
Introduction of predicate logics
PaperNo10-KaramiHabibiSafariZarrabi-IJCMS
A Coq Library for the Theory of Relational Calculus
Function and Recursively defined function
S. Duplij, Polyadic integer numbers and finite (m,n)-fields (Journal version,...
5.3 Basic functions. Dynamic slides.
Rouviere

More from Vlad Patryshev (20)

PDF
Formal methods 4 - Z notation
PDF
Truth, deduction, computation lecture i (last one)
PDF
Truth, deduction, computation lecture h
PDF
Truth, deduction, computation lecture g
PDF
Truth, deduction, computation lecture e
PDF
Truth, deduction, computation lecture d
PDF
Truth, deduction, computation lecture c
PDF
Truth, deduction, computation lecture b
PDF
Truth, deduction, computation lecture a
PDF
Truth, deduction, computation lecture 9
PDF
Truth, deduction, computation lecture 8
PDF
Truth, deduction, computation lecture 6
PDF
Truth, deduction, computation; lecture 5
PDF
Truth, deduction, computation; lecture 4
PDF
Truth, deduction, computation; lecture 3
PDF
Truth, deduction, computation; lecture 2
PDF
Truth, deduction, computation; lecture 1
PPT
Pathela m
PPT
Nguyenmaria
Formal methods 4 - Z notation
Truth, deduction, computation lecture i (last one)
Truth, deduction, computation lecture h
Truth, deduction, computation lecture g
Truth, deduction, computation lecture e
Truth, deduction, computation lecture d
Truth, deduction, computation lecture c
Truth, deduction, computation lecture b
Truth, deduction, computation lecture a
Truth, deduction, computation lecture 9
Truth, deduction, computation lecture 8
Truth, deduction, computation lecture 6
Truth, deduction, computation; lecture 5
Truth, deduction, computation; lecture 4
Truth, deduction, computation; lecture 3
Truth, deduction, computation; lecture 2
Truth, deduction, computation; lecture 1
Pathela m
Nguyenmaria

Recently uploaded (20)

PDF
Computing-Curriculum for Schools in Ghana
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Cell Types and Its function , kingdom of life
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Insiders guide to clinical Medicine.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Pharma ospi slides which help in ospi learning
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Computing-Curriculum for Schools in Ghana
2.FourierTransform-ShortQuestionswithAnswers.pdf
Anesthesia in Laparoscopic Surgery in India
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Cell Types and Its function , kingdom of life
Abdominal Access Techniques with Prof. Dr. R K Mishra
Insiders guide to clinical Medicine.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
VCE English Exam - Section C Student Revision Booklet
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
human mycosis Human fungal infections are called human mycosis..pptx
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Pharma ospi slides which help in ospi learning
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Final Presentation General Medicine 03-08-2024.pptx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES

Formal methods 6 - elements of algebra

  • 1. Formal Methods in Software Lecture 6. Elements of Algebra Vlad Patryshev SCU 2014
  • 2. In This Lecture ● monoid ● group ● groupoid ● category
  • 3. Monoid An object X (e.g. a set, a type in programming language), binary operation Op, nullary operation Zero; Laws: ● Op is associative ● Zero is neutral re: Op
  • 4. Monoid: examples ● Real numbers ℝ and multiplication; 1. is neutral element ● Natural numbers ℕ, max, 0 ● Sets and union; ∅ is neutral ● Lists, concatenation, empty list ● Predicates, conjunction, TRUE ● Given an X, functions: X → X, their composition, idX as neutral
  • 5. Mappings of Monoids Given monoids (A,opa ,za ) and (B,opb ,zb ), define a mapping f that preserves structure: ● f: A → B - that is, defined on elements of A, mapping them to B ● f(x opa y) = f(x) opb f(y) ● f(za ) = zb E.g. ● exp: (ℝ,+,0) → (ℝ,*,1) ● sum: List[Int] → (Int,+,0)
  • 6. Monoid of Endomorphisms Definition. Endomorphism is a function f:X → X Endomorphisms form a monoid, ({f:X → X}, ∘, idx ) If X is a finite set, the size is |X||X| , so we denote this monoid XX . Example: id ā b̄ swap a a a b b b b a b a
  • 7. Group Group is a monoid (A,op,0) where each element has an inverse: ∀x∈A ∃y∈A ((x op y) = 0) ∧ ((y op x) = 0) Notation: y = x-1 , or y = inv(x) E.g. ● (ℤ,+,0); inv(x) = -x
  • 8. Group of Isomorphisms In monoid ({f:X → X}, ∘, idx ) take only such functions that have an inverse they are called isomorphisms. f is an isomorphism if ∃g:X→X (f∘g = idx ) ∧ (g∘f = idx ) It is also known a bijection in the case when X is a set. Examples: (_+7):ℝ→ℝ; (-3.4*_):ℝ→ℝ
  • 9. Group of Permutations Take a set of n elements, {0,1,2,...,n}, and its isomorphic endomorphisms They are called permutations. The group of all permutations on n elements is called An . |An | = n! Sorting n elements amounts to finding the right one out of n! elements. With no extra knowledge, binary search gives an estimate O(log(n!))=O(n log(n)) 0 1 2 po p1 p2 (p0 ,p1 ,p2 )
  • 10. What if there’s more than one X? Have a bunch of objects, (X1 ,X2 ,...,Xn ) take all isomorphisms between them: invertible functions of kind f:Xi →Xj It is not a group, and not a monoid: 1. composition is only allowed between f:Xi →Xj and g:Xj →Xk 2. no common neutral element, but idi :Xi →Xi Still, have associativity, neutrality, inverses. It is called Groupoid
  • 11. Examples of Groupoids ● a group is a groupoid ● X and Y are objects. Iso(X,X) ∪ Iso(Y,Y) is a groupoid ● ● Set A, and an identity on each element - this makes a discrete groupoid
  • 12. What If Not Only Isomorphisms Have a bunch of objects, (X1 ,X2 ,...,Xn ) take functions between them, so that: 1. idi :Xi →Xi included, for each i; 2. if f:Xi →Xj and g:Xj →Xk are present, so is g∘f:Xi →Xk Have associativity, have neutrality; inverses optional. It is called Category
  • 13. Examples of Categories ● Every monoid is a category (with just one object) ● Every groupoid is a category (all functions invertible) ● Category of all sets and their functions ● Category of all monoids and their functions ● Tiny things, like ○ Category 1 = ○ Category 1+1 = ○ Category 2 = ○ Category 3 =
  • 14. Java as a Category Objects (Xi ): all types and classes (Integer, String, java.util.Date, Map<X,Y>) Functions: all imaginable static functions, plus methods, plus identities E.g. toString: Integer → String It is not an isomorphism: some strings are not results of toString. But it is an injection; injection is called monomorphism in Category Theory. Integer.parseInt: String → Integer - not even a function. Either have to restrict to representations of integers, or redefine “function”.