8.3

#### 1.11Equivalence 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
A predicate for equivalence relations.

 procedure(equivalence-relation-holds? relation x y) → boolean? relation : equivalence-relation? x : any/c y : any/c
Tests whether x and y are equivalent, according to relation.

Examples:
 > (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
Constructs an equivalence relation that tests whether two values are equivalent by calling function.

 procedure(equivalence-relation-function relation) → (-> any/c any/c boolean?) relation : equivalence-relation?
Extracts the function from relation that implements the behavior of calling equivalence-relation-holds? with relation.

 value
An equivalence relation that considers two values equivalent when they are equal?.

 value
An equivalence relation that considers two values equivalent when they refer to the same object, i.e. when they are eq?.

 value
An equivalence relation on numbers that is consistent with the IEEE standard for numeric equality, as implemented by =. Beware that this breaks the reflexive property of equivalence relations, as IEEE specifies that +nan.0 (and +nan.0) must not be equal to itself. If this relation is restricted to numbers other than +nan.0 and +nan.0, then it obeys the laws of an equivalence relation.

 procedure(equivalence-relation-map relation f) → equivalence-relation? relation : equivalence-relation? f : (-> any/c any/c)
Wraps relation as an equivalence relation that first applies f to its inputs, then compares the returned results with relation.

Examples:
 > (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