Published October 18, 2026
Polynomials
A polynomial is a mathematical expression consisting of indeterminates (also called variables) and coefficients, that involves only the operators of addition, subtraction, multiplication and exponentiation to unsigned integer powers and has a finite number of terms. For the polynomial $x^2 - 9x + 6$ we have a single indeterminate $x$ and 3 coefficients for each power of x, $\lbrace 6, -9, 1 \rbrace$. We can have multiple indeterminates, like the polynomial $x^3 - yz + 1$ where we have 3, namely $x$, $y$ and $z$.
For the purpose of this tutorial we will work with polynomials with a single indeterminate and integer coefficients.
A polynomial in a single indeterminate $x$ can always be written in the form $$ a_nx^n + a_{n-1}x^{n-1} + \cdots + a_2x^2 + a_1x^1 + a_0x^0 $$ where $a_0, a_1, \cdots a_n$ are constants called the coefficients of the polynomial and $x$ is the indeterminate. The degree of the polynomial is given by the coefficient of the highest power of $x$ that is not 0. In this case, if $a_n \neq 0$, then the degree of this polynomial is $n$.
Let's define this Polynomial type that we could work with. Create a
new file ascuns/src/poly.rsto hold the definition. The indeterminate has its powers increase
incrementally: $x^0, x^1, x^2 ... x^n$, which means, we can store the polynomial as a vector of its
coefficients, lowest power first. The coefficient at index i belongs to $x^i$. For example
$x^3 - 9x^2 + 9x - 6$ becomes [-6, 9, -9, 1].
//! Module that defines the structure and the behaviour of a polynomial representation.
pub struct Polynomial {
pub coeffs: Vec<i64>,
}
impl From<Vec<i64>> for Polynomial {
fn from(coeffs: Vec<i64>) -> Self {
Self {coeffs}
}
}
We also add our new module in src/main.rs
// ascuns/src/main.rs
mod poly;