java.lang.Object
java.lang.Record
com.darkcollective.relix.provenance.Polynomial
Record Components:
terms - canonical monomial → positive-coefficient map; never null
truncated - whether terms were dropped to stay within the representation bound

public record Polynomial(SortedMap<Monomial,BigInteger> terms, boolean truncated) extends Record
A provenance polynomial — an element of the lineage semiring ℕ[X]. It is a sum of monomials, each with a positive BigInteger coefficient, recording the full why-provenance of a tuple: every distinct derivation (monomial) and its multiplicity (coefficient).

Held in canonical form: a sorted map of monomial → non-zero coefficient (a coefficient of zero means that derivation is absent, so it is never a key). The empty polynomial is 0. The truncated flag records that a PolynomialSemiring operation hit the monomial cap and dropped some terms — the degraded mode (a sound under-approximation; the surviving terms are real derivations, but the polynomial is incomplete).

  • Constructor Summary

    Constructors
    Constructor
    Description
    Polynomial(SortedMap<Monomial,BigInteger> terms, boolean truncated)
    Canonicalises terms: defensively copies into a TreeMap (so iteration is in the deterministic Monomial order) and drops any zero-coefficient term.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    boolean
    Returns whether this is the zero polynomial.
    static Polynomial
    one()
    Returns the constant polynomial 1 (the multiplicative identity).
    render(boolean detailed)
    Returns this polynomial rendered with variables optionally enriched by their captured source columns.
    int
    Returns the number of distinct monomials (derivations) — the representation size.
    Returns the value of the terms record component.
    Returns the rendered polynomial, e.g. 2·Orders#1·Customers#1 + Orders#2.
    boolean
    Returns the value of the truncated record component.
    static Polynomial
    Returns the single-variable polynomial x for a structured source.
    static Polynomial
    Returns the single-variable polynomial x.
    static Polynomial
    Returns the zero polynomial 0 (no derivations — an absent tuple).

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Polynomial

      public Polynomial(SortedMap<Monomial,BigInteger> terms, boolean truncated)
      Canonicalises terms: defensively copies into a TreeMap (so iteration is in the deterministic Monomial order) and drops any zero-coefficient term. Negative coefficients are rejected — ℕ[X] has natural-number coefficients.
      Parameters:
      terms - monomial → coefficient map; never null
      truncated - whether some terms were dropped to honour the bound
  • Method Details

    • zero

      public static Polynomial zero()
      Returns the zero polynomial 0 (no derivations — an absent tuple).
      Returns:
      the zero polynomial 0 (no derivations — an absent tuple)
    • one

      public static Polynomial one()
      Returns the constant polynomial 1 (the multiplicative identity).
      Returns:
      the constant polynomial 1 (the multiplicative identity)
    • variable

      public static Polynomial variable(String name)
      Returns the single-variable polynomial x. The lift token for one base-tuple occurrence.
      Parameters:
      name - the variable label (by convention <relation>#<ordinal>)
      Returns:
      the single-variable polynomial x
    • variable

      public static Polynomial variable(SourceRef ref)
      Returns the single-variable polynomial x for a structured source. The lift token for one base-tuple occurrence, carrying its captured columns so the resulting lineage is machine-actionable.
      Parameters:
      ref - the structured source identity; never null
      Returns:
      the single-variable polynomial x for a structured source
    • isZero

      public boolean isZero()
      Returns whether this is the zero polynomial.
      Returns:
      whether this is the zero polynomial
    • size

      public int size()
      Returns the number of distinct monomials (derivations) — the representation size.
      Returns:
      the number of distinct monomials (derivations) — the representation size
    • toString

      public String toString()
      Returns the rendered polynomial, e.g. 2·Orders#1·Customers#1 + Orders#2. 0 for the zero polynomial; a trailing + ⋯ when truncated().
      Specified by:
      toString in class Record
      Returns:
      the rendered polynomial, e.g. 2·Orders#1·Customers#1 + Orders#2
    • render

      public String render(boolean detailed)
      Returns this polynomial rendered with variables optionally enriched by their captured source columns. render(false) is the compact form (the toString() default, e.g. 2·Orders#1·Customers#1 + Orders#2); render(true) expands each variable to its detailed label, e.g. Orders#1{id: 42}, when structured source columns are present.
      Parameters:
      detailed - whether to append captured source columns to each variable
      Returns:
      this polynomial rendered with variables optionally enriched by their captured source columns
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • terms

      public SortedMap<Monomial,BigInteger> terms()
      Returns the value of the terms record component.
      Returns:
      the value of the terms record component
    • truncated

      public boolean truncated()
      Returns the value of the truncated record component.
      Returns:
      the value of the truncated record component