Skip to main content

omnibias.boolean.jax.ops.gates

0.1.0a2AlphaPython >=3.10Apache-2.0

Boolean truth tables, multilinear extensions, algebraic spectra, and finite-temperature gate systems.

import omnibias.boolean.jax.ops.gates
Module 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.

FUNCTION

linear_threshold​

omnibias.boolean.jax.ops.linear_thresholdSource ↗
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.

Parameters

NameType & defaultContract
inputspositional-or-keywordSequence[Array]RequiredSee the operation contract and implementation below.
weightspositional-or-keywordSequence[float]RequiredSee the operation contract and implementation below.
biaspositional-or-keywordfloatRequiredSee the operation contract and implementation below.
betapositional-or-keywordfloatDefault: 10.0See the operation contract and implementation below.
ReturnsArray
Explicit validation & failure cases
  • When len(inputs) != len(weights), raises ValueError('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_threshold
  • omnibias.boolean.jax.ops.gates.linear_threshold
FUNCTION

soft_and​

omnibias.boolean.jax.ops.soft_andSource ↗
soft_and(a: Array, b: Array) -> Array

a AND b = a * b (product t-norm).

Parameters

NameType & defaultContract
apositional-or-keywordArrayRequiredSee the operation contract and implementation below.
bpositional-or-keywordArrayRequiredSee the operation contract and implementation below.
ReturnsArray
Executed 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" -q
Read the implementation
def soft_and(a: Array, b: Array) -> Array:
    """``a AND b = a * b`` (product t-norm)."""
    return a * b
Other public import paths
  • omnibias.boolean.jax.ops.soft_and
  • omnibias.boolean.jax.ops.gates.soft_and
FUNCTION

soft_implies​

omnibias.boolean.jax.ops.soft_impliesSource ↗
soft_implies(a: Array, b: Array) -> Array

a -> b = 1 - a + a*b.

Parameters

NameType & defaultContract
apositional-or-keywordArrayRequiredSee the operation contract and implementation below.
bpositional-or-keywordArrayRequiredSee the operation contract and implementation below.
ReturnsArray
Executed 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" -q
Read the implementation
def soft_implies(a: Array, b: Array) -> Array:
    """``a -> b = 1 - a + a*b``."""
    return 1.0 - a + a * b
Other public import paths
  • omnibias.boolean.jax.ops.soft_implies
  • omnibias.boolean.jax.ops.gates.soft_implies
FUNCTION

soft_majority3​

omnibias.boolean.jax.ops.soft_majority3Source ↗
soft_majority3(a: Array, b: Array, c: Array) -> Array

3-input majority ab + bc + ca - 2abc (exact on vertices).

Parameters

NameType & defaultContract
apositional-or-keywordArrayRequiredSee the operation contract and implementation below.
bpositional-or-keywordArrayRequiredSee the operation contract and implementation below.
cpositional-or-keywordArrayRequiredSee the operation contract and implementation below.
ReturnsArray
Read 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 * c
Other public import paths
  • omnibias.boolean.jax.ops.soft_majority3
  • omnibias.boolean.jax.ops.gates.soft_majority3
FUNCTION

soft_nand​

omnibias.boolean.jax.ops.soft_nandSource ↗
soft_nand(a: Array, b: Array) -> Array

a NAND b = 1 - a*b.

Parameters

NameType & defaultContract
apositional-or-keywordArrayRequiredSee the operation contract and implementation below.
bpositional-or-keywordArrayRequiredSee the operation contract and implementation below.
ReturnsArray
Executed 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" -q
Read the implementation
def soft_nand(a: Array, b: Array) -> Array:
    """``a NAND b = 1 - a*b``."""
    return 1.0 - a * b
Other public import paths
  • omnibias.boolean.jax.ops.soft_nand
  • omnibias.boolean.jax.ops.gates.soft_nand
FUNCTION

soft_nor​

omnibias.boolean.jax.ops.soft_norSource ↗
soft_nor(a: Array, b: Array) -> Array

a NOR b = 1 - (a + b - a*b).

Parameters

NameType & defaultContract
apositional-or-keywordArrayRequiredSee the operation contract and implementation below.
bpositional-or-keywordArrayRequiredSee the operation contract and implementation below.
ReturnsArray
Read 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_nor
  • omnibias.boolean.jax.ops.gates.soft_nor
FUNCTION

soft_not​

omnibias.boolean.jax.ops.soft_notSource ↗
soft_not(a: Array) -> Array

NOT a = 1 - a.

Parameters

NameType & defaultContract
apositional-or-keywordArrayRequiredSee the operation contract and implementation below.
ReturnsArray
Read the implementation
def soft_not(a: Array) -> Array:
    """``NOT a = 1 - a``."""
    return 1.0 - a
Other public import paths
  • omnibias.boolean.jax.ops.soft_not
  • omnibias.boolean.jax.ops.gates.soft_not
FUNCTION

soft_or​

omnibias.boolean.jax.ops.soft_orSource ↗
soft_or(a: Array, b: Array) -> Array

a OR b = a + b - a*b (probabilistic sum).

Parameters

NameType & defaultContract
apositional-or-keywordArrayRequiredSee the operation contract and implementation below.
bpositional-or-keywordArrayRequiredSee the operation contract and implementation below.
ReturnsArray
Executed 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" -q
Read the implementation
def soft_or(a: Array, b: Array) -> Array:
    """``a OR b = a + b - a*b`` (probabilistic sum)."""
    return a + b - a * b
Other public import paths
  • omnibias.boolean.jax.ops.soft_or
  • omnibias.boolean.jax.ops.gates.soft_or
FUNCTION

soft_xnor​

omnibias.boolean.jax.ops.soft_xnorSource ↗
soft_xnor(a: Array, b: Array) -> Array

a XNOR b = 1 - (a + b - 2*a*b).

Parameters

NameType & defaultContract
apositional-or-keywordArrayRequiredSee the operation contract and implementation below.
bpositional-or-keywordArrayRequiredSee the operation contract and implementation below.
ReturnsArray
Read 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_xnor
  • omnibias.boolean.jax.ops.gates.soft_xnor
FUNCTION

soft_xor​

omnibias.boolean.jax.ops.soft_xorSource ↗
soft_xor(a: Array, b: Array) -> Array

a XOR b = a + b - 2*a*b.

Parameters

NameType & defaultContract
apositional-or-keywordArrayRequiredSee the operation contract and implementation below.
bpositional-or-keywordArrayRequiredSee the operation contract and implementation below.
ReturnsArray
Executed 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" -q
Read the implementation
def soft_xor(a: Array, b: Array) -> Array:
    """``a XOR b = a + b - 2*a*b``."""
    return a + b - 2.0 * a * b
Other public import paths
  • omnibias.boolean.jax.ops.soft_xor
  • omnibias.boolean.jax.ops.gates.soft_xor
FUNCTION

threshold_and​

omnibias.boolean.jax.ops.threshold_andSource ↗
threshold_and(a: Array, b: Array, beta: float=10.0) -> Array

Hard a AND b (fires iff a + b >= 2); sigmoid(beta z) backward.

Parameters

NameType & defaultContract
apositional-or-keywordArrayRequiredSee the operation contract and implementation below.
bpositional-or-keywordArrayRequiredSee the operation contract and implementation below.
betapositional-or-keywordfloatDefault: 10.0See the operation contract and implementation below.
ReturnsArray
Read 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_and
  • omnibias.boolean.jax.ops.gates.threshold_and
FUNCTION

threshold_not​

omnibias.boolean.jax.ops.threshold_notSource ↗
threshold_not(a: Array, beta: float=10.0) -> Array

Hard NOT a (fires iff a < 0.5); sigmoid(beta z) backward.

Parameters

NameType & defaultContract
apositional-or-keywordArrayRequiredSee the operation contract and implementation below.
betapositional-or-keywordfloatDefault: 10.0See the operation contract and implementation below.
ReturnsArray
Read 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_not
  • omnibias.boolean.jax.ops.gates.threshold_not
FUNCTION

threshold_or​

omnibias.boolean.jax.ops.threshold_orSource ↗
threshold_or(a: Array, b: Array, beta: float=10.0) -> Array

Hard a OR b (fires iff a + b >= 1); sigmoid(beta z) backward.

Parameters

NameType & defaultContract
apositional-or-keywordArrayRequiredSee the operation contract and implementation below.
bpositional-or-keywordArrayRequiredSee the operation contract and implementation below.
betapositional-or-keywordfloatDefault: 10.0See the operation contract and implementation below.
ReturnsArray
Read 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_or
  • omnibias.boolean.jax.ops.gates.threshold_or