All guards in the theory language
Last updated
Last updated
This chapter presents guards (operators) that may be used to write rules. Such guards may be used to constrain the domain of application of a rule, using informations related to the goal and the hypothesis. To help writing and verifying the rules, all the guards of the theory language are documented thereafter.
A guard is a special antecedent in a rule. In fact, each guard in a rule is interpreted directly before the rule being effectively applied or not. Evaluating a guard never results in the creation of a SUCCESSor. The evalution of a guard may succeed or fail. For a rule to be effectively applicable, all the associated guard must be successful .
The following table summarizes the guard constructs:
bmatch bnot
band | conjunction of two guards |
---|---|
g1 : guard
g2 : guard
guard
Combines several guards.
The evaluation strategy differs according to the nature of the guards g1 and g2 :
if g1 is binhyp(H ), or binhyp(n,H ), or binhyp(m,n,H ), and if, in the last two cases, n is a wildcard, then the resulting guard succeeds if there exists an hypothesis h that matches H and that is such that g2 is successful
if g1 is a bsubfrm, bsearch or brule guard, then the resulting guard is successful if there exists a wildcard instantiation such that g1 successful , and such that g2 is successful .
in all other cases, the resulting guard is successful if both guards g1 and g2, evaluated in sequence are successful . If g2 fails, the evaluation does not backtrack to g1 as in the preceding cases.
Result
g : guard
Guard
Used to simplify expression of guards in case of failure.
The evaluation of bnot(g) is successful if the evaluation of g is a failure.
Result
v: variable or variable list
f: formula
V: wildcard
Guard
To create fresh variables.
The evaluation is always successful . The wildcard V is instantiated with as many variables as there are in v. Moreover the new variables are not free in f. If v is not free in f, then V is the same as v.
Result
h : formula
Guard
This guard gets the hypothesis in a proof.
The evaluation of the guard is successful when the proof contains hypothesis and that the conjunction of these hypothesis matches with formula h. These hypothesis also depend on the type of guard:
Guard bgethyp only yields the main hypothesis;
Guard bgetallhyp yields the main hypothesis as well as the hypothesis derived from these main hypothesis.
In any case, all the wildcards of h are instantiated.
Result
h: formula
n: formula
m: number
Guard
To access an hypothesis.
The guard binhyp(h) is successful when there exists an hypothesis that matches h. When there are several hypothesis, the last one is picked. All wildcards of h are instantiated. The evaluation of the guard binhyp(n,h ) depends on the nature of n: When n is a number, the evaluation is successful when the hypothesis of rank n exists and matches hypothesis h. All wildcards of h are instantiated. When n is a wildcard, the evaluation is successful if there exists an hypothesis that matches hypothesis h. n is then instantiated with the rank of h. All wildcards of h are instantiated. In all other cases, the evaluation fails. The evaluation of the guard binhyp(m,n,h) is similar to that of the guard binhyp(n,h), but in the case where n is a wildcard, the selected hypothesis is the last that matches h and with rank smaller or equal to i m. Note the similarities between these last two forms of the binhyp guard and the guards brule and lemma.
Result
l : list of variables
Guard
To get the list of quantified variables at the current rewrite position.
The guard is always successful . If there is at least one quantified variable at the current rewrite position, l contains the list of quantified variables. Othewise l contains ?. For instance, if the current goal is
and the rule
is applied, then Q will be (aa,bb,cc).
This guard is used within rewrite rules. It provides the guarantee that one does not mix quantified with non-quantified variables. It is often used in conjunction with the absence of freedom guard bnfree x E. ? E is always true, whatever E is.
Result
x: variable
p: formula
q: formula
e: formula
Guard
Checks if a quantified formula may be instantiated.
For the guard to be successful , it is first necessary that the formula p does not contain quantifiers. Then it is required that there exists a formula f such that the substitution of x by f in p is the same as formula q. Finally, formula f must match e. All wildcards in e are instantiated.
Result
f: formula
g: formula
Guard
Tests if a formula matches another formula.
The guard is successful if formula f matches formula g. All wildcards in g are instantiated.
Result
p: formula
l : non-atomic formula
r: formula
s: formula
Guard
To search, and possibly modify an element in a list.
The formula l has the form l1 op … op li op … op ln where n is greater than or equal to 2 and op is a binary operator.
The guard bsearch(p,l,r ) is successful when there exists a sub-formula li that matches p, and when the formula obtained by removing li from l matches formula r.
The guard bsearch(p,l,r,s ) is successful when there exists a sub-formula li that matches p, and when the formula obtained by substituting li in l with the corresponding instance matches formula r.
All wildcards in p, r and s are instantiated.
f: formula
Guard
To test that a formula is a character string.
The evaluation of the guard is successful if f is a character string (i.e. a sequence in characters between double-quotes). A double-quote may be present inside the string if it is preceded by a backslash.
Result
g: formula
d: formula
p: formula
q: formula
v: formula
Guard
Tests the presence of a sub-formula in a formula and substitute it with another one.
For the evaluation of the first type of guard to be successful , it is first necessary that a formula f of p matches g (not instantiated). We then consider p obtained by substitution, in p, by the instantiated sub-formula f. Such formula p must match q (not instantiated). Most of the time, q is a simple wildcard.
In the second type of guard, the list of quantified variables on which f depends is also considered. If there is no such variable, then the list contains a single element: ?. This list must match v, not instantiated. Most of the time v is also a simple wildcard. All remaining unmatched wildcards are instantiated.
Result
m: formula
n: formula
op: comparison operator
Guard
To compare two numeric values.
The evaluation of the guard is successful when m and n related by the specified operator. The comparison operators:
Equal: =
Different: /=
Smaller: <
Smaller or equal: <=
Greater: >
Greater or equal: >=
When the operator is equality or difference, the evaluation of the guard is also successful when m and n are both identifiers that are related by the operator
Result
f : formula
Guard
To test that a formula is a variable.
The evaluation is successful if f is a variable. Recall that a variable is either a letter (wildcard) or an identifier that do not start with an underscore, or one of the two previous possibilities followed by a $ and a number smaller than 10000, or a list composed of distinct elements that fall into the previous cases.
Result
bfresh
construction of a fresh variable
bgetallhyp
obtains all the hypothesis
binhyp
tests the presence of a formula in (as ???) an hypothesis
blvar
lists the quantified variables
identity by matching
negation of a guard
bnum
numerality test
bpattern
tests formula matching
bsearch
tests presence in a list
bstring
tests if is a character string
bsubfrm
finds sub-formulas
btest
numeric comparison
bvrb
variable test