PRD Safeness Operational
All excerpts about safeness, including related definitions, from this version of the PRD draft.
Contents
Overview
...
Production rule interchange
...
The semantics of condition formulas and the semantics of rules and rule sets make no assumption regarding how condition formulas are evaluated. In particular, they do not require that condition formula be evaluated using pattern matching. However, RIF-PRD conformance, as defined in the section Conformance and interoperability, requires only support for safe rules, that is, forward-chaining rules where the conditions can be evaluated based on pattern matching only.
...
Conditions
Abstract syntax
Terms
...
The function Var(e) that maps a term e to the set of its free variables is defined as follows:
- if e ∈ Const, then Var(e) = {};
- if e ∈ Var, then Var(e) = {e};
- if f(arg_{1}...arg_{n}), n ≥ 0, is a positional term, then, Var(f(arg_{1}...arg_{n}) = ∪_{i=1...n} Var(arg_{i});
Atomic formulas
...
The function Var, that was defined for terms, is extended to map an atomic formula to the set of its free variables:
- if p(arg_{1}...arg_{n}), n ≥ 0, is an atom, then, Var(p(arg_{1}...arg_{n}) = Var(External(p(arg_{1}...arg_{n})) = ∪_{i=1...n} Var(arg_{i});
- if t_{1} and t_{2} are terms, then Var(t_{1} [=|#|##] t_{2}) Var(t_{1}) ∪ Var(t_{2});
- if o', k_{i}, i = 1...n, and v_{i}, i = 1...n, n ≥ 1, are terms, then Var(o[k_{1}->v_{1} ... k_{n}->v_{n}]) Var(o) ∪_{i=1...n} Var(k_{i}) ∪_{i=1...n} Var(v_{i}).
RIF-PRD does not require that a conformant consumer be capable of constraint resolution to evaluate condition formulas. To help specify the corresponding syntactic restriction on RIF-PRD condition formulas, we define, for any atomic formula, a, the two following sets:
- a set UBV(a), of the unconditionally bindable variables of a, that is, of the variables that occur in a and that are guaranteed to be bound without constraint resolution is a is satisfied;
- and a set, CBV(a), of conditionally bindable variables. Each variable, v ∈ CBV(a) is associated with the set, BCOND(v, a), that contains the set of the variables occuring in a that guarantee, if they are bound when a is evaluated, that v can be bound without constraint resolution, if a is satisfied.
The sets UBV(a) and CBV(a) of the unconditionally and conditionally bindable variables in an atomic formula a are defined as follows:
- if a is an atom, p(t_{1}...t_{n}), n ≥ 0, a frame, t_{1}[t_{2}->t_{3}], a membership formula, t_{1}#t_{2}, or a subclass formula, t_{1}##t_{2}, then either
- the only variables in a are arguments of the atomic formula itself: Var(a) ⊆ {t_{1}...t_{n}}, and UBV(a) = Var(a) and CBV(a) = ∅;
- or no argument of the atomic formula is a variable: Var(a) ∩ {t_{1}...t_{n}} = ∅, and UBV(a) = CBV(a) = ∅;
- otherwise, that is, if some of the arguments of a are variables, but others are terms that contain variables, then UBV(a) = ∅ and either
- the conditional bindability of none of these variables depends on itself, that is, varg ∩ cond = ∅, where varg = Var(a) ∩ {t_{1}...t_{n}} and cond = ∪_{∀ ti=1..n ∉ Var(a)} Var(t_{i}), and CBV(a) = varg, and, ∀ v ∈ CBV(a), BCOND(v, a) = {cond};
- or CBV(a) = ∅;
- else if a is an equality formula, t_{1} = t_{2}, or an externally defined equality predicate: pred:numeric-equal(t_{1}, t_{2}), pred:boolean-equal(t_{1}, t_{2}), pred:dateTime-equal(t_{1}, t_{2}), pred:date-equal(t_{1}, t_{2}), pred:time-equal(t_{1}, t_{2}), pred:duration-equal(t_{1}, t_{2}), pred:XMLLiteral-equal(t_{1}, t_{2}); or the externally defined predicate pred:iri-string(t_{1}, t_{2}), then either
- t_{1} and t_{2} are, both, variables, and UBV(a) = ∅ and CBV(a) = {t_{1}, t_{2}}, with BCOND(t_{1}, a) = {{t_{2}}} and BCOND(t_{2}, a) = {{t_{1}}};
- or only t_{1} is a variable, and either
- Var(t_{2}) = ∅, and UBV(a) = {t_{1}} and CBV(a) = ∅;
- or t_{1} ∈ Var(t_{2}), and UBV(a) = ∅ and CBV(a) = ∅;
- or UBV(a) = ∅ and CBV(a) = {t_{1}}, and BCOND(t_{1}, a) = {Var(t_{2})};
- or only t_{2} is a variable, and either
- Var(t_{1}) = ∅, and UBV(a) = {t_{2}} and CBV(a) = ∅;
- or t_{2} ∈ Var(t_{1}), and UBV(a) = ∅ and CBV(a) = ∅;
- or UBV(a) = ∅ and CBV(a) = {t_{2}}, and BCOND(t_{2}, a) = {Var(t_{1})};
- otherwise UBV(a) = CBV(a) = ∅;
- else if a is the externally defined predicate pred:list-contains(l, e), then either
- e is a variable, and either
- Var(l) = ∅, and UBV(a) = {e} and CBV(a) = ∅;
- or e ∈ Var(l), and UBV(a) = CBV(a) = ∅;
- or CBV(a) = {e}, with BCOND(e, a) = {Var(l)}, and UBV(a) = ∅;
- or e is not a variable, and UBV(a) = CBV(a) = ∅;
- e is a variable, and either
- else if a is any other externally defined predicate, then UBV(a) = CBV(a) = ∅.
Formulas
...
The function Var, that was defined for atomic formulas, is extended to map a condition formula to the set of its free variables:
- if f_{i}, i = 0...n, n ≥ 0, are condition formulas, then Var([And|Or](f_{1}...f_{n})) ∪_{i=0...n} Var(f_{i});
- if f is a condition formula, then Var(Not(f)) Var(f);
- if f is a condition formula and x_{i} ∈ Var for i = 1...n, then, Var(Exists x_{1} ... x_{n} (f)) = Var(f) - {x_{i} | i = 1...n}.
...
The definition of the set UBV(f) of the unconditionally bindable variables and the set CBV(f) of the conditionally bindable variables, that have been defined for atomic formulas is also extended to any condition formula.
When condition formulas are combined, a variable, x, that was conditionally bindable in one component, depending on another variable, y being bound, may become unconditionally bindable in the combination, e.g. because y is unconditionally bindable in the combination, or because the combination is a conjunction, and x, itself, is unconditionally bindable in another conjunct.
To take care of that, we define, first, the function reduceBCV, that updates ietratively the status of conditionally bindable variables in a formula, f, based on the state of the set of unconditionally bindable variables in f:
reduceCBV (f) While ∃ v ∈ CBV(f), ∃ c ∈ BCOND(v, f), such that c ⊆ UBV(f) BCV(f) := BCV(f)\v UBV(f) := UBV(f) + v
The definition of the sets UBV(f) and CBV(f) is extended recursively, as follows, to a condition formula f:
- if f is a conjunction, And(f_{1}...f_{n}), n ≥ 0, then
- UBV(f) and CBV(f) are initialized with ∪_{i=1..n} UBV(f_{i}) and ∪_{i=1..n} CBV(f_{i}) - UBV(f), respectively,
- ∀ v ∈ CBV(f), BCOND(v, f) = ∪_{fi=1..n} BCOND(v, f_{i}): the bindability conditions associated to the variables in CBV(f) are updated, taking into account that a conditionally bindable variable can be bound if the variables in any bindability condition from any of the conjuncts are bound;
- and reduceCBV(f) is executed to update UBV(f) and CBV(f), removing from CBV(f) and adding to UBV(f) all the variables that are conditionally bindable in some conjunct, conditioned on the bindability of variables that are unconditionally bindable in some other conjunct;
- else if f is a disjunction, Or(f_{1}...f_{n}), n ≥ 0, then UBV(f) = ∩_{i=1..n} UBV(f_{i}), CBV(f) = ∩_{i=1..n} CBV(f_{i}), and ∀ v ∈ CBV(f), BCOND(v, f) = ∪_{fi=1..n} BCOND(v, f_{i}). Since only the variables that are unconditionally bindable in all the disjuncts are in UBV(f), CBV(f) cannot be reduced;
- else if f is a negation, INeg(f'), and UBV(f) = CBV(f) = ∅;
- else if is an existentially quantified condition formula, Exists v_{1}...v_{n} (f'), then either
- {v_{1}...v_{n}} ⊆ UBV(f'), that is, all the quantified variables are unconditionally bindable in f' , and
- UBV(f) = UBV(f') - {v_{1}...v_{n}};
- CBV(f) = CBV(f');
- ∀ v ∈ CBF(f), BCOND(v, f) = BCOND(v, f') - {c ∈ BCOND(v, f')| c ∩ {v_{1}...v_{n}} ≠ ∅}: bindability conditions that depend on variables that are existentially quantified in f are useless outside of f, and they are, accordingly, removed;
- or it is guaranteed that some of the quantified variables cannot be bound, at least not without constraint resolution, and UBV(f) = CBV(f) = ∅. We call such an existential formula unsafe, by extension of the notion of safeness that is defined in [RIF-Core].
- {v_{1}...v_{n}} ⊆ UBV(f'), that is, all the quantified variables are unconditionally bindable in f' , and
The definition of unconditionally bindable variables in RIF-PRD condition formulas extends the definition of restricted variables in [LEE08]. We extend the definition of a safe formula accordingly.
Definition (Safe condition formula). A RIF-PRD condition formula, f, is safe if and only if, either
- f is an existential condition formula, ∃ {v_{1}...v_{n}} (f'), and {v_{1}...v_{n}} ⊆ UBV(f');
- or f does not contain any existential sub-formula,
- or all the existential sub-formulas of f are safe. ☐
...
Operational semantics of condition formulas
...
The semantics is specified in terms of matching substitutions in the sections below. The specification makes no assumption regarding how matching substitutions are determined, and safeness if, therefore, not required from well-formed condition formulas. However, RIF-PRD conformance requires processing of safe condition formulas only.
...
Actions
...
Production rules and rule sets
Abstract synatx
...
Well-formed rules and groups
The function Var(f), that has been defined for condition formulas and extended to actions, is further extended to rules, as follows:
- if f is an action block that declares action variables ?v_{1} ... ?v_{n}, n ≥ 0, and that contains actions a_{1} ... a_{m}, m ≥ 1, then Var(f) = ∪_{1 ≤ i ≤ m} Var(a_{i}) \ {?v_{1} ... ?v_{n}};
- if f is a conditional action block where c is the condition formula and a is the action block, then Var(f) = Var(c) ∪ Var(a);
- if f is a quantified rule where ?v_{1} ... ?v_{n}, n > 0, are the declared variables; p_{1} ... p_{m}, m ≥ 0, are the binding patterns, and r is the rule, then Var(f) = (Var(r) ∪ Var(p_{1}) ∪ ... ∪ Var(p_{m})) \ {?v_{1} ... ?v_{n}}.
If f is a rule, Var(f) is the set of the free variables in f. In addition, we define the functions CVar(r) and AVar(r), that return, respectively, the set of the condition variables and the of the action variables in a rule, r:
- if r is an action block that declares action variables ?v_{1} ... ?v_{n}, n ≥ 0, and that contains actions a_{1} ... a_{m}, m ≥ 1, then CVar(r) = ∅ and AVar(r) = ∪_{1 ≤ i ≤ m} Var(a_{i}) \ {?v_{1} ... ?v_{n}};
- if r is a conditional action block where c is the condition formula and a is the action block, then CVar(r) = Var(c) and AVar(r) = AVar(a);
- if r is a rule with quantified variables, Forall ?v1...?vn such that (p_{1}...p_{m}) (r'), n ≥ 1, m ≥ 0, then AVar(r) = AVar(r') and CVar(r) = CVar(r') ∪ Var(p_{1}) ∪ ... ∪ Var(p_{m}).
The definition of the sets UBV(r) and CBV(r), that have been defined for condition formulas, is extended to any rule, r, as follows:
- if r is an unconditional action block, then UBV(r) = CBV(r) = ∅; or
- else if r is a conditional action block, if C then A, then UBV(r) = UBV(C) and CBV(r) = CBV(C); or
- else if r is a rule with declared variables, Forall ?v1...?vn such that (f_{1}...f_{m-1}) (f_{m}), where n ≥ 1, m ≥ 1, and f_{n}, is a rule, then consider the formula f' = And(f_{1}...f_{m}), and compute UBV(f') and CBV(f') (according to the definition in the section Formulas). Either
- if {v_{1}...v_{n}} ⊆ UBV(f'), that is, all the quantified variables are unconditionally bindable in f' , then
- UBV(f) = UBV(f') - {v_{1}...v_{n}};
- CBV(f) = CBV(f');
- ∀ v ∈ CBF(f), BCOND(v, f) = BCOND(v, f') - {c ∈ BCOND(v, f')| c ∩ {v_{1}...v_{n}} ≠ ∅}: bindability conditions that depend on variables that are universally quantified in f are useless outside of f, and they are, accordingly, removed;
- else it is guaranteed that some of the quantified variables cannot be bound, at least not without constraint resolution, and UBV(f) = CBV(f) = ∅. We call such a rule unsafe, by extension of the notion of safeness that is defined in [RIF-Core].
- if {v_{1}...v_{n}} ⊆ UBV(f'), that is, all the quantified variables are unconditionally bindable in f' , then
RIF-PRD extends the definition of safeness in [RIF-Core] as follows.
Definition (Safe rule). A RIF-PRD rule, r, is safe if and only if and, either
- it is an unconditional or a conditional action block,
- or it is a rule with quantified variables, Forall ?v1...?vn such that (p_{1}...p_{m}) (r'), n ≥ 1, m ≥ 0, and
- {v_{1}...v_{n}} ⊆ UBV(And(p_{1}, ..., p_{m}, r')),
- and the binding patterns, p_{1}, ..., p_{m}, if any, are all safe condition formulas,
- and the rule in the scope of the quantifier, r' , is safe,
- and either Var(r) ≠ ∅ or AVar(r) ⊆ CVar(r). ☐
A safe rule set contains only safe rules.
Definition (Well-formed rule). A rule, r, is a well-formed rule if and only if either
- r is an unconditional well-formed action block, a,
- or r is a conditional action block where the condition formula, c, is a well-formed condition formula, and the action block, a, is a well-formed action block,
- or r is a quantified rule (with or without binding patterns), Forall V [such that P](r'), and
- each of the binding patterns, p_{i} ∈ P = {p_{1},...,p_{n}}, n ≥ 0, is a well-formed condition formula,
- and the quantified rule, r', is a well-formed rule. ☐
Definition (Well-formed group). A well-formed group is either:
- a group that contains no rule or group (an empty group), or
- a group, G that contains only well-formed groups, g_{1}...g_{n}, n ≥ 0, and well-formed rules, r_{1}...r_{m}, m ≥ 0, such that ∀ r_{i} ∈ G, Var(r_{i}) = ∅ and AVar(r_{i}) ⊆ CVar(r_{i}). ☐
The set of the well-formed groups contains all the production rule sets that can be meaningfully interchanged using RIF-PRD.
The specification of the operational semantics of rules and rule sets assumes that all the variables that occur in the action blocks of a rule are bound during the evaluation the condition or binding patterns of the same rule. It makes no assumption regarding how condition formulas, in the rules, are evaluated: it is not required, therefore, that a well-formed group contains only safe rules. RIF-PRD conformance, however, requires only processing of safe rules.
...
Conformance and interoperability
...
Conformance Clauses
Definition (RIF-PRD conformance).
- A RIF processor is a conformant RIF-PRD_{Τ,Ε,C,H} consumer iff it implements a semantics-preserving mapping from the set of all safe RIF-PRD_{Τ,Ε,C,H} rule sets to the language L of the processor;
- A RIF processor is a conformant RIF-PRD_{Τ,Ε,C,H} producer iff it implements a semantics-preserving mapping from a subset of the language L of the processor to a set of safe RIF-PRD_{Τ,Ε,C,H} rule sets;
- An admissible document is an XML document that conforms to all the syntactic constraints of RIF-PRD, including ones that cannot be checked by an XML Schema validator;
- A conformant RIF-PRD consumer is a conformant RIF-PRD_{Τ,Ε,C,H} consumer in which Τ consists only of the symbol spaces and datatypes, Ε consists only of the externally defined functions and predicates, C consists only of the conflict resolution strategies, and H consists only of halting tests that are required by RIF-PRD. The required symbol spaces are rif:iri and rif:local, and the datatypes and externally defined terms (built-ins) are the ones specified in [RIF-DTB] and in the section Built-in actions. The required conflict resolution strategy is the one that is identified as rif:forwardChaining, as specified in section Conflict resolution; and the required halting test is the one specified in section Halting test. A conformant RIF-PRD consumer must reject all inputs that do not match the syntax of RIF-PRD. If it implements extensions, it may do so under user control -- having a "strict RIF-PRD" mode and a "run-with-extensions" mode;
- A conformant RIF-PRD producer is a conformant RIF-PRD_{Τ,Ε,C,H} producer which produces documents that include only the symbol spaces, datatypes, externals, conflict resolution strategies and halting tests that are required by RIF-PRD. ☐
...