pub fn extract_coefficient_map(
expr: &Expression,
var: &Symbol,
) -> HashMap<i64, Expression>Expand description
Extract all coefficients of a polynomial as a map from degree to coefficient
Returns a HashMap where keys are degrees and values are coefficients.
§Arguments
expr- The polynomial expressionvar- The variable to extract coefficients for
§Returns
A HashMap mapping degree (i64) to coefficient (Expression)
§Examples
use mathhook_core::core::polynomial::extract_coefficient_map;
use mathhook_core::{expr, symbol};
let x = symbol!(x);
let poly = expr!((3 * (x ^ 2)) + (2 * x) + 1);
let coeffs = extract_coefficient_map(&poly, &x);
// coeffs[0] = 1, coeffs[1] = 2, coeffs[2] = 3