API reference

Alternative basis arrays

Construct and convert Newton, first-kind Chebyshev, and Bernstein representations. Coefficient extent and basis metadata are retained.

Every computational call accepts a shared Budget or max_steps=. See the tutorial for examples, domain restrictions, and the meaning of retained metadata.

Save and restore these values with poly.io.

Array

@fieldwise_init
struct Array[k: Int](Copyable, Movable, Iterable, Sized, _WithModulus, _Record)

Immutable basis coefficients with retained representation metadata.

Parameters.

  • k: The inferred exact field: QQ, QQi, GF(p), AA, or QQbar.

Defined in src/poly/basis.mojo.

Array.IteratorType

comptime IteratorType[iterable_mut: Bool, //, iterable_origin: Origin[mut=iterable_mut]]: Iterator = _BasisIterator[Self.k, ImmOrigin(iterable_origin)]

A borrowing coefficient iterator.

Parameters.

  • iterable_mut: Whether the source origin permits mutation.
  • iterable_origin: The lifetime of the source.

Array.modulus

def modulus(self) -> UInt64

Return the retained prime, or zero for QQ and QQi.

Returns. The prime modulus or zero.

Array.domain

def domain(self) -> String

Return the retained coefficient field.

Returns. QQ, QQi, or GF(p).

Array.basis

def basis(self) -> String

Return the name of the retained basis.

Returns. The name newton, chebyshev, or bernstein.

asarray

def asarray[I: Iterable, N: Iterable](values: I, mut budget: Budget, *, basis: String, nodes: N) raises PolyError -> Array[_FieldKind[_Join[_Kind[_Element[I]], _Kind[_Element[N]]]]]

Interpret the supplied values as basis coefficients, preserving every trailing zero.

Parameters.

  • I: The coefficient iterable type.
  • N: The node iterable type.

Arguments.

  • values: Ascending coefficients in the named basis.
  • budget: The shared work allowance, including preparation and result storage.
  • basis: The name newton, chebyshev, or bernstein.
  • nodes: Newton nodes; empty for other bases.

Returns. An immutable basis representation; integer inputs promote to QQ.

Raises.

  • PolyError: DOMAIN for incompatible inputs or unavailable divisions, LIMIT for exhausted work, or CAPACITY for unrepresentable storage.

Defined in src/poly/basis.mojo.

from_polynomial

def from_polynomial[I: Iterable, N: Iterable](values: I, mut budget: Budget, *, basis: String, nodes: N, degree: Int = -1) raises PolyError -> Array[_FieldKind[_Join[_Kind[_Element[I]], _Kind[_Element[N]]]]]

Convert ascending monomial coefficients to the requested basis.

Parameters.

  • I: The coefficient iterable type.
  • N: The node iterable type.

Arguments.

  • values: Ascending monomial coefficients.
  • budget: The shared work allowance, including preparation and result storage.
  • basis: The name newton, chebyshev, or bernstein.
  • nodes: Newton nodes; empty for other bases.
  • degree: The retained Bernstein degree; -1 chooses the polynomial degree, at least zero.

Returns. An immutable basis representation; integer inputs promote to QQ.

Raises.

  • PolyError: DOMAIN for incompatible inputs or unavailable divisions, LIMIT for exhausted work, or CAPACITY for unrepresentable storage.

Defined in src/poly/basis.mojo.

to_polynomial

def to_polynomial[k: Int](values: Array[k], mut budget: Budget) raises PolyError -> dense.Array[k]

Expand a basis representation into ascending monomial coefficients.

Parameters.

  • k: The inferred coefficient field.

Arguments.

  • values: The prepared basis coefficients.
  • budget: The shared work allowance, including preparation and result storage.

Returns. A canonical dense polynomial in the same field.

Raises.

  • PolyError: DOMAIN for incompatible inputs or unavailable divisions, LIMIT for exhausted work, or CAPACITY for unrepresentable storage.

Defined in src/poly/basis.mojo.

coefficients

def coefficients[k: Int](values: Array[k], mut budget: Budget) raises PolyError -> Values[_Scalar[k], k]

Copy the retained coefficients without dropping trailing zeros.

Parameters.

  • k: The inferred coefficient field.

Arguments.

  • values: The prepared basis representation.
  • budget: The shared work allowance, including preparation and result storage.

Returns. An immutable sequence retaining its field metadata.

Raises.

  • PolyError: DOMAIN for incompatible inputs or unavailable divisions, LIMIT for exhausted work, or CAPACITY for unrepresentable storage.

Defined in src/poly/basis.mojo.

nodes

def nodes[k: Int](values: Array[k], mut budget: Budget) raises PolyError -> Values[_Scalar[k], k]

Copy the retained nodes without dropping trailing zeros.

Parameters.

  • k: The inferred coefficient field.

Arguments.

  • values: The prepared basis representation.
  • budget: The shared work allowance, including preparation and result storage.

Returns. An immutable sequence retaining its field metadata.

Raises.

  • PolyError: DOMAIN for incompatible inputs or unavailable divisions, LIMIT for exhausted work, or CAPACITY for unrepresentable storage.

Defined in src/poly/basis.mojo.

evaluate

def evaluate[k: Int, T: Copyable & Deinitable](values: Array[k], point: T, mut budget: Budget) raises PolyError -> _Scalar[_Join[k, _Kind[T]]]

Evaluate directly in the retained basis, promoting the point and coefficients together.

Parameters.

  • k: The inferred coefficient field.
  • T: The exact point type.

Arguments.

  • values: The prepared basis representation.
  • point: An exact scalar in a compatible domain.
  • budget: The shared work allowance, including preparation and result storage.

Returns. The exact value from nested Newton, Clenshaw, or de Casteljau evaluation.

Raises.

  • PolyError: DOMAIN for incompatible inputs or unavailable divisions, LIMIT for exhausted work, or CAPACITY for unrepresentable storage.

Defined in src/poly/basis.mojo.

subdivide

def subdivide[k: Int, T: Copyable & Deinitable](values: Array[k], point: T, mut budget: Budget) raises PolyError -> Tuple[Array[_Join[k, _Kind[T]]], Array[_Join[k, _Kind[T]]]]

Subdivide a Bernstein representation at an exact parameter.

Parameters.

  • k: The inferred coefficient field.
  • T: The exact parameter type.

Arguments.

  • values: Bernstein coefficients.
  • point: The split parameter; values outside [0,1] give affine extrapolations.
  • budget: The shared work allowance, including preparation and result storage.

Returns. Representations of p(pointx) and p(point+(1-point)x), retaining degree.

Raises.

  • PolyError: DOMAIN for incompatible inputs or unavailable divisions, LIMIT for exhausted work, or CAPACITY for unrepresentable storage.

Defined in src/poly/basis.mojo.

add

def add[ka: Int, kb: Int](a: Array[ka], b: Array[kb], mut budget: Budget) raises PolyError -> Array[_Join[ka, kb]]

Add representations of the same basis kind. The result retains the left Newton nodes.

Parameters.

  • ka: The left coefficient field.
  • kb: The right coefficient field.

Arguments.

  • a: The left basis representation.
  • b: The right representation with a compatible field and matching basis kind.
  • budget: The shared work allowance, including preparation and result storage.

Returns. A new basis array; insufficient retained Newton nodes raise DOMAIN.

Raises.

  • PolyError: DOMAIN for incompatible inputs or unavailable divisions, LIMIT for exhausted work, or CAPACITY for unrepresentable storage.

Defined in src/poly/basis.mojo.

subtract

def subtract[ka: Int, kb: Int](a: Array[ka], b: Array[kb], mut budget: Budget) raises PolyError -> Array[_Join[ka, kb]]

Subtract representations of the same basis kind. The result retains the left Newton nodes.

Parameters.

  • ka: The left coefficient field.
  • kb: The right coefficient field.

Arguments.

  • a: The left basis representation.
  • b: The right representation with a compatible field and matching basis kind.
  • budget: The shared work allowance, including preparation and result storage.

Returns. A new basis array; insufficient retained Newton nodes raise DOMAIN.

Raises.

  • PolyError: DOMAIN for incompatible inputs or unavailable divisions, LIMIT for exhausted work, or CAPACITY for unrepresentable storage.

Defined in src/poly/basis.mojo.

multiply

def multiply[ka: Int, kb: Int](a: Array[ka], b: Array[kb], mut budget: Budget) raises PolyError -> Array[_Join[ka, kb]]

Multiply representations of the same basis kind. The result retains the left Newton nodes.

Parameters.

  • ka: The left coefficient field.
  • kb: The right coefficient field.

Arguments.

  • a: The left basis representation.
  • b: The right representation with a compatible field and matching basis kind.
  • budget: The shared work allowance, including preparation and result storage.

Returns. A new basis array; insufficient retained Newton nodes raise DOMAIN.

Raises.

  • PolyError: DOMAIN for incompatible inputs or unavailable divisions, LIMIT for exhausted work, or CAPACITY for unrepresentable storage.

Defined in src/poly/basis.mojo.

negative

def negative[k: Int](values: Array[k], mut budget: Budget) raises PolyError -> Array[k]

Negate the represented polynomial and return coefficients in the same basis.

Parameters.

  • k: The inferred coefficient field.

Arguments.

  • values: The basis representation; integration uses a zero constant.
  • budget: The shared work allowance, including preparation and result storage.

Returns. A new representation; Newton nodes are retained and must cover the resulting degree.

Raises.

  • PolyError: DOMAIN for incompatible inputs or unavailable divisions, LIMIT for exhausted work, or CAPACITY for unrepresentable storage.

Defined in src/poly/basis.mojo.

derivative

def derivative[k: Int](values: Array[k], mut budget: Budget) raises PolyError -> Array[k]

Differentiate the represented polynomial and return coefficients in the same basis.

Parameters.

  • k: The inferred coefficient field.

Arguments.

  • values: The basis representation; integration uses a zero constant.
  • budget: The shared work allowance, including preparation and result storage.

Returns. A new representation; Newton nodes are retained and must cover the resulting degree.

Raises.

  • PolyError: DOMAIN for incompatible inputs or unavailable divisions, LIMIT for exhausted work, or CAPACITY for unrepresentable storage.

Defined in src/poly/basis.mojo.

integral

def integral[k: Int](values: Array[k], mut budget: Budget) raises PolyError -> Array[k]

Integrate the represented polynomial and return coefficients in the same basis.

Parameters.

  • k: The inferred coefficient field.

Arguments.

  • values: The basis representation; integration uses a zero constant.
  • budget: The shared work allowance, including preparation and result storage.

Returns. A new representation; Newton nodes are retained and must cover the resulting degree.

Raises.

  • PolyError: DOMAIN for incompatible inputs or unavailable divisions, LIMIT for exhausted work, or CAPACITY for unrepresentable storage.

Defined in src/poly/basis.mojo.

to_core

def to_core[k: Int](values: Array[k], mut budget: Budget, *, variable: Int64 = 0) raises PolyError -> BasisPolynomial[_Field[k]]

Export independent mutable core coefficients and nodes.

Parameters.

  • k: The inferred coefficient field.

Arguments.

  • values: The prepared representation.
  • budget: The shared work allowance, including preparation and result storage.
  • variable: The core variable ID assigned to the exported value.

Returns. An independent core basis representation.

Raises.

  • PolyError: DOMAIN for incompatible inputs or unavailable divisions, LIMIT for exhausted work, or CAPACITY for unrepresentable storage.

Defined in src/poly/basis.mojo.

from_core

def from_core[C: CoefficientField](values: BasisPolynomial[C], mut budget: Budget) raises PolyError -> Array[_CoreKind[C]]

Validate and copy a core basis representation, preserving coefficient extent.

Parameters.

  • C: The inferred supported exact coefficient field.

Arguments.

  • values: A mutable core basis representation.
  • budget: The shared work allowance, including preparation and result storage.

Returns. An independent representation using array axis zero.

Raises.

  • PolyError: DOMAIN for incompatible inputs or unavailable divisions, LIMIT for exhausted work, or CAPACITY for unrepresentable storage.

Defined in src/poly/basis.mojo.

Numerical construction uses context=; arithmetic keeps precision explicit on every call. See the numerical tutorial.

NumericArray

@fieldwise_init
struct NumericArray[D: NumericDomain](Copyable, Movable, Iterable, Sized, _Record)

Immutable numerical coefficients in a Newton, Chebyshev, or Bernstein basis.

Parameters.

  • D: The numerical coefficient domain.

Defined in src/poly/basis.mojo.

NumericArray.IteratorType

comptime IteratorType[iterable_mut: Bool, //, iterable_origin: Origin[mut=iterable_mut]]: Iterator = _NumericIterator[Self.D, ImmOrigin(iterable_origin)]

Borrow the representation's complete coefficient sequence.

Parameters.

  • iterable_mut: Whether the borrowing origin is mutable.
  • iterable_origin: The source origin.

NumericArray.basis

def basis(self) -> String

Return the retained basis name.

Returns. Newton, Chebyshev, or Bernstein in lowercase.