persistent-equivalence-0.2: Persistent equivalence relations (aka union-find)

Data.Equivalence.Persistent

Description

Code for manipulation of equivalence classes on index types. An Equivalence is an equivalence relation. The empty equivalence relation is constructed over a ranges of values using emptyEquivalence. Less discerning equivalence relations can be obtained with equate and equateAll. The relation can be tested with equiv and equivalent, and canonical representatives can be chosen with repr.

An example follows:

 import Data.Equivalence.Persistent

 rel = equateAll [1,3,5,7,9]
     . equate 5 6
     . equate 2 4
     $ emptyEquivalence (1,10)

 test1 = equiv rel 3 5 -- This is True
 test2 = equiv rel 1 6 -- This is True
 test3 = equiv rel 4 6 -- This is False

Synopsis

Documentation

data Equivalence i Source

An Equivalence is an equivalence relation on a range of values of some index type.

emptyEquivalence :: Ix i => (i, i) -> Equivalence iSource

emptyEquivalence is an equivalence relation that equates two values only when they are equal to each other. It is the most discerning such relation possible.

domain :: Ix i => Equivalence i -> (i, i)Source

Gets the domain of an equivalence relation, as the ordered pair of index bounds.

repr :: Ix i => Equivalence i -> i -> iSource

repr gives a canonical representative of the equivalence class containing x. It is chosen arbitrarily, but is always the same for a given class and Equivalence value.

If you are using this function, you're probably doing something wrong. Please note that:

  • The representative chosen depends on the order in which the equivalence relation was built, and is not always the same for values that represent the same relation.
  • The representative is not particularly stable. Uses of equate are highly likely to change it.
  • If all you need is some representative of the equivalence class, you have to provide one as input to the function anyway, so you may as well use that.

Because of this, the function may be removed in a future version. Please contact me if you have a compelling use for it.

equiv :: Ix i => Equivalence i -> i -> i -> BoolSource

Determines if two values are equivalent under the given equivalence relation.

equivalent :: Ix i => Equivalence i -> [i] -> BoolSource

Determines if all of the given values are equivalent under the given equivalence relation.

equate :: Ix i => i -> i -> Equivalence i -> Equivalence iSource

Construct the equivalence relation obtained by equating the given two values. This combines equivalence classes.

equateAll :: Ix i => [i] -> Equivalence i -> Equivalence iSource

Construct the equivalence relation obtained by equating all of the given values. This combines equivalence classes.