public class Bounds extends Object
It records information about whether new bounds information has recently (since the last call to startAnalysis) been added. The implementation may even record which variables have recently changed, so that clients can decide whether or not it is worth re-analyzing a given FlatPred. TODO: the record of which variables have changed is not currently used. Before it is used, it needs to be updated so that it changes when aliases are added.
The constructor and the startAnalysis method both take a 'parent' object as a parameter, so that these bounds objects can be built into a tree, where each node of the tree stores the bounds information for a local scope such as within a quantifier, or within a disjunction. The startAnalysis method copies bounds information from the parent into the child, but additional bounds information added to the child does not flow back to the parent.
This class also counts the number of bounds deductions that it has detected (see the getDeductions method). Child Bounds objects typically add their deduction count to their parent, so that the count at the root of the Bounds tree gives the total number of deductions that have been made in the current pass. The general idea is to continue making passes until no further deductions are made in a pass, which shows that a fix-point has been reached.
Modifier and Type | Field and Description |
---|---|
protected int |
deductions_
The number of bounds deductions in this scope (and child scopes).
|
protected Bounds |
parent_ |
Constructor and Description |
---|
Bounds(Bounds parent)
Create a fresh Bounds object with no bounds values.
|
Modifier and Type | Method and Description |
---|---|
void |
addAlias(net.sourceforge.czt.z.ast.ZName var1,
net.sourceforge.czt.z.ast.ZName var2)
Add another alias for var.
|
void |
addConst(net.sourceforge.czt.z.ast.ZName name,
net.sourceforge.czt.z.ast.Expr value)
Add name=value to the bounds information.
|
void |
addDeductions(int count)
Increment the deductions counter by count.
|
boolean |
addLower(net.sourceforge.czt.z.ast.ZName var0,
BigInteger lower)
Adds another lower bound for var.
|
void |
addStructureArg(net.sourceforge.czt.z.ast.ZName var,
Object argPos,
net.sourceforge.czt.z.ast.ZName argName)
Record the fact that var is a structure, and the name of one of its
arguments (subcomponents).
|
boolean |
addUpper(net.sourceforge.czt.z.ast.ZName var0,
BigInteger upper)
Adds another upper bound for var.
|
boolean |
anyBoundsChanged(Collection<net.sourceforge.czt.z.ast.ZName> vars)
True iff the bounds of any name in vars have changed.
|
boolean |
boundsChanged()
True iff some tighter bounds information has been
deduced (or inherited from a parent) in this inference pass.
|
boolean |
boundsChanged(net.sourceforge.czt.z.ast.ZName key)
True iff the bounds of key have changed in this pass.
|
void |
endAnalysis()
This should be called at the end of each bounds inference pass.
|
Set<net.sourceforge.czt.z.ast.ZName> |
getAliases(net.sourceforge.czt.z.ast.ZName var)
Returns a list of all known aliases for var.
|
Set<net.sourceforge.czt.z.ast.ZName> |
getAliasKeys()
Returns the keys that have alias information.
|
protected net.sourceforge.czt.z.ast.ZName |
getBestAlias(net.sourceforge.czt.z.ast.ZName var)
Returns the ZName that has the bounds information attached to it.
|
int |
getDeductions()
The number of bounds deductions in this scope (and child scopes).
|
EvalSet |
getEvalSet(net.sourceforge.czt.z.ast.ZName var0)
Get the EvalSet for var, if known.
|
Set<net.sourceforge.czt.z.ast.ZName> |
getEvalSetKeys()
Returns the keys that have set information.
|
BigInteger |
getLower(net.sourceforge.czt.z.ast.ZName var)
Get the optional lower bound for var.
|
Set<net.sourceforge.czt.z.ast.ZName> |
getLowerKeys()
Returns the keys that have lower bounds.
|
RangeSet |
getRange(net.sourceforge.czt.z.ast.ZName var0)
Returns the lower and/or upper bounds of an integer
variable (if known), or null otherwise.
|
Map<Object,net.sourceforge.czt.z.ast.ZName> |
getStructure(net.sourceforge.czt.z.ast.ZName var)
Returns information about the argument names of a structure
such as a tuple or binding.
|
Set<net.sourceforge.czt.z.ast.ZName> |
getStructureKeys()
Returns the names that are known to be structures (tuples/bindings).
|
BigInteger |
getUpper(net.sourceforge.czt.z.ast.ZName var)
Get the optional upper bound for var.
|
Set<net.sourceforge.czt.z.ast.ZName> |
getUpperKeys()
Returns the keys that have upper bounds.
|
boolean |
includesZero(net.sourceforge.czt.z.ast.ZName name)
True iff the set of possible values for name includes 0.
|
boolean |
isAliased(net.sourceforge.czt.z.ast.ZName var,
net.sourceforge.czt.z.ast.ZName other)
True iff var and other are known to be aliased.
|
static boolean |
isBetterLowerBound(BigInteger lo1,
BigInteger lo2)
True iff lo1 is a better (tighter) lower bound than lo2.
|
static boolean |
isBetterUpperBound(BigInteger lo1,
BigInteger lo2)
True iff lo1 is a better (tighter) upper bound than lo2.
|
static <V> String |
printMap(Map<net.sourceforge.czt.z.ast.ZName,V> map)
A alternative version of Map<ZName,???>.toString()
that prints the names in a non-unicode way.
|
boolean |
setEvalSet(net.sourceforge.czt.z.ast.ZName var0,
EvalSet set)
Set the EvalSet for var.
|
void |
startAnalysis()
Resets the deductions counter and marks all vars as not-yet-changed.
|
void |
startAnalysis(Bounds parent)
This is similar to startAnalysis with no parameters, but
it also updates the local bounds information from the parent.
|
String |
toString() |
protected Bounds parent_
protected int deductions_
public Bounds(Bounds parent)
parent
- Optional parent to inherit bounds from.public void startAnalysis(Bounds parent)
This method should be used in preference to startAnalysis() whenever bounds inference starts on a Bounds object that is within a nested scope, such as a quantifiers or disjunction. The idea is that bounds information from the parent should flow down into the child, but not in the reverse direction (though a few inferBounds methods like in FlatOr may choose to propagate some common bounds information back up to the parent).
parent
- Bounds information from an outer scope.public void startAnalysis()
public void endAnalysis()
public int getDeductions()
public void addDeductions(int count)
public boolean boundsChanged()
public boolean boundsChanged(net.sourceforge.czt.z.ast.ZName key)
public boolean anyBoundsChanged(Collection<net.sourceforge.czt.z.ast.ZName> vars)
public Set<net.sourceforge.czt.z.ast.ZName> getLowerKeys()
public Set<net.sourceforge.czt.z.ast.ZName> getUpperKeys()
public Set<net.sourceforge.czt.z.ast.ZName> getEvalSetKeys()
public static <V> String printMap(Map<net.sourceforge.czt.z.ast.ZName,V> map)
public void addConst(net.sourceforge.czt.z.ast.ZName name, net.sourceforge.czt.z.ast.Expr value)
public EvalSet getEvalSet(net.sourceforge.czt.z.ast.ZName var0)
var
- The name of an integer variable.public boolean setEvalSet(net.sourceforge.czt.z.ast.ZName var0, EvalSet set)
var
- The name of an integer variable.set
- A non-null EvalSet (usually a FuzzySet).public static boolean isBetterLowerBound(BigInteger lo1, BigInteger lo2)
lo1
- Optional new lower boundlo2
- Optional old lower boundpublic static boolean isBetterUpperBound(BigInteger lo1, BigInteger lo2)
lo1
- Optional new upper boundlo2
- Optional old upper boundpublic BigInteger getLower(net.sourceforge.czt.z.ast.ZName var)
var
- The name of an integer variable.public BigInteger getUpper(net.sourceforge.czt.z.ast.ZName var)
var
- The name of an integer variable.public RangeSet getRange(net.sourceforge.czt.z.ast.ZName var0)
public boolean addLower(net.sourceforge.czt.z.ast.ZName var0, BigInteger lower)
var
- The name of an integer variable.lower
- The lower bound (must be non-null).public boolean addUpper(net.sourceforge.czt.z.ast.ZName var0, BigInteger upper)
var
- The name of an integer variable.upper
- The upper bound (must be non-null).public Set<net.sourceforge.czt.z.ast.ZName> getAliasKeys()
public Set<net.sourceforge.czt.z.ast.ZName> getAliases(net.sourceforge.czt.z.ast.ZName var)
var
- protected net.sourceforge.czt.z.ast.ZName getBestAlias(net.sourceforge.czt.z.ast.ZName var)
public boolean isAliased(net.sourceforge.czt.z.ast.ZName var, net.sourceforge.czt.z.ast.ZName other)
public void addAlias(net.sourceforge.czt.z.ast.ZName var1, net.sourceforge.czt.z.ast.ZName var2)
var1
- var2
- public Set<net.sourceforge.czt.z.ast.ZName> getStructureKeys()
public Map<Object,net.sourceforge.czt.z.ast.ZName> getStructure(net.sourceforge.czt.z.ast.ZName var)
var
- The name of the whole structurepublic void addStructureArg(net.sourceforge.czt.z.ast.ZName var, Object argPos, net.sourceforge.czt.z.ast.ZName argName)
var
- The name of the whole structure.argPos
- An Integer for tuples, or a ZName for bindings.argName
- The name of the argument.public boolean includesZero(net.sourceforge.czt.z.ast.ZName name)
name
- The name of an integer variableCopyright © 2003–2016 Community Z Tools Project. All rights reserved.