Sets, Logic & Combinatorics
IntermediateSets group distinct items, logic combines true/false conditions, and combinatorics counts possibilities — the discrete foundations behind algorithms, feature engineering, and reasoning systems.
Overview
Not all AI math is continuous. Discrete mathematics — sets, logic, and counting — underlies algorithms, data structures, symbolic reasoning, and a surprising amount of practical ML plumbing. Set operations (union, intersection, difference) power deduplication, vocabulary building, and metrics like Jaccard similarity used in retrieval. Boolean logic (AND/OR/NOT, implication) is the basis of rule systems, decision-tree splits, and the conditions guardrails evaluate. Combinatorics — permutations and combinations — is how you count configurations, reason about the size of a hypothesis space, compute probabilities, and understand why brute-force search explodes (the combinatorial explosion that motivates smarter algorithms and heuristics). These tools are less glamorous than gradients but show up constantly when you build real systems around models.
Set operations power similarity and dedup
Intersection over union (Jaccard) is a workhorse similarity measure for tags, tokens, and retrieval. Sets also deduplicate and build vocabularies.
a = {"nlp", "python", "ml", "data"}
b = {"python", "ml", "cloud"}
print(a & b) # {'ml','python'} intersection
print(a | b) # union
jaccard = len(a & b) / len(a | b)
print(round(jaccard, 3)) # 0.4 -> set-based similarityCombinatorics: counting and the explosion
Permutations (order matters) and combinations (order does not) count possibilities. They explain probabilities and why exhaustive search is infeasible past small sizes.
from math import comb, perm, factorial
print(comb(52, 5)) # 2,598,960 five-card poker hands (order-free)
print(perm(10, 3)) # 720 ordered arrangements of 3 from 10
# Combinatorial explosion: arrangements of n items = n!
for n in [5, 10, 15]:
print(n, factorial(n)) # 120, 3.6M, 1.3 trillion -> why we need heuristicsKey Points to Remember
- 1Set operations (∪, ∩, −) power dedup, vocabularies, and Jaccard similarity
- 2Boolean logic underlies rule systems, decision-tree splits, and guardrail conditions
- 3Combinatorics counts arrangements (permutations) and selections (combinations)
- 4Factorial growth explains the combinatorial explosion that motivates heuristics & search
Interview Questions
Sign in to ask AriaWhat is Jaccard similarity and where is it used?
Difference between a permutation and a combination — give an example of each.
Why does combinatorial explosion make brute-force search impractical, and what do we do instead?
Ask Aria about Sets, Logic & Combinatorics
Your personal AI tutor — ask anything about this concept
Revision Status
Personal Notes
Sign in to save personal notes for this topic.
Discussion
Sign in to join the discussion.