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 doubleconstantThe numerical value of the constant@Nullable StringconstantKeyThe string relating to this special constant (null if normal constant)static HashMap<String,Double>specialConstantsSymbols or Strings with a dedicated value. -
Constructor Summary
-
Method Summary
Modifier and Type Method Description static doubleaddSpecialConstant(String string, double value)Defines a new special constantGeneralFunctionclone()Returns a clone of thisGeneralFunctionintcompareSelf(GeneralFunction that)Used internally for comparing two functions of the same exact typebooleanequalsFunction(GeneralFunction that)Returns true when the two fully-simplified functions are equaldoubleevaluate(Map<String,Double> variableValues)Evaluates aGeneralFunctionat a point denoted by aMapGeneralFunctiongetDerivative(String varID)Returns the derivative of aGeneralFunctionwith respect to a variable.static doublegetSpecialConstant(String string)Returns the value of a special constantinthashCode()Returns a hash code value for this objectbooleanisSpecial()Returns true if the Constant is a specialConstantstatic booleanisSpecialConstant(String string)Returns true if string is a specialConstantstatic doubleremoveSpecialConstant(String string)Removes a special constantstatic voidresetConstants()GeneralFunctionsimplify()Returns thisGeneralFunction, simplifiedGeneralFunctionsubstituteAll(Predicate<? super GeneralFunction> test, Function<? super GeneralFunction,? extends GeneralFunction> replacer)StringtoString()Returns a String representation of thisGeneralFunctionMethods inherited from class EndpointFunction
getName, getOperands, iterator, toLatex, toOutputFunctionMethods 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 newConstantfrom the specified numerical value- Parameters:
constant- The numerical value of the constant
-
Constant
public Constant(String constantKey)Constructs a new specialConstantfrom 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:EvaluableEvaluates aGeneralFunctionat a point denoted by aMap- Parameters:
variableValues- the values of the variables in theGeneralFunctionat the point- Returns:
- the value of the
GeneralFunctionat 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:GeneralFunctionReturns a String representation of thisGeneralFunction- Specified by:
toStringin interfaceOutputFunction- Specified by:
toStringin classGeneralFunction- Returns:
- String representation of this function
-
getDerivative
Description copied from interface:DifferentiableReturns the derivative of aGeneralFunctionwith 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:GeneralFunctionReturns a clone of thisGeneralFunction- Specified by:
clonein classGeneralFunction- Returns:
- a clone of this function
-
simplify
Description copied from interface:SimplifiableReturns 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:
substituteAllin classEndpointFunction- Parameters:
test- checks if the function should be replacedreplacer- replaces the function- Returns:
- a new
GeneralFunctionwith all replacements made
-
equalsFunction
Description copied from class:GeneralFunctionReturns true when the two fully-simplified functions are equal- Specified by:
equalsFunctionin classGeneralFunction- Parameters:
that- TheGeneralFunctionthat 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:GeneralFunctionUsed internally for comparing two functions of the same exact type- Specified by:
compareSelfin classGeneralFunction- Parameters:
that- theGeneralFunctionthat this is compared against- Returns:
- the comparison
-
hashCode
public int hashCode()Description copied from class:GeneralFunctionReturns a hash code value for this object- Specified by:
hashCodein interfaceOutputFunction- Specified by:
hashCodein classGeneralFunction- Returns:
- a hash code value for this object
-