Skip to main content

omnibias.core.verified.enclosure_collapse

0.5.0rc1Release candidatePython >=3.10Apache-2.0

Coefficient recurrences, activation contracts, jet algebra, and verified arithmetic shared by the numerical backends.

import omnibias.core.verified.enclosure_collapse
Module contract & mathematical conventions

Enclosure Collapse algebra and the Width Law (theory 01-14).

The founding bias collapse (delta -> 0) yields a smooth sigma^(K-1). Temperature collapse (beta -> inf, feasibility) yields a 0/1 step. Enclosure Collapse is the third limit: width -> 0 of a *sound enclosure*. The output is a point plus a proof, not a derivative and not a 0/1 step. Do not conflate the three.

There is no operator Collapse([lo, hi]) -> point. Identifying endpoints (lo := hi) is unsound and is not an API.

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.

Imports & aliases​

These names share a definition with another public module. Follow a name for its full contract, parameters, and examples.

Import from this moduleCanonical reference
WidthBudgetomnibias.core.verified.enclosure_collapse.WidthBudget
CONSTANT

CRITICAL_POINT_FACTOR​

omnibias.core.verified.enclosure_collapse.CRITICAL_POINT_FACTORSource ↗
CRITICAL_POINT_FACTOR = 1

This exported constant is defined by the expression above. Its exact value and annotation come from the pinned source; use it with the module contract.

Regression example · g1 width law critical point factor

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_g1_width_law_critical_point_factor(activation: str, n: int, center: float) -> None:
    law = width_law(activation, n, center, kind="critical_point")
    assert law.exponent == 2
    assert CRITICAL_POINT_FACTOR == 1
    r = 1e-3
    enc = measured_critical_width(activation, n, center, r)
    ratio = enc.width / (r**2)
    assert abs(ratio - law.predicted_leading.mid) / max(law.predicted_leading.mid, 1e-12) < 0.25
python -m pytest packages/omnibias-core/tests/verified/test_enclosure_collapse.py -k test_g1_width_law_critical_point_factor -q
Read the implementation
CRITICAL_POINT_FACTOR = 1
CONSTANT

MEAN_VALUE_FACTOR​

omnibias.core.verified.enclosure_collapse.MEAN_VALUE_FACTORSource ↗
MEAN_VALUE_FACTOR = 2

This exported constant is defined by the expression above. Its exact value and annotation come from the pinned source; use it with the module contract.

Regression example · g1 width law mean value limit

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_g1_width_law_mean_value_limit(activation: str, n: int, center: float) -> None:
    law = width_law(activation, n, center, kind="mean_value")
    assert law.exponent == 1
    assert law.kind == "mean_value"
    errors: list[float] = []
    for r in (1e-2, 1e-3, 1e-4):
        enc = measured_mean_value_width(activation, n, center, r)
        ratio = enc.width / (MEAN_VALUE_FACTOR * r)
        errors.append(abs(ratio - law.predicted_leading.mid))
        pred = predicted_width(law, r)
        assert pred.lo >= 0.0
    assert errors[-1] < 5e-3
    assert errors[-1] <= errors[0]
python -m pytest packages/omnibias-core/tests/verified/test_enclosure_collapse.py -k test_g1_width_law_mean_value_limit -q
Read the implementation
MEAN_VALUE_FACTOR = 2
CLASS

RecommendedAction​

omnibias.core.verified.RecommendedActionSource ↗
class RecommendedAction

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.

What to do when a named WidthBudget piece dominates.

Parameters

NameType & defaultContract
dominantdataclass fieldDominantNameRequiredSee the operation contract and implementation below.
actiondataclass fieldActionNameRequiredSee the operation contract and implementation below.
reasondataclass fieldstrRequiredSee the operation contract and implementation below.
Executed regression · diagnose width maps each dominant

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_diagnose_width_maps_each_dominant() -> None:
    expected = {
        "truncation": "raise_order",
        "wrapping": "subdivide",
        "jacobian": "shrink_step",
        "rounding": "stop_floor",
    }
    for dominant, action in expected.items():
        parts = {"truncation": 0.0, "jacobian": 0.0, "wrapping": 0.0, "rounding": 0.0}
        parts[dominant] = 1.0
        rec = diagnose_width(WidthBudget(**parts))
        assert isinstance(rec, RecommendedAction)
        assert rec.dominant == dominant
        assert rec.action == action
        payload = rec.to_payload()
        assert payload["dominant"] == dominant
        assert payload["action"] == action
        assert payload["reason"]
python -m pytest "packages/omnibias-core/tests/verified/test_enclosure_collapse.py::test_diagnose_width_maps_each_dominant" -q

Fields & methods

dominantfield
dominant: DominantName

Declared DominantName field on RecommendedAction. A value must be provided when constructing the configuration, unless an inherited constructor supplies it.

View source ↗
actionfield
action: ActionName

Declared ActionName field on RecommendedAction. A value must be provided when constructing the configuration, unless an inherited constructor supplies it.

View source ↗
reasonfield
reason: str

Declared str field on RecommendedAction. A value must be provided when constructing the configuration, unless an inherited constructor supplies it.

View source ↗
to_payloadmethod
to_payload(self) -> dict[str, str]

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

Returns: dict[str, str]

Executed regression · diagnose width maps each dominant

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_diagnose_width_maps_each_dominant() -> None:
    expected = {
        "truncation": "raise_order",
        "wrapping": "subdivide",
        "jacobian": "shrink_step",
        "rounding": "stop_floor",
    }
    for dominant, action in expected.items():
        parts = {"truncation": 0.0, "jacobian": 0.0, "wrapping": 0.0, "rounding": 0.0}
        parts[dominant] = 1.0
        rec = diagnose_width(WidthBudget(**parts))
        assert isinstance(rec, RecommendedAction)
        assert rec.dominant == dominant
        assert rec.action == action
        payload = rec.to_payload()
        assert payload["dominant"] == dominant
        assert payload["action"] == action
        assert payload["reason"]
python -m pytest "packages/omnibias-core/tests/verified/test_enclosure_collapse.py::test_diagnose_width_maps_each_dominant" -q
Method implementation
    def to_payload(self) -> dict[str, str]:
        return {
            "dominant": self.dominant,
            "action": self.action,
            "reason": self.reason,
        }
View source ↗
Read the implementation
class RecommendedAction:
    """What to do when a named ``WidthBudget`` piece dominates."""

    dominant: DominantName
    action: ActionName
    reason: str

    def to_payload(self) -> dict[str, str]:
        return {
            "dominant": self.dominant,
            "action": self.action,
            "reason": self.reason,
        }
Other public import paths
  • omnibias.core.verified.RecommendedAction
  • omnibias.core.verified.enclosure_collapse.RecommendedAction
CLASS

WidthLaw​

omnibias.core.verified.WidthLawSource ↗
class WidthLaw

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.

Closed-form leading coefficient of enclosure width.

Parameters

NameType & defaultContract
centerdataclass fieldfloatRequiredSee the operation contract and implementation below.
orderdataclass fieldintRequiredSee the operation contract and implementation below.
predicted_leadingdataclass fieldIntervalRequiredSee the operation contract and implementation below.
exponentdataclass fieldintRequiredSee the operation contract and implementation below.
activationdataclass fieldstrRequiredSee the operation contract and implementation below.
kinddataclass fieldWidthLawKindRequiredSee the operation contract and implementation below.

Fields & methods

centerfield
center: float

Declared float field on WidthLaw. A value must be provided when constructing the configuration, unless an inherited constructor supplies it.

View source ↗
orderfield
order: int

Declared int field on WidthLaw. A value must be provided when constructing the configuration, unless an inherited constructor supplies it.

View source ↗
predicted_leadingfield
predicted_leading: Interval

Declared Interval field on WidthLaw. A value must be provided when constructing the configuration, unless an inherited constructor supplies it.

View source ↗
exponentfield
exponent: int

Declared int field on WidthLaw. A value must be provided when constructing the configuration, unless an inherited constructor supplies it.

View source ↗
activationfield
activation: str

Declared str field on WidthLaw. A value must be provided when constructing the configuration, unless an inherited constructor supplies it.

View source ↗
kindfield
kind: WidthLawKind

Declared WidthLawKind field on WidthLaw. A value must be provided when constructing the configuration, unless an inherited constructor supplies it.

View source ↗
Read the implementation
class WidthLaw:
    """Closed-form leading coefficient of enclosure width."""

    center: float
    order: int
    predicted_leading: Interval
    exponent: int
    activation: str
    kind: WidthLawKind
Other public import paths
  • omnibias.core.verified.WidthLaw
  • omnibias.core.verified.enclosure_collapse.WidthLaw
FUNCTION

diagnose_width​

omnibias.core.verified.diagnose_widthSource ↗
diagnose_width(budget: WidthBudget) -> RecommendedAction

Recommend an action from an existing WidthBudget. Does not fork the type.

Parameters

NameType & defaultContract
budgetpositional-or-keywordWidthBudgetRequiredSee the operation contract and implementation below.
ReturnsRecommendedAction
Executed regression · diagnose width maps each dominant

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_diagnose_width_maps_each_dominant() -> None:
    expected = {
        "truncation": "raise_order",
        "wrapping": "subdivide",
        "jacobian": "shrink_step",
        "rounding": "stop_floor",
    }
    for dominant, action in expected.items():
        parts = {"truncation": 0.0, "jacobian": 0.0, "wrapping": 0.0, "rounding": 0.0}
        parts[dominant] = 1.0
        rec = diagnose_width(WidthBudget(**parts))
        assert isinstance(rec, RecommendedAction)
        assert rec.dominant == dominant
        assert rec.action == action
        payload = rec.to_payload()
        assert payload["dominant"] == dominant
        assert payload["action"] == action
        assert payload["reason"]
python -m pytest "packages/omnibias-core/tests/verified/test_enclosure_collapse.py::test_diagnose_width_maps_each_dominant" -q
Read the implementation
def diagnose_width(budget: WidthBudget) -> RecommendedAction:
    """Recommend an action from an existing ``WidthBudget``. Does not fork the type."""
    match budget.dominant:
        case "truncation" | "jacobian" | "wrapping" | "rounding" as name:
            return RecommendedAction(name, _ACTIONS[name], _REASONS[name])
        case other:
            raise ValueError(f"unknown WidthBudget dominant {other!r}")
Other public import paths
  • omnibias.core.verified.diagnose_width
  • omnibias.core.verified.enclosure_collapse.diagnose_width
FUNCTION

honesty_payload​

omnibias.core.verified.enclosure_collapse.honesty_payloadSource ↗
honesty_payload() -> dict[str, object]

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

Returnsdict[str, object]
Executed regression · honesty names three limits

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_honesty_names_three_limits() -> None:
    payload = honesty_payload()
    assert payload["founding_bias_collapse"] is True
    assert payload["temperature_collapse"] is False
    assert payload["enclosure_collapse"] is True
    assert payload["width_to_zero"] is True
    assert payload["not_a_derivative"] is True
    assert payload["not_a_01_step"] is True
    assert payload["theorem_prover_verified"] is False
python -m pytest "packages/omnibias-core/tests/verified/test_enclosure_collapse.py::test_honesty_names_three_limits" -q
Read the implementation
def honesty_payload() -> dict[str, object]:
    return {
        "founding_bias_collapse": True,
        "temperature_collapse": False,
        "enclosure_collapse": True,
        "width_to_zero": True,
        "not_a_derivative": True,
        "not_a_01_step": True,
        "theorem_prover_verified": False,
        "mathlib_verified": False,
    }
FUNCTION

measured_critical_width​

omnibias.core.verified.measured_critical_widthSource ↗
measured_critical_width(activation: str, n: int, center: float, r: float) -> Interval

Second-order form f(c) + f''(I)·(I-c)^2 (factor locked to 1).

Parameters

NameType & defaultContract
activationpositional-or-keywordstrRequiredSee the operation contract and implementation below.
npositional-or-keywordintRequiredSee the operation contract and implementation below.
centerpositional-or-keywordfloatRequiredSee the operation contract and implementation below.
rpositional-or-keywordfloatRequiredSee the operation contract and implementation below.
ReturnsInterval
Explicit validation & failure cases
  • When n < 0, raises ValueError('n must be >= 0').

These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.

Executed regression · g1 width law critical point factor

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_g1_width_law_critical_point_factor(activation: str, n: int, center: float) -> None:
    law = width_law(activation, n, center, kind="critical_point")
    assert law.exponent == 2
    assert CRITICAL_POINT_FACTOR == 1
    r = 1e-3
    enc = measured_critical_width(activation, n, center, r)
    ratio = enc.width / (r**2)
    assert abs(ratio - law.predicted_leading.mid) / max(law.predicted_leading.mid, 1e-12) < 0.25
python -m pytest "packages/omnibias-core/tests/verified/test_enclosure_collapse.py::test_g1_width_law_critical_point_factor[sigmoid-1-0.0]" -q
Read the implementation
def measured_critical_width(activation: str, n: int, center: float, r: float) -> Interval:
    """Second-order form ``f(c) + f''(I)·(I-c)^2`` (factor locked to 1)."""
    if n < 0:
        raise ValueError("n must be >= 0")
    c, box = _box(center, r)
    f_c = sigma_tower_interval(activation, c, n)[n]
    f_pp = sigma_tower_interval(activation, box, n + 2)[n + 2]
    return f_c + f_pp * (box - c) ** 2
Other public import paths
  • omnibias.core.verified.measured_critical_width
  • omnibias.core.verified.enclosure_collapse.measured_critical_width
FUNCTION

measured_mean_value_width​

omnibias.core.verified.measured_mean_value_widthSource ↗
measured_mean_value_width(activation: str, n: int, center: float, r: float) -> Interval

Mean-value enclosure f(c) + f'(I)·(I-c) of sigma^(n) on I(r).

Parameters

NameType & defaultContract
activationpositional-or-keywordstrRequiredSee the operation contract and implementation below.
npositional-or-keywordintRequiredSee the operation contract and implementation below.
centerpositional-or-keywordfloatRequiredSee the operation contract and implementation below.
rpositional-or-keywordfloatRequiredSee the operation contract and implementation below.
ReturnsInterval
Explicit validation & failure cases
  • When n < 0, raises ValueError('n must be >= 0').

These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.

Executed regression · mean value rejects nonpositive radius

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_mean_value_rejects_nonpositive_radius() -> None:
    with pytest.raises(ValueError, match="positive"):
        measured_mean_value_width("sigmoid", 0, 0.0, 0.0)
python -m pytest "packages/omnibias-core/tests/verified/test_enclosure_collapse.py::test_mean_value_rejects_nonpositive_radius" -q
Regression example · g1 width law critical point factor

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_g1_width_law_critical_point_factor(activation: str, n: int, center: float) -> None:
    law = width_law(activation, n, center, kind="critical_point")
    assert law.exponent == 2
    assert CRITICAL_POINT_FACTOR == 1
    r = 1e-3
    enc = measured_critical_width(activation, n, center, r)
    ratio = enc.width / (r**2)
    assert abs(ratio - law.predicted_leading.mid) / max(law.predicted_leading.mid, 1e-12) < 0.25
python -m pytest packages/omnibias-core/tests/verified/test_enclosure_collapse.py -k test_g1_width_law_critical_point_factor -q
Read the implementation
def measured_mean_value_width(activation: str, n: int, center: float, r: float) -> Interval:
    """Mean-value enclosure ``f(c) + f'(I)·(I-c)`` of ``sigma^(n)`` on ``I(r)``."""
    if n < 0:
        raise ValueError("n must be >= 0")
    c, box = _box(center, r)
    f_c = sigma_tower_interval(activation, c, n)[n]
    f_prime = sigma_tower_interval(activation, box, n + 1)[n + 1]
    return f_c + f_prime * (box - c)
Other public import paths
  • omnibias.core.verified.measured_mean_value_width
  • omnibias.core.verified.enclosure_collapse.measured_mean_value_width
FUNCTION

measured_taylor_remainder​

omnibias.core.verified.measured_taylor_remainderSource ↗
measured_taylor_remainder(activation: str, n: int, center: float, r: float, order: int) -> Interval

Lagrange remainder enclosure of sigma^(n) after order N.

Parameters

NameType & defaultContract
activationpositional-or-keywordstrRequiredSee the operation contract and implementation below.
npositional-or-keywordintRequiredSee the operation contract and implementation below.
centerpositional-or-keywordfloatRequiredSee the operation contract and implementation below.
rpositional-or-keywordfloatRequiredSee the operation contract and implementation below.
orderpositional-or-keywordintRequiredSee the operation contract and implementation below.
ReturnsInterval
Explicit validation & failure cases
  • When n < 0 or order < 0, raises ValueError('n and order must be >= 0').

These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.

Executed regression · g1 width law taylor remainder

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_g1_width_law_taylor_remainder() -> None:
    activation, n, center, order = "sigmoid", 0, 0.3, 2
    law = width_law(activation, n, center, kind="taylor_remainder", order=order)
    assert law.exponent == order + 1
    r = 5e-3
    rem = measured_taylor_remainder(activation, n, center, r, order)
    pred = predicted_width(law, r)
    assert rem.width > 0.0
    assert pred.contains(rem.width) or abs(rem.width - pred.mid) / max(pred.mid, 1e-18) < 0.5
python -m pytest "packages/omnibias-core/tests/verified/test_enclosure_collapse.py::test_g1_width_law_taylor_remainder" -q
Read the implementation
def measured_taylor_remainder(activation: str, n: int, center: float, r: float, order: int) -> Interval:
    """Lagrange remainder enclosure of ``sigma^(n)`` after order ``N``."""
    if n < 0 or order < 0:
        raise ValueError("n and order must be >= 0")
    _c, box = _box(center, r)
    deriv = sigma_tower_interval(activation, box, n + order + 1)[n + order + 1]
    return deriv * (box - Interval.point(float(center))) ** (order + 1) / float(_factorial(order + 1))
Other public import paths
  • omnibias.core.verified.measured_taylor_remainder
  • omnibias.core.verified.enclosure_collapse.measured_taylor_remainder
FUNCTION

predicted_width​

omnibias.core.verified.predicted_widthSource ↗
predicted_width(law: WidthLaw, r: float) -> Interval

Enclosure of the predicted width C * r^exponent (with locked factors).

Parameters

NameType & defaultContract
lawpositional-or-keywordWidthLawRequiredSee the operation contract and implementation below.
rpositional-or-keywordfloatRequiredSee the operation contract and implementation below.
ReturnsInterval
Executed regression · g1 width law taylor remainder

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_g1_width_law_taylor_remainder() -> None:
    activation, n, center, order = "sigmoid", 0, 0.3, 2
    law = width_law(activation, n, center, kind="taylor_remainder", order=order)
    assert law.exponent == order + 1
    r = 5e-3
    rem = measured_taylor_remainder(activation, n, center, r, order)
    pred = predicted_width(law, r)
    assert rem.width > 0.0
    assert pred.contains(rem.width) or abs(rem.width - pred.mid) / max(pred.mid, 1e-18) < 0.5
python -m pytest "packages/omnibias-core/tests/verified/test_enclosure_collapse.py::test_g1_width_law_taylor_remainder" -q
Regression example · g1 width law mean value limit

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_g1_width_law_mean_value_limit(activation: str, n: int, center: float) -> None:
    law = width_law(activation, n, center, kind="mean_value")
    assert law.exponent == 1
    assert law.kind == "mean_value"
    errors: list[float] = []
    for r in (1e-2, 1e-3, 1e-4):
        enc = measured_mean_value_width(activation, n, center, r)
        ratio = enc.width / (MEAN_VALUE_FACTOR * r)
        errors.append(abs(ratio - law.predicted_leading.mid))
        pred = predicted_width(law, r)
        assert pred.lo >= 0.0
    assert errors[-1] < 5e-3
    assert errors[-1] <= errors[0]
python -m pytest packages/omnibias-core/tests/verified/test_enclosure_collapse.py -k test_g1_width_law_mean_value_limit -q
Read the implementation
def predicted_width(law: WidthLaw, r: float) -> Interval:
    """Enclosure of the predicted width ``C * r^exponent`` (with locked factors)."""
    radius = _require_radius(r)
    scale = Interval.point(radius) ** law.exponent
    if law.kind == "mean_value":
        return law.predicted_leading * scale * MEAN_VALUE_FACTOR
    if law.kind == "critical_point":
        return law.predicted_leading * scale * CRITICAL_POINT_FACTOR
    factor = 2 if law.exponent % 2 == 1 else 1
    return law.predicted_leading * scale * factor
Other public import paths
  • omnibias.core.verified.predicted_width
  • omnibias.core.verified.enclosure_collapse.predicted_width
FUNCTION

rounding_floor_witness​

omnibias.core.verified.rounding_floor_witnessSource ↗
rounding_floor_witness() -> Interval

Lemma Floor: a non-exact evaluation whose width is at least 2 ulp.

ReturnsInterval
Executed regression · g2 lemma floor two ulp

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_g2_lemma_floor_two_ulp() -> None:
    witness = rounding_floor_witness()
    assert witness.width >= two_ulp(0.0)
    mid = witness.mid
    assert witness.contains(1.0 / 3.0) or abs(mid - 1.0 / 3.0) <= witness.width
    assert witness.lo < witness.hi
python -m pytest "packages/omnibias-core/tests/verified/test_enclosure_collapse.py::test_g2_lemma_floor_two_ulp" -q
Read the implementation
def rounding_floor_witness() -> Interval:
    """Lemma Floor: a non-exact evaluation whose width is at least ``2 ulp``."""
    return Interval.point(1.0) / 3.0
Other public import paths
  • omnibias.core.verified.rounding_floor_witness
  • omnibias.core.verified.enclosure_collapse.rounding_floor_witness
FUNCTION

two_ulp​

omnibias.core.verified.enclosure_collapse.two_ulpSource ↗
two_ulp(x: float) -> float

Two outward steps from x in the +inf direction.

Parameters

NameType & defaultContract
xpositional-or-keywordfloatRequiredSee the operation contract and implementation below.
Returnsfloat
Executed regression · g2 lemma floor two ulp

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_g2_lemma_floor_two_ulp() -> None:
    witness = rounding_floor_witness()
    assert witness.width >= two_ulp(0.0)
    mid = witness.mid
    assert witness.contains(1.0 / 3.0) or abs(mid - 1.0 / 3.0) <= witness.width
    assert witness.lo < witness.hi
python -m pytest "packages/omnibias-core/tests/verified/test_enclosure_collapse.py::test_g2_lemma_floor_two_ulp" -q
Read the implementation
def two_ulp(x: float) -> float:
    """Two outward steps from ``x`` in the ``+inf`` direction."""
    return math.nextafter(math.nextafter(float(x), math.inf), math.inf)
FUNCTION

width_law​

omnibias.core.verified.width_lawSource ↗
width_law(activation: str, n: int, center: float, *, kind: WidthLawKind='mean_value', order: int | None=None) -> WidthLaw

Leading coefficient of w(r) from the closed-form tower.

n is the order of f = sigma^(n). Mean-value uses |f'(c)| = |sigma^(n+1)(c)| with exponent 1. Critical-point uses |f''(c)| with exponent 2 and factor CRITICAL_POINT_FACTOR. Taylor remainder of order N uses |f^{(N+1)}(c)| / (N+1)!.

Parameters

NameType & defaultContract
activationpositional-or-keywordstrRequiredSee the operation contract and implementation below.
npositional-or-keywordintRequiredSee the operation contract and implementation below.
centerpositional-or-keywordfloatRequiredSee the operation contract and implementation below.
kindkeyword-onlyWidthLawKindDefault: 'mean_value'See the operation contract and implementation below.
orderkeyword-onlyint | NoneDefault: NoneSee the operation contract and implementation below.
ReturnsWidthLaw
Explicit validation & failure cases
  • When n < 0, raises ValueError('n must be >= 0').
  • When not first[n + 1].contains_zero() and abs(first[n + 1].mid) > 1e-09, raises ValueError("critical_point requires f'(c) near 0").
  • When n_order < 0, raises ValueError('Taylor order N must be >= 0').

These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.

Executed regression · g1 width law critical point factor

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_g1_width_law_critical_point_factor(activation: str, n: int, center: float) -> None:
    law = width_law(activation, n, center, kind="critical_point")
    assert law.exponent == 2
    assert CRITICAL_POINT_FACTOR == 1
    r = 1e-3
    enc = measured_critical_width(activation, n, center, r)
    ratio = enc.width / (r**2)
    assert abs(ratio - law.predicted_leading.mid) / max(law.predicted_leading.mid, 1e-12) < 0.25
python -m pytest "packages/omnibias-core/tests/verified/test_enclosure_collapse.py::test_g1_width_law_critical_point_factor[sigmoid-1-0.0]" -q
Regression example · g1 width law taylor remainder

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_g1_width_law_taylor_remainder() -> None:
    activation, n, center, order = "sigmoid", 0, 0.3, 2
    law = width_law(activation, n, center, kind="taylor_remainder", order=order)
    assert law.exponent == order + 1
    r = 5e-3
    rem = measured_taylor_remainder(activation, n, center, r, order)
    pred = predicted_width(law, r)
    assert rem.width > 0.0
    assert pred.contains(rem.width) or abs(rem.width - pred.mid) / max(pred.mid, 1e-18) < 0.5
python -m pytest packages/omnibias-core/tests/verified/test_enclosure_collapse.py -k test_g1_width_law_taylor_remainder -q
Read the implementation
def width_law(
    activation: str,
    n: int,
    center: float,
    *,
    kind: WidthLawKind = "mean_value",
    order: int | None = None,
) -> WidthLaw:
    """Leading coefficient of ``w(r)`` from the closed-form tower.

    ``n`` is the order of ``f = sigma^(n)``. Mean-value uses
    ``|f'(c)| = |sigma^(n+1)(c)|`` with exponent 1. Critical-point uses
    ``|f''(c)|`` with exponent 2 and factor ``CRITICAL_POINT_FACTOR``.
    Taylor remainder of order ``N`` uses ``|f^{(N+1)}(c)| / (N+1)!``.
    """
    if n < 0:
        raise ValueError("n must be >= 0")
    name = str(activation)
    if kind == "mean_value":
        leading = _abs_at_center(name, center, n + 1)
        return WidthLaw(float(center), 0, leading, 1, name, kind)
    if kind == "critical_point":
        first = sigma_tower_interval(name, Interval.point(float(center)), n + 2)
        if not first[n + 1].contains_zero() and abs(first[n + 1].mid) > 1e-9:
            raise ValueError("critical_point requires f'(c) near 0")
        leading = first[n + 2].abs()
        return WidthLaw(float(center), 1, leading, 2, name, kind)
    if kind == "taylor_remainder":
        n_order = 2 if order is None else int(order)
        if n_order < 0:
            raise ValueError("Taylor order N must be >= 0")
        deriv_order = n + n_order + 1
        leading = _abs_at_center(name, center, deriv_order) / float(_factorial(n_order + 1))
        return WidthLaw(float(center), n_order, leading, n_order + 1, name, kind)
    raise ValueError(f"unknown WidthLaw kind {kind!r}")
Other public import paths
  • omnibias.core.verified.width_law
  • omnibias.core.verified.enclosure_collapse.width_law