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[]
functions
The array ofGeneralFunction
s operated on by theCommutativeFunction
-
Constructor Summary
Constructors Constructor Description CommutativeFunction(GeneralFunction... functions)
Constructs a newCommutativeFunction
-
Method Summary
Modifier and Type Method Description 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 equalGeneralFunction[]
getFunctions()
Returnsfunctions
abstract double
getIdentityValue()
Returns the identity of thisCommutativeFunction
, such as 0 for + or gcd and 1 for * or lcmabstract CommutativeFunction
getInstance(GeneralFunction... functions)
Returns an instance of thisGeneralFunction
protected Collector<CharSequence,?,String>
getJoiningCollector()
Returns a collector used to create thetoString
of theCommutativeFunction
int
hashCode()
Returns a hash code value for this object@NotNull Iterator<GeneralFunction>
iterator()
Returns an iterator over the operands of thisGeneralFunction
abstract double
operate(double a, double b)
Performs the operation of thisCommutativeFunction
on the two inputsGeneralFunction
simplify()
Returns thisGeneralFunction
, simplifiedCommutativeFunction
simplifyConstants()
Combines allConstant
s usingoperate(double, double)
CommutativeFunction
simplifyElements()
Simplifies each element of thisCommutativeFunction
CommutativeFunction
simplifyIdentity()
Removes all instances of the identity of the function fromfunctions
CommutativeFunction
simplifyInternal()
Simplifies thisCommutativeFunction
using all methods that are guaranteed to return aCommutativeFunction
of the same typeCommutativeFunction
simplifyPull()
Composes all sub-functions of the same type.GeneralFunction
simplifyTrivialElement()
Returns identityConstant
iffunctions
length is 0 and returns theGeneralFunction
iffunctions
length is 1GeneralFunction
substituteAll(Predicate<? super GeneralFunction> test, Function<? super GeneralFunction,? extends GeneralFunction> replacer)
OutputFunction
toOutputFunction()
Converts this function into anOutputFunction
for use in string conversionString
toString()
Returns a String representation of thisGeneralFunction
Methods inherited from class GeneralFunction
clone, compareTo, derivativeAt, equals, equalsSimplified, getNthDerivative, getSimplifiedDerivative, substituteVariables
-
Field Details
-
functions
The array ofGeneralFunction
s operated on by theCommutativeFunction
-
-
Constructor Details
-
CommutativeFunction
Constructs a newCommutativeFunction
- Parameters:
functions
- TheGeneralFunction
s that will be acted on
-
-
Method Details
-
getFunctions
Returnsfunctions
- Returns:
functions
-
getInstance
Returns an instance of thisGeneralFunction
- Parameters:
functions
- theGeneralFunction
s that will be acted on- Returns:
- an instance of this
GeneralFunction
-
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
-
getJoiningCollector
protected Collector<CharSequence,?,String> getJoiningCollector()Returns a collector used to create thetoString
of theCommutativeFunction
- Returns:
- a joining collector
-
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
-
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
-
toOutputFunction
Description copied from interface:Outputable
Converts this function into anOutputFunction
for 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:
substituteAll
in classGeneralFunction
- Parameters:
test
- checks if the function should be replacedreplacer
- replaces the function- Returns:
- a new
GeneralFunction
with all replacements made
-
simplify
Description copied from interface:Simplifiable
Returns thisGeneralFunction
, simplified- Returns:
- the simplified function
-
simplifyInternal
Simplifies thisCommutativeFunction
using all methods that are guaranteed to return aCommutativeFunction
of the same type- Returns:
- the simplified
CommutativeFunction
-
simplifyElements
Simplifies each element of thisCommutativeFunction
- Returns:
- a new
CommutativeFunction
with each element offunctions
simplified
-
simplifyIdentity
Removes all instances of the identity of the function fromfunctions
- Returns:
- a new
CommutativeFunction
with
-
simplifyConstants
Combines allConstant
s usingoperate(double, double)
- Returns:
- a new
CommutativeFunction
with the combinedConstant
s
-
simplifyPull
Composes all sub-functions of the same type. Ex:(a+(b+c))
becomes(a+b+c)
- Returns:
- a new
CommutativeFunction
with all compositions performed
-
simplifyTrivialElement
Returns identityConstant
iffunctions
length is 0 and returns theGeneralFunction
iffunctions
length is 1- Returns:
- identity
Constant
iffunctions
length is 0 and returns theGeneralFunction
iffunctions
length 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 thisCommutativeFunction
on 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:GeneralFunction
Returns a hash code value for this object- Specified by:
hashCode
in classGeneralFunction
- Returns:
- a hash code value for this object
-
iterator
Description copied from class:GeneralFunction
Returns an iterator over the operands of thisGeneralFunction
- Specified by:
iterator
in interfaceIterable<GeneralFunction>
- Specified by:
iterator
in classGeneralFunction
- Returns:
- an iterator over the operands of this
GeneralFunction
-