Interface FormulaManager
-
- All Known Implementing Classes:
AbstractFormulaManager
public interface FormulaManagerFormulaManager class contains all operations which can be performed on formulas.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description BooleanFormulaapplyTactic(BooleanFormula input, Tactic tactic)Apply a tactic which performs formula transformation.AppenderdumpFormula(BooleanFormula pT)Serialize an input formula to an SMT-LIB format.Stringescape(String variableName)Get an escaped symbol/name for variables or undefined functions, if necessary.Map<String,Formula>extractVariables(Formula f)Extract the names of all free variables and UFs in a formula.Map<String,Formula>extractVariablesAndUFs(Formula f)Extract the names of all free variables and UFs in a formula.ArrayFormulaManagergetArrayFormulaManager()Returns the Array-Theory.BitvectorFormulaManagergetBitvectorFormulaManager()Returns the Bitvector-Theory.BooleanFormulaManagergetBooleanFormulaManager()Returns the Boolean-Theory.FloatingPointFormulaManagergetFloatingPointFormulaManager()Returns the Floating-Point-Theory.<T extends Formula>
FormulaType<T>getFormulaType(T formula)Returns the type of the given Formula.IntegerFormulaManagergetIntegerFormulaManager()Returns the Integer-Theory.QuantifiedFormulaManagergetQuantifiedFormulaManager()Returns the interface for handling quantifiers.RationalFormulaManagergetRationalFormulaManager()Returns the Rational-Theory.SLFormulaManagergetSLFormulaManager()Returns the Seperation-Logic-Theory.UFManagergetUFManager()Returns the function for dealing with uninterpreted functions (UFs).booleanisValidName(String variableName)Check whether the given String can be used as symbol/name for variables or undefined functions.<T extends Formula>
TmakeApplication(FunctionDeclaration<T> declaration, List<? extends Formula> args)Create a function application to the given list of arguments.<T extends Formula>
TmakeApplication(FunctionDeclaration<T> declaration, Formula... args)Create a function application to the given list of arguments.<T extends Formula>
TmakeVariable(FormulaType<T> formulaType, String name)Create variable of the type equal toformulaType.BooleanFormulaparse(String s)Parse a boolean formula given as a String in an SMT-LIB file format.<T extends Formula>
Tsimplify(T input)Simplify an input formula, while ensuring equivalence.<T extends Formula>
Tsubstitute(T f, Map<? extends Formula,? extends Formula> fromToMapping)Substitute every occurrence of any item fromchangeFromin formulafto the corresponding occurrence fromchangeTo.<T extends Formula>
TtransformRecursively(T f, FormulaTransformationVisitor pFormulaVisitor)Visit the formula recursively with a givenFormulaVisitor.BooleanFormulatranslateFrom(BooleanFormula formula, FormulaManager otherContext)Translates the formula from another context into the context represented bythis.Stringunescape(String variableName)Unescape the symbol/name for variables or undefined functions, if necessary.<R> Rvisit(Formula f, FormulaVisitor<R> rFormulaVisitor)Visit the formula with a given visitor.voidvisitRecursively(Formula f, FormulaVisitor<TraversalProcess> rFormulaVisitor)Visit the formula recursively with a givenFormulaVisitor.
-
-
-
Method Detail
-
getIntegerFormulaManager
IntegerFormulaManager getIntegerFormulaManager()
Returns the Integer-Theory. Because most SAT-solvers support automatic casting between Integer- and Rational-Theory, the Integer- and the RationalFormulaManager both return the same Formulas for numeric operations like ADD, SUBTRACT, TIMES, LESSTHAN, EQUAL and others.- Throws:
UnsupportedOperationException- If the theory is not supported by the solver.
-
getRationalFormulaManager
RationalFormulaManager getRationalFormulaManager()
Returns the Rational-Theory. Because most SAT-solvers support automatic casting between Integer- and Rational-Theory, the Integer- and the RationalFormulaManager both return the same Formulas for numeric operations like ADD, SUBTRACT, TIMES, LESSTHAN, EQUAL, etc.- Throws:
UnsupportedOperationException- If the theory is not supported by the solver.
-
getBooleanFormulaManager
BooleanFormulaManager getBooleanFormulaManager()
Returns the Boolean-Theory.
-
getArrayFormulaManager
ArrayFormulaManager getArrayFormulaManager()
Returns the Array-Theory.- Throws:
UnsupportedOperationException- If the theory is not supported by the solver.
-
getBitvectorFormulaManager
BitvectorFormulaManager getBitvectorFormulaManager()
Returns the Bitvector-Theory.- Throws:
UnsupportedOperationException- If the theory is not supported by the solver.
-
getFloatingPointFormulaManager
FloatingPointFormulaManager getFloatingPointFormulaManager()
Returns the Floating-Point-Theory.- Throws:
UnsupportedOperationException- If the theory is not supported by the solver.
-
getUFManager
UFManager getUFManager()
Returns the function for dealing with uninterpreted functions (UFs).
-
getSLFormulaManager
SLFormulaManager getSLFormulaManager()
Returns the Seperation-Logic-Theory.- Throws:
UnsupportedOperationException- If the theory is not supported by the solver.
-
getQuantifiedFormulaManager
QuantifiedFormulaManager getQuantifiedFormulaManager()
Returns the interface for handling quantifiers.- Throws:
UnsupportedOperationException- If the theory is not supported by the solver.
-
makeVariable
<T extends Formula> T makeVariable(FormulaType<T> formulaType, String name)
Create variable of the type equal toformulaType.- Parameters:
formulaType- the type of the variable.name- the name of the variable.- Returns:
- the created variable.
-
makeApplication
<T extends Formula> T makeApplication(FunctionDeclaration<T> declaration, List<? extends Formula> args)
Create a function application to the given list of arguments.- Parameters:
declaration- Function declarationargs- List of arguments- Returns:
- Constructed formula
-
makeApplication
<T extends Formula> T makeApplication(FunctionDeclaration<T> declaration, Formula... args)
Create a function application to the given list of arguments.- Parameters:
declaration- Function declarationargs- List of arguments- Returns:
- Constructed formula
-
getFormulaType
<T extends Formula> FormulaType<T> getFormulaType(T formula)
Returns the type of the given Formula.
-
parse
BooleanFormula parse(String s) throws IllegalArgumentException
Parse a boolean formula given as a String in an SMT-LIB file format.- Returns:
- The same formula in the internal representation.
- Throws:
IllegalArgumentException- If the string cannot be parsed.
-
dumpFormula
Appender dumpFormula(BooleanFormula pT)
Serialize an input formula to an SMT-LIB format. Very useful when passing formulas between different solvers.To get a String, simply call
Object.toString()on the returned object. This method is lazy and does not create an output string until the returned object is actually used.- Returns:
- SMT-LIB formula serialization.
-
applyTactic
BooleanFormula applyTactic(BooleanFormula input, Tactic tactic) throws InterruptedException
Apply a tactic which performs formula transformation. The available tactics depend on the used solver.- Throws:
InterruptedException
-
simplify
<T extends Formula> T simplify(T input) throws InterruptedException
Simplify an input formula, while ensuring equivalence.For solvers that do not provide a simplification API, an original formula is returned.
- Parameters:
input- The input formula- Returns:
- Simplified version of the formula
- Throws:
InterruptedException
-
visit
@CanIgnoreReturnValue <R> R visit(Formula f, FormulaVisitor<R> rFormulaVisitor)
Visit the formula with a given visitor.
-
visitRecursively
void visitRecursively(Formula f, FormulaVisitor<TraversalProcess> rFormulaVisitor)
Visit the formula recursively with a givenFormulaVisitor.This method guarantees that the traversal is done iteratively, without using Java recursion, and thus is not prone to StackOverflowErrors.
Furthermore, this method also guarantees that every equal part of the formula is visited only once. Thus it can be used to traverse DAG-like formulas efficiently.
-
transformRecursively
<T extends Formula> T transformRecursively(T f, FormulaTransformationVisitor pFormulaVisitor)
Visit the formula recursively with a givenFormulaVisitor.This method guarantees that the traversal is done iteratively, without using Java recursion, and thus is not prone to StackOverflowErrors.
Furthermore, this method also guarantees that every equal part of the formula is visited only once. Thus it can be used to traverse DAG-like formulas efficiently.
- Parameters:
pFormulaVisitor- Transformation described by the user.
-
extractVariables
Map<String,Formula> extractVariables(Formula f)
Extract the names of all free variables and UFs in a formula.- Parameters:
f- The input formula- Returns:
- Map from variable names to the corresponding formulas.
-
extractVariablesAndUFs
Map<String,Formula> extractVariablesAndUFs(Formula f)
Extract the names of all free variables and UFs in a formula.- Parameters:
f- The input formula- Returns:
- Map from variable names to the corresponding formulas. If an UF occurs multiple times in the input formula, an arbitrary instance of an application of this UF is in the map.
-
substitute
<T extends Formula> T substitute(T f, Map<? extends Formula,? extends Formula> fromToMapping)
Substitute every occurrence of any item fromchangeFromin formulafto the corresponding occurrence fromchangeTo.E.g. if
changeFromcontains a variableaandchangeTocontains a variableball occurrences ofawill be changed tobin the returned formula.- Parameters:
f- Formula to change.fromToMapping- Mapping of old and new formula parts.- Returns:
- Formula with parts replaced.
-
translateFrom
BooleanFormula translateFrom(BooleanFormula formula, FormulaManager otherContext)
Translates the formula from another context into the context represented bythis. Default implementation relies on string serialization (dumpFormula(BooleanFormula)andparse(String)), but each solver may implement more efficient translation between its own contexts.- Parameters:
formula- Formula belonging tootherContext.otherContext- Formula manager belonging to the other context.- Returns:
- Formula belonging to
thiscontext.
-
isValidName
boolean isValidName(String variableName)
Check whether the given String can be used as symbol/name for variables or undefined functions.We explicitly state that with further development of SMT solvers and the SMTLib specification, the list of forbidden variable names may change in the future. Users should if possible not use logical or mathematical operators, or keywords strongly depending on SMTlib.
If a variable name is rejected, a possibility is escaping, e.g. either substituting the whole variable name or just every invalid character with an escaped form. We recommend to use an escape sequence based on the token "JAVASMT", because it might be unusual enough to appear when encoding a user's problem in SMT. Please not that you might also have to handle escaping the escape sequence. Examples:
- the invalid variable name
"="(logical operator for equality) can be replaced with a string"JAVASMT_EQUALS". - the invalid SMTlib-escaped variable name
"|test|"(the solver SMTInterpol does not allow the pipe symbol"|"in names) can be replaced with"JAVASMT_PIPEtestJAVASMT_PIPE".
- the invalid variable name
-
escape
String escape(String variableName)
Get an escaped symbol/name for variables or undefined functions, if necessary.See
isValidName(String)for further details.
-
unescape
String unescape(String variableName)
Unescape the symbol/name for variables or undefined functions, if necessary.The result is undefined for Strings that are not properly escaped.
See
isValidName(String)for further details.
-
-