omnibias.boolean.jax.ops.gates
Boolean truth tables, multilinear extensions, algebraic spectra, and finite-temperature gate systems.
import omnibias.boolean.jax.ops.gatesModule contract & mathematical conventions
Soft logic gates (jax): product-t-norm and hard-forward threshold gates.
Bit-identical twin of omnibias.boolean.torch.ops.gates. The product-t-norm
gates are the multilinear extensions of the Boolean gates (exact on the cube
vertices, smooth inside); the threshold gates have a hard {0, 1} forward with
the sigmoid(beta z) surrogate backward from
omnibias.binary.jax.ops.binarize01.
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.
linear_threshold
omnibias.boolean.jax.ops.linear_thresholdSource ↗linear_threshold(inputs: Sequence[Array], weights: Sequence[float], bias: float, beta: float=10.0) -> ArrayHard linear-threshold gate H(sum_k w_k x_k + bias) with surrogate backward.
Parameters
| Name | Type & default | Contract |
|---|---|---|
inputspositional-or-keyword | Sequence[Array]Required | See the operation contract and implementation below. |
weightspositional-or-keyword | Sequence[float]Required | See the operation contract and implementation below. |
biaspositional-or-keyword | floatRequired | See the operation contract and implementation below. |
betapositional-or-keyword | floatDefault: 10.0 | See the operation contract and implementation below. |
ArrayExplicit validation & failure cases
- When
len(inputs) != len(weights), raisesValueError('inputs and weights must have equal length').
These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.
Read the implementation
def linear_threshold(
inputs: Sequence[Array], weights: Sequence[float], bias: float, beta: float = 10.0
) -> Array:
"""Hard linear-threshold gate ``H(sum_k w_k x_k + bias)`` with surrogate backward."""
if len(inputs) != len(weights):
raise ValueError("inputs and weights must have equal length")
acc = inputs[0] * weights[0]
for x, w in zip(inputs[1:], weights[1:], strict=False):
acc = acc + x * w
return binarize01(acc + bias, beta)Other public import paths
omnibias.boolean.jax.ops.linear_thresholdomnibias.boolean.jax.ops.gates.linear_threshold
soft_and
omnibias.boolean.jax.ops.soft_andSource ↗soft_and(a: Array, b: Array) -> Arraya AND b = a * b (product t-norm).
Parameters
| Name | Type & default | Contract |
|---|---|---|
apositional-or-keyword | ArrayRequired | See the operation contract and implementation below. |
bpositional-or-keyword | ArrayRequired | See the operation contract and implementation below. |
ArrayExecuted regression · gates parity
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_gates_parity() -> None:
rng = random.Random(20)
for _ in range(20):
a, b = rng.random(), rng.random()
for name in ("soft_and", "soft_or", "soft_xor", "soft_nand", "soft_implies"):
tg = getattr(tb, name)
jg = getattr(jb, name)
tv = float(tg(torch.tensor(a, dtype=torch.float64), torch.tensor(b, dtype=torch.float64)))
jv = float(jg(jnp.asarray(a, dtype=jnp.float64), jnp.asarray(b, dtype=jnp.float64)))
assert tv == pytest.approx(jv, rel=1e-9, abs=1e-11)python -m pytest "packages/omnibias-boolean/tests/test_cross_backend.py::test_gates_parity" -qRead the implementation
def soft_and(a: Array, b: Array) -> Array:
"""``a AND b = a * b`` (product t-norm)."""
return a * bOther public import paths
omnibias.boolean.jax.ops.soft_andomnibias.boolean.jax.ops.gates.soft_and
soft_implies
omnibias.boolean.jax.ops.soft_impliesSource ↗soft_implies(a: Array, b: Array) -> Arraya -> b = 1 - a + a*b.
Parameters
| Name | Type & default | Contract |
|---|---|---|
apositional-or-keyword | ArrayRequired | See the operation contract and implementation below. |
bpositional-or-keyword | ArrayRequired | See the operation contract and implementation below. |
ArrayExecuted regression · gates parity
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_gates_parity() -> None:
rng = random.Random(20)
for _ in range(20):
a, b = rng.random(), rng.random()
for name in ("soft_and", "soft_or", "soft_xor", "soft_nand", "soft_implies"):
tg = getattr(tb, name)
jg = getattr(jb, name)
tv = float(tg(torch.tensor(a, dtype=torch.float64), torch.tensor(b, dtype=torch.float64)))
jv = float(jg(jnp.asarray(a, dtype=jnp.float64), jnp.asarray(b, dtype=jnp.float64)))
assert tv == pytest.approx(jv, rel=1e-9, abs=1e-11)python -m pytest "packages/omnibias-boolean/tests/test_cross_backend.py::test_gates_parity" -qRead the implementation
def soft_implies(a: Array, b: Array) -> Array:
"""``a -> b = 1 - a + a*b``."""
return 1.0 - a + a * bOther public import paths
omnibias.boolean.jax.ops.soft_impliesomnibias.boolean.jax.ops.gates.soft_implies
soft_majority3
omnibias.boolean.jax.ops.soft_majority3Source ↗soft_majority3(a: Array, b: Array, c: Array) -> Array3-input majority ab + bc + ca - 2abc (exact on vertices).
Parameters
| Name | Type & default | Contract |
|---|---|---|
apositional-or-keyword | ArrayRequired | See the operation contract and implementation below. |
bpositional-or-keyword | ArrayRequired | See the operation contract and implementation below. |
cpositional-or-keyword | ArrayRequired | See the operation contract and implementation below. |
ArrayRead the implementation
def soft_majority3(a: Array, b: Array, c: Array) -> Array:
"""3-input majority ``ab + bc + ca - 2abc`` (exact on vertices)."""
return a * b + b * c + c * a - 2.0 * a * b * cOther public import paths
omnibias.boolean.jax.ops.soft_majority3omnibias.boolean.jax.ops.gates.soft_majority3
soft_nand
omnibias.boolean.jax.ops.soft_nandSource ↗soft_nand(a: Array, b: Array) -> Arraya NAND b = 1 - a*b.
Parameters
| Name | Type & default | Contract |
|---|---|---|
apositional-or-keyword | ArrayRequired | See the operation contract and implementation below. |
bpositional-or-keyword | ArrayRequired | See the operation contract and implementation below. |
ArrayExecuted regression · gates parity
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_gates_parity() -> None:
rng = random.Random(20)
for _ in range(20):
a, b = rng.random(), rng.random()
for name in ("soft_and", "soft_or", "soft_xor", "soft_nand", "soft_implies"):
tg = getattr(tb, name)
jg = getattr(jb, name)
tv = float(tg(torch.tensor(a, dtype=torch.float64), torch.tensor(b, dtype=torch.float64)))
jv = float(jg(jnp.asarray(a, dtype=jnp.float64), jnp.asarray(b, dtype=jnp.float64)))
assert tv == pytest.approx(jv, rel=1e-9, abs=1e-11)python -m pytest "packages/omnibias-boolean/tests/test_cross_backend.py::test_gates_parity" -qRead the implementation
def soft_nand(a: Array, b: Array) -> Array:
"""``a NAND b = 1 - a*b``."""
return 1.0 - a * bOther public import paths
omnibias.boolean.jax.ops.soft_nandomnibias.boolean.jax.ops.gates.soft_nand
soft_nor
omnibias.boolean.jax.ops.soft_norSource ↗soft_nor(a: Array, b: Array) -> Arraya NOR b = 1 - (a + b - a*b).
Parameters
| Name | Type & default | Contract |
|---|---|---|
apositional-or-keyword | ArrayRequired | See the operation contract and implementation below. |
bpositional-or-keyword | ArrayRequired | See the operation contract and implementation below. |
ArrayRead the implementation
def soft_nor(a: Array, b: Array) -> Array:
"""``a NOR b = 1 - (a + b - a*b)``."""
return 1.0 - (a + b - a * b)Other public import paths
omnibias.boolean.jax.ops.soft_noromnibias.boolean.jax.ops.gates.soft_nor
soft_not
omnibias.boolean.jax.ops.soft_notSource ↗soft_not(a: Array) -> ArrayNOT a = 1 - a.
Parameters
| Name | Type & default | Contract |
|---|---|---|
apositional-or-keyword | ArrayRequired | See the operation contract and implementation below. |
ArrayRead the implementation
def soft_not(a: Array) -> Array:
"""``NOT a = 1 - a``."""
return 1.0 - aOther public import paths
omnibias.boolean.jax.ops.soft_notomnibias.boolean.jax.ops.gates.soft_not
soft_or
omnibias.boolean.jax.ops.soft_orSource ↗soft_or(a: Array, b: Array) -> Arraya OR b = a + b - a*b (probabilistic sum).
Parameters
| Name | Type & default | Contract |
|---|---|---|
apositional-or-keyword | ArrayRequired | See the operation contract and implementation below. |
bpositional-or-keyword | ArrayRequired | See the operation contract and implementation below. |
ArrayExecuted regression · gates parity
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_gates_parity() -> None:
rng = random.Random(20)
for _ in range(20):
a, b = rng.random(), rng.random()
for name in ("soft_and", "soft_or", "soft_xor", "soft_nand", "soft_implies"):
tg = getattr(tb, name)
jg = getattr(jb, name)
tv = float(tg(torch.tensor(a, dtype=torch.float64), torch.tensor(b, dtype=torch.float64)))
jv = float(jg(jnp.asarray(a, dtype=jnp.float64), jnp.asarray(b, dtype=jnp.float64)))
assert tv == pytest.approx(jv, rel=1e-9, abs=1e-11)python -m pytest "packages/omnibias-boolean/tests/test_cross_backend.py::test_gates_parity" -qRead the implementation
def soft_or(a: Array, b: Array) -> Array:
"""``a OR b = a + b - a*b`` (probabilistic sum)."""
return a + b - a * bOther public import paths
omnibias.boolean.jax.ops.soft_oromnibias.boolean.jax.ops.gates.soft_or
soft_xnor
omnibias.boolean.jax.ops.soft_xnorSource ↗soft_xnor(a: Array, b: Array) -> Arraya XNOR b = 1 - (a + b - 2*a*b).
Parameters
| Name | Type & default | Contract |
|---|---|---|
apositional-or-keyword | ArrayRequired | See the operation contract and implementation below. |
bpositional-or-keyword | ArrayRequired | See the operation contract and implementation below. |
ArrayRead the implementation
def soft_xnor(a: Array, b: Array) -> Array:
"""``a XNOR b = 1 - (a + b - 2*a*b)``."""
return 1.0 - (a + b - 2.0 * a * b)Other public import paths
omnibias.boolean.jax.ops.soft_xnoromnibias.boolean.jax.ops.gates.soft_xnor
soft_xor
omnibias.boolean.jax.ops.soft_xorSource ↗soft_xor(a: Array, b: Array) -> Arraya XOR b = a + b - 2*a*b.
Parameters
| Name | Type & default | Contract |
|---|---|---|
apositional-or-keyword | ArrayRequired | See the operation contract and implementation below. |
bpositional-or-keyword | ArrayRequired | See the operation contract and implementation below. |
ArrayExecuted regression · gates parity
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_gates_parity() -> None:
rng = random.Random(20)
for _ in range(20):
a, b = rng.random(), rng.random()
for name in ("soft_and", "soft_or", "soft_xor", "soft_nand", "soft_implies"):
tg = getattr(tb, name)
jg = getattr(jb, name)
tv = float(tg(torch.tensor(a, dtype=torch.float64), torch.tensor(b, dtype=torch.float64)))
jv = float(jg(jnp.asarray(a, dtype=jnp.float64), jnp.asarray(b, dtype=jnp.float64)))
assert tv == pytest.approx(jv, rel=1e-9, abs=1e-11)python -m pytest "packages/omnibias-boolean/tests/test_cross_backend.py::test_gates_parity" -qRead the implementation
def soft_xor(a: Array, b: Array) -> Array:
"""``a XOR b = a + b - 2*a*b``."""
return a + b - 2.0 * a * bOther public import paths
omnibias.boolean.jax.ops.soft_xoromnibias.boolean.jax.ops.gates.soft_xor
threshold_and
omnibias.boolean.jax.ops.threshold_andSource ↗threshold_and(a: Array, b: Array, beta: float=10.0) -> ArrayHard a AND b (fires iff a + b >= 2); sigmoid(beta z) backward.
Parameters
| Name | Type & default | Contract |
|---|---|---|
apositional-or-keyword | ArrayRequired | See the operation contract and implementation below. |
bpositional-or-keyword | ArrayRequired | See the operation contract and implementation below. |
betapositional-or-keyword | floatDefault: 10.0 | See the operation contract and implementation below. |
ArrayRead the implementation
def threshold_and(a: Array, b: Array, beta: float = 10.0) -> Array:
"""Hard ``a AND b`` (fires iff ``a + b >= 2``); ``sigmoid(beta z)`` backward."""
return binarize01(a + b - 1.5, beta)Other public import paths
omnibias.boolean.jax.ops.threshold_andomnibias.boolean.jax.ops.gates.threshold_and
threshold_not
omnibias.boolean.jax.ops.threshold_notSource ↗threshold_not(a: Array, beta: float=10.0) -> ArrayHard NOT a (fires iff a < 0.5); sigmoid(beta z) backward.
Parameters
| Name | Type & default | Contract |
|---|---|---|
apositional-or-keyword | ArrayRequired | See the operation contract and implementation below. |
betapositional-or-keyword | floatDefault: 10.0 | See the operation contract and implementation below. |
ArrayRead the implementation
def threshold_not(a: Array, beta: float = 10.0) -> Array:
"""Hard ``NOT a`` (fires iff ``a < 0.5``); ``sigmoid(beta z)`` backward."""
return binarize01(0.5 - a, beta)Other public import paths
omnibias.boolean.jax.ops.threshold_notomnibias.boolean.jax.ops.gates.threshold_not
threshold_or
omnibias.boolean.jax.ops.threshold_orSource ↗threshold_or(a: Array, b: Array, beta: float=10.0) -> ArrayHard a OR b (fires iff a + b >= 1); sigmoid(beta z) backward.
Parameters
| Name | Type & default | Contract |
|---|---|---|
apositional-or-keyword | ArrayRequired | See the operation contract and implementation below. |
bpositional-or-keyword | ArrayRequired | See the operation contract and implementation below. |
betapositional-or-keyword | floatDefault: 10.0 | See the operation contract and implementation below. |
ArrayRead the implementation
def threshold_or(a: Array, b: Array, beta: float = 10.0) -> Array:
"""Hard ``a OR b`` (fires iff ``a + b >= 1``); ``sigmoid(beta z)`` backward."""
return binarize01(a + b - 0.5, beta)Other public import paths
omnibias.boolean.jax.ops.threshold_oromnibias.boolean.jax.ops.gates.threshold_or