Skip to main content

omnibias.sos.families

0.1.0a2AlphaPython >=3.10AGPL / commercial

Sum-of-squares constructions, polynomial positivity checks, and rigorous validation of proposed Gram matrices.

import omnibias.sos.families
Module contract & mathematical conventions

SOS degree box: positivity in a Gram span, not “only equations.”

Shared formulas do not imply universal floating-point identity. Verify dtype, shape, derivative-order support, and the stated numerical assumptions for the path you use.

CLASS

SosDegreeFamily​

omnibias.sos.families.SosDegreeFamilySource ↗
class SosDegreeFamily

Dataclass constructor fields; inherited fields, if any, are declared by the base class. A field(...) expression describes a default factory or field options, not a literal argument default.

Candidate = half-degree; check = existing certify_sos on a planted poly.

Parameters

NameType & defaultContract
polynomialdataclass fieldPolynomialDefault: field(default_factory=planted_sum_of_squares)See the operation contract and implementation below.
max_half_degreedataclass fieldintDefault: 2See the operation contract and implementation below.
namedataclass fieldstrDefault: 'sos_degree_search'See the operation contract and implementation below.
completedataclass fieldboolDefault: TrueSee the operation contract and implementation below.
statementdataclass fieldStatementDefault: field(default_factory=lambda: Statement(name='sos_degree_search', obligation='the planted polynomial is SOS at some half-degree in the box', parent='global nonnegativity', parent_status='already_true'))See the operation contract and implementation below.
Executed regression · sos template planted hits

Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.

def test_sos_template_planted_hits() -> None:
    family = SosTemplateFamily()
    result = run_discovery(family.statement, family, "score_guided", budget=4)
    assert result.status == "PROVED"
    assert result.check is not None
    assert result.check.payload["honesty"]["no_condition_exists_claim"] is False
    assert result.check.payload["honesty"]["discovered_by_omnibias"] is True
python -m pytest "packages/omnibias-sos/tests/test_conditions.py::test_sos_template_planted_hits" -q

Fields & methods

polynomialfield
polynomial: Polynomial = field(default_factory=planted_sum_of_squares)

Declared Polynomial field on SosDegreeFamily. Default expression: field(default_factory=planted_sum_of_squares).

View source ↗
max_half_degreefield
max_half_degree: int = 2

Declared int field on SosDegreeFamily. Default expression: 2.

View source ↗
namefield
name: str = 'sos_degree_search'

Declared str field on SosDegreeFamily. Default expression: 'sos_degree_search'.

View source ↗
completefield
complete: bool = True

Declared bool field on SosDegreeFamily. Default expression: True.

View source ↗
statementfield
statement: Statement = field(default_factory=lambda: Statement(name='sos_degree_search', obligation='the planted polynomial is SOS at some half-degree in the box', parent='global nonnegativity', parent_status='already_true'))

Declared Statement field on SosDegreeFamily. Default expression: field(default_factory=lambda: Statement(name='sos_degree_search', obligation='the planted polynomial is SOS at some half-degree in the box', parent='global nonnegativity', parent_status='already_true')).

View source ↗
cardinalitymethod
cardinality(self) -> int

See the class contract above and the exact method implementation below.

Returns: int

Method implementation
    def cardinality(self) -> int:
        return self.max_half_degree
View source ↗
originmethod
origin(self) -> int

See the class contract above and the exact method implementation below.

Returns: int

Method implementation
    def origin(self) -> int:
        return 1
View source ↗
neighborsmethod
neighbors(self, candidate: Candidate) -> Sequence[int]

See the class contract above and the exact method implementation below.

Parameters

NameType & defaultContract
candidatepositional-or-keywordCandidateRequiredSee the operation contract and implementation below.

Returns: Sequence[int]

Method implementation
    def neighbors(self, candidate: Candidate) -> Sequence[int]:
        value = int(candidate)  # type: ignore[arg-type]
        out: list[int] = []
        if value > 1:
            out.append(value - 1)
        if value < self.max_half_degree:
            out.append(value + 1)
        return out
View source ↗
scoremethod
score(self, candidate: Candidate) -> int

See the class contract above and the exact method implementation below.

Parameters

NameType & defaultContract
candidatepositional-or-keywordCandidateRequiredSee the operation contract and implementation below.

Returns: int

Method implementation
    def score(self, candidate: Candidate) -> int:
        return -int(candidate)  # type: ignore[arg-type]
View source ↗
checkmethod
check(self, candidate: Candidate) -> ExactCheck | None

See the class contract above and the exact method implementation below.

Parameters

NameType & defaultContract
candidatepositional-or-keywordCandidateRequiredSee the operation contract and implementation below.

Returns: ExactCheck | None

Executed regression · sos template planted hits

Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.

def test_sos_template_planted_hits() -> None:
    family = SosTemplateFamily()
    result = run_discovery(family.statement, family, "score_guided", budget=4)
    assert result.status == "PROVED"
    assert result.check is not None
    assert result.check.payload["honesty"]["no_condition_exists_claim"] is False
    assert result.check.payload["honesty"]["discovered_by_omnibias"] is True
python -m pytest "packages/omnibias-sos/tests/test_conditions.py::test_sos_template_planted_hits" -q
Method implementation
    def check(self, candidate: Candidate) -> ExactCheck | None:
        half = int(candidate)  # type: ignore[arg-type]
        if not 1 <= half <= self.max_half_degree:
            return None
        cert = certify_sos(self.polynomial, half_degree=half)
        ok = cert.status == "proved"
        return ExactCheck(
            ok=ok,
            payload={
                "half_degree": half,
                "status": cert.status,
                "honesty": {
                    "discovered_by_omnibias": ok,
                    "unproven_claim": False,
                },
            },
        )
View source ↗
Read the implementation
class SosDegreeFamily:
    """Candidate = half-degree; check = existing ``certify_sos`` on a planted poly."""

    polynomial: Polynomial = field(default_factory=planted_sum_of_squares)
    max_half_degree: int = 2
    name: str = "sos_degree_search"
    complete: bool = True
    statement: Statement = field(
        default_factory=lambda: Statement(
            name="sos_degree_search",
            obligation="the planted polynomial is SOS at some half-degree in the box",
            parent="global nonnegativity",
            parent_status="already_true",
        )
    )

    def cardinality(self) -> int:
        return self.max_half_degree

    def origin(self) -> int:
        return 1

    def neighbors(self, candidate: Candidate) -> Sequence[int]:
        value = int(candidate)  # type: ignore[arg-type]
        out: list[int] = []
        if value > 1:
            out.append(value - 1)
        if value < self.max_half_degree:
            out.append(value + 1)
        return out

    def score(self, candidate: Candidate) -> int:
        return -int(candidate)  # type: ignore[arg-type]

    def check(self, candidate: Candidate) -> ExactCheck | None:
        half = int(candidate)  # type: ignore[arg-type]
        if not 1 <= half <= self.max_half_degree:
            return None
        cert = certify_sos(self.polynomial, half_degree=half)
        ok = cert.status == "proved"
        return ExactCheck(
            ok=ok,
            payload={
                "half_degree": half,
                "status": cert.status,
                "honesty": {
                    "discovered_by_omnibias": ok,
                    "unproven_claim": False,
                },
            },
        )
FUNCTION

planted_sum_of_squares​

omnibias.sos.families.planted_sum_of_squaresSource ↗
planted_sum_of_squares() -> Polynomial

The module contract describes the context for this operation. Its signature, explicit validation, return expressions, and implementation are recorded below.

ReturnsPolynomial
Executed regression · sos template planted hits

Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.

def test_sos_template_planted_hits() -> None:
    family = SosTemplateFamily()
    result = run_discovery(family.statement, family, "score_guided", budget=4)
    assert result.status == "PROVED"
    assert result.check is not None
    assert result.check.payload["honesty"]["no_condition_exists_claim"] is False
    assert result.check.payload["honesty"]["discovered_by_omnibias"] is True
python -m pytest "packages/omnibias-sos/tests/test_conditions.py::test_sos_template_planted_hits" -q
Read the implementation
def planted_sum_of_squares() -> Polynomial:
    x = Polynomial.variable(0, 2)
    y = Polynomial.variable(1, 2)
    one = Polynomial.constant(1.0, 2)
    return x * x + y * y + one