Package net.sf.tweety.math.term
Class Term
- java.lang.Object
-
- net.sf.tweety.math.term.Term
-
- Direct Known Subclasses:
AssociativeOperation
,Constant
,Difference
,Fraction
,FunctionalTerm
,Variable
public abstract class Term extends java.lang.Object
This class models a mathematical term.- Author:
- Matthias Thimm
-
-
Constructor Summary
Constructors Constructor Description Term()
-
Method Summary
Modifier and Type Method Description Sum
add(Term t)
Returns the sum of this and the given term.abstract void
collapseAssociativeOperations()
This method collapses all associative operations appearing in this term, e.g.abstract Term
derive(Variable v)
Differentiates the term with respect to the given variable.double
doubleValue()
Computes the actual value of this term if it contains no variables.static double[][]
evaluateMatrix(java.util.List<java.util.List<Term>> functions, double[] values, java.util.List<Variable> variables)
Evaluates each function in the given matrix with the given values for variables.static double[]
evaluateVector(java.util.List<Term> functions, double[] values, java.util.List<Variable> variables)
Evaluates each function in the given list with the given values for variables.static java.util.List<java.lang.Double>
evaluateVector(java.util.List<Term> functions, java.util.Map<Variable,? extends Term> mapping)
Evaluates each function in the given list with the given values for variables.abstract void
expandAssociativeOperations()
This method expands all associative operations appearing in this term, e.g.abstract java.util.Set<AbsoluteValue>
getAbsoluteValues()
Returns all absolute values of this term.abstract java.util.Set<Maximum>
getMaximums()
Returns all maximums of this term.abstract java.util.Set<Minimum>
getMinimums()
Returns all minimums of this term.abstract java.util.Set<Product>
getProducts()
Returns all products of this term.abstract java.util.Set<Variable>
getVariables()
Returns all variables in this term.boolean
isContinuous()
Checks whether this term is continuous in all appearing variables.abstract boolean
isContinuous(Variable v)
Checks whether this term is continuous in v.abstract boolean
isInteger()
Checks whether this term represents an integer value.boolean
isLinear()
Checks whether this term is linear.Term
min(Term t)
Returns the minimum of this and the given term.Difference
minus(Term t)
Returns the sum of this and (-1) * the given term.Product
mult(Term t)
Returns the product of this and the given term.Term
replaceAllTerms(double[] values, java.util.List<Variable> variables)
Replaces terms according to the given map.Term
replaceAllTerms(java.util.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
toLinearForm()
Converts this term into a linear normal form, i.e.abstract java.lang.String
toString()
abstract Constant
value()
Computes the actual value of this term if it contains no variables.
-
-
-
Method Detail
-
add
public Sum add(Term t)
Returns the sum of this and the given term.- Parameters:
t
- a term- Returns:
- the sum of this and the given term.
-
minus
public Difference minus(Term t)
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
public Product mult(Term t)
Returns the product of this and the given term.- Parameters:
t
- a term.- Returns:
- the product of this and the given term.
-
min
public Term min(Term t)
Returns the minimum of this and the given term.- Parameters:
t
- a term.- Returns:
- the minimum of this and the given term.
-
value
public abstract Constant value() throws java.lang.IllegalArgumentException
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:
java.lang.IllegalArgumentException
- if this term contains at least on variable.
-
doubleValue
public double doubleValue() throws java.lang.IllegalArgumentException
Computes the actual value of this term if it contains no variables.- Returns:
- the double value of this term.
- Throws:
java.lang.IllegalArgumentException
- if this term contains at least on variable.
-
isContinuous
public abstract boolean isContinuous(Variable v)
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
public abstract java.util.Set<Variable> getVariables()
Returns all variables in this term.- Returns:
- all variables in this term.
-
getProducts
public abstract java.util.Set<Product> getProducts()
Returns all products of this term.- Returns:
- all products of this term.
-
getMinimums
public abstract java.util.Set<Minimum> getMinimums()
Returns all minimums of this term.- Returns:
- all minimums of this term.
-
getMaximums
public abstract java.util.Set<Maximum> getMaximums()
Returns all maximums of this term.- Returns:
- all maximums of this term.
-
getAbsoluteValues
public abstract java.util.Set<AbsoluteValue> 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
public abstract Sum toLinearForm() throws java.lang.IllegalArgumentException
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:
java.lang.IllegalArgumentException
- if this term cannot be converted into a linear normal form.
-
replaceTerm
public abstract Term replaceTerm(Term toSubstitute, Term substitution)
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
public static java.util.List<java.lang.Double> evaluateVector(java.util.List<Term> functions, java.util.Map<Variable,? extends Term> mapping)
Evaluates each function in the given list with the given values for variables.- Parameters:
functions
- a list of functionsmapping
- a map mapping variables to terms- Returns:
- the values
-
evaluateVector
public static double[] evaluateVector(java.util.List<Term> functions, double[] values, java.util.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(java.util.List<java.util.List<Term>> functions, double[] values, java.util.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
public Term replaceAllTerms(double[] values, java.util.List<Variable> variables)
Replaces terms according to the given map.- Parameters:
values
- an array of values.variables
- A list of variables that shall be substituted by the given values- Returns:
- a term.
-
replaceAllTerms
public Term replaceAllTerms(java.util.Map<? extends Term,? extends Term> substitutes)
Replaces terms according to the given map.- Parameters:
substitutes
- a map.- Returns:
- a term.
-
isLinear
public boolean isLinear()
Checks whether this term is linear.- Returns:
- "true" if this term is linear.
-
simplify
public 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.- Returns:
- the simplified term.
-
derive
public abstract Term derive(Variable v) throws NonDifferentiableException
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
public abstract java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-