SlideShare a Scribd company logo
Abstract Algebra and
Category Theory
Naveen Muguda
• Data processing is, generally, "the collection and manipulation of
items of data to produce meaningful information”.
• Validation – Ensuring that supplied data is correct and relevant.
• Sorting – "arranging items in some sequence and/or in different sets."
• Summarization – reducing detail data to its main points.
• Aggregation – combining multiple pieces of data.
• Analysis – the "collection, organization, analysis, interpretation and
presentation of data."
• Reporting – list detail or summary data or computed information.
• Classification – separation of data into various categories.
Abstract Algebra and Category Theory
Multiple perspectives
Different shapes, same view
Bubble Sort Quick Sort
sorts yes yes
Complexity O(n ^ 2) O(n lgn)
progression
• Data structures, Complexity Theory …….. Algebraic Structures,
Category Theory
def sum(list: List[Int]): Int = {
if(list.isEmpty) 0
else list.head + sum(list.tail)
}
Abstract Algebra and Category Theory
Dimensions of Data processing
data
container
logic
Dimensions of Data processing
data
container
logic
Abstract Algebra
Category Theory
Closure
• 2 + 3 = 5 (whole number)
• 2 - 3 = -1 (not an positive integer)
• When an operation is performed on any two things of a kind, it
results in another thing of the same kind.
associativity
Abstract Algebra and Category Theory
• def fold[A1 >: A](z: A1)(op: (A1, A1) ⇒ A1): A1
• val l = List(1, 3, 5, 11)
println(l.fold(100) (_ - _));
(1 – 3) – 5 != 1 - (3 – 5)
Algebraic Structure
• a Set with finite operations and set of laws these operations obey
Algebraic Structures
• a magma consists of a set equipped with a closed single binary
operation
• a semigroup : an associative magma
• a monoid : a semigroup with Identity element.
• a group : a monoid with a unary operation (inverse), giving rise
to inverse elements.
Loop invariants
int result = 0
for(int index = 0; index < a.length; a++)
result += a[i]
result = sum { a, [0, index)}
• [Int, 0, +] is a monoid
void mergeSort(List list, int l, int r)
{
if (l < r)
{
// Same as (l+r)/2, but avoids overflow for
// large l and h
int m = l+(r-l)/2;
// Sort first and second halves
mergeSort(list, l, m);
mergeSort(list, m+1, r);
merge(list, l, m, r);
}
}
[SortedList, Merge, Empty List] is a monoid
Representation
• Set in maths => java.util.Set, scala.collection.
Typeclass
• Type class is a class (group) of types, which satisfies some contract-
defined trait
• functionality (trait and implementation) can be added without any
changes to the original code
Typeclass in Scala
a type class consists of three components:
1. The type class itself, which is defined as a trait that takes at least
one generic parameter
2. Instances of the type class for the data types you want to extend
3. Interface methods you expose to users of your new API
trait Monoid[A] {
// an identity element
def id: A
// an associative
operation
def op(x: A, y: A): A
}
implicit val intAddition = new Monoid[Int] {
def id = 0
def op(x:Int, y: Int) = x + y
}
implicit def fold[A](la: List[A])(implicit am: Monoid[A]): A =
la.foldLeft(am.id)(am.op)
fold(List(1, 3, 4)) => 8
monoids
• Boolean, True, &&
• Boolean, False, ||
• Integer, 0, +
• Integer, 1, *
• Integer, Integer.Min, max
• Integer, Integer.Max, min
• fold(l)( integerAdditionMonoid) => sum
• fold(l) (integerMultiplicationMonoid) => product
Monoids, monoids
• Binary Search Tree
• Priority Queue
Abstract Algebra and Category Theory
• Associativity enables parallelism
Interesting monoids
• List, concatenation
• Set, {}, Union
• Sorted List, merge
Abstract Algebra and Category Theory
Find if an element is present in an array
implicit val boolOr = new Monoid[Boolean] {
def id = false;
def op(x: Boolean , y: Boolean) = x || y
}
val list = List(1, 3, 4)
println(fold(list.map(x => x == 2))); The list was converted to a list of Booleans
and then folded over
Abstract Algebra and Category Theory
• combine => max, reduce => max
If we want to calculate mean
• mean(0, 20, 10, 25, 15) = 14
• mean(mean(0, 20, 10), mean(25, 15)) = mean(10, 20) = 15
monoidfy
public class Pair {
int sum;
int count;
}
Pair merge(Pair first, Pair second) {
return new Pair(first.sum + second.sum, first.count + second.count);
}
Monoid homomorphisms
• List of integers => list of Booleans => fold
• Which computing platforms has this kind of behavior
Abstract Algebra and Category Theory
Abstract Algebra and Category Theory
• List<String> => List<Integer> : word count
• List<String> => String :longest word:
• List<String> => Map<String, Integer> :word frequency
PACELC
Streams Sketches
• Probabilistic Data structures
• Bloom Filters, HyperLogLog etc
• They are monoidal
• Used in stream processing
Abstract Algebra and Category Theory
Lambda Architecture, Summing Bird
CRDT
• Grow only counter
Category
• Category of numbers and <=
• Category of all sets and subset relation
• Category of sets and functions
• Objects and arrows
• If f and g exists then g.f should exist
• Totality is not assumed
Functor
Abstract Algebra and Category Theory
Abstract Algebra and Category Theory
• trait Functor[F[_]] { def map[A, B](fa: F[A])(f: A => B): F[B] }
Monads
trait Monad[F[_]] {
def flatMap[A, B](fa: F[A])(f: (A) => F[B]):
F[B] def pure[A](x: A): F[A]
}
IPL team isSpinner
Kohli RCB no
Chahal RCB yes
Kuldeep KKR yes
Pujara null no
Team Won IPL in
RCB null
KKR 2012, 2014
Different containers, different behaviors
• Optional.of(“pujara”). map(getIplTeam).map(firstWonIn) =>
Optional.empty
• Optional.of(“kohli”). map(getIplTeam).map(firstWonIn) =>
Optional.empty
• Set.of(“kohli”, “chahal”, “kuldeep”).map(getIplTeam) => Set.of(“RCB”,
“KKR”)
• Set.of(“kohli”, “chahal”, “kuldeep”).map(getIplTeam).flatMap(wonIn)
=> Set.of(2012, 2014)
• List.of(“kohli”, “chahal”, “kuldeep”).map(getIplTeam) => List.of(“RCB”,
“RCB”, “KKR”)
Optional
List
Set
map
filter
flatmap
fold
7constructs vs 12
“Structure” preserving operations
Set.of(“kohli”, “chahal”, “kuldeep”)
.filter(isSpinner)
.map(getIplTeam)
.flatMap(wonIn) => Set.of(2012, 2014)
Implement a Monad

More Related Content

PPT
Lecture 2a arrays
Victor Palmar
 
PPTX
Data structures and algorithms
Hoang Nguyen
 
PDF
2nd puc computer science chapter 3 data structures 1
Aahwini Esware gowda
 
PPT
Data structure
viswanathV8
 
PDF
Data Structures (BE)
PRABHAHARAN429
 
PPTX
Data structures
Pranav Gupta
 
PDF
Data structure ppt
Prof. Dr. K. Adisesha
 
PPT
Data Structure and Algorithms Arrays
ManishPrajapati78
 
Lecture 2a arrays
Victor Palmar
 
Data structures and algorithms
Hoang Nguyen
 
2nd puc computer science chapter 3 data structures 1
Aahwini Esware gowda
 
Data structure
viswanathV8
 
Data Structures (BE)
PRABHAHARAN429
 
Data structures
Pranav Gupta
 
Data structure ppt
Prof. Dr. K. Adisesha
 
Data Structure and Algorithms Arrays
ManishPrajapati78
 

What's hot (20)

PPTX
Data Structures (CS8391)
Elavarasi K
 
PPTX
Row major and column major in 2 d
nikhilarora2211
 
PPTX
Set data structure
Tech_MX
 
PPTX
Lecture 3 data structures and algorithms
Aakash deep Singhal
 
PPTX
Data structure and its types
Navtar Sidhu Brar
 
PDF
Introduction to Data Structure
Prof Ansari
 
PPT
arrays
Enakshi Chanda
 
PPTX
Introduction to data_structure
Ashim Lamichhane
 
PPT
Arrays
SARITHA REDDY
 
PDF
Elementary data structure
Biswajit Mandal
 
PPT
Unit 1 introduction to data structure
kalyanineve
 
PPTX
Arrays in C++
Kashif Nawab
 
PPT
Arrays Data Structure
student
 
PPT
Arrays and structures
Mohd Arif
 
PPTX
Arrays In C++
Awais Alam
 
PPT
02 Arrays And Memory Mapping
Qundeel
 
PPTX
ARRAY
ayush raj
 
PPTX
Data structures
Sneha Chopra
 
PDF
9 python data structure-2
Prof. Dr. K. Adisesha
 
PPTX
2. Array in Data Structure
Mandeep Singh
 
Data Structures (CS8391)
Elavarasi K
 
Row major and column major in 2 d
nikhilarora2211
 
Set data structure
Tech_MX
 
Lecture 3 data structures and algorithms
Aakash deep Singhal
 
Data structure and its types
Navtar Sidhu Brar
 
Introduction to Data Structure
Prof Ansari
 
Introduction to data_structure
Ashim Lamichhane
 
Elementary data structure
Biswajit Mandal
 
Unit 1 introduction to data structure
kalyanineve
 
Arrays in C++
Kashif Nawab
 
Arrays Data Structure
student
 
Arrays and structures
Mohd Arif
 
Arrays In C++
Awais Alam
 
02 Arrays And Memory Mapping
Qundeel
 
ARRAY
ayush raj
 
Data structures
Sneha Chopra
 
9 python data structure-2
Prof. Dr. K. Adisesha
 
2. Array in Data Structure
Mandeep Singh
 
Ad

Similar to Abstract Algebra and Category Theory (20)

PPTX
Data structure and algorithm list structures
gangaresearch21
 
PPTX
R교육1
Kangwook Lee
 
ODP
Collections In Scala
Knoldus Inc.
 
PDF
GE3151_PSPP_UNIT_4_Notes
Guru Nanak Technical Institutions
 
PDF
R training2
Hellen Gakuruh
 
PDF
DS Complete notes for Computer science and Engineering
RAJASEKHARV8
 
DOCX
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Malikireddy Bramhananda Reddy
 
PDF
Aj unit2 notesjavadatastructures
Arthik Daniel
 
PDF
DATA STRUCTURES USING C -ENGGDIGEST
Swapnil Mishra
 
PPTX
Brief Explanation On List and Dictionaries of Python
nikhita4775
 
PPTX
Language R
Girish Khanzode
 
PDF
Data Structures 01
Budditha Hettige
 
PPT
standard template library(STL) in C++
•sreejith •sree
 
PPTX
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
Dev Chauhan
 
PPTX
16. Arrays Lists Stacks Queues
Intro C# Book
 
PDF
Scala collections api expressivity and brevity upgrade from java
IndicThreads
 
PPTX
R1-Intro (2udsjhfkjdshfkjsdkfhsdkfsfsffs
sabari Giri
 
PPTX
Basic of array and data structure, data structure basics, array, address calc...
nsitlokeshjain
 
PPTX
Python data type
Jaya Kumari
 
PPT
Chap09
Terry Yoast
 
Data structure and algorithm list structures
gangaresearch21
 
R교육1
Kangwook Lee
 
Collections In Scala
Knoldus Inc.
 
GE3151_PSPP_UNIT_4_Notes
Guru Nanak Technical Institutions
 
R training2
Hellen Gakuruh
 
DS Complete notes for Computer science and Engineering
RAJASEKHARV8
 
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Malikireddy Bramhananda Reddy
 
Aj unit2 notesjavadatastructures
Arthik Daniel
 
DATA STRUCTURES USING C -ENGGDIGEST
Swapnil Mishra
 
Brief Explanation On List and Dictionaries of Python
nikhita4775
 
Language R
Girish Khanzode
 
Data Structures 01
Budditha Hettige
 
standard template library(STL) in C++
•sreejith •sree
 
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
Dev Chauhan
 
16. Arrays Lists Stacks Queues
Intro C# Book
 
Scala collections api expressivity and brevity upgrade from java
IndicThreads
 
R1-Intro (2udsjhfkjdshfkjsdkfhsdkfsfsffs
sabari Giri
 
Basic of array and data structure, data structure basics, array, address calc...
nsitlokeshjain
 
Python data type
Jaya Kumari
 
Chap09
Terry Yoast
 
Ad

More from Naveenkumar Muguda (12)

PPTX
Ads quality
Naveenkumar Muguda
 
PPTX
Components: An overlooked abstraction
Naveenkumar Muguda
 
PPTX
Powerful software linkedin
Naveenkumar Muguda
 
PPTX
Yin Yangs of Software Development
Naveenkumar Muguda
 
PPTX
Programming in the large
Naveenkumar Muguda
 
PPTX
Invariants & inversions
Naveenkumar Muguda
 
PPTX
Functional Programming, simplified
Naveenkumar Muguda
 
PPTX
Software Development: Beyond Training wheels
Naveenkumar Muguda
 
PPTX
Log* with Cassandra
Naveenkumar Muguda
 
PDF
Refactoring et al
Naveenkumar Muguda
 
PDF
System design
Naveenkumar Muguda
 
Ads quality
Naveenkumar Muguda
 
Components: An overlooked abstraction
Naveenkumar Muguda
 
Powerful software linkedin
Naveenkumar Muguda
 
Yin Yangs of Software Development
Naveenkumar Muguda
 
Programming in the large
Naveenkumar Muguda
 
Invariants & inversions
Naveenkumar Muguda
 
Functional Programming, simplified
Naveenkumar Muguda
 
Software Development: Beyond Training wheels
Naveenkumar Muguda
 
Log* with Cassandra
Naveenkumar Muguda
 
Refactoring et al
Naveenkumar Muguda
 
System design
Naveenkumar Muguda
 

Recently uploaded (20)

PDF
EVS+PRESENTATIONS EVS+PRESENTATIONS like
saiyedaqib429
 
PDF
2025 Laurence Sigler - Advancing Decision Support. Content Management Ecommer...
Francisco Javier Mora Serrano
 
PDF
Machine Learning All topics Covers In This Single Slides
AmritTiwari19
 
PPTX
Chapter_Seven_Construction_Reliability_Elective_III_Msc CM
SubashKumarBhattarai
 
PDF
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
PPT
Understanding the Key Components and Parts of a Drone System.ppt
Siva Reddy
 
PDF
Zero Carbon Building Performance standard
BassemOsman1
 
PPTX
Tunnel Ventilation System in Kanpur Metro
220105053
 
PPT
1. SYSTEMS, ROLES, AND DEVELOPMENT METHODOLOGIES.ppt
zilow058
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PDF
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
PPTX
22PCOAM21 Session 2 Understanding Data Source.pptx
Guru Nanak Technical Institutions
 
PDF
Packaging Tips for Stainless Steel Tubes and Pipes
heavymetalsandtubes
 
PPTX
Civil Engineering Practices_BY Sh.JP Mishra 23.09.pptx
bineetmishra1990
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PPTX
MULTI LEVEL DATA TRACKING USING COOJA.pptx
dollysharma12ab
 
PDF
Introduction to Ship Engine Room Systems.pdf
Mahmoud Moghtaderi
 
PDF
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
PDF
Advanced LangChain & RAG: Building a Financial AI Assistant with Real-Time Data
Soufiane Sejjari
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
EVS+PRESENTATIONS EVS+PRESENTATIONS like
saiyedaqib429
 
2025 Laurence Sigler - Advancing Decision Support. Content Management Ecommer...
Francisco Javier Mora Serrano
 
Machine Learning All topics Covers In This Single Slides
AmritTiwari19
 
Chapter_Seven_Construction_Reliability_Elective_III_Msc CM
SubashKumarBhattarai
 
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
Understanding the Key Components and Parts of a Drone System.ppt
Siva Reddy
 
Zero Carbon Building Performance standard
BassemOsman1
 
Tunnel Ventilation System in Kanpur Metro
220105053
 
1. SYSTEMS, ROLES, AND DEVELOPMENT METHODOLOGIES.ppt
zilow058
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
22PCOAM21 Session 2 Understanding Data Source.pptx
Guru Nanak Technical Institutions
 
Packaging Tips for Stainless Steel Tubes and Pipes
heavymetalsandtubes
 
Civil Engineering Practices_BY Sh.JP Mishra 23.09.pptx
bineetmishra1990
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
MULTI LEVEL DATA TRACKING USING COOJA.pptx
dollysharma12ab
 
Introduction to Ship Engine Room Systems.pdf
Mahmoud Moghtaderi
 
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
Advanced LangChain & RAG: Building a Financial AI Assistant with Real-Time Data
Soufiane Sejjari
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 

Abstract Algebra and Category Theory

  • 1. Abstract Algebra and Category Theory Naveen Muguda
  • 2. • Data processing is, generally, "the collection and manipulation of items of data to produce meaningful information”.
  • 3. • Validation – Ensuring that supplied data is correct and relevant. • Sorting – "arranging items in some sequence and/or in different sets." • Summarization – reducing detail data to its main points. • Aggregation – combining multiple pieces of data. • Analysis – the "collection, organization, analysis, interpretation and presentation of data." • Reporting – list detail or summary data or computed information. • Classification – separation of data into various categories.
  • 7. Bubble Sort Quick Sort sorts yes yes Complexity O(n ^ 2) O(n lgn)
  • 8. progression • Data structures, Complexity Theory …….. Algebraic Structures, Category Theory
  • 9. def sum(list: List[Int]): Int = { if(list.isEmpty) 0 else list.head + sum(list.tail) }
  • 11. Dimensions of Data processing data container logic
  • 12. Dimensions of Data processing data container logic Abstract Algebra Category Theory
  • 13. Closure • 2 + 3 = 5 (whole number) • 2 - 3 = -1 (not an positive integer) • When an operation is performed on any two things of a kind, it results in another thing of the same kind.
  • 16. • def fold[A1 >: A](z: A1)(op: (A1, A1) ⇒ A1): A1 • val l = List(1, 3, 5, 11) println(l.fold(100) (_ - _)); (1 – 3) – 5 != 1 - (3 – 5)
  • 17. Algebraic Structure • a Set with finite operations and set of laws these operations obey
  • 18. Algebraic Structures • a magma consists of a set equipped with a closed single binary operation • a semigroup : an associative magma • a monoid : a semigroup with Identity element. • a group : a monoid with a unary operation (inverse), giving rise to inverse elements.
  • 19. Loop invariants int result = 0 for(int index = 0; index < a.length; a++) result += a[i] result = sum { a, [0, index)}
  • 20. • [Int, 0, +] is a monoid
  • 21. void mergeSort(List list, int l, int r) { if (l < r) { // Same as (l+r)/2, but avoids overflow for // large l and h int m = l+(r-l)/2; // Sort first and second halves mergeSort(list, l, m); mergeSort(list, m+1, r); merge(list, l, m, r); } } [SortedList, Merge, Empty List] is a monoid
  • 22. Representation • Set in maths => java.util.Set, scala.collection.
  • 23. Typeclass • Type class is a class (group) of types, which satisfies some contract- defined trait • functionality (trait and implementation) can be added without any changes to the original code
  • 24. Typeclass in Scala a type class consists of three components: 1. The type class itself, which is defined as a trait that takes at least one generic parameter 2. Instances of the type class for the data types you want to extend 3. Interface methods you expose to users of your new API
  • 25. trait Monoid[A] { // an identity element def id: A // an associative operation def op(x: A, y: A): A } implicit val intAddition = new Monoid[Int] { def id = 0 def op(x:Int, y: Int) = x + y } implicit def fold[A](la: List[A])(implicit am: Monoid[A]): A = la.foldLeft(am.id)(am.op) fold(List(1, 3, 4)) => 8
  • 26. monoids • Boolean, True, && • Boolean, False, || • Integer, 0, + • Integer, 1, * • Integer, Integer.Min, max • Integer, Integer.Max, min
  • 27. • fold(l)( integerAdditionMonoid) => sum • fold(l) (integerMultiplicationMonoid) => product
  • 28. Monoids, monoids • Binary Search Tree • Priority Queue
  • 31. Interesting monoids • List, concatenation • Set, {}, Union • Sorted List, merge
  • 33. Find if an element is present in an array implicit val boolOr = new Monoid[Boolean] { def id = false; def op(x: Boolean , y: Boolean) = x || y } val list = List(1, 3, 4) println(fold(list.map(x => x == 2))); The list was converted to a list of Booleans and then folded over
  • 35. • combine => max, reduce => max
  • 36. If we want to calculate mean • mean(0, 20, 10, 25, 15) = 14 • mean(mean(0, 20, 10), mean(25, 15)) = mean(10, 20) = 15
  • 37. monoidfy public class Pair { int sum; int count; } Pair merge(Pair first, Pair second) { return new Pair(first.sum + second.sum, first.count + second.count); }
  • 38. Monoid homomorphisms • List of integers => list of Booleans => fold • Which computing platforms has this kind of behavior
  • 41. • List<String> => List<Integer> : word count • List<String> => String :longest word: • List<String> => Map<String, Integer> :word frequency
  • 43. Streams Sketches • Probabilistic Data structures • Bloom Filters, HyperLogLog etc • They are monoidal • Used in stream processing
  • 48. • Category of numbers and <= • Category of all sets and subset relation • Category of sets and functions
  • 49. • Objects and arrows • If f and g exists then g.f should exist • Totality is not assumed
  • 53. • trait Functor[F[_]] { def map[A, B](fa: F[A])(f: A => B): F[B] }
  • 54. Monads trait Monad[F[_]] { def flatMap[A, B](fa: F[A])(f: (A) => F[B]): F[B] def pure[A](x: A): F[A] }
  • 55. IPL team isSpinner Kohli RCB no Chahal RCB yes Kuldeep KKR yes Pujara null no Team Won IPL in RCB null KKR 2012, 2014
  • 56. Different containers, different behaviors • Optional.of(“pujara”). map(getIplTeam).map(firstWonIn) => Optional.empty • Optional.of(“kohli”). map(getIplTeam).map(firstWonIn) => Optional.empty • Set.of(“kohli”, “chahal”, “kuldeep”).map(getIplTeam) => Set.of(“RCB”, “KKR”) • Set.of(“kohli”, “chahal”, “kuldeep”).map(getIplTeam).flatMap(wonIn) => Set.of(2012, 2014) • List.of(“kohli”, “chahal”, “kuldeep”).map(getIplTeam) => List.of(“RCB”, “RCB”, “KKR”)
  • 58. “Structure” preserving operations Set.of(“kohli”, “chahal”, “kuldeep”) .filter(isSpinner) .map(getIplTeam) .flatMap(wonIn) => Set.of(2012, 2014)