Instructions to use SZLHOLDINGS/szl-lambda-gate with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Kernels
How to use SZLHOLDINGS/szl-lambda-gate with Kernels:
# !pip install kernels from kernels import get_kernel kernel = get_kernel("SZLHOLDINGS/szl-lambda-gate") - Notebooks
- Google Colab
- Kaggle
lambda-gate public API v0.2.0
Browse files
build/torch-universal/szl_lambda_gate/__init__.py
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: Apache-2.0
|
| 2 |
+
# © 2026 SZL Holdings · Stephen P. Lutar · ORCID 0009-0001-0110-4173
|
| 3 |
+
"""szl_lambda_gate — the Lambda-Spine aggregator (Λ) as a universal kernel.
|
| 4 |
+
|
| 5 |
+
A pure-PyTorch (universal) kernel from SZL Holdings for the Hugging Face
|
| 6 |
+
Kernel Hub. It ports the canonical Λ aggregator into a differentiable,
|
| 7 |
+
torch.compile-friendly torch op:
|
| 8 |
+
|
| 9 |
+
Λ(x) = ∏ xᵢ^{wᵢ}, Σwᵢ = 1, wᵢ > 0, xᵢ ∈ [0,1] (weighted geometric mean)
|
| 10 |
+
|
| 11 |
+
plus an ADVISORY governance gate (Λ vs threshold), the four carried axioms as
|
| 12 |
+
real runtime self-checks, and pure nn.Module layers.
|
| 13 |
+
|
| 14 |
+
Load from the Hub:
|
| 15 |
+
|
| 16 |
+
import torch
|
| 17 |
+
from kernels import get_kernel
|
| 18 |
+
|
| 19 |
+
lg = get_kernel("SZLHOLDINGS/szl-lambda-gate")
|
| 20 |
+
axes = torch.tensor([0.9, 0.8, 0.95]) # axis scores in [0,1]
|
| 21 |
+
score = lg.lambda_aggregate(axes) # Λ(x) ∈ [0,1]
|
| 22 |
+
res = lg.lambda_gate(axes, threshold=0.5) # ADVISORY pass/fail
|
| 23 |
+
print(res.score, res.passed, res.advisory)
|
| 24 |
+
|
| 25 |
+
WHAT Λ IS / IS NOT (HONESTY — SZL Holdings doctrine v11):
|
| 26 |
+
Λ is the weighted-geometric-mean aggregator — a non-compensatory, ADVISORY
|
| 27 |
+
way to roll axis scores in [0,1] into one number (any zeroed axis zeroes the
|
| 28 |
+
aggregate). It is NOT "proven trust" and NOT a closed theorem: Λ-uniqueness
|
| 29 |
+
remains Conjecture 1 (OPEN — an unresolved CAUCHY_ND step plus a missing
|
| 30 |
+
symmetry axiom). Label it honestly everywhere; a gate "pass" is advisory.
|
| 31 |
+
|
| 32 |
+
PROVENANCE: backed by the Lean 4 formalization szl-holdings/lutar-lean
|
| 33 |
+
(749 declarations / 14 axioms / 163 tracked sorries),
|
| 34 |
+
DOI 10.5281/zenodo.20434308 (lutar-lean). Λ uniqueness = Conjecture 1 (open).
|
| 35 |
+
"""
|
| 36 |
+
from typing import Optional
|
| 37 |
+
|
| 38 |
+
import torch
|
| 39 |
+
|
| 40 |
+
from . import layers # noqa: F401 (must be importable for Hub layer mapping)
|
| 41 |
+
from ._lambda import YUYAY_AXES, YUYAY_FLOORS, LambdaGateResult
|
| 42 |
+
from ._lambda import find_axiom_violation as _find_axiom_violation
|
| 43 |
+
from ._lambda import is_bounded_by_max as _is_bounded_by_max
|
| 44 |
+
from ._lambda import is_egyptian_exact as _is_egyptian_exact
|
| 45 |
+
from ._lambda import is_homogeneous as _is_homogeneous
|
| 46 |
+
from ._lambda import is_monotone as _is_monotone
|
| 47 |
+
from ._lambda import lambda_aggregate as _lambda_aggregate
|
| 48 |
+
from ._lambda import lambda_gate as _lambda_gate
|
| 49 |
+
from ._lambda import lambda_gate_batch as _lambda_gate_batch
|
| 50 |
+
from ._lambda import selfcheck as _selfcheck
|
| 51 |
+
from ._lambda import yuyay_weights as _yuyay_weights
|
| 52 |
+
|
| 53 |
+
__all__ = [
|
| 54 |
+
"lambda_aggregate",
|
| 55 |
+
"lambda_gate",
|
| 56 |
+
"lambda_gate_batch",
|
| 57 |
+
"LambdaGateResult",
|
| 58 |
+
"is_monotone",
|
| 59 |
+
"is_egyptian_exact",
|
| 60 |
+
"is_bounded_by_max",
|
| 61 |
+
"is_homogeneous",
|
| 62 |
+
"find_axiom_violation",
|
| 63 |
+
"selfcheck",
|
| 64 |
+
"yuyay_weights",
|
| 65 |
+
"YUYAY_AXES",
|
| 66 |
+
"YUYAY_FLOORS",
|
| 67 |
+
"layers",
|
| 68 |
+
"DOCTRINE_FOOTER",
|
| 69 |
+
"PROVENANCE",
|
| 70 |
+
"__version__",
|
| 71 |
+
]
|
| 72 |
+
|
| 73 |
+
__version__ = "0.2.0"
|
| 74 |
+
DOCTRINE_FOOTER = (
|
| 75 |
+
"SZL Holdings · Λ = Conjecture 1 (ADVISORY, weighted geometric mean) · "
|
| 76 |
+
"uniqueness OPEN · NOT proven trust · honesty over checklist"
|
| 77 |
+
)
|
| 78 |
+
PROVENANCE = {
|
| 79 |
+
"lean_repo": "szl-holdings/lutar-lean",
|
| 80 |
+
"lean_declarations": 749,
|
| 81 |
+
"lean_axioms": 14,
|
| 82 |
+
"lean_tracked_sorries": 163,
|
| 83 |
+
"doi_lutar_lean": "10.5281/zenodo.20434308",
|
| 84 |
+
"lambda_status": "Conjecture 1 (open) — uniqueness unproven; advisory only",
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def lambda_aggregate(
|
| 89 |
+
axes: torch.Tensor,
|
| 90 |
+
weights: Optional[torch.Tensor] = None,
|
| 91 |
+
) -> torch.Tensor:
|
| 92 |
+
"""Λ(x) = ∏ xᵢ^{wᵢ}, the weighted geometric mean over the last dim of axes.
|
| 93 |
+
|
| 94 |
+
See ``szl_lambda_gate._lambda.lambda_aggregate``. Axis scores in [0,1],
|
| 95 |
+
uniform weights when ``weights`` is None. Differentiable, batched, and
|
| 96 |
+
torch.compile-friendly. ADVISORY — NOT proven trust.
|
| 97 |
+
"""
|
| 98 |
+
return _lambda_aggregate(axes, weights=weights)
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
def lambda_gate(
|
| 102 |
+
axes: torch.Tensor,
|
| 103 |
+
weights: Optional[torch.Tensor] = None,
|
| 104 |
+
threshold: float = 0.5,
|
| 105 |
+
) -> LambdaGateResult:
|
| 106 |
+
"""ADVISORY Λ governance gate: returns LambdaGateResult(score, passed,
|
| 107 |
+
threshold, advisory). ``passed`` = Λ(axes) >= threshold. A pass is an
|
| 108 |
+
advisory, non-compensatory signal — NOT proven trust (Λ = Conjecture 1).
|
| 109 |
+
"""
|
| 110 |
+
return _lambda_gate(axes, weights=weights, threshold=threshold)
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def lambda_gate_batch(
|
| 114 |
+
candidates: torch.Tensor,
|
| 115 |
+
weights: Optional[torch.Tensor] = None,
|
| 116 |
+
threshold: float = 0.5,
|
| 117 |
+
) -> LambdaGateResult:
|
| 118 |
+
"""ADVISORY batch gate over many candidate action-vectors (shape (..., N, k)).
|
| 119 |
+
|
| 120 |
+
The realistic per-inference-step call: score all N candidates at once and
|
| 121 |
+
return the advisory pass mask. Returns LambdaGateResult(score, passed,
|
| 122 |
+
threshold, advisory) with score/passed of shape (..., N). NOT proven trust.
|
| 123 |
+
"""
|
| 124 |
+
return _lambda_gate_batch(candidates, weights=weights, threshold=threshold)
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def yuyay_weights(dtype: torch.dtype = torch.float64, device=None) -> torch.Tensor:
|
| 128 |
+
"""Canonical 13-axis Yuyay Λ weight vector (uniform 1/13), ADVISORY only.
|
| 129 |
+
|
| 130 |
+
Use as ``weights`` over the 13 ``YUYAY_AXES``. The yuyay_v3 gate is a
|
| 131 |
+
conjunctive AND with per-axis floors (``YUYAY_FLOORS``); this Λ roll-up is
|
| 132 |
+
the weighted geometric mean and is ADVISORY — NOT proven trust.
|
| 133 |
+
"""
|
| 134 |
+
return _yuyay_weights(dtype=dtype, device=device)
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
def find_axiom_violation(k=5, trials=200, weights=None, seed=0, tol=1e-6):
|
| 138 |
+
"""Random-search for any A1–A4 violation; returns (axiom, axes, weights) or
|
| 139 |
+
None. An honest falsification attempt — finding nothing is evidence, not a
|
| 140 |
+
proof (Λ-uniqueness is Conjecture 1, open).
|
| 141 |
+
"""
|
| 142 |
+
return _find_axiom_violation(k=k, trials=trials, weights=weights, seed=seed, tol=tol)
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
def selfcheck(k=5, trials=64, seed=0) -> dict:
|
| 146 |
+
"""Expose the A1–A4 empirical self-checks + version as a single verdict dict.
|
| 147 |
+
|
| 148 |
+
Callable as get_kernel(...).selfcheck(). EMPIRICAL checks on sampled inputs,
|
| 149 |
+
NOT a proof of Λ-uniqueness (Conjecture 1, open). Advisory only.
|
| 150 |
+
"""
|
| 151 |
+
return _selfcheck(k=k, trials=trials, seed=seed)
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
# ---- axiom runtime self-checks (real, verifiable; NOT a uniqueness proof) -- #
|
| 155 |
+
def is_monotone(axes, weights=None, delta=0.05, tol=1e-7) -> bool:
|
| 156 |
+
"""A1 IsMonotone self-check: Λ is non-decreasing in each axis (on this data)."""
|
| 157 |
+
return _is_monotone(axes, weights=weights, delta=delta, tol=tol)
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
def is_egyptian_exact(c, k=3, weights=None, tol=1e-5) -> bool:
|
| 161 |
+
"""A3 IsEgyptianExact self-check: Λ(c, …, c) = c."""
|
| 162 |
+
return _is_egyptian_exact(c, k=k, weights=weights, tol=tol)
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
def is_bounded_by_max(axes, weights=None, tol=1e-6) -> bool:
|
| 166 |
+
"""A4 IsBounded self-check: Λ(x) ≤ maxᵢ xᵢ."""
|
| 167 |
+
return _is_bounded_by_max(axes, weights=weights, tol=tol)
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
def is_homogeneous(axes, t, weights=None, tol=1e-5) -> bool:
|
| 171 |
+
"""A2 IsHomogeneous(degree 1) self-check: Λ(t·x) = t·Λ(x)."""
|
| 172 |
+
return _is_homogeneous(axes, t, weights=weights, tol=tol)
|