Class DebuggingFormulaManager
- java.lang.Object
-
- org.sosy_lab.java_smt.delegate.debugging.DebuggingFormulaManager
-
- All Implemented Interfaces:
FormulaManager
public class DebuggingFormulaManager extends Object implements FormulaManager
-
-
Method Summary
All Methods Instance Methods Concrete 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.ImmutableMap<String,Formula>extractVariables(Formula f)Extract the names of all free variables and UFs in a formula.ImmutableMap<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.EnumerationFormulaManagergetEnumerationFormulaManager()Returns the Enumeration Theory, e.g., also known as 'limited domain'.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.StringFormulaManagergetStringFormulaManager()Returns the String 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 SMTLIB 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 otherManager)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
public IntegerFormulaManager getIntegerFormulaManager()
Description copied from interface:FormulaManagerReturns 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.- Specified by:
getIntegerFormulaManagerin interfaceFormulaManager
-
getRationalFormulaManager
public RationalFormulaManager getRationalFormulaManager()
Description copied from interface:FormulaManagerReturns 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.- Specified by:
getRationalFormulaManagerin interfaceFormulaManager
-
getBooleanFormulaManager
public BooleanFormulaManager getBooleanFormulaManager()
Description copied from interface:FormulaManagerReturns the Boolean-Theory.- Specified by:
getBooleanFormulaManagerin interfaceFormulaManager
-
getArrayFormulaManager
public ArrayFormulaManager getArrayFormulaManager()
Description copied from interface:FormulaManagerReturns the Array-Theory.- Specified by:
getArrayFormulaManagerin interfaceFormulaManager
-
getBitvectorFormulaManager
public BitvectorFormulaManager getBitvectorFormulaManager()
Description copied from interface:FormulaManagerReturns the Bitvector-Theory.- Specified by:
getBitvectorFormulaManagerin interfaceFormulaManager
-
getFloatingPointFormulaManager
public FloatingPointFormulaManager getFloatingPointFormulaManager()
Description copied from interface:FormulaManagerReturns the Floating-Point-Theory.- Specified by:
getFloatingPointFormulaManagerin interfaceFormulaManager
-
getUFManager
public UFManager getUFManager()
Description copied from interface:FormulaManagerReturns the function for dealing with uninterpreted functions (UFs).- Specified by:
getUFManagerin interfaceFormulaManager
-
getSLFormulaManager
public SLFormulaManager getSLFormulaManager()
Description copied from interface:FormulaManagerReturns the Seperation-Logic-Theory.- Specified by:
getSLFormulaManagerin interfaceFormulaManager
-
getQuantifiedFormulaManager
public QuantifiedFormulaManager getQuantifiedFormulaManager()
Description copied from interface:FormulaManagerReturns the interface for handling quantifiers.- Specified by:
getQuantifiedFormulaManagerin interfaceFormulaManager
-
getStringFormulaManager
public StringFormulaManager getStringFormulaManager()
Description copied from interface:FormulaManagerReturns the String Theory.- Specified by:
getStringFormulaManagerin interfaceFormulaManager
-
getEnumerationFormulaManager
public EnumerationFormulaManager getEnumerationFormulaManager()
Description copied from interface:FormulaManagerReturns the Enumeration Theory, e.g., also known as 'limited domain'.- Specified by:
getEnumerationFormulaManagerin interfaceFormulaManager
-
makeVariable
public <T extends Formula> T makeVariable(FormulaType<T> formulaType, String name)
Description copied from interface:FormulaManagerCreate variable of the type equal toformulaType.- Specified by:
makeVariablein interfaceFormulaManager- Parameters:
formulaType- the type of the variable.name- the name of the variable.- Returns:
- the created variable.
-
makeApplication
public <T extends Formula> T makeApplication(FunctionDeclaration<T> declaration, List<? extends Formula> args)
Description copied from interface:FormulaManagerCreate a function application to the given list of arguments.- Specified by:
makeApplicationin interfaceFormulaManager- Parameters:
declaration- Function declarationargs- List of arguments- Returns:
- Constructed formula
-
makeApplication
public <T extends Formula> T makeApplication(FunctionDeclaration<T> declaration, Formula... args)
Description copied from interface:FormulaManagerCreate a function application to the given list of arguments.- Specified by:
makeApplicationin interfaceFormulaManager- Parameters:
declaration- Function declarationargs- List of arguments- Returns:
- Constructed formula
-
getFormulaType
public <T extends Formula> FormulaType<T> getFormulaType(T formula)
Description copied from interface:FormulaManagerReturns the type of the given Formula.- Specified by:
getFormulaTypein interfaceFormulaManager
-
parse
public BooleanFormula parse(String s) throws IllegalArgumentException
Description copied from interface:FormulaManagerParse a boolean formula given as a String in an SMTLIB file format. We expect exactly one assertion to be contained in the query.Example:
(declare-fun x () Int)(assert (= 0 x))It depends on the used SMT solver whether the given query must be self-contained and include declarations for all used symbols or not, and also whether the query is allowed to contain symbols with equal name, but different type/sort than existing symbols. The safest way is to always declare all used symbols and to avoid conflicting types for them.
The behavior of the SMT solver is undefined if commands are provided in the SMTLIB-based String that are different from declarations or an assertion, such as
push/poporset-info. Most solvers just ignore those commands.Variables that are defined, but not used in the assertion, might be ignored by the SMT solver, and they might not be available for later usage.
- Specified by:
parsein interfaceFormulaManager- Returns:
- A single formula from the assertion in the internal representation.
- Throws:
IllegalArgumentException- If the string cannot be parsed.
-
dumpFormula
public Appender dumpFormula(BooleanFormula pT)
Description copied from interface:FormulaManagerSerialize 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.- Specified by:
dumpFormulain interfaceFormulaManager- Returns:
- SMT-LIB formula serialization.
-
applyTactic
public BooleanFormula applyTactic(BooleanFormula input, Tactic tactic) throws InterruptedException, SolverException
Description copied from interface:FormulaManagerApply a tactic which performs formula transformation. The available tactics depend on the used solver.- Specified by:
applyTacticin interfaceFormulaManager- Throws:
InterruptedException- If the solver is interrupted.SolverException- If the solver fails to apply the tactic.
-
simplify
public <T extends Formula> T simplify(T input) throws InterruptedException
Description copied from interface:FormulaManagerSimplify an input formula, while ensuring equivalence.For solvers that do not provide a simplification API, an original formula is returned.
If the solver throws an error, we ignore the specific exception (except interrupts) and also return the original formula.
- Specified by:
simplifyin interfaceFormulaManager- Parameters:
input- The input formula- Returns:
- Simplified version of the formula
- Throws:
InterruptedException- If the solver is interrupted.
-
visit
public <R> R visit(Formula f, FormulaVisitor<R> rFormulaVisitor)
Description copied from interface:FormulaManagerVisit the formula with a given visitor.This method does not recursively visit subcomponents of a formula its own, so the given
FormulaVisitorneeds to call such visitation on its own.Please be aware that calling this method might cause extensive stack usage depending on the nesting of the given formula and the given
FormulaVisitor. Additionally, sub-formulas that are used several times in the formula might be visited several times. For an efficient formula traversing, we also provideFormulaManager.visitRecursively(Formula, FormulaVisitor).- Specified by:
visitin interfaceFormulaManager- Parameters:
f- formula to be visitedrFormulaVisitor- an implementation that provides steps for each kind of formula.
-
visitRecursively
public void visitRecursively(Formula f, FormulaVisitor<TraversalProcess> rFormulaVisitor)
Description copied from interface:FormulaManagerVisit the formula recursively with a givenFormulaVisitor. This method traverses subcomponents of a formula automatically, depending on the return value of theTraversalProcessin the 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.
The traversal is done in PRE-ORDER manner with regard to caching identical subtrees, i.e., a parent will be visited BEFORE its children. The unmodified child-formulas are passed as argument to the parent's visitation.
- Specified by:
visitRecursivelyin interfaceFormulaManager
-
transformRecursively
public <T extends Formula> T transformRecursively(T f, FormulaTransformationVisitor pFormulaVisitor)
Description copied from interface:FormulaManagerVisit 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.
The traversal is done in POST-ORDER manner with regard to caching identical subtrees, i.e., a parent will be visited AFTER its children. The result of the child-visitation is passed as argument to the parent's visitation.
- Specified by:
transformRecursivelyin interfaceFormulaManagerpFormulaVisitor- Transformation described by the user.
-
extractVariables
public ImmutableMap<String,Formula> extractVariables(Formula f)
Description copied from interface:FormulaManagerExtract the names of all free variables and UFs in a formula.- Specified by:
extractVariablesin interfaceFormulaManager- Parameters:
f- The input formula- Returns:
- Map from variable names to the corresponding formulas.
-
extractVariablesAndUFs
public ImmutableMap<String,Formula> extractVariablesAndUFs(Formula f)
Description copied from interface:FormulaManagerExtract the names of all free variables and UFs in a formula.- Specified by:
extractVariablesAndUFsin interfaceFormulaManager- 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
public <T extends Formula> T substitute(T f, Map<? extends Formula,? extends Formula> fromToMapping)
Description copied from interface:FormulaManagerSubstitute 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.- Specified by:
substitutein interfaceFormulaManager- Parameters:
f- Formula to change.fromToMapping- Mapping of old and new formula parts.- Returns:
- Formula with parts replaced.
-
translateFrom
public BooleanFormula translateFrom(BooleanFormula formula, FormulaManager otherManager)
Description copied from interface:FormulaManagerTranslates the formula from another context into the context represented bythis. Default implementation relies on string serialization (FormulaManager.dumpFormula(BooleanFormula)andFormulaManager.parse(String)), but each solver may implement more efficient translation between its own contexts.- Specified by:
translateFromin interfaceFormulaManager- Parameters:
formula- Formula belonging tootherContext.otherManager- Formula manager belonging to the other context.- Returns:
- Formula belonging to
thiscontext.
-
isValidName
public boolean isValidName(String variableName)
Description copied from interface:FormulaManagerCheck 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 using 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 note 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".
- Specified by:
isValidNamein interfaceFormulaManager
- the invalid variable name
-
escape
public String escape(String variableName)
Description copied from interface:FormulaManagerGet an escaped symbol/name for variables or undefined functions, if necessary.See
FormulaManager.isValidName(String)for further details.- Specified by:
escapein interfaceFormulaManager
-
unescape
public String unescape(String variableName)
Description copied from interface:FormulaManagerUnescape the symbol/name for variables or undefined functions, if necessary.The result is undefined for Strings that are not properly escaped.
See
FormulaManager.isValidName(String)for further details.- Specified by:
unescapein interfaceFormulaManager
-
-