public class TypeTestClosure extends AbstractClosureRule implements Proof.LinearRule
Responsible for handling type tests. There are three essential cases that it covers: first, the expansion of type invariants; second, the closure of multiple tests over the same left-hand side; third, the retyping of a given variable. We now consider each of these in turn.
Expansion of type invariants. Consider the following assertion:
type nat is (int x) where x >= 0
assert:
forall(int x):
if:
x is nat
then:
x >= 0
For proof-by-contradiction we have x is nat && x < 0. Type
expansion takes the test x is nat and infers
nat(x), which represents the invariant for type nat
applied to x. This is then separately expanded to
x >= 0 as expected, thus giving the contradiction.
Closure over Type Tests. Consider the following assertion
type nullint is (null|int x)
type boolint is (bool|int x)
assert:
forall({any f} x):
if:
x.f is nullint
x.f is boolint
then:
x.f is int
In this case, to arrive at the contradiction we have to "close over"
x.f is nullint and x.f is boolint to conclude that
x is int. This is done by intersecting nullint with
boolint.
Retyping of Variables. In the case of a variable being tested (e.g.
x is int), we can perform a complete retyping of all
expressions involving x to exploit this additional information.
As an example, consider this assertion:
assert:
forall(int[] xs, any i):
if:
i is int
then:
xs[i] is int
In this case, the expression xs[i] can only be typed after
variable i is retyped to int.
simp, types| Constructor and Description |
|---|
TypeTestClosure(Simplification simplify,
TypeSystem types) |
| Modifier and Type | Method and Description |
|---|---|
Proof.State |
apply(Proof.Delta.Set existingTruths,
Proof.State head,
Formula newTruth) |
String |
getName()
Get the name of this rule
|
apply, apply, getExistingTruthsextractDefinedTerms, findAllInstances, substituteclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitapplypublic TypeTestClosure(Simplification simplify, TypeSystem types)
public String getName()
Proof.RulegetName in interface Proof.Rulepublic Proof.State apply(Proof.Delta.Set existingTruths, Proof.State head, Formula newTruth) throws wybs.lang.NameResolver.ResolutionError
apply in class AbstractClosureRulewybs.lang.NameResolver.ResolutionErrorCopyright © 2017. All rights reserved.