Skip to content

PascalRankCertificate

from tensorsig.offset_coded_signatures.pascal_certificate import PascalRankCertificate

Input-bound PBW--forest rows, a nonsingular minor, and a nullspace basis.

These exact witnesses certify a homogeneous primitive value rank for a raw binary scalar Pascal code. They do not supply a runtime encoder or decoder.

matrix_rank property

matrix_rank: int

Rank of the certificate's PBW--forest constraint matrix.

defect property

defect: int

Nullity of the constraint matrix, subtracted from the ambient Lie rank.

primitive_rank property

primitive_rank: int

Primitive value rank after keeping ambient weights up to weight.

nonzeros property

nonzeros: int

Number of stored nonzero coefficients in the defining matrix.

verify

verify(*, max_degree: int = 10, max_columns: int = 4096) -> bool

Bind F.60 rows to the input, then replay the minor/nullspace witnesses.

Source code in src/tensorsig/offset_coded_signatures/pascal_certificate.py
def verify(self, *, max_degree: int = 10, max_columns: int = 4096) -> bool:
    """Bind F.60 rows to the input, then replay the minor/nullspace witnesses."""
    try:
        _validate_parameters(self.degree, self.window, self.weight)
    except TypeError, ValueError:
        return False
    if (
        type(max_degree) is not int
        or type(max_columns) is not int
        or self.degree > max_degree
        or max_degree < 1
        or max_columns < 1
        or type(self.column_count) is not int
        or self.column_count
        != sum(comb(self.degree, s) for s in range(self.window, self.weight + 1))
        or self.column_count > max_columns
    ):
        return False
    if any(
        type(value) is not tuple
        for value in (self.rows, self.pivot_rows, self.pivot_columns, self.kernel)
    ):
        return False
    if (
        len(self.pivot_rows) != len(self.pivot_columns)
        or any(
            type(row) is not int or not 0 <= row < len(self.rows)
            for row in self.pivot_rows
        )
        or any(
            type(col) is not int or not 0 <= col < self.column_count
            for col in self.pivot_columns
        )
        or len(set(self.pivot_rows)) != len(self.pivot_rows)
        or len(set(self.pivot_columns)) != len(self.pivot_columns)
    ):
        return False
    for entries in (*self.rows, *self.kernel):
        if type(entries) is not tuple or any(
            type(pair) is not tuple or len(pair) != 2 for pair in entries
        ):
            return False
        if any(
            type(col) is not int
            or not 0 <= col < self.column_count
            or type(value) not in (int, Fraction)
            or not value
            for col, value in entries
        ):
            return False
        if len({col for col, _ in entries}) != len(entries):
            return False
    expected_rows = (
        _certificate_rows(self.degree, self.window, self.weight)[0]
        if self.column_count
        else ()
    )
    if self.rows != expected_rows:
        return False
    if len(self.kernel) != self.column_count - self.matrix_rank:
        return False
    free = sorted(set(range(self.column_count)) - set(self.pivot_columns))
    vectors = [dict(vector) for vector in self.kernel]
    if any(
        vector.get(column, 0) != int(i == j)
        for i, vector in enumerate(vectors)
        for j, column in enumerate(free)
    ):
        return False
    if any(
        sum(value * vector.get(column, 0) for column, value in row)
        for row in self.rows
        for vector in vectors
    ):
        return False
    minor = [
        [
            Fraction(dict(self.rows[row]).get(column, 0))
            for column in self.pivot_columns
        ]
        for row in self.pivot_rows
    ]
    # Independent dense elimination of the retained square minor proves >=rank.
    for pivot in range(len(minor)):
        chosen = next(
            (row for row in range(pivot, len(minor)) if minor[row][pivot]), None
        )
        if chosen is None:
            return False
        minor[pivot], minor[chosen] = minor[chosen], minor[pivot]
        for row in range(pivot + 1, len(minor)):
            scale = minor[row][pivot] / minor[pivot][pivot]
            if not scale:
                continue
            for col in range(pivot, len(minor)):
                minor[row][col] -= scale * minor[pivot][col]
    return True