Package functions.commutative
Class CommutativeFunction
Object
GeneralFunction
CommutativeFunction
- All Implemented Interfaces:
Differentiable,Evaluable,Outputable,Simplifiable,Comparable<GeneralFunction>,Iterable<GeneralFunction>
- Direct Known Subclasses:
IntegerCommutativeFunction,Product,Sum
public abstract class CommutativeFunction extends GeneralFunction
The abstract
CommutativeFunction class represents function that are commutative. Ex: addition or multiplication-
Field Summary
Fields Modifier and Type Field Description protected GeneralFunction[]functionsThe array ofGeneralFunctions operated on by theCommutativeFunction -
Constructor Summary
Constructors Constructor Description CommutativeFunction(GeneralFunction... functions)Constructs a newCommutativeFunction -
Method Summary
Modifier and Type Method Description intcompareSelf(GeneralFunction that)Used internally for comparing two functions of the same exact typebooleanequalsFunction(GeneralFunction that)Returns true when the two fully-simplified functions are equalGeneralFunction[]getFunctions()Returnsfunctionsabstract doublegetIdentityValue()Returns the identity of thisCommutativeFunction, such as 0 for + or gcd and 1 for * or lcmabstract CommutativeFunctiongetInstance(GeneralFunction... functions)Returns an instance of thisGeneralFunctionprotected Collector<CharSequence,?,String>getJoiningCollector()Returns a collector used to create thetoStringof theCommutativeFunctioninthashCode()Returns a hash code value for this object@NotNull Iterator<GeneralFunction>iterator()Returns an iterator over the operands of thisGeneralFunctionabstract doubleoperate(double a, double b)Performs the operation of thisCommutativeFunctionon the two inputsGeneralFunctionsimplify()Returns thisGeneralFunction, simplifiedCommutativeFunctionsimplifyConstants()Combines allConstants usingoperate(double, double)CommutativeFunctionsimplifyElements()Simplifies each element of thisCommutativeFunctionCommutativeFunctionsimplifyIdentity()Removes all instances of the identity of the function fromfunctionsCommutativeFunctionsimplifyInternal()Simplifies thisCommutativeFunctionusing all methods that are guaranteed to return aCommutativeFunctionof the same typeCommutativeFunctionsimplifyPull()Composes all sub-functions of the same type.GeneralFunctionsimplifyTrivialElement()Returns identityConstantiffunctionslength is 0 and returns theGeneralFunctioniffunctionslength is 1GeneralFunctionsubstituteAll(Predicate<? super GeneralFunction> test, Function<? super GeneralFunction,? extends GeneralFunction> replacer)OutputFunctiontoOutputFunction()Converts this function into anOutputFunctionfor use in string conversionStringtoString()Returns a String representation of thisGeneralFunctionMethods inherited from class GeneralFunction
clone, compareTo, derivativeAt, equals, equalsSimplified, getNthDerivative, getSimplifiedDerivative, substituteVariables
-
Field Details
-
functions
The array ofGeneralFunctions operated on by theCommutativeFunction
-
-
Constructor Details
-
CommutativeFunction
Constructs a newCommutativeFunction- Parameters:
functions- TheGeneralFunctions that will be acted on
-
-
Method Details
-
getFunctions
Returnsfunctions- Returns:
functions
-
getInstance
Returns an instance of thisGeneralFunction- Parameters:
functions- theGeneralFunctions that will be acted on- Returns:
- an instance of this
GeneralFunction
-
toString
public String toString()Description copied from class:GeneralFunctionReturns a String representation of thisGeneralFunction- Specified by:
toStringin classGeneralFunction- Returns:
- String representation of this function
-
getJoiningCollector
protected Collector<CharSequence,?,String> getJoiningCollector()Returns a collector used to create thetoStringof theCommutativeFunction- Returns:
- a joining collector
-
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
-
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
-
toOutputFunction
Description copied from interface:OutputableConverts this function into anOutputFunctionfor use in string conversion- Returns:
- this function as an
OutputFunction
-
substituteAll
public GeneralFunction substituteAll(Predicate<? super GeneralFunction> test, Function<? super GeneralFunction,? extends GeneralFunction> replacer)Description copied from class:GeneralFunction- Specified by:
substituteAllin classGeneralFunction- Parameters:
test- checks if the function should be replacedreplacer- replaces the function- Returns:
- a new
GeneralFunctionwith all replacements made
-
simplify
Description copied from interface:SimplifiableReturns thisGeneralFunction, simplified- Returns:
- the simplified function
-
simplifyInternal
Simplifies thisCommutativeFunctionusing all methods that are guaranteed to return aCommutativeFunctionof the same type- Returns:
- the simplified
CommutativeFunction
-
simplifyElements
Simplifies each element of thisCommutativeFunction- Returns:
- a new
CommutativeFunctionwith each element offunctionssimplified
-
simplifyIdentity
Removes all instances of the identity of the function fromfunctions- Returns:
- a new
CommutativeFunctionwith
-
simplifyConstants
Combines allConstants usingoperate(double, double)- Returns:
- a new
CommutativeFunctionwith the combinedConstants
-
simplifyPull
Composes all sub-functions of the same type. Ex:(a+(b+c))becomes(a+b+c)- Returns:
- a new
CommutativeFunctionwith all compositions performed
-
simplifyTrivialElement
Returns identityConstantiffunctionslength is 0 and returns theGeneralFunctioniffunctionslength is 1- Returns:
- identity
Constantiffunctionslength is 0 and returns theGeneralFunctioniffunctionslength is 1
-
getIdentityValue
public abstract double getIdentityValue()Returns the identity of thisCommutativeFunction, such as 0 for + or gcd and 1 for * or lcm- Returns:
- the identity of this
CommutativeFunction
-
operate
public abstract double operate(double a, double b)Performs the operation of thisCommutativeFunctionon the two inputs- Parameters:
a- the first inputb- the second input- Returns:
- the operation applied to the inputs
-
hashCode
public int hashCode()Description copied from class:GeneralFunctionReturns a hash code value for this object- Specified by:
hashCodein classGeneralFunction- Returns:
- a hash code value for this object
-
iterator
Description copied from class:GeneralFunctionReturns an iterator over the operands of thisGeneralFunction- Specified by:
iteratorin interfaceIterable<GeneralFunction>- Specified by:
iteratorin classGeneralFunction- Returns:
- an iterator over the operands of this
GeneralFunction
-