Multilinear extensions¶
- class vfhe.arith.MLE(ring: RNSRing | None = None, variables: list | None = None, evaluations: FieldVector | list | None = None, coefficients: FieldVector | list | None = None, num_vars: int | None = None, field: Field | None = None)¶
A multilinear extension as a dense table of 2^n coefficients.
Two properties of the table, deliberately not subclasses, because they vary independently:
`basis` —
MLE_Basis.eval, the hypercube evaluations (passevaluations=), orMLE_Basis.coeff, the monomial coefficients (passcoefficients=, entrybmultiplying prod_{i in bits(b)} x_i, i.e. a multilinear polynomial rather than an extension table). Both bind a variable by folding (lo, hi) pairs; only the fold differs — interpolationlo + r*(hi - lo)in the evaluation basis, Hornerc_lo + r*c_hiin the monomial one.to_coefficients()converts.coefficient type — with a
ring, entries arevfhe.arith.Polynomialover thatRingand the C kernels (mle_dense_poly_*) do the work; with afield, the table is onevfhe.arith.FieldVectorover thatFieldand every fold is a handful of whole-vector operations; without either, entries are plain Python values (any type with+and*, e.g. ints) folded in Python. The kernels additionally require the evaluation basis, sonative_table()/vector_table(), notisinstance, is what protocols gate on.
Variable order is generic: any variable may be bound at any position, in any order (
evaluate)._binddispatches on the variable’s position to the layout implemented most efficiently: adjacent entries for the first (LSB) variable, the two table halves for the last (MSB) one, and stride-computed pairs for anything in between.tableholds the entries (also keeping them alive across C calls) andtable_ptris the array of their handles the kernels take (None without a ring) — the two are always views of the same entries, replaced together by_set_table. Over a field,tableis theFieldVectoritself (indexable and iterable like the list it replaces).- property num_vars: int¶
The number of free variables; derived, so it cannot go stale.
- classmethod eq(domain, point: list, variables: list | None = None) MLE¶
The multilinear equality polynomial eq~(point, .) as a dense table: table[b] = prod_i (point_i * b_i + (1 - point_i) * (1 - b_i)), the chi_w Lagrange basis of [Tha22, section 3.5].
domainis the Ring or Field of the coefficients;pointentries are its elements (or ints, lifted to constants); entry i pairs with variable i (the table’s LSB-first order).
- classmethod from_uint64(ring: RNSRing, variables: list, values: Buffer, repr: Representation = Representation.coeff) MLE¶
A table over
ringin the evaluation basis, itsn = 2^len(variables)entries read fromvaluesin representationrepr, one after another, each laid out asRNSPolynomial.from_uint64reads it: words(b * ell + i) * Nto(b * ell + i + 1) * N - 1are the row of entrybmoduloring.primes[i]. InRepresentation.coeffword(b * ell + i) * N + jis coefficientj; inRepresentation.ntta row holds theN / dslots one after another, asRNSPolynomial.to_uint64describes.valuesis anarray('Q')or any C-contiguous buffer ofn * ell * Nunsigned 64-bit integers, such as anumpy.uint64array of shape(n, ell, N). Every word must be below its row’s prime; ValueError otherwise. The entries are held inRepresentation.ntt, as every native table’s; coefficient rows are transformed in the same native call that reads them.
- to_uint64(repr: Representation = Representation.coeff) array¶
The entries’ rows in representation
repr, as onearray('Q')laid out asfrom_uint64reads it: entrybis wordsb * ell * Nto(b + 1) * ell * N - 1, asRNSPolynomial.to_uint64gives it.numpy.frombuffer(words, numpy.uint64).reshape(n, ell, N)reads it without copying. Needs a table over an RNS ring; the entries are left as they are.
- to_NTT() None¶
Put every entry in NTT (RNS) form, the representation the C kernels read; a no-op on a table of plain Python values.
The kernels read
coeffsdirectly and fold the whole table as if it were uniform, so a table holding a mix of representations would give silent garbage; this establishes their precondition instead. Cheap when the table is already normalized: each entry’sto_NTT()is then just a flag check. (Entries no longer become mixed just from being read – arith’s readers convert a copy – but a table can still be assembled from coefficient-form elements.)
- to_coefficients() MLE¶
This MLE in the monomial basis, index-aligned with the evaluation table (coefficient of prod_{i in bits(b)} x_i at position b; LSB-first variable order). Per variable the butterfly is c_hi = e_hi - e_lo, c_lo = e_lo; self is left untouched.
- classmethod linear_combination(tables: Sequence[MLE], coefficients: Sequence) MLE¶
The table
sum_i coefficients[i] * tables[i], entry by entry.The tables must share their variables, in the same order, their ring or field and their basis; the result has them too. A coefficient is an element of that ring or field, or an integer. Over a ring, tables and coefficients not in NTT form are converted in place.
- evaluate(point: dict | list, in_place: bool = True) MLE¶
Bind the variables in
pointto concrete values; variables not inpointstay free. Returns the folded MLE.
- constant()¶
The single value of a fully-evaluated (0-variable) MLE.
- digest() bytes¶
A 32-byte digest of the table: the chain of its basis, its variables in order and one digest of all its entries.
- class vfhe.arith.SparseMLE(variables: list | None = None, evaluations: dict | None = None, num_vars: int | None = None, ring: RNSRing | None = None, field: Field | None = None)¶
A sparse map of hypercube evaluations:
evaluations[index] = valuefor the nonzero entries,indexpacking the variables LSB-first like a dense table’s position. The carrier of wiring predicates and other mostly-zero tables.Independent of
MLEon purpose — it supports the linear operations (add / sub / scale) and evaluation at a full point (evaluate, the sum over the nonzeros of value times the eq~ factors, O(nnz * vars)), but none of the per-variable folding a dense table exists for: binding a variable at a time would need the dense form, so a partial point raises. Defined oracles (virtual.py) bind symbolically and only ever query a constituent at a full point, which is what makes a sparse constituent sufficient there;materialize()gives the denseMLEwhen a fold is really wanted. Values are non-negative ints or elements of the domain (ring=/field=, or plain Python values without either).- property num_vars: int¶
The number of free variables; derived, so it cannot go stale.
- nonzeros()¶
The (index, value) pairs, in insertion order.
- evaluate(point: dict | list, in_place: bool = False) SparseMLE¶
The value at a full point, as a 0-variable SparseMLE (so that
constant()reads it, like a folded dense table): sum_{k nonzero} value_k * prod_i (point_i if k_i else 1 - point_i). A partial point raises: this form has no per-variable fold.
- constant()¶
The single value of a fully-evaluated (0-variable) SparseMLE.
- restrict(fixed: dict) SparseMLE¶
The slice of this table at
fixed, a map from some of its variables to the constants 0 or 1: the sparse table over the remaining variables, in their order, whose nonzeros are the entries of this one whose bits at the fixed variables equal the constants. One pass over the nonzeros. A slice, not a partial evaluation: a constant outside {0, 1}, or a variable not of this table, raises.
- digest() bytes¶
A 32-byte digest of the table: its variables and its nonzero entries in index order (not insertion order).
- class vfhe.arith.MLE_Basis(*values)¶
- class vfhe.arith.MLE_Variable(name: str)¶
A named variable identifier for MLEs, compared by identity.
Any hashable works as an MLE variable; this class is the default used when only
num_varsis given. It is a plain name, unrelated to any protocol-level variable a consumer may also callVariable.- digest() bytes¶
A 32-byte digest of the variable, by its name.