Package functions
Class GeneralFunction
Object
GeneralFunction
- All Implemented Interfaces:
Differentiable
,Evaluable
,Outputable
,Simplifiable
,Comparable<GeneralFunction>
,Iterable<GeneralFunction>
- Direct Known Subclasses:
BinaryFunction
,CommutativeFunction
,EndpointFunction
,UnitaryFunction
public abstract class GeneralFunction extends Object implements Evaluable, Differentiable, Simplifiable, Comparable<GeneralFunction>, Iterable<GeneralFunction>, Outputable
A
GeneralFunction
is the generalized abstract function used throughout the CAS.
It is critical to note that ALL FUNCTIONS ARE IMMUTABLE: as a consequence, methods such as Simplifiable.simplify()
return a function that has been simplified rather than simplifying the caller in place.-
Field Summary
Fields Modifier and Type Field Description protected Map<String,GeneralFunction>
derivatives
Caches derivatives with the key corresponding to thevarID
of the derivativestatic Class<?>[]
sortOrder
Describes the order that aGeneralFunction
should appear in a sorted array (used incompareTo(GeneralFunction)
) -
Constructor Summary
Constructors Constructor Description GeneralFunction()
-
Method Summary
Modifier and Type Method Description abstract GeneralFunction
clone()
Returns a clone of thisGeneralFunction
protected abstract int
compareSelf(GeneralFunction that)
Used internally for comparing two functions of the same exact typeint
compareTo(@NotNull GeneralFunction that)
GeneralFunction
s of different types are sorted according tosortOrder
andMiscTools.findClassValue(GeneralFunction)
, and functions of the same exact type are sorted usingcompareSelf(GeneralFunction)
double
derivativeAt(String varID, Map<String,Double> point)
Returns the value of the derivative atpoint
boolean
equals(Object that)
Compares two functions withequalsFunction(GeneralFunction)
abstract boolean
equalsFunction(GeneralFunction that)
Returns true when the two fully-simplified functions are equalboolean
equalsSimplified(GeneralFunction that)
Simplifies the two functions, then compares them withequalsFunction(GeneralFunction)
GeneralFunction
getNthDerivative(String varID, int N)
Returns theN
th derivative of aGeneralFunction
with respect to a variableGeneralFunction
getSimplifiedDerivative(String varID)
abstract int
hashCode()
Returns a hash code value for this objectabstract @NotNull Iterator<GeneralFunction>
iterator()
Returns an iterator over the operands of thisGeneralFunction
abstract GeneralFunction
substituteAll(Predicate<? super GeneralFunction> test, Function<? super GeneralFunction,? extends GeneralFunction> replacer)
GeneralFunction
substituteVariables(Map<String,? extends GeneralFunction> toSubstitute)
Substitutes variables with functions as specified in a mapabstract String
toString()
Returns a String representation of thisGeneralFunction
-
Field Details
-
sortOrder
public static final Class<?>[] sortOrderDescribes the order that aGeneralFunction
should appear in a sorted array (used incompareTo(GeneralFunction)
) -
derivatives
Caches derivatives with the key corresponding to thevarID
of the derivative
-
-
Constructor Details
-
GeneralFunction
public GeneralFunction()
-
-
Method Details
-
toString
public abstract String toString()Returns a String representation of thisGeneralFunction
- Overrides:
toString
in classObject
- Returns:
- String representation of this function
-
clone
Returns a clone of thisGeneralFunction
- Overrides:
clone
in classObject
- Returns:
- a clone of this function
-
getSimplifiedDerivative
-
getNthDerivative
Description copied from interface:Differentiable
Returns theN
th derivative of aGeneralFunction
with respect to a variable- Specified by:
getNthDerivative
in interfaceDifferentiable
- Parameters:
varID
- the ID of the variable that is differentiated againstN
- the amount of times to differentiate- Returns:
- the
N
th derivative of the function with respect tovarID
-
derivativeAt
public double derivativeAt(String varID, Map<String,Double> point)Returns the value of the derivative atpoint
- Parameters:
varID
- the variable being differentiated againstpoint
- the point to find the derivative at- Returns:
- the value of the derivative at
point
-
substituteAll
public abstract GeneralFunction substituteAll(Predicate<? super GeneralFunction> test, Function<? super GeneralFunction,? extends GeneralFunction> replacer)- Parameters:
test
- checks if the function should be replacedreplacer
- replaces the function- Returns:
- a new
GeneralFunction
with all replacements made
-
substituteVariables
Substitutes variables with functions as specified in a map- Parameters:
toSubstitute
- the map betweenVariable
strings andGeneralFunction
s- Returns:
- the new
GeneralFunction
after all substitutions are preformed
-
equalsFunction
Returns true when the two fully-simplified functions are equal- Parameters:
that
- TheGeneralFunction
that the current function is being checked against- Returns:
- true if the two functions are equal
-
equalsSimplified
Simplifies the two functions, then compares them withequalsFunction(GeneralFunction)
- Parameters:
that
- the function to be compared against- Returns:
- true if they're equal when simplified
-
equals
public boolean equals(Object that)Compares two functions withequalsFunction(GeneralFunction)
- Overrides:
equals
in classObject
- Parameters:
that
- the object to be compared against- Returns:
- true if they're equal
-
compareSelf
Used internally for comparing two functions of the same exact type- Parameters:
that
- theGeneralFunction
that this is compared against- Returns:
- the comparison
-
compareTo
GeneralFunction
s of different types are sorted according tosortOrder
andMiscTools.findClassValue(GeneralFunction)
, and functions of the same exact type are sorted usingcompareSelf(GeneralFunction)
- Specified by:
compareTo
in interfaceComparable<GeneralFunction>
- Parameters:
that
- theGeneralFunction
that this is compared against- Returns:
- the comparison
-
hashCode
public abstract int hashCode()Returns a hash code value for this object- Overrides:
hashCode
in classObject
- Returns:
- a hash code value for this object
-
iterator
Returns an iterator over the operands of thisGeneralFunction
- Specified by:
iterator
in interfaceIterable<GeneralFunction>
- Returns:
- an iterator over the operands of this
GeneralFunction
-