Package org.tweetyproject.math.term
Class Term
java.lang.Object
org.tweetyproject.math.term.Term
- Direct Known Subclasses:
AssociativeOperation
,Constant
,Difference
,Fraction
,FunctionalTerm
,Variable
This class models a mathematical term.
- Author:
- Matthias Thimm
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns the sum of this and the given term.abstract void
This method collapses all associative operations appearing in this term, e.g.abstract Term
Differentiates the term with respect to the given variable.double
Computes the actual value of this term if it contains no variables.static double[][]
Evaluates each function in the given matrix with the given values for variables.static double[]
evaluateVector
(List<Term> functions, double[] values, List<Variable> variables) Evaluates each function in the given list with the given values for variables.Evaluates each function in the given list with the given values for variables.abstract void
This method expands all associative operations appearing in this term, e.g.abstract Set
<AbsoluteValue> Returns all absolute values of this term.Returns all maximums of this term.Returns all minimums of this term.Returns all products of this term.getSums()
Returns all sums of this term.getTerms()
Getter TermsReturns all variables in this term.boolean
Checks whether this term is continuous in all appearing variables.abstract boolean
Checks whether this term is continuous in v.abstract boolean
Checks whether this term represents an integer value.boolean
isLinear()
Checks whether this term is linear.boolean
Checks whether this term is quadratic.Returns the minimum of this and the given term.Returns the sum of this and (-1) * the given term.Returns the product of this and the given term.replaceAllTerms
(double[] values, List<Variable> variables) Replaces terms according to the given map.replaceAllTerms
(Map<? extends Term, ? extends Term> substitutes) Replaces terms according to the given map.abstract Term
replaceTerm
(Term toSubstitute, Term substitution) Replaces each occurrence of "toSubstitute" by "substitution" and return the new term.abstract Term
simplify()
Simplifies this term in an equivalent way:
- Replaces products that contain a zero by the constant zero
- Removes a term one from products
- Removes a term zero from sums
- Aggregates constants in sums, products, and minimums
- Evaluates functional terms on constants
- Simplifies fractions where possible.abstract Sum
Converts this term into a linear normal form, i.e.abstract Sum
Return a quadratic formabstract String
toString()
abstract Constant
value()
Computes the actual value of this term if it contains no variables.
-
Constructor Details
-
Term
public Term()
-
-
Method Details
-
add
-
minus
Returns the sum of this and (-1) * the given term.- Parameters:
t
- a term- Returns:
- the sum of this and (-1) * the given term.
-
mult
-
min
-
value
Computes the actual value of this term if it contains no variables.- Returns:
- the value of this term, either a float or an integer.
- Throws:
IllegalArgumentException
- if this term contains at least on variable.
-
doubleValue
Computes the actual value of this term if it contains no variables.- Returns:
- the double value of this term.
- Throws:
IllegalArgumentException
- if this term contains at least on variable.
-
isContinuous
Checks whether this term is continuous in v.- Parameters:
v
- a variable- Returns:
- "true" iff this term is continuous in v.
-
isContinuous
public boolean isContinuous()Checks whether this term is continuous in all appearing variables.- Returns:
- "true" iff this term is continuous in all appearing variables
-
getVariables
-
getProducts
-
getSums
-
getMinimums
-
getMaximums
-
getAbsoluteValues
Returns all absolute values of this term.- Returns:
- all absolute values of this term.
-
isInteger
public abstract boolean isInteger()Checks whether this term represents an integer value.- Returns:
- "true" iff this term represents an integer value.
-
toLinearForm
Converts this term into a linear normal form, i.e. into a sum of products of a constant and a variable.- Returns:
- a term in linear normal form.
- Throws:
IllegalArgumentException
- if this term cannot be converted into a linear normal form.
-
toQuadraticForm
Return a quadratic form- Returns:
- a quadratic form
- Throws:
IllegalArgumentException
- error
-
replaceTerm
Replaces each occurrence of "toSubstitute" by "substitution" and return the new term.- Parameters:
toSubstitute
- the term to be substitutedsubstitution
- the new term- Returns:
- this term where "toSubstitute" is replaced by "substitution"
-
evaluateVector
-
evaluateVector
public static double[] evaluateVector(List<Term> functions, double[] values, List<Variable> variables) Evaluates each function in the given list with the given values for variables.- Parameters:
functions
- a list of functionsvalues
- the values of the variablesvariables
- the (ordered) list of variables- Returns:
- the values
-
evaluateMatrix
public static double[][] evaluateMatrix(List<List<Term>> functions, double[] values, List<Variable> variables) Evaluates each function in the given matrix with the given values for variables.- Parameters:
functions
- a list of functionsvalues
- the values of the variablesvariables
- the (ordered) list of variables- Returns:
- the values
-
replaceAllTerms
-
replaceAllTerms
-
isLinear
public boolean isLinear()Checks whether this term is linear.- Returns:
- "true" if this term is linear.
-
isQuadratic
public boolean isQuadratic()Checks whether this term is quadratic.- Returns:
- "true" if this term is quadratic.
-
simplify
Simplifies this term in an equivalent way:
- Replaces products that contain a zero by the constant zero
- Removes a term one from products
- Removes a term zero from sums
- Aggregates constants in sums, products, and minimums
- Evaluates functional terms on constants
- Simplifies fractions where possible.- Returns:
- the simplified term.
-
getTerms
-
derive
Differentiates the term with respect to the given variable.- Parameters:
v
- a variable.- Returns:
- the derivation of this term wrt. the given variable.
- Throws:
NonDifferentiableException
- if the term cannot be differentiated.
-
collapseAssociativeOperations
public abstract void collapseAssociativeOperations()This method collapses all associative operations appearing in this term, e.g. every min{min{a,b},c} becomes min{a,b,c}. -
expandAssociativeOperations
public abstract void expandAssociativeOperations()This method expands all associative operations appearing in this term, e.g. every min{a,b,c} becomes min{min{a,b},c}. -
toString
-