Lesson 5 of 15
Relations
Binary Relations
A binary relation on a set is a subset of . We write (or ) when is related to .
Key Properties
| Property | Definition | Example |
|---|---|---|
| Reflexive | on | |
| Symmetric | on | |
| Antisymmetric | on | |
| Transitive | on |
Equivalence Relations
A relation that is reflexive, symmetric, and transitive is an equivalence relation. It partitions the domain into disjoint equivalence classes .
Example: "same remainder mod 3" is an equivalence relation on , with classes .
def is_equivalence(relation, domain):
return (is_reflexive(relation, domain) and
is_symmetric(relation) and
is_transitive(relation))
# R = {(1,1),(2,2),(3,3),(1,2),(2,1)} — two classes: {1,2} and {3}
R = {(1,1),(2,2),(3,3),(1,2),(2,1)}
print(is_equivalence(R, {1,2,3})) # True
Your Task
Implement is_reflexive, is_symmetric, is_transitive, and is_equivalence.
Pyodide loading...
Loading...
Click "Run" to execute your code.