Skip to main content

omnibias.boolean.torch.ops.spectrum

0.1.0a2AlphaPython >=3.10Apache-2.0

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

import omnibias.boolean.torch.ops.spectrum
Module contract & mathematical conventions

Differentiable Boolean spectrum engine (torch) via multivariate jets.

The whole Boolean spectrum is read off the *mixed partial derivatives* of the multilinear extension. For cube values v the extension F is built as a multivariate jet at a base point with omnibias.torch.jet_mv.identity_jet and the truncated Cauchy product (omnibias.core.multi_index.multiply_table), and then omnibias.torch.jet_mv.jet_partials returns every coefficient at once:

  • the {0,1} **Mobius** coefficient m_S = d^{|S|} F / prod_{i in S} d x_i at x = 0 (its reduction mod 2 is the GF(2) ANF), and
  • the {+-1} **Walsh/Fourier** coefficient hat f(S) from the same machinery in the chi = 1 - 2x basis.

Everything is differentiable in v (the transform is linear), so these feed the design losses. The exact omnibias.boolean._core transforms are the ground truth the tests check against.

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

algebraic_degree_soft​

omnibias.boolean.torch.ops.algebraic_degree_softSource ↗
algebraic_degree_soft(values: Sequence[float] | Tensor) -> Tensor

Spectral-energy-weighted mean monomial order (a smooth degree proxy).

sum_S |S| hat f(S)^2 / sum_S hat f(S)^2. This is a differentiable surrogate for the integer algebraic degree, not the exact value; the exact degree is omnibias.boolean._core.algebraic_degree.

Parameters

NameType & defaultContract
valuespositional-or-keywordSequence[float] | TensorRequiredSee the operation contract and implementation below.
ReturnsTensor
Executed regression · degree soft of 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_degree_soft_of_parity() -> None:
    # 2-bit XOR is pure order-2 in the Walsh basis -> soft degree == 2.
    xor = (0, 1, 1, 0)
    vals = torch.tensor(pm1_values(xor), dtype=torch.float64)
    assert float(spectrum.algebraic_degree_soft(vals)) == pytest.approx(2.0, abs=1e-9)
python -m pytest "packages/omnibias-boolean/tests/test_spectrum.py::test_degree_soft_of_parity" -q
Read the implementation
def algebraic_degree_soft(values: Sequence[float] | Tensor) -> Tensor:
    """Spectral-energy-weighted mean monomial order (a smooth degree proxy).

    ``sum_S |S| hat f(S)^2 / sum_S hat f(S)^2``. This is a differentiable surrogate
    for the integer algebraic degree, not the exact value; the exact degree is
    :func:`omnibias.boolean._core.algebraic_degree`.
    """
    w = walsh_coeffs(values)
    n = _num_vars(w.shape[0])
    orders = torch.tensor(
        [bin(mask).count("1") for mask in range(1 << n)],
        dtype=w.dtype,
        device=w.device,
    )
    energy = (w**2).sum()
    return (orders * w**2).sum() / energy
Other public import paths
  • omnibias.boolean.torch.ops.algebraic_degree_soft
  • omnibias.boolean.torch.ops.spectrum.algebraic_degree_soft
FUNCTION

influences_diff​

omnibias.boolean.torch.ops.influences_diffSource ↗
influences_diff(values: Sequence[float] | Tensor) -> Tensor

Per-coordinate influence Inf_i = sum_{S in i} hat f(S)^2 (differentiable).

Pass {+-1} output values; equals the exact _core influences for a Boolean function.

Parameters

NameType & defaultContract
valuespositional-or-keywordSequence[float] | TensorRequiredSee the operation contract and implementation below.
ReturnsTensor
Executed regression · influence penalty is differentiable

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_influence_penalty_is_differentiable() -> None:
    vals = torch.rand(8, dtype=torch.float64, requires_grad=True)
    design.influence_penalty(vals).backward()
    assert vals.grad is not None
python -m pytest "packages/omnibias-boolean/tests/test_design.py::test_influence_penalty_is_differentiable" -q
Regression example · influences match core

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_influences_match_core() -> None:
    for tt in _tts(13):
        vals = torch.tensor(pm1_values(tt), dtype=torch.float64)
        got = spectrum.influences_diff(vals).detach().numpy()
        want = np.array(_walsh.influences(tt), dtype=np.float64)
        assert np.allclose(got, want, rtol=1e-9, atol=1e-9)
python -m pytest packages/omnibias-boolean/tests/test_spectrum.py -k test_influences_match_core -q
Read the implementation
def influences_diff(values: Sequence[float] | Tensor) -> Tensor:
    """Per-coordinate influence ``Inf_i = sum_{S in i} hat f(S)^2`` (differentiable).

    Pass ``{+-1}`` output values; equals the exact ``_core`` influences for a
    Boolean function.
    """
    w = walsh_coeffs(values)
    n = _num_vars(w.shape[0])
    out = []
    for i in range(n):
        idx = [mask for mask in range(1 << n) if (mask >> i) & 1]
        out.append((w[idx] ** 2).sum())
    return torch.stack(out)
Other public import paths
  • omnibias.boolean.torch.ops.influences_diff
  • omnibias.boolean.torch.ops.spectrum.influences_diff
FUNCTION

mobius_coeffs​

omnibias.boolean.torch.ops.mobius_coeffsSource ↗
mobius_coeffs(values: Sequence[float] | Tensor) -> Tensor

{0,1} Mobius / multilinear coefficients m_S (indexed by subset mask).

Parameters

NameType & defaultContract
valuespositional-or-keywordSequence[float] | TensorRequiredSee the operation contract and implementation below.
ReturnsTensor
Executed regression · spectrum is differentiable

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_spectrum_is_differentiable() -> None:
    vals = torch.rand(8, dtype=torch.float64, requires_grad=True)
    spectrum.mobius_coeffs(vals).pow(2).sum().backward()
    assert vals.grad is not None
python -m pytest "packages/omnibias-boolean/tests/test_spectrum.py::test_spectrum_is_differentiable" -q
Regression example · mobius parity

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_mobius_parity() -> None:
    for tt in _tts(21):
        t = _np(tb.mobius_coeffs(torch.tensor(tt, dtype=torch.float64)))
        j = _np(jb.mobius_coeffs(jnp.asarray(tt, dtype=jnp.float64)))
        assert np.allclose(t, j, rtol=1e-9, atol=1e-11)
python -m pytest packages/omnibias-boolean/tests/test_cross_backend.py -k test_mobius_parity -q
Read the implementation
def mobius_coeffs(values: Sequence[float] | Tensor) -> Tensor:
    """``{0,1}`` Mobius / multilinear coefficients ``m_S`` (indexed by subset mask)."""
    return _coeffs_vector(_as_tensor(values), "mobius")
Other public import paths
  • omnibias.boolean.torch.ops.mobius_coeffs
  • omnibias.boolean.torch.ops.spectrum.mobius_coeffs
FUNCTION

mobius_spectrum​

omnibias.boolean.torch.ops.mobius_spectrumSource ↗
mobius_spectrum(values: Sequence[float] | Tensor) -> dict[frozenset[int], Tensor]

Mobius coefficients as a {variable-set: m_S} mapping.

Parameters

NameType & defaultContract
valuespositional-or-keywordSequence[float] | TensorRequiredSee the operation contract and implementation below.
Returnsdict[frozenset[int], Tensor]
Read the implementation
def mobius_spectrum(values: Sequence[float] | Tensor) -> dict[frozenset[int], Tensor]:
    """Mobius coefficients as a ``{variable-set: m_S}`` mapping."""
    return _to_spectrum(mobius_coeffs(values))
Other public import paths
  • omnibias.boolean.torch.ops.mobius_spectrum
  • omnibias.boolean.torch.ops.spectrum.mobius_spectrum
FUNCTION

walsh_coeffs​

omnibias.boolean.torch.ops.walsh_coeffsSource ↗
walsh_coeffs(values: Sequence[float] | Tensor) -> Tensor

{+-1} Walsh / Fourier coefficients hat f(S) (indexed by subset mask).

Pass the {+-1} *output* values (e.g. 1 - 2*tt) to match the usual Fourier normalization.

Parameters

NameType & defaultContract
valuespositional-or-keywordSequence[float] | TensorRequiredSee the operation contract and implementation below.
ReturnsTensor
Executed regression · influence penalty is differentiable

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_influence_penalty_is_differentiable() -> None:
    vals = torch.rand(8, dtype=torch.float64, requires_grad=True)
    design.influence_penalty(vals).backward()
    assert vals.grad is not None
python -m pytest "packages/omnibias-boolean/tests/test_design.py::test_influence_penalty_is_differentiable" -q
Regression example · walsh coeffs match core

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_walsh_coeffs_match_core() -> None:
    for tt in _tts(12):
        vals = torch.tensor(pm1_values(tt), dtype=torch.float64)
        got = spectrum.walsh_coeffs(vals).detach().numpy()
        want = np.array(_walsh.fourier_coeffs(tt, "pm1"), dtype=np.float64)
        assert np.allclose(got, want, rtol=1e-9, atol=1e-9)
python -m pytest packages/omnibias-boolean/tests/test_spectrum.py -k test_walsh_coeffs_match_core -q
Read the implementation
def walsh_coeffs(values: Sequence[float] | Tensor) -> Tensor:
    """``{+-1}`` Walsh / Fourier coefficients ``hat f(S)`` (indexed by subset mask).

    Pass the ``{+-1}`` *output* values (e.g. ``1 - 2*tt``) to match the usual
    Fourier normalization.
    """
    return _coeffs_vector(_as_tensor(values), "walsh")
Other public import paths
  • omnibias.boolean.torch.ops.walsh_coeffs
  • omnibias.boolean.torch.ops.spectrum.walsh_coeffs
FUNCTION

walsh_spectrum​

omnibias.boolean.torch.ops.walsh_spectrumSource ↗
walsh_spectrum(values: Sequence[float] | Tensor) -> dict[frozenset[int], Tensor]

Walsh/Fourier coefficients as a {variable-set: hat f(S)} mapping.

Parameters

NameType & defaultContract
valuespositional-or-keywordSequence[float] | TensorRequiredSee the operation contract and implementation below.
Returnsdict[frozenset[int], Tensor]
Read the implementation
def walsh_spectrum(values: Sequence[float] | Tensor) -> dict[frozenset[int], Tensor]:
    """Walsh/Fourier coefficients as a ``{variable-set: hat f(S)}`` mapping."""
    return _to_spectrum(walsh_coeffs(values))
Other public import paths
  • omnibias.boolean.torch.ops.walsh_spectrum
  • omnibias.boolean.torch.ops.spectrum.walsh_spectrum