Formal methods 6 - elements of algebra

1,034 views

Published on

My course of Formal Methods at Santa Clara University, Winter 2014.

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,034
On SlideShare
0
From Embeds
0
Number of Embeds
48
Actions
Shares
0
Downloads
20
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Formal methods 6 - elements of algebra

  1. 1. Formal Methods in Software Lecture 6. Elements of Algebra Vlad Patryshev SCU 2014
  2. 2. In This Lecture ● monoid ● group ● groupoid ● category
  3. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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”.
  15. 15. References https://docs.google.com/presentation/d/1M0ozs06eLh9GWvi- RhPvah6YBzQ2lclqbPGUADpg0H4/edit?usp=sharing http://www.amazon.com/Category-Computer-Scientists-Foundations-Computing/dp/0262660717 Wikipedia

×