Term

Struct Term 

Source
pub struct Term<const NUM_VARIABLES: usize> { /* private fields */ }
Expand description

Represents a single term in a polynomial with NUM_VARIABLES variables.

A term consists of a coefficient and an array of VarFunctions, each applied to a corresponding variable in the input.

For example, for NUM_VARIABLES = 2:

use const_poly::{Term, VarFunction::*};
const TERM: Term<2> = Term::new(3.0, [Sin, Pow(2)]);

represents the term 3 * sin(x_0) * (x_1)^2.

Implementations§

Source§

impl<const NUM_VARIABLES: usize> Term<NUM_VARIABLES>

Source

pub const fn new( coefficient: f64, functions: [VarFunction; NUM_VARIABLES], ) -> Self

Creates a new Term with the specified coefficient and functions.

§Parameters
  • coefficient: The scalar multiplier for the term.
  • functions: An array of VarFunctions, one per variable.
§Returns

A new Term instance.

§Example
use const_poly::{Term, VarFunction::*};
const TERM: Term<2> = Term::new(2.0, [Sin, Pow(3)]);

represents the term 2.0 * sin(x_0) * (x_1)^3.

Source

pub const fn evaluate(&self, vars: [f64; NUM_VARIABLES]) -> f64

Evaluates the term for the given variables.

Applies each function in functions to the corresponding variable, then multiplies all results together with the coefficient.

§Parameters
  • vars: An array of variables of length NUM_VARIABLES.
§Returns

The floating-point result of evaluating the term.

§Example
use const_poly::{Term, VarFunction::*};
const TERM: Term<1> = Term::new(2.0, [Sin]);
const val: f64 = TERM.evaluate([1.57079632679]); // Approx sin(pi/2)
assert!((val - 2.0).abs() < 1e-6);

Trait Implementations§

Source§

impl<const NUM_VARIABLES: usize> Clone for Term<NUM_VARIABLES>

Source§

fn clone(&self) -> Term<NUM_VARIABLES>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const NUM_VARIABLES: usize> Copy for Term<NUM_VARIABLES>

Auto Trait Implementations§

§

impl<const NUM_VARIABLES: usize> Freeze for Term<NUM_VARIABLES>

§

impl<const NUM_VARIABLES: usize> RefUnwindSafe for Term<NUM_VARIABLES>

§

impl<const NUM_VARIABLES: usize> Send for Term<NUM_VARIABLES>

§

impl<const NUM_VARIABLES: usize> Sync for Term<NUM_VARIABLES>

§

impl<const NUM_VARIABLES: usize> Unpin for Term<NUM_VARIABLES>

§

impl<const NUM_VARIABLES: usize> UnwindSafe for Term<NUM_VARIABLES>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.