Polynomial

com.phasmidsoftware.number.core.numerical.Polynomial
trait Polynomial[X] extends X => X

Represents a polynomial function with a numeric type parameter X. Supports evaluation, differentiation, and construction of new polynomials.

TODO create an abstract Polynomial which will have the implicit Numeric[X] value

Attributes

Graph
Supertypes
trait X => X
class Object
trait Matchable
class Any
Known subtypes

Members list

Value members

Abstract methods

def coefficients: Seq[X]

Retrieves the coefficients of the polynomial in ascending order of powers.

Retrieves the coefficients of the polynomial in ascending order of powers.

Attributes

Returns

a sequence of coefficients of type X, where the ith element corresponds to the coefficient of the x∧i term

def degree: Int

Returns the degree of the polynomial.

Returns the degree of the polynomial.

Attributes

Returns

the degree of the polynomial as an integer

def numeric: Numeric[X]

Retrieves the Numeric instance associated with the polynomial.

Retrieves the Numeric instance associated with the polynomial.

Attributes

Returns

the Numeric instance of type X, which provides numeric operations for the coefficients

def unit(degree: Int, coefficients: Seq[X])(implicit xn: Numeric[X]): Polynomial[X]

Constructs a polynomial with the given degree and coefficients.

Constructs a polynomial with the given degree and coefficients.

Value parameters

coefficients

a sequence of coefficients of type X, where the ith element corresponds to the coefficient of the x∧i term

degree

the degree of the polynomial, an integer representing the highest power of x

xn

an implicit Numeric instance that provides numeric operations for the type X

Attributes

Returns

a new Polynomial instance of type X constructed with the specified degree and coefficients

Concrete methods

def apply(x: X): X

Evaluates the polynomial for a given input value.

Evaluates the polynomial for a given input value.

The method calculates the polynomial value by summing the contributions of each term. Each term is computed as the coefficient multiplied by the corresponding power of the input value.

Value parameters

x

the input value of type X at which the polynomial is to be evaluated

Attributes

Returns

the value of the polynomial at the given input value

Computes the derivative of the polynomial.

Computes the derivative of the polynomial.

Attributes

Returns

a new polynomial representing the derivative of the current polynomial

def derivativeN(n: Int): Polynomial[X]

Computes the nth derivative of the polynomial.

Computes the nth derivative of the polynomial.

TODO fix me

Value parameters

n

the number of times to compute the derivative, where n must be a non-negative integer

Attributes

Returns

a new polynomial representing the nth derivative of the current polynomial

def nthDerivative(n: Int, x: X): X

Computes the nth derivative of the polynomial and evaluates it at the given input value.

Computes the nth derivative of the polynomial and evaluates it at the given input value.

Value parameters

n

the order of the derivative to compute, where n is a non-negative integer

x

the input value of type X at which the nth derivative will be evaluated

Attributes

Returns

the result of evaluating the nth derivative of the polynomial at the given input value

Inherited methods

def andThen[A](g: X => A): X => A

Composes two instances of Function1 in a new Function1, with this function applied first.

Composes two instances of Function1 in a new Function1, with this function applied first.

Type parameters

A

the result type of function g

Value parameters

g

a function R => A

Attributes

Returns

a new function f such that f(x) == g(apply(x))

Inherited from:
Function1
def compose[A](g: A => X): A => X

Composes two instances of Function1 in a new Function1, with this function applied last.

Composes two instances of Function1 in a new Function1, with this function applied last.

Type parameters

A

the type to which function g can be applied

Value parameters

g

a function A => T1

Attributes

Returns

a new function f such that f(x) == apply(g(x))

Inherited from:
Function1
override def toString(): String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Definition Classes
Function1 -> Any
Inherited from:
Function1

Concrete fields

lazy val render: String

Generates a string representation of the polynomial in the format: "Polynomial(degree, coefficient1, coefficient2, ..., coefficientN)".

Generates a string representation of the polynomial in the format: "Polynomial(degree, coefficient1, coefficient2, ..., coefficientN)".

Attributes

Returns

a string that represents the polynomial, including its degree and coefficients