Package functions.endpoint
Class Constant
Object
GeneralFunction
EndpointFunction
Constant
- All Implemented Interfaces:
Differentiable
,Evaluable
,Outputable
,Simplifiable
,Comparable<GeneralFunction>
,Iterable<GeneralFunction>
,OutputFunction
public class Constant extends EndpointFunction
-
Field Summary
Fields Modifier and Type Field Description double
constant
The numerical value of the constant@Nullable String
constantKey
The string relating to this special constant (null if normal constant)static HashMap<String,Double>
specialConstants
Symbols or Strings with a dedicated value. -
Constructor Summary
-
Method Summary
Modifier and Type Method Description static double
addSpecialConstant(String string, double value)
Defines a new special constantGeneralFunction
clone()
Returns a clone of thisGeneralFunction
int
compareSelf(GeneralFunction that)
Used internally for comparing two functions of the same exact typeboolean
equalsFunction(GeneralFunction that)
Returns true when the two fully-simplified functions are equaldouble
evaluate(Map<String,Double> variableValues)
Evaluates aGeneralFunction
at a point denoted by aMap
GeneralFunction
getDerivative(String varID)
Returns the derivative of aGeneralFunction
with respect to a variable.static double
getSpecialConstant(String string)
Returns the value of a special constantint
hashCode()
Returns a hash code value for this objectboolean
isSpecial()
Returns true if the Constant is a specialConstant
static boolean
isSpecialConstant(String string)
Returns true if string is a specialConstant
static double
removeSpecialConstant(String string)
Removes a special constantstatic void
resetConstants()
GeneralFunction
simplify()
Returns thisGeneralFunction
, simplifiedGeneralFunction
substituteAll(Predicate<? super GeneralFunction> test, Function<? super GeneralFunction,? extends GeneralFunction> replacer)
String
toString()
Returns a String representation of thisGeneralFunction
Methods inherited from class EndpointFunction
getName, getOperands, iterator, toLatex, toOutputFunction
Methods inherited from class GeneralFunction
compareTo, derivativeAt, equals, equalsSimplified, getNthDerivative, getSimplifiedDerivative, substituteVariables
-
Field Details
-
specialConstants
public static final HashMap<String,Double> specialConstantsSymbols or Strings with a dedicated value. The defaults areπ
ande
. -
constant
public final double constantThe numerical value of the constant -
constantKey
@Nullable public final @Nullable String constantKeyThe string relating to this special constant (null if normal constant)
-
-
Constructor Details
-
Constant
public Constant(double constant)Constructs a newConstant
from the specified numerical value- Parameters:
constant
- The numerical value of the constant
-
Constant
public Constant(String constantKey)Constructs a new specialConstant
from its String- Parameters:
constantKey
- The string of the specialConstant
-
-
Method Details
-
isSpecialConstant
public static boolean isSpecialConstant(String string)Returns true if string is a specialConstant
- Parameters:
string
- The string that is being checked if it is a special constant- Returns:
- true if string is a special
Constant
-
getSpecialConstant
public static double getSpecialConstant(String string)Returns the value of a special constant- Parameters:
string
- name of constant- Returns:
- the value of the constant
-
addSpecialConstant
public static double addSpecialConstant(String string, double value)Defines a new special constant- Parameters:
string
- name of constantvalue
- value of constant- Returns:
- the value of the constant for convenience
-
removeSpecialConstant
public static double removeSpecialConstant(String string)Removes a special constant- Parameters:
string
- name of constant- Returns:
- the value of the constant
-
evaluate
public double evaluate(Map<String,Double> variableValues)Description copied from interface:Evaluable
Evaluates aGeneralFunction
at a point denoted by aMap
- Parameters:
variableValues
- the values of the variables in theGeneralFunction
at the point- Returns:
- the value of the
GeneralFunction
at the point
-
isSpecial
public boolean isSpecial()Returns true if the Constant is a specialConstant
- Returns:
- true if the Constant is a special
Constant
-
toString
public String toString()Description copied from class:GeneralFunction
Returns a String representation of thisGeneralFunction
- Specified by:
toString
in interfaceOutputFunction
- Specified by:
toString
in classGeneralFunction
- Returns:
- String representation of this function
-
getDerivative
Description copied from interface:Differentiable
Returns the derivative of aGeneralFunction
with respect to a variable. Should not be used in general;GeneralFunction.getSimplifiedDerivative(java.lang.String)
is strongly preferred.- Parameters:
varID
- the ID of the variable that is differentiated against- Returns:
- the derivative of the function with respect to
varID
-
clone
Description copied from class:GeneralFunction
Returns a clone of thisGeneralFunction
- Specified by:
clone
in classGeneralFunction
- Returns:
- a clone of this function
-
simplify
Description copied from interface:Simplifiable
Returns thisGeneralFunction
, simplified- Returns:
- the simplified function
-
substituteAll
public GeneralFunction substituteAll(Predicate<? super GeneralFunction> test, Function<? super GeneralFunction,? extends GeneralFunction> replacer)Description copied from class:GeneralFunction
- Overrides:
substituteAll
in classEndpointFunction
- Parameters:
test
- checks if the function should be replacedreplacer
- replaces the function- Returns:
- a new
GeneralFunction
with all replacements made
-
equalsFunction
Description copied from class:GeneralFunction
Returns true when the two fully-simplified functions are equal- Specified by:
equalsFunction
in classGeneralFunction
- Parameters:
that
- TheGeneralFunction
that the current function is being checked against- Returns:
- true if the two functions are equal
-
resetConstants
public static void resetConstants() -
compareSelf
Description copied from class:GeneralFunction
Used internally for comparing two functions of the same exact type- Specified by:
compareSelf
in classGeneralFunction
- Parameters:
that
- theGeneralFunction
that this is compared against- Returns:
- the comparison
-
hashCode
public int hashCode()Description copied from class:GeneralFunction
Returns a hash code value for this object- Specified by:
hashCode
in interfaceOutputFunction
- Specified by:
hashCode
in classGeneralFunction
- Returns:
- a hash code value for this object
-