binius_math/
error.rs

1// Copyright 2024-2025 Irreducible Inc.
2
3use std::ops::Range;
4
5#[derive(Debug, thiserror::Error)]
6pub enum Error {
7	#[error("argument {arg} does not have expected length {expected}")]
8	IncorrectArgumentLength { arg: String, expected: usize },
9	#[error("the matrix is not square")]
10	MatrixNotSquare,
11	#[error("the matrix is singular")]
12	MatrixIsSingular,
13	#[error("domain size is larger than the field")]
14	DomainSizeTooLarge,
15	#[error("the inputted packed values slice had an unexpected length")]
16	InvalidPackedValuesLength,
17	#[error("remap index identifier not found in superset")]
18	RemapIdentifierNotFound,
19	#[error("duplicate point in domain")]
20	DuplicateDomainPoint,
21	#[error("expected the number of evaluations to match the domain size")]
22	ExtrapolateNumberOfEvaluations,
23	#[error("{0}")]
24	FieldError(#[from] binius_field::Error),
25	#[error(
26		"batch evaluation expects input slices to have the same length as the output slice;
27		expected length {expected}, got length {actual}"
28	)]
29	BatchEvaluateSizeMismatch { expected: usize, actual: usize },
30	#[error("the query must have size {expected}")]
31	IncorrectQuerySize { expected: usize },
32	#[error("the nonzero scalar prefix should be at most {expected}")]
33	IncorrectNonzeroScalarPrefix { expected: usize },
34	#[error("Polynomial error: {0}")]
35	PolynomialError(Box<dyn std::error::Error + Send + Sync>),
36	#[error("MultilinearQuery is full, cannot update further. Has {max_query_vars} variables")]
37	MultilinearQueryFull { max_query_vars: usize },
38	#[error("argument length must be a power of two")]
39	PowerOfTwoLengthRequired,
40	#[error("argument {arg} must be in the range {range:?}")]
41	ArgumentRangeError { arg: String, range: Range<usize> },
42	#[error("logarithm of embedding degree of {log_embedding_degree} is too large.")]
43	LogEmbeddingDegreeTooLarge { log_embedding_degree: usize },
44	#[error("the polynomial is expected to have {expected} variables, and instead has {actual}")]
45	IncorrectNumberOfVariables { expected: usize, actual: usize },
46	#[error("indexed point on hypercube is out of range: index={index}")]
47	HypercubeIndexOutOfRange { index: usize },
48	#[error("the output polynomial must have size {expected}")]
49	IncorrectOutputPolynomialSize { expected: usize },
50	#[error("the total number of coefficients, {total_length}, in the piecewise multilinear is too large: {total_length} > 2^{total_n_vars}")]
51	PiecewiseMultilinearTooLong {
52		total_length: usize,
53		total_n_vars: usize,
54	},
55	#[error("there are a total of {actual} polynomials, according to n_pieces_by_vars, while you have provided evaluations for {expected}")]
56	PiecewiseMultilinearIncompatibleEvals { actual: usize, expected: usize },
57	#[error("cannot fold a constant multilinear")]
58	ConstantFold,
59	#[error("the function expects the expression to have degree at most 1")]
60	NonLinearExpression,
61}