MCPcopy Create free account
hub / github.com/ElementsProject/elements / poly_tracemod

Function poly_tracemod

src/minisketch/tests/pyminisketch.py:238–251  ·  view source on GitHub ↗

Compute y + y^2 + y^4 + ... + y^(2^(field_size-1)) mod poly, where y = param*x.

(poly, param, gf)

Source from the content-addressed store, hash-verified

236 return [0 if i & 1 else gf.sqr(poly[i // 2]) for i in range(2 * len(poly) - 1)]
237
238def poly_tracemod(poly, param, gf):
239 """Compute y + y^2 + y^4 + ... + y^(2^(field_size-1)) mod poly, where y = param*x."""
240 out = [0, param]
241 for _ in range(gf.field_size - 1):
242 # In each loop iteration i, we start with out = y + y^2 + ... + y^(2^i). By squaring that we
243 # transform it into out = y^2 + y^4 + ... + y^(2^(i+1)).
244 out = poly_sqr(out, gf)
245 # Thus, we just need to add y again to it to get out = y + ... + y^(2^(i+1)).
246 while len(out) < 2:
247 out.append(0)
248 out[1] = param
249 # Finally take a modulus to keep the intermediary polynomials small.
250 _, out = poly_divmod(out, poly, gf)
251 return out
252
253def poly_frobeniusmod(poly, gf):
254 """Compute x^(2^field_size) mod poly."""

Callers 1

rec_splitFunction · 0.85

Calls 2

poly_sqrFunction · 0.85
poly_divmodFunction · 0.85

Tested by

no test coverage detected