Enum Class CountingSemiring

java.lang.Object
java.lang.Enum<CountingSemiring>
com.darkcollective.relix.provenance.CountingSemiring
All Implemented Interfaces:
Semiring<BigInteger>, Serializable, Comparable<CountingSemiring>, Constable

public enum CountingSemiring extends Enum<CountingSemiring> implements Semiring<BigInteger>
The counting semiring (ℕ, +, ×, 0, 1) — bag semantics (row multiplicity) and, over a weighted closure, path counting.

⊕ adds the multiplicities of alternative derivations, ⊗ multiplies the multiplicities of a join's inputs, 0 is 0 (absent), and 1 is 1.

Annotations are BigInteger rather than a fixed-width integer because multiplicities and path counts can grow without bound (a dense reachability graph has exponentially many paths); arbitrary precision avoids silent overflow, consistent with the engine's BigInteger-backed generators.

  • Enum Constant Details

    • INSTANCE

      public static final CountingSemiring INSTANCE
      The singleton instance.
  • Method Details

    • values

      public static CountingSemiring[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static CountingSemiring valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • zero

      public BigInteger zero()
      Description copied from interface: Semiring
      Returns the additive identity 0. It is the identity of Semiring.plus(K, K) and the annihilator of Semiring.times(K, K), and denotes an absent tuple.
      Specified by:
      zero in interface Semiring<BigInteger>
      Returns:
      the additive identity 0
    • one

      public BigInteger one()
      Description copied from interface: Semiring
      Returns the multiplicative identity 1. It is the identity of Semiring.times(K, K).
      Specified by:
      one in interface Semiring<BigInteger>
      Returns:
      the multiplicative identity 1
    • plus

      public BigInteger plus(BigInteger a, BigInteger b)
      Description copied from interface: Semiring
      Combines two annotations with ⊕ — the way alternative derivations of the same tuple (union, projection) are merged. Associative and commutative, with identity Semiring.zero().
      Specified by:
      plus in interface Semiring<BigInteger>
      Parameters:
      a - the first annotation
      b - the second annotation
      Returns:
      a ⊕ b
    • times

      public BigInteger times(BigInteger a, BigInteger b)
      Description copied from interface: Semiring
      Combines two annotations with ⊗ — the way the joint requirements of a tuple (join, product) are merged. Associative and commutative, with identity Semiring.one(), annihilated by Semiring.zero().
      Specified by:
      times in interface Semiring<BigInteger>
      Parameters:
      a - the first annotation
      b - the second annotation
      Returns:
      a ⊗ b
    • base

      public BigInteger base(BaseTuple tuple)
      Returns the tuple's multiplicity. A numeric weight is read as a whole number of occurrences, truncating any fractional part; a tuple with no numeric weight counts once, which is what makes an unweighted graph's annotation its path count.
      Specified by:
      base in interface Semiring<BigInteger>
      Parameters:
      tuple - the base tuple; never null
      Returns:
      the tuple's multiplicity