On this page:
equivalence-relation?
equivalence-relation-holds?
make-equivalence-relation
equivalence-relation-function
natural-equality
object-identity-equality
numeric-equality
equivalence-relation-map
8.3

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:

procedure

(equivalence-relation? v)  boolean?

  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:

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.

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

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

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