Class AbstractNumeralFormulaManager<TFormulaInfo,TType,TEnv,ParamFormulaType extends NumeralFormula,ResultFormulaType extends NumeralFormula,TFuncDecl>
- java.lang.Object
-
- org.sosy_lab.java_smt.basicimpl.AbstractNumeralFormulaManager<TFormulaInfo,TType,TEnv,ParamFormulaType,ResultFormulaType,TFuncDecl>
-
- All Implemented Interfaces:
NumeralFormulaManager<ParamFormulaType,ResultFormulaType>
public abstract class AbstractNumeralFormulaManager<TFormulaInfo,TType,TEnv,ParamFormulaType extends NumeralFormula,ResultFormulaType extends NumeralFormula,TFuncDecl> extends Object implements NumeralFormulaManager<ParamFormulaType,ResultFormulaType>
Similar to the other Abstract*FormulaManager classes in this package, this class serves as a helper for implementingNumeralFormulaManager. It handles all the unwrapping and wrapping fromFormulainstances to solver-specific formula representations, such that the concrete class needs to handle only its own internal types.- Implementation Requirements:
- The method
NumeralFormulaManager.getFormulaType()must be safe to be called from the constructor (the default implementations ofIntegerFormulaManagerandRationalFormulaManagersatisfy this).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAbstractNumeralFormulaManager.NonLinearArithmetic
-
Field Summary
Fields Modifier and Type Field Description protected FormulaCreator<TFormulaInfo,TType,TEnv,TFuncDecl>formulaCreator
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractNumeralFormulaManager(FormulaCreator<TFormulaInfo,TType,TEnv,TFuncDecl> pCreator, AbstractNumeralFormulaManager.NonLinearArithmetic pNonLinearArithmetic)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description ResultFormulaTypeadd(ParamFormulaType pNumber1, ParamFormulaType pNumber2)protected abstract TFormulaInfoadd(TFormulaInfo pParam1, TFormulaInfo pParam2)protected TFormulaInfodecimalAsInteger(BigDecimal val)This method tries to represent a BigDecimal using only BigInteger.BooleanFormuladistinct(List<ParamFormulaType> pNumbers)All given numbers are pairwise unequal.protected abstract TFormulaInfodistinctImpl(List<TFormulaInfo> pNumbers)ResultFormulaTypedivide(ParamFormulaType pNumber1, ParamFormulaType pNumber2)Create a formula representing the division of two operands according to Boute's Euclidean definition (DOI: 10.1145/128861.128862).protected TFormulaInfodivide(TFormulaInfo pParam1, TFormulaInfo pParam2)If a solver does not support this operation, e.g.BooleanFormulaequal(ParamFormulaType pNumber1, ParamFormulaType pNumber2)protected abstract TFormulaInfoequal(TFormulaInfo pParam1, TFormulaInfo pParam2)protected TFormulaInfoextractInfo(Formula pBits)NumeralFormula.IntegerFormulafloor(ParamFormulaType number)Theflooroperation returns the nearest integer formula that is less or equal to the given argument formula.protected TFormulaInfofloor(TFormulaInfo number)protected FormulaCreator<TFormulaInfo,TType,TEnv,TFuncDecl>getFormulaCreator()BooleanFormulagreaterOrEquals(ParamFormulaType pNumber1, ParamFormulaType pNumber2)protected abstract TFormulaInfogreaterOrEquals(TFormulaInfo pParam1, TFormulaInfo pParam2)BooleanFormulagreaterThan(ParamFormulaType pNumber1, ParamFormulaType pNumber2)protected abstract TFormulaInfogreaterThan(TFormulaInfo pParam1, TFormulaInfo pParam2)protected abstract booleanisNumeral(TFormulaInfo val)Check whether the argument is a numeric constant (including negated constants).BooleanFormulalessOrEquals(ParamFormulaType pNumber1, ParamFormulaType pNumber2)protected abstract TFormulaInfolessOrEquals(TFormulaInfo pParam1, TFormulaInfo pParam2)BooleanFormulalessThan(ParamFormulaType pNumber1, ParamFormulaType pNumber2)protected abstract TFormulaInfolessThan(TFormulaInfo pParam1, TFormulaInfo pParam2)ResultFormulaTypemakeNumber(double pNumber)Create a numeric literal with a given value.ResultFormulaTypemakeNumber(long i)ResultFormulaTypemakeNumber(String i)ResultFormulaTypemakeNumber(BigDecimal pNumber)Create a numeric literal with a given value.ResultFormulaTypemakeNumber(BigInteger i)ResultFormulaTypemakeNumber(Rational pRational)protected abstract TFormulaInfomakeNumberImpl(double pNumber)protected abstract TFormulaInfomakeNumberImpl(long i)protected abstract TFormulaInfomakeNumberImpl(String i)protected abstract TFormulaInfomakeNumberImpl(BigDecimal pNumber)protected abstract TFormulaInfomakeNumberImpl(BigInteger i)protected TFormulaInfomakeNumberImpl(Rational pRational)ResultFormulaTypemakeVariable(String pVar)Creates a variable with exactly the given name.protected abstract TFormulaInfomakeVariableImpl(String i)BooleanFormulamodularCongruence(ParamFormulaType pNumber1, ParamFormulaType pNumber2, long pModulo)BooleanFormulamodularCongruence(ParamFormulaType pNumber1, ParamFormulaType pNumber2, BigInteger pModulo)protected TFormulaInfomodularCongruence(TFormulaInfo a, TFormulaInfo b, long m)protected TFormulaInfomodularCongruence(TFormulaInfo a, TFormulaInfo b, BigInteger m)ResultFormulaTypemodulo(ParamFormulaType pNumber1, ParamFormulaType pNumber2)protected TFormulaInfomodulo(TFormulaInfo pParam1, TFormulaInfo pParam2)If a solver does not support this operation, e.g.ResultFormulaTypemultiply(ParamFormulaType pNumber1, ParamFormulaType pNumber2)protected TFormulaInfomultiply(TFormulaInfo pParam1, TFormulaInfo pParam2)If a solver does not support this operation, e.g.ResultFormulaTypenegate(ParamFormulaType pNumber)protected abstract TFormulaInfonegate(TFormulaInfo pParam1)ResultFormulaTypesubtract(ParamFormulaType pNumber1, ParamFormulaType pNumber2)protected abstract TFormulaInfosubtract(TFormulaInfo pParam1, TFormulaInfo pParam2)ResultFormulaTypesum(List<ParamFormulaType> operands)protected TFormulaInfosumImpl(List<TFormulaInfo> operands)protected TTypetoSolverType(FormulaType<?> formulaType)protected TFormulaInfotoType(TFormulaInfo param)Make sure the value is of correct type (Int vs.protected ResultFormulaTypewrap(TFormulaInfo pTerm)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.sosy_lab.java_smt.api.NumeralFormulaManager
getFormulaType
-
-
-
-
Field Detail
-
formulaCreator
protected final FormulaCreator<TFormulaInfo,TType,TEnv,TFuncDecl> formulaCreator
-
-
Constructor Detail
-
AbstractNumeralFormulaManager
protected AbstractNumeralFormulaManager(FormulaCreator<TFormulaInfo,TType,TEnv,TFuncDecl> pCreator, AbstractNumeralFormulaManager.NonLinearArithmetic pNonLinearArithmetic)
-
-
Method Detail
-
wrap
protected ResultFormulaType wrap(TFormulaInfo pTerm)
-
isNumeral
protected abstract boolean isNumeral(TFormulaInfo val)
Check whether the argument is a numeric constant (including negated constants).
-
makeNumber
public ResultFormulaType makeNumber(long i)
- Specified by:
makeNumberin interfaceNumeralFormulaManager<TFormulaInfo,TType>
-
makeNumberImpl
protected abstract TFormulaInfo makeNumberImpl(long i)
-
makeNumber
public ResultFormulaType makeNumber(BigInteger i)
- Specified by:
makeNumberin interfaceNumeralFormulaManager<TFormulaInfo,TType>
-
makeNumberImpl
protected abstract TFormulaInfo makeNumberImpl(BigInteger i)
-
makeNumber
public ResultFormulaType makeNumber(String i)
- Specified by:
makeNumberin interfaceNumeralFormulaManager<TFormulaInfo,TType>
-
makeNumberImpl
protected abstract TFormulaInfo makeNumberImpl(String i)
-
makeNumber
public ResultFormulaType makeNumber(Rational pRational)
- Specified by:
makeNumberin interfaceNumeralFormulaManager<TFormulaInfo,TType>
-
makeNumberImpl
protected TFormulaInfo makeNumberImpl(Rational pRational)
-
makeNumber
public ResultFormulaType makeNumber(double pNumber)
Description copied from interface:NumeralFormulaManagerCreate a numeric literal with a given value. Note: if the theory represented by this instance cannot handle rational numbers, the value may get rounded or otherwise represented imprecisely.- Specified by:
makeNumberin interfaceNumeralFormulaManager<TFormulaInfo,TType>
-
makeNumberImpl
protected abstract TFormulaInfo makeNumberImpl(double pNumber)
-
makeNumber
public ResultFormulaType makeNumber(BigDecimal pNumber)
Description copied from interface:NumeralFormulaManagerCreate a numeric literal with a given value. Note: if the theory represented by this instance cannot handle rational numbers, the value may get rounded or otherwise represented imprecisely.- Specified by:
makeNumberin interfaceNumeralFormulaManager<TFormulaInfo,TType>
-
makeNumberImpl
protected abstract TFormulaInfo makeNumberImpl(BigDecimal pNumber)
-
decimalAsInteger
protected final TFormulaInfo decimalAsInteger(BigDecimal val)
This method tries to represent a BigDecimal using only BigInteger. It can be used for implementingmakeNumber(BigDecimal)when the current theory supports only integers and division by constants.
-
makeVariable
public ResultFormulaType makeVariable(String pVar)
Description copied from interface:NumeralFormulaManagerCreates a variable with exactly the given name.Please make sure that the given name is valid in SMT-LIB2. Take a look at
FormulaManager.isValidName(java.lang.String)for further information.This method does not quote or unquote the given name, but uses the plain name "AS IS".
Formula.toString()can return a different String than the given one.- Specified by:
makeVariablein interfaceNumeralFormulaManager<TFormulaInfo,TType>
-
makeVariableImpl
protected abstract TFormulaInfo makeVariableImpl(String i)
-
negate
public ResultFormulaType negate(ParamFormulaType pNumber)
- Specified by:
negatein interfaceNumeralFormulaManager<TFormulaInfo,TType>
-
negate
protected abstract TFormulaInfo negate(TFormulaInfo pParam1)
-
add
public ResultFormulaType add(ParamFormulaType pNumber1, ParamFormulaType pNumber2)
- Specified by:
addin interfaceNumeralFormulaManager<TFormulaInfo,TType>
-
add
protected abstract TFormulaInfo add(TFormulaInfo pParam1, TFormulaInfo pParam2)
-
sum
public ResultFormulaType sum(List<ParamFormulaType> operands)
- Specified by:
sumin interfaceNumeralFormulaManager<TFormulaInfo,TType>
-
sumImpl
protected TFormulaInfo sumImpl(List<TFormulaInfo> operands)
-
subtract
public ResultFormulaType subtract(ParamFormulaType pNumber1, ParamFormulaType pNumber2)
- Specified by:
subtractin interfaceNumeralFormulaManager<TFormulaInfo,TType>
-
subtract
protected abstract TFormulaInfo subtract(TFormulaInfo pParam1, TFormulaInfo pParam2)
-
divide
public ResultFormulaType divide(ParamFormulaType pNumber1, ParamFormulaType pNumber2)
Description copied from interface:NumeralFormulaManagerCreate a formula representing the division of two operands according to Boute's Euclidean definition (DOI: 10.1145/128861.128862).If the denominator evaluates to zero (division-by-zero), either directly as value or indirectly via an additional constraint, then the solver is allowed to choose an arbitrary value for the result of the division (cf. SMTLib standard version 2.6 for the division operator in Int or Real theory). The details of this are implementation specific and may change solver by solver.
Note: Some solvers, e.g., Yices2, abort with an exception when exploring a division-by-zero during the SAT-check. This is not compliant to the SMTLIB standard, but sadly happens.
- Specified by:
dividein interfaceNumeralFormulaManager<TFormulaInfo,TType>
-
divide
protected TFormulaInfo divide(TFormulaInfo pParam1, TFormulaInfo pParam2)
If a solver does not support this operation, e.g. because of missing support for non-linear arithmetics, we throw UnsupportedOperationException.- Parameters:
pParam1- the dividendpParam2- the divisor
-
modulo
public ResultFormulaType modulo(ParamFormulaType pNumber1, ParamFormulaType pNumber2)
-
modulo
protected TFormulaInfo modulo(TFormulaInfo pParam1, TFormulaInfo pParam2)
If a solver does not support this operation, e.g. because of missing support for non-linear arithmetics, we throw UnsupportedOperationException.- Parameters:
pParam1- the dividendpParam2- the divisor
-
modularCongruence
public BooleanFormula modularCongruence(ParamFormulaType pNumber1, ParamFormulaType pNumber2, long pModulo)
-
modularCongruence
public BooleanFormula modularCongruence(ParamFormulaType pNumber1, ParamFormulaType pNumber2, BigInteger pModulo)
-
modularCongruence
protected TFormulaInfo modularCongruence(TFormulaInfo a, TFormulaInfo b, BigInteger m)
- Parameters:
a- first operandb- second operandm- the modulus- Returns:
- the formula representing
a = b (mod m)
-
modularCongruence
protected TFormulaInfo modularCongruence(TFormulaInfo a, TFormulaInfo b, long m)
- Parameters:
a- first operandb- second operandm- the modulus- Returns:
- the formula representing
a = b (mod m)
-
multiply
public ResultFormulaType multiply(ParamFormulaType pNumber1, ParamFormulaType pNumber2)
- Specified by:
multiplyin interfaceNumeralFormulaManager<TFormulaInfo,TType>
-
multiply
protected TFormulaInfo multiply(TFormulaInfo pParam1, TFormulaInfo pParam2)
If a solver does not support this operation, e.g. because of missing support for non-linear arithmetics, we throw UnsupportedOperationException.- Parameters:
pParam1- first factorpParam2- second factor
-
equal
public BooleanFormula equal(ParamFormulaType pNumber1, ParamFormulaType pNumber2)
- Specified by:
equalin interfaceNumeralFormulaManager<TFormulaInfo,TType>
-
equal
protected abstract TFormulaInfo equal(TFormulaInfo pParam1, TFormulaInfo pParam2)
-
distinct
public BooleanFormula distinct(List<ParamFormulaType> pNumbers)
Description copied from interface:NumeralFormulaManagerAll given numbers are pairwise unequal.- Specified by:
distinctin interfaceNumeralFormulaManager<TFormulaInfo,TType>
-
distinctImpl
protected abstract TFormulaInfo distinctImpl(List<TFormulaInfo> pNumbers)
-
greaterThan
public BooleanFormula greaterThan(ParamFormulaType pNumber1, ParamFormulaType pNumber2)
- Specified by:
greaterThanin interfaceNumeralFormulaManager<TFormulaInfo,TType>
-
greaterThan
protected abstract TFormulaInfo greaterThan(TFormulaInfo pParam1, TFormulaInfo pParam2)
-
greaterOrEquals
public BooleanFormula greaterOrEquals(ParamFormulaType pNumber1, ParamFormulaType pNumber2)
- Specified by:
greaterOrEqualsin interfaceNumeralFormulaManager<TFormulaInfo,TType>
-
greaterOrEquals
protected abstract TFormulaInfo greaterOrEquals(TFormulaInfo pParam1, TFormulaInfo pParam2)
-
lessThan
public BooleanFormula lessThan(ParamFormulaType pNumber1, ParamFormulaType pNumber2)
- Specified by:
lessThanin interfaceNumeralFormulaManager<TFormulaInfo,TType>
-
lessThan
protected abstract TFormulaInfo lessThan(TFormulaInfo pParam1, TFormulaInfo pParam2)
-
lessOrEquals
public BooleanFormula lessOrEquals(ParamFormulaType pNumber1, ParamFormulaType pNumber2)
- Specified by:
lessOrEqualsin interfaceNumeralFormulaManager<TFormulaInfo,TType>
-
lessOrEquals
protected abstract TFormulaInfo lessOrEquals(TFormulaInfo pParam1, TFormulaInfo pParam2)
-
floor
public NumeralFormula.IntegerFormula floor(ParamFormulaType number)
Description copied from interface:NumeralFormulaManagerTheflooroperation returns the nearest integer formula that is less or equal to the given argument formula.For rational formulas, SMTlib2 denotes this operation as
to_int.- Specified by:
floorin interfaceNumeralFormulaManager<TFormulaInfo,TType>
-
floor
protected TFormulaInfo floor(TFormulaInfo number)
-
toType
protected TFormulaInfo toType(TFormulaInfo param)
Make sure the value is of correct type (Int vs. Real) and add a cast if necessary.
-
getFormulaCreator
protected final FormulaCreator<TFormulaInfo,TType,TEnv,TFuncDecl> getFormulaCreator()
-
extractInfo
protected final TFormulaInfo extractInfo(Formula pBits)
-
toSolverType
protected final TType toSolverType(FormulaType<?> formulaType)
-
-