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
PPTX
Data structures and algorithms
PDF
2nd puc computer science chapter 3 data structures 1
PPT
Data structure
PDF
Data Structures (BE)
PPTX
Data structures
PDF
Data structure ppt
PPT
Data Structure and Algorithms Arrays
Lecture 2a arrays
Data structures and algorithms
2nd puc computer science chapter 3 data structures 1
Data structure
Data Structures (BE)
Data structures
Data structure ppt
Data Structure and Algorithms Arrays

What's hot (20)

PPTX
Data Structures (CS8391)
PPTX
Row major and column major in 2 d
PPTX
Set data structure
PPTX
Lecture 3 data structures and algorithms
PPTX
Data structure and its types
PDF
Introduction to Data Structure
PPT
PPTX
Introduction to data_structure
PPT
PDF
Elementary data structure
PPT
Unit 1 introduction to data structure
PPTX
Arrays in C++
PPT
Arrays Data Structure
PPT
Arrays and structures
PPTX
Arrays In C++
PPT
02 Arrays And Memory Mapping
PPTX
ARRAY
PPTX
Data structures
PDF
9 python data structure-2
PPTX
2. Array in Data Structure
Data Structures (CS8391)
Row major and column major in 2 d
Set data structure
Lecture 3 data structures and algorithms
Data structure and its types
Introduction to Data Structure
Introduction to data_structure
Elementary data structure
Unit 1 introduction to data structure
Arrays in C++
Arrays Data Structure
Arrays and structures
Arrays In C++
02 Arrays And Memory Mapping
ARRAY
Data structures
9 python data structure-2
2. Array in Data Structure
Ad

Similar to Abstract Algebra and Category Theory (20)

PPTX
Data structure and algorithm list structures
PPTX
R교육1
ODP
Collections In Scala
PDF
GE3151_PSPP_UNIT_4_Notes
PDF
R training2
PDF
DS Complete notes for Computer science and Engineering
DOCX
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
PDF
Aj unit2 notesjavadatastructures
PDF
DATA STRUCTURES USING C -ENGGDIGEST
PPTX
Brief Explanation On List and Dictionaries of Python
PPTX
Language R
PDF
Data Structures 01
PPT
standard template library(STL) in C++
PPTX
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
PPTX
16. Arrays Lists Stacks Queues
PDF
Scala collections api expressivity and brevity upgrade from java
PPTX
R1-Intro (2udsjhfkjdshfkjsdkfhsdkfsfsffs
PPTX
Basic of array and data structure, data structure basics, array, address calc...
PPTX
Python data type
PPT
Chap09
Data structure and algorithm list structures
R교육1
Collections In Scala
GE3151_PSPP_UNIT_4_Notes
R training2
DS Complete notes for Computer science and Engineering
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Aj unit2 notesjavadatastructures
DATA STRUCTURES USING C -ENGGDIGEST
Brief Explanation On List and Dictionaries of Python
Language R
Data Structures 01
standard template library(STL) in C++
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
16. Arrays Lists Stacks Queues
Scala collections api expressivity and brevity upgrade from java
R1-Intro (2udsjhfkjdshfkjsdkfhsdkfsfsffs
Basic of array and data structure, data structure basics, array, address calc...
Python data type
Chap09
Ad

More from Naveenkumar Muguda (12)

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

Recently uploaded (20)

PDF
737-MAX_SRG.pdf student reference guides
PDF
Design Guidelines and solutions for Plastics parts
PPTX
Management Information system : MIS-e-Business Systems.pptx
PDF
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
PDF
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
PPTX
Fundamentals of Mechanical Engineering.pptx
PPTX
CURRICULAM DESIGN engineering FOR CSE 2025.pptx
PPTX
Information Storage and Retrieval Techniques Unit III
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PDF
distributed database system" (DDBS) is often used to refer to both the distri...
PDF
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
PPTX
Graph Data Structures with Types, Traversals, Connectivity, and Real-Life App...
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
PDF
III.4.1.2_The_Space_Environment.p pdffdf
PDF
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
PPTX
Software Engineering and software moduleing
PDF
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
PPTX
Chemical Technological Processes, Feasibility Study and Chemical Process Indu...
PDF
Visual Aids for Exploratory Data Analysis.pdf
737-MAX_SRG.pdf student reference guides
Design Guidelines and solutions for Plastics parts
Management Information system : MIS-e-Business Systems.pptx
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
Fundamentals of Mechanical Engineering.pptx
CURRICULAM DESIGN engineering FOR CSE 2025.pptx
Information Storage and Retrieval Techniques Unit III
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
distributed database system" (DDBS) is often used to refer to both the distri...
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
Graph Data Structures with Types, Traversals, Connectivity, and Real-Life App...
Fundamentals of safety and accident prevention -final (1).pptx
III.4.1.2_The_Space_Environment.p pdffdf
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
Software Engineering and software moduleing
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
Chemical Technological Processes, Feasibility Study and Chemical Process Indu...
Visual Aids for Exploratory Data Analysis.pdf

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)