Class SimpleReasoner
- All Implemented Interfaces:
Reasoner
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionassumptionAsInterval(SymbolicConstant symbolicConstant) If the context can be represented as a simple interval constraint, i.e., an expression of the form A <= x <= B, where A and B are concrete numbers, x is the given symbolic constant, and <= could be < in either case, this returns the interval [A,B] (or (A,B], or, ...).booleancheckBigOClaim(BooleanExpression indexConstraint, NumericExpression lhs, NumericSymbolicConstant[] limitVars, int[] orders) Attempts to prove a uniform "Big-O" claim.In the process of simplifying the initial context, this simplifier may have "solved" for some of the symbolic constants occurring in the context.extractNumber(NumericExpression expression) If the given expression can be reduced to a concrete numeric value using the context, returns that concrete value, else returns null.Returns the full context associated to this Reasoner.Returns the reduced context associated to this Reasoner.Returns an interval over-approximation of the given expression.booleanisValid(BooleanExpression predicate) Equivalent tovalid(predicate).getResultType()==ResultType.YES.simplify(BooleanExpression expression) Simplifies the given boolean expression.simplify(NumericExpression expression) Simplifies the given numeric expression.simplify(SymbolicExpression expression) Simplify the given expression under the context.universe()unsat(BooleanExpression predicate) Attempts to determine whether the statement p(x) && q(x) is unsatisfiable.valid(BooleanExpression predicate) Attempts to determine whether the statement p(x)=>q(x) is a tautology.validOrModel(BooleanExpression predicate) Attempts to determine whether p(x)=>q(x) is valid, and, if not, also returns a model (counter-example).
-
Constructor Details
-
SimpleReasoner
-
-
Method Details
-
universe
-
getReducedContext
Description copied from interface:ReasonerReturns the reduced context associated to this Reasoner. This expression may differ from the original one used to create the Reasoner because it was simplified or put into a canonical form. Moreover, symbolic constants which have been "solved" may be removed from the context. (For the context with additional equations giving those solved values, use methodReasoner.getFullContext()). This context will not change after creation.- Specified by:
getReducedContextin interfaceReasoner- Returns:
- the reduced context associated to this Reasoner
-
getFullContext
Description copied from interface:ReasonerReturns the full context associated to this Reasoner. This expression may differ from the original one used to create the Reasoner because it was simplified or put into a canonical form. The full context includes equations where one side is a symbolic constant and the other is the solved value. (For the context without those equations, use methodReasoner.getReducedContext()). Hence the expression returned is equivalent to the original given expression. This context will not change after creation.- Specified by:
getFullContextin interfaceReasoner- Returns:
- the reduced context associated to this Reasoner
-
assumptionAsInterval
Description copied from interface:ReasonerIf the context can be represented as a simple interval constraint, i.e., an expression of the form A <= x <= B, where A and B are concrete numbers, x is the given symbolic constant, and <= could be < in either case, this returns the interval [A,B] (or (A,B], or, ...). Else returns null.- Specified by:
assumptionAsIntervalin interfaceReasoner- Parameters:
symbolicConstant- the variable s around which the context may be expressed as an interval constraint- Returns:
- the interval constraint or null
-
simplify
Description copied from interface:ReasonerSimplify the given expression under the context. The simplified expression is guaranteed to be equivalent to the given one under the context. I.e., if p and q are the two expressions, and c is the context, then given any assignment of concrete values to symbolic constants for which c holds, p and q will evaluate to the same concrete value.
Note that the expression can have any type, including array, function, tuple, etc. The simplified expression may have a different type, but the new type is guaranteed to be equivalent to the original under the context. For example, if the given expression has type int[N] (array of int of length N), the simplified expression might have type int[3] (e.g., if the context was "N=3").
Example:
given context: N>=0 && N>=1 simplified context: N>=1 result of simplify (N>=1) : true result of simplify (N>=2) : N>=2 result of simplify (N<0) : false
-
simplify
Description copied from interface:ReasonerSimplifies the given boolean expression. Result is same as that ofReasoner.simplify(SymbolicExpression), but this saves you the trouble of casting toBooleanExpression. -
simplify
Description copied from interface:ReasonerSimplifies the given numeric expression. Result is same as that ofReasoner.simplify(SymbolicExpression), but this saves you the trouble of casting toNumericExpression. -
valid
Description copied from interface:ReasonerAttempts to determine whether the statement p(x)=>q(x) is a tautology. Here, p is the "assumption", q is the "predicate", and x stands for the set of all symbolic constants which occur in p or q.
A result of YES implies forall x.(p(x)=>q(x)). A result of NO implies nsat(p)||exists x.(p(x)&&!q(x)). Nothing can be concluded from a result of MAYBE.
nsat(p) means p is not satisfiable, i.e., forall x.!p(x), or equivalently !exists x.p(x). Note that if p is not satisfiable then any of the three possible results could be returned.
Consider a call to valid(true,q). If this returns YES then forall x.q(x) (i.e., q is a tautology). If it returns NO then exists x.!q(x) (i.e., q is not a tautology).
Consider a call to valid(true,!q). If this returns YES then q is not satisfiable. If it returns no, then q is satisfiable.
-
validOrModel
Description copied from interface:ReasonerAttempts to determine whether p(x)=>q(x) is valid, and, if not, also returns a model (counter-example). The specification is exactly the same as for
Reasoner.valid(edu.udel.cis.vsl.sarl.IF.expr.BooleanExpression), except that aValidityResultis returned. This provides a methodValidityResult.getResultType()that returns the result type, but also a methodModelResult.getModel()that provides the model. That method will return null if the result type is YES or MAYBE. It may return null even if the result type is NO, either because the assumption is not satisfiable or a model could not be found for some reason.If the model is non-null, it will be a map in which the key set consists of all the symbolic constants of non-function type that occur in the assumption or predicate. The value associated to a key will be a concrete symbolic expression.
- Specified by:
validOrModelin interfaceReasoner- Parameters:
predicate- the predicate q(x)- Returns:
- a validity result as specified above
-
constantSubstitutionMap
Description copied from interface:ReasonerIn the process of simplifying the initial context, this simplifier may have "solved" for some of the symbolic constants occurring in the context. This method returns a map in which the keys are those symbolic constants and the value associated to a key is the "solved" value. The solved value will be substituted for the symbolic constants in any expression given to theReasoner.simplify(edu.udel.cis.vsl.sarl.IF.expr.SymbolicExpression)method of this simplifier.- Specified by:
constantSubstitutionMapin interfaceReasoner- Returns:
- a mapping from some symbolic constants occurring in original context to their solved values
-
isValid
Description copied from interface:ReasonerEquivalent tovalid(predicate).getResultType()==ResultType.YES. -
extractNumber
Description copied from interface:ReasonerIf the given expression can be reduced to a concrete numeric value using the context, returns that concrete value, else returns null.- Specified by:
extractNumberin interfaceReasoner- Parameters:
expression- any numeric expression- Returns:
- the concrete (Number) numeric value of that expression or null
-
intervalApproximation
Description copied from interface:ReasonerReturns an interval over-approximation of the given expression. It is guaranteed that under this reasoner's context, any value taken on by the expression must be contained in the interval returned. The interval returned will have the same type as the expression.- Specified by:
intervalApproximationin interfaceReasoner- Parameters:
expr- the numeric expression (either integer or real type)- Returns:
- an interval which contains all possible values the expression may assume under the context of this reasoner
-
checkBigOClaim
public boolean checkBigOClaim(BooleanExpression indexConstraint, NumericExpression lhs, NumericSymbolicConstant[] limitVars, int[] orders) Description copied from interface:ReasonerAttempts to prove a uniform "Big-O" claim. The claim has the following form:
lhs = O(h1^n1) + ... + O(hk^nk)
Here, lhs or "left hand side expression" is an expression of real type. The h1, ..., hk or "limit variables" are symbolic constants of real type, the variables that are tending towards 0. The n1, ..., nk the corresponding "orders" of the limit variables; they are are concrete nonnegative integers.The lhs may involve the hi and also other free variables; typically these will be index variables for indexing into arrays. Assumptions on any of these can be included in the
constraintargument.- Specified by:
checkBigOClaimin interfaceReasoner- Parameters:
indexConstraint- any additional constraint (beyond the context) you want to assume when checking the claim; typically range constraints on index variableslhs- the left hand side expression, an expression of real type involving any or all of the symbolic constants mentioned, as well as otherslimitVars- the limit variables; an array of length korders- the orders of the limit variables; the length must be the same as the length oflimitVars(k)- Returns:
trueif the O-claim can be proved. Afalseresult does not mean the O-claim is false, it just means it could not be proved
-
unsat
Description copied from interface:ReasonerAttempts to determine whether the statement p(x) && q(x) is unsatisfiable. Here, p is the "context", q is the "predicate", and x stands for the set of all symbolic constants which occur in p or q.
A result of type YES implies
forall x. !(p(x) && q(x)). A result of NO impliesexists x. p(x)&&q(x). Nothing can be concluded from a result of MAYBE.- Specified by:
unsatin interfaceReasoner- Parameters:
predicate- the boolean expression q(x)- Returns:
- a
ValidityResultwhose type must satisfy the constraints described above
-