Package daikon.inv
Class Implication
-
- All Implemented Interfaces:
Serializable
,Cloneable
- Direct Known Subclasses:
GuardingImplication
public class Implication extends Joiner
The Implication invariant class is used internally within Daikon to handle invariants that are only true when certain other conditions are also true (splitting).- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class Invariant
Invariant.ClassVarnameComparator, Invariant.ClassVarnameFormulaComparator, Invariant.InvariantComparatorForPrinting, Invariant.Match
-
-
Field Summary
Fields Modifier and Type Field Description boolean
iff
-
Fields inherited from class Invariant
CONFIDENCE_JUSTIFIED, CONFIDENCE_NEVER, CONFIDENCE_UNJUSTIFIED, debug, debugFlow, debugGuarding, debugIsObvious, debugIsWorthPrinting, debugPrint, debugPrintEquality, dkconfig_confidence_limit, dkconfig_fuzzy_ratio, dkconfig_simplify_define_predicates, falsified, invariantEnabledDefault, isGuardingPredicate, min_mod_non_missing_samples, ppt, PROBABILITY_JUSTIFIED, PROBABILITY_NEVER, PROBABILITY_UNJUSTIFIED
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected double
computeConfidence()
This method computes the confidence that this invariant occurred by chance.Invariant
consequent()
boolean
enabled()
Returns whether or not this class of invariants is currently enabled.String
format_using(OutputFormat format)
Return a printed representation of this invariant, in the given format.boolean
hasUninterestingConstant()
An invariant that includes an uninteresting constant (say, "size(x[]) < 237") is likely to be an artifact of the way the program was tested, rather than a statement that would in fact hold over all possible executions.protected Invariant
instantiate_dyn(PptSlice slice)
Instantiates (creates) an invariant of the same class on the specified slice.boolean
isAllPrestate()
Returns true if this invariant is only over prestate variables.@Nullable DiscardInfo
isObviousDynamically(VarInfo[] vis)
Return non-null if this invariant is necessarily true from a fact that can be determined dynamically (after checking data) -- for the given varInfos rather than the varInfos of this.@Nullable DiscardInfo
isObviousDynamically_SomeInEquality()
Return true if the rightr side of the implication some equality combinations of its member variables are dynamically obvious.@Nullable DiscardInfo
isObviousStatically(VarInfo[] vis)
Return true if this invariant is necessarily true from a fact that can be determined statically -- for the given varInfos rather than the varInfos of this.@Nullable DiscardInfo
isObviousStatically_SomeInEquality()
Return true if the right side of the implication and some equality combinations of its member variables are statically obvious.boolean
isSameFormula(Invariant other)
Returns true iff the two invariants represent the same mathematical formula.boolean
isSameInvariant(Invariant other)
Returns true iff the argument is the "same" invariant as this.boolean
log(String format, @Nullable Object... args)
Logs a description of the invariant and the specified msg via the logger as described indaikon.Debug#log(Logger, Class, Ppt, VarInfo[], String)
.void
log(Logger log, String msg)
Logs a description of the invariant and the specified msg via the logger as described indaikon.Debug#log(Logger, Class, Ppt, VarInfo[], String)
.static @Nullable Implication
makeImplication(PptTopLevel ppt, Invariant predicate, Invariant consequent, boolean iff, Invariant orig_predicate, Invariant orig_consequent)
Creates a new Implication Invariant and adds it to the PptTopLevel.Invariant
predicate()
String
repr()
For printing invariants, there are two interfaces: repr gives a low-level representation (Invariant.repr_prob()
also prints the confidence), andInvariant.format()
gives a high-level representation for user output.boolean
valid_types(VarInfo[] vis)
Returns whether or not the invariant is valid over the basic types in vis.-
Methods inherited from class Joiner
isObviousDerived, isObviousImplied, isValidEscExpression, resurrect_done
-
Methods inherited from class Invariant
add_sample, asInvClass, checkRep, clear_falsified, clone, clone_and_permute, conf_is_ge, confidence_and, confidence_and, confidence_or, createGuardedInvariant, createGuardingPredicate, enoughSamples, falsify, find, format, format_classname, format_too_few_samples, format_unimplemented, formatFuzzy, get_comparability, get_ni_suppressions, getConfidence, getGuardingList, getGuardingList, instantiate, instantiate_ok, is_false, is_ni_suppressed, isActive, isEqualityComparison, isExact, isExclusiveFormula, isObvious, isObviousDynamically, isObviousDynamically_SomeInEqualityHelper, isObviousStatically, isObviousStatically_AllInEquality, isObviousStatically_SomeInEqualityHelper, isReflexive, isValidExpression, isWorthPrinting, justified, logDetail, logOn, match, merge, mergeFormulasOk, permute, prob_and, prob_and, prob_is_ge, prob_or, repCheck, repr_prob, resurrect, simplify_format_double, simplify_format_long, simplify_format_string, state_match, toString, toString, transfer, usesVar, usesVar, usesVarDerived, varNames
-
-
-
-
Field Detail
-
iff
public boolean iff
-
-
Method Detail
-
consequent
public Invariant consequent()
-
makeImplication
public static @Nullable Implication makeImplication(PptTopLevel ppt, Invariant predicate, Invariant consequent, boolean iff, Invariant orig_predicate, Invariant orig_consequent)
Creates a new Implication Invariant and adds it to the PptTopLevel.- Returns:
- null if predicate and the consequent are the same, or if the PptTopLevel already contains this Implication
-
computeConfidence
protected double computeConfidence()
Description copied from class:Invariant
This method computes the confidence that this invariant occurred by chance. Clients should callInvariant.getConfidence()
instead.This method need not check the value of field "falsified", as the caller does that.
- Specified by:
computeConfidence
in classInvariant
- Returns:
- confidence of this invariant
- See Also:
Invariant.getConfidence()
-
repr
public String repr(@GuardSatisfied Implication this)
Description copied from class:Invariant
For printing invariants, there are two interfaces: repr gives a low-level representation (Invariant.repr_prob()
also prints the confidence), andInvariant.format()
gives a high-level representation for user output.
-
format_using
@SideEffectFree public String format_using(@GuardSatisfied Implication this, OutputFormat format)
Description copied from class:Invariant
Return a printed representation of this invariant, in the given format.- Specified by:
format_using
in classJoiner
-
isObviousStatically
@Pure public @Nullable DiscardInfo isObviousStatically(VarInfo[] vis)
Description copied from class:Invariant
Return true if this invariant is necessarily true from a fact that can be determined statically -- for the given varInfos rather than the varInfos of this. Conceptually, this means "is this invariant statically obvious if its VarInfos were switched with vis?" Intended to be overridden by subclasses. Should only do static checking.Precondition: vis.length == this.ppt.var_infos.length
- Overrides:
isObviousStatically
in classInvariant
- Parameters:
vis
- the VarInfos this invariant is obvious over. The position and data type of the variables is the *same* as that of this.ppt.var_infos.
-
isObviousDynamically
@Pure public @Nullable DiscardInfo isObviousDynamically(VarInfo[] vis)
Description copied from class:Invariant
Return non-null if this invariant is necessarily true from a fact that can be determined dynamically (after checking data) -- for the given varInfos rather than the varInfos of this. Conceptually, this means, "Is this invariant dynamically obvious if its VarInfos were switched with vis?" Intended to be overriden by subclasses so they can filter invariants after checking; the overriding method should first call "super.isObviousDynamically(vis)". Since this method is dynamic, it should only be called after all processing.- Overrides:
isObviousDynamically
in classInvariant
-
isObviousStatically_SomeInEquality
@Pure public @Nullable DiscardInfo isObviousStatically_SomeInEquality()
Return true if the right side of the implication and some equality combinations of its member variables are statically obvious. For example, if a == b, and f(a) is obvious, then so is f(b). We use the someInEquality (or least interesting) method during printing so we only print an invariant if all its variables are interesting, since a single, static, non interesting occurance means all the equality combinations aren't interesting.This must be overridden for Implication because the right side is the invariant of interest. The standard version passes the vis from the slice containing the implication itself (slice 0).
- Overrides:
isObviousStatically_SomeInEquality
in classInvariant
- Returns:
- the VarInfo array that contains the VarInfos that showed this invariant to be obvious. The contains variables that are elementwise in the same equality set as this.ppt.var_infos. Can be null if no such assignment exists.
-
isObviousDynamically_SomeInEquality
@Pure public @Nullable DiscardInfo isObviousDynamically_SomeInEquality()
Return true if the rightr side of the implication some equality combinations of its member variables are dynamically obvious. For example, a == b, and f(a) is obvious, so is f(b). We use the someInEquality (or least interesting) method during printing so we only print an invariant if all its variables are interesting, since a single, dynamic, non interesting occurance means all the equality combinations aren't interesting.This must be overridden for Implication because the right side is the invariant of interest. The standard version passes the vis from the slice containing the implication itself (slice 0).
- Overrides:
isObviousDynamically_SomeInEquality
in classInvariant
- Returns:
- the VarInfo array that contains the VarInfos that showed this invariant to be obvious. The contains variables that are elementwise in the same equality set as this.ppt.var_infos. Can be null if no such assignment exists.
-
isSameFormula
@Pure public boolean isSameFormula(Invariant other)
Description copied from class:Invariant
Returns true iff the two invariants represent the same mathematical formula. Does not consider the context such as variable names, confidences, sample counts, value counts, or related quantities. As a rule of thumb, if two invariants format the same, this method returns true. Furthermore, in many cases, if an invariant does not involve computed constants (as "x>c" and "y=ax+b" do for constants a, b, and c), then this method vacuously returns true.- Overrides:
isSameFormula
in classJoiner
- Parameters:
other
- the invariant to compare to this one- Returns:
- true iff the two invariants represent the same mathematical formula. Does not consider
-
isSameInvariant
@EnsuresNonNullIf(result=true, expression="#1") @Pure public boolean isSameInvariant(Invariant other)
Description copied from class:Invariant
Returns true iff the argument is the "same" invariant as this. Same, in this case, means a matching type, formula, and variable names.- Overrides:
isSameInvariant
in classJoiner
- Parameters:
other
- the other invariant to compare to this one- Returns:
- true iff the argument is the "same" invariant as this
-
hasUninterestingConstant
public boolean hasUninterestingConstant()
Description copied from class:Invariant
An invariant that includes an uninteresting constant (say, "size(x[]) < 237") is likely to be an artifact of the way the program was tested, rather than a statement that would in fact hold over all possible executions.- Overrides:
hasUninterestingConstant
in classInvariant
-
isAllPrestate
@Pure public boolean isAllPrestate()
Description copied from class:Invariant
Returns true if this invariant is only over prestate variables.- Overrides:
isAllPrestate
in classInvariant
- Returns:
- true if this invariant is only over prestate variables
-
log
public void log(Logger log, String msg)
Logs a description of the invariant and the specified msg via the logger as described indaikon.Debug#log(Logger, Class, Ppt, VarInfo[], String)
. Uses the consequent as the logger.
-
log
@FormatMethod public boolean log(@UnknownInitialization(Implication.class) Implication this, String format, @Nullable Object... args)
Logs a description of the invariant and the specified msg via the logger as described indaikon.Debug#log(Logger, Class, Ppt, VarInfo[], String)
. Uses the consequent as the logger.
-
enabled
public boolean enabled( Implication this)
Description copied from class:Invariant
Returns whether or not this class of invariants is currently enabled.Its implementation is almost always
return dkconfig_enabled;
.
-
valid_types
public boolean valid_types( Implication this, VarInfo[] vis)
Description copied from class:Invariant
Returns whether or not the invariant is valid over the basic types in vis. This only checks basic types (scalar, string, array, etc) and should match the basic superclasses of invariant (SingleFloat, SingleScalarSequence, ThreeScalar, etc). More complex checks that depend on variable details can be implemented in instantiate_ok().- Specified by:
valid_types
in classInvariant
- See Also:
Invariant.instantiate_ok(VarInfo[])
-
instantiate_dyn
protected Invariant instantiate_dyn( Implication this, PptSlice slice)
Description copied from class:Invariant
Instantiates (creates) an invariant of the same class on the specified slice. Must be overridden in each class. Must be used rather thanInvariant.clone()
so that checks inInvariant.instantiate(daikon.PptSlice)
for reasonable invariants are done.The implementation of this method is almost always
return new <em>InvName</em>(slice);
- Specified by:
instantiate_dyn
in classInvariant
- Returns:
- the new invariant
-
-