1.11 Equivalence Relations
(require rebellion/base/equivalence-relation) | |
package: rebellion |
An equivalence relation is a boolean-returning function of two arguments that returns true when two values are equivalent, according to some notion of equivalence. The details of what counts as equivalent vary based on the equivalence relation used, but all equivalence relations should obey the following laws:
Reflexive property —
every value should always be equivalent to itself, meaning (equivalence-relation-holds? rel x x) is always true. Symmetric property —
if two values are equivalent, then the order in which they are given to the function should not matter, meaning (equivalence-relation-holds? rel x y) implies (equivalence-relation-holds? rel y x). Transitive property —
if x is equivalent to y, and y is equivalent to z, then x must be equivalent to z.
procedure
v : any/c
procedure
(equivalence-relation-holds? relation x y) → boolean?
relation : equivalence-relation? x : any/c y : any/c
> (equivalence-relation-holds? natural-equality 1 1) #t
> (equivalence-relation-holds? natural-equality 1 2) #f
procedure
(make-equivalence-relation function [ #:name name]) → equivalence-relation? function : (-> any/c any/c boolean?) name : (or/c interned-symbol? #f) = #f
procedure
(equivalence-relation-function relation)
→ (-> any/c any/c boolean?) relation : equivalence-relation?
procedure
(equivalence-relation-map relation f) → equivalence-relation?
relation : equivalence-relation? f : (-> any/c any/c)
> (define string-length= (equivalence-relation-map natural-equality string-length)) > (equivalence-relation-holds? string-length= "hello" "world") #t
> (equivalence-relation-holds? string-length= "goodbye" "world") #f