is_polynomial

Function is_polynomial 

Source
pub fn is_polynomial(expr: &Expression, var: &Symbol) -> bool
Expand description

Check if expression is a polynomial in the given variable

§Arguments

  • expr - The expression to check
  • var - The variable

§Examples

use mathhook_core::{Expression, symbol};
use mathhook_core::calculus::integrals::rational::helpers::is_polynomial;

let x = symbol!(x);
let poly = Expression::add(vec![
    Expression::pow(Expression::symbol(x.clone()), Expression::integer(2)),
    Expression::symbol(x.clone()),
    Expression::integer(1),
]);

assert!(is_polynomial(&poly, &x));

let non_poly = Expression::function("sin", vec![Expression::symbol(x.clone())]);
assert!(!is_polynomial(&non_poly, &x));