Package functions.binary
Class Pow
Object
- All Implemented Interfaces:
Differentiable
,Evaluable
,Outputable
,Simplifiable
,Comparable<GeneralFunction>
,Iterable<GeneralFunction>
public class Pow extends BinaryFunction
-
Field Summary
-
Constructor Summary
Constructors Constructor Description Pow(GeneralFunction exponent, GeneralFunction base)
Constructs a newPow
-
Method Summary
Modifier and Type Method Description Pow
clone()
Returns a clone of thisGeneralFunction
Product
distributeExponents()
Returns aProduct
where the exponent is distributed to each term.double
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.BinaryFunction
getInstance(GeneralFunction function1, GeneralFunction function2)
Returns an instance of thisGeneralFunction
, using the correct subclassPow
multiplyExponents()
Simplifies instances of a power raised to a power.GeneralFunction
simplify()
Returns thisGeneralFunction
, simplifiedGeneralFunction
simplifyFOC()
GeneralFunction
simplifyLogsOfSameBase()
If the exponent is a logarithm with the same base as thePow
, it returns the argument of the logarithmGeneralFunction
simplifyObviousExponentsAndFOC()
Returns aGeneralFunction
where obvious exponents (ex:(x+1)^1 or (x-1)^0
) have been simplified and functions of constants (ex:2^7
) are simplifiedOutputFunction
toOutputFunction()
Converts this function into anOutputFunction
for use in string conversionGeneralFunction
toSpecialCase()
String
toString()
Returns a String representation of thisGeneralFunction
Product
unwrapIntegerPower()
GeneralFunction
unwrapIntegerPowerSafe()
Given aPow
, checks if the exponent is a positive integer, and if so, appliesunwrapIntegerPower()
Methods inherited from class BinaryFunction
compareSelf, equalsFunction, getFunction1, getFunction2, hashCode, iterator, substituteAll
Methods inherited from class GeneralFunction
compareTo, derivativeAt, equals, equalsSimplified, getNthDerivative, getSimplifiedDerivative, substituteVariables
-
Constructor Details
-
Method Details
-
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
-
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
-
getInstance
Description copied from class:BinaryFunction
Returns an instance of thisGeneralFunction
, using the correct subclass- Specified by:
getInstance
in classBinaryFunction
- Parameters:
function1
- Constructor parameter 1function2
- Constructor parameter 2- Returns:
- an instance of this
GeneralFunction
-
clone
Description copied from class:GeneralFunction
Returns a clone of thisGeneralFunction
- Specified by:
clone
in classGeneralFunction
- Returns:
- a clone of this function
-
toSpecialCase
-
toString
public String toString()Description copied from class:GeneralFunction
Returns a String representation of thisGeneralFunction
- Specified by:
toString
in classGeneralFunction
- Returns:
- String representation of this function
-
simplify
Description copied from interface:Simplifiable
Returns thisGeneralFunction
, simplified- Returns:
- the simplified function
-
simplifyObviousExponentsAndFOC
Returns aGeneralFunction
where obvious exponents (ex:(x+1)^1 or (x-1)^0
) have been simplified and functions of constants (ex:2^7
) are simplified- Returns:
- a
GeneralFunction
where obvious exponents and functions of constants are simplified
-
simplifyFOC
Description copied from class:BinaryFunction
- Overrides:
simplifyFOC
in classBinaryFunction
- Returns:
- a new
Constant
of theBinaryFunction
evaluated if both operands are aConstant
-
multiplyExponents
Simplifies instances of a power raised to a power. Example:(x^2)^3 = x^6
- Returns:
- a
Pow
where the exponents are multiplied
-
distributeExponents
Returns aProduct
where the exponent is distributed to each term. Example:(xy)^2 = (x^2)(y^2)
- Returns:
- a
Product
with the exponent distributed
-
unwrapIntegerPowerSafe
Given aPow
, checks if the exponent is a positive integer, and if so, appliesunwrapIntegerPower()
- Returns:
this
or a new unwrappedProduct
-
unwrapIntegerPower
- Returns:
- a new unwrapped
Product
- Throws:
RuntimeException
- if the exponent is not a positive integer
-
simplifyLogsOfSameBase
If the exponent is a logarithm with the same base as thePow
, it returns the argument of the logarithm- Returns:
- the argument of the logarithm in the exponent, if the exponent is a logarithm with the same base as the
Pow
-
toOutputFunction
Description copied from interface:Outputable
Converts this function into anOutputFunction
for use in string conversion- Specified by:
toOutputFunction
in interfaceOutputable
- Overrides:
toOutputFunction
in classBinaryFunction
- Returns:
- this function as an
OutputFunction
-