W3C


RIF Production Rule Dialect

W3C Editor's Draft 25 November 2008

This version:
http://www.w3.org/2005/rules/wg/draft/ED-rif-prd-20081125/
Latest editor's draft:
http://www.w3.org/2005/rules/wg/draft/rif-prd/
Previous version:
http://www.w3.org/2005/rules/wg/draft/ED-rif-prd-20081121/ (color-coded diff)
Editors:
Christian de Sainte Marie, ILOG
Adrian Paschke, Free University Berlin
Gary Hallmark, Oracle


Abstract

This document specifies RIF-PRD, a Rule Interchange Format (RIF) dialect to enable the interchange of production rules.

Status of this Document

May Be Superseded

This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.

This document is being published as one of a set of 5 documents:

  1. RIF Use Cases and Requirements
  2. RIF Core
  3. RIF Datatypes and Built-Ins 1.0
  4. RIF Production Rule Dialect (this document)
  5. RIF (Rule Interchange Format) Test Cases

Please Comment By 2008-11-28

The Rule Interchange Format (RIF) Working Group seeks public feedback on these Working Drafts. Please send your comments to public-rif-comments@w3.org (public archive). If possible, please offer specific changes to the text that would address your concern. You may also wish to check the Wiki Version of this document for internal-review comments and changes being drafted which may address your concerns.

No Endorsement

Publication as a Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.

Patents

This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.


Contents

1 Overview

This document specifies the production rule dialect of the W3C rule interchange format (RIF-PRD), a common XML serialisation format for many production rule languages.

Production rules are rules with an "if" part and a "then" part. The "if" part, also called a "condition", is like the condition part of logic rules (as covered by the basic logic dialect of the W3C rule interchange format, RIF-BLD). The "then" part of production rules may contain actions, unlike the conclusion of logic rules that may contain only a logical statement. Actions can modify the facts, not only the knowledge base; and they can have other side-effects.

Example 1.1. «A customer becomes a "Gold" customer as soon as his cumulative purchases during the current year top $5000»; «Customers that become "Gold" customers must be notified immediately, and a golden customer card will be printed and sent to them within one week»; «For shopping carts worth more than $1000, "Gold" customers receive an additional discount of 10% of the total amount», are all examples of production rules.

As a production rule interchange format, RIF-PRD specifies an abstract syntax that is shared by many concrete production rule languages for the most widely used features, and associates each abstract construct with normative semantics (section 2, Abstract syntax and Semantics) and a normative XML concrete syntax (section 3, XML syntax).

Production rules are statements of programming logic that specify the execution of one or more actions in the case that their conditions are satisfied. Production rules therefore have an operational semantic (formalizing state changes, e.g., on the basis of a state transition system formalism). The OMG Production Rule Representation specification [PRR] summarizes it as follows:

  1. Match: the rules are instantiated based on the definition of the rule conditions and the current state of the data source;
  2. Conflict resolution: select rule instances to be executed, per strategy;
  3. Act: change state of data source, by executing the selected rule instances’ actions. If a terminal state has not been reached, the control loops back to the first step (Match).

In the section Operational semantics of rules and rule sets, the semantics for rules and rule sets is specified, accordingly, as a label terminal transition system [ref Plotkin].

However, as a RIF dialect, RIF-PRD has also been designed to maximize interoperability between rule languages over the World Wide Web. In RIF, this is achieved by sharing the same syntax for constructs that have the same semantics across multiple dialects. As a consequence, RIF-PRD shares most of the syntax for rule conditions with RIF-BLD, and the semantics associated to the syntactic constructs used for representing the condition part of rules in RIF-PRD is specified, in the section Semantics of conditions, in terms of a model theory, as it is in the specification of RIF-BLD as well. In addition to emphasizing the similarity between the two dialects, it allows them to share the same definition for data types and built-ins by reference to the RIF data types and built-ins specification.

In the section Operational semantics of actions, the semantics associated with the constructs used to represent the action part of rules in RIF-PRD is specified in terms of a transition relation between successive states of the data source, as defined by the condition formulae that they entail, thus making the link between the model-theoretic semantics of conditions and the operational semantics of rules and rulesets.

The abstract syntax is specified in mathematical english, and the abstract syntactic constructs defined in section 2, Abstract syntax and Semantics, are mapped one to one onto the concrete XML syntax in section 3, XML syntax. A lightweight notation is also defined along with the abstract syntax, to allow for a human-friendlier specification of the semantics. A more complete presentation syntax is specified using an EBNF in section 4. However, only the XML syntax and the associated semantics are normative. A normative XML schema will also be provided in future versions of the document;

Example 1.2. In RIF-PRD presentation syntax, the first rule in example 1.1. might be represented as follows:

Prefix(ex1 http://rif.example.com/2008/prd#)
(* ex1:rule_1 *)
Forall ?customer ?purchasesYTD (
 If      And( ?customer#ex1:Customer
                ?customer[ex1:purchasesYTD->?purchasesYTD]
                External(pred:numeric-greater-than(?purchasesYTD 5000)))
 Then ex1:Gold(?customer) )

RIF-PRD and RIF-BLD share more than part of their condition language, and whole RIF documents have the same syntax and the same intended meaning in both dialects. The correspondence between RIF-PRD and RIF-BLD is detailed in Appendix: Compatibility with RIF-BLD.

This document is mostly intended for the designers and developers of RIF-PRD implementations, that is, applications that serialize production rules as RIF-PRD XML (producer applications) and/or that deserialize RIF-PRD XML documents into production rules (consumer applications).


2 Abstact syntax and Semantics

2.1 Conditions

This section specifies the language of the rule conditions that can be serialized using RIF-PRD, by specifying:

Note to the reader: this section depends on Section Constants, Symbol Spaces, and Datatypes of [RIF-DTB].

2.1.1 Abstract syntax

For a production rule language to be able to interchange rules using RIF-PRD, its alphabet for expressing the condition parts of a rule must, at the abstract syntax level, consist of:

For the sake of readibility and simplicity, this specification introduces a notation for these constructs. That notation is not intended to be a concrete syntax and it leaves out many details that are not needed for its purpose: the only concrete syntax for RIF-PRD is the XML syntax.

Notice that the production rule systems for which RIF-PRD aims to provide a common XML serialization use only externally specified functions, e.g. builtins. This is one of two points where the syntaxes for conditions in RIF-PRD and RIF-BLD differ, since RIF-BLD specifies, in addition, a construct for serializing the logic functions that logic languages also use.

The second point of difference between the syntaxes for conditions in RIF-PRD and RIF-BLD is that, unlike RIF-PRD, RIF-BLD does not specify a construct for negation. This is because logic rule languages use many different kinds of negations, none of them prevalent enough to justify inclusion in the basic logic dialect of RIF (see also the RIF framework for logic dialects).

2.1.1.1 Terms

The most basic construct that can be serialized using RIF-PRD is the term. RIF-PRD provides for the representation and interchange of several kinds of terms: constants, variables, positional terms and terms with named arguments

Definition (Term).

  1. Constants and variables. If tConst or tVar then t is a simple term.
  2. Positional terms. If tConst and t1, ..., tn, n≥0, are terms then t(t1 ... tn) is a positional term.
    Here, the constant t represents a function and t1, ..., tn represent argument values.
  3. Terms with named arguments. A term with named arguments is of the form t(s1->v1 ... sn->vn), where n≥0, tConst and v1, ..., vn are terms and s1, ..., sn are pairwise distinct symbols from the set ArgNames.
    The constant t here represents a function; s1, ..., sn represent argument names; and v1, ..., vn represent argument values. The argument names, s1, ..., sn, are required to be pairwise distinct. Terms with named arguments are like positional terms except that the arguments are named and their order is immaterial. Note that a term of the form f() is, trivially, both a positional term and a term with named arguments.
2.1.1.2 Atomics

The atomic truth-valued constructs that can be serialized using RIF-PRD are called atomics.

Definition (Atomic). An atomic can have several different forms and is defined as follows:

  1. Positional atomics. If tConst and t1, ..., tn, n≥0, are terms then t(t1 ... tn) is a positional atomic (or simply a positional atom).
  2. Atomics with named arguments. An atomic with named arguments (or simply a atom with named arguments) is of the form t(s1->v1 ... sn->vn), where n≥0, tConst and v1, ..., vn are terms and s1, ..., sn are pairwise distinct symbols from the set ArgNames.
    The constant t here represents a predicate; s1, ..., sn represent argument names; and v1, ..., vn represent argument values. The argument names, s1, ..., sn, are required to be pairwise distinct. Atoms with named arguments are like positional Atoms except that the arguments are named and their order is immaterial. Note that an atom of the form t() is, trivially, both a positional atom and an atom with named arguments.
  3. Equality atomics. t = s is an equality atomic, if t and s are terms.
  4. Class membership atomics (or just membership atomics). t#s is a membership atomic if t and s are terms. the term t is the object and the term s is the class.
  5. Subclass atomics. t##s is a subclass atomic if t and s are terms.
  6. Frame atomics. t[p1->v1 ... pn->vn] is a frame atomic (or simply a frame) if t, p1, ..., pn, v1, ..., vn, n ≥ 0, are terms. The term t is the object of the frame; the pi are the property or attribute names; and the vi are the property or attribute values. In this document, an attribute/value pair is sometimes called a slot.
    Membership, subclass, and frame atomics are used to describe objects, classifications and class hierarchies.
  7. Externally defined atomics. If t is a positional, named-argument, or a frame atomic then External(t) is an externally defined atomic.
    Such atomics are used for representing built-in predicates as well as "procedurally attached" predicates, which might exist in various rule-based systems or applications, but are not specified by RIF-PRD.

Note that not only predicates, but also frame atomics can be externally defined. Therefore, external information sources can be modeled in an object-oriented way via frames. For instance, External("http://example.com/acme"^^rif:iri["http://example.com/mycompany/president"^^rif:iri(?Year) -> ?Pres]) could be a representation of an externally defined method "http://example.com/mycompany/president"^^rif:iri in an external object "http://example.com/acme"^^rif:iri.   ☐

Observe that the argument names of frames, p1, ..., pn, are terms and so, as a special case, can be variables. In contrast, atoms with named arguments can use only the symbols from ArgNames to represent their argument names. They cannot be constants from Const or variables from Var.

Note that atomics are sometimes also called terms, e.g. in the realm of logic languages: the specification of RIF-BLD, in particular, follows that usage. The abstract syntactic elements that are called terms in this specification, are called basic terms in the specification of RIF-BLD.

2.1.1.3 Formulas

Composite truth-valued constructs that can be serialized using RIF-PRD are called formulas.

Any atomic is also an atomic formula.

Note that terms (constants, variables and functions) are not formulas.

More general formulas are constructed out of the atomic formulas with the help of logical connectives.

Definition (Condition formula). A condition formula can have several different forms and is defined as follows:

  1. Atomic: If φ is an atomic formula then it is also a condition formula.
  2. Conjunction: If φ1, ..., φn, n ≥ 0, are condition formulas then so is And(φ1 ... φn), called a conjunctive formula. As a special case, And() is allowed and is treated as a tautology, i.e., a formula that is always true.
  3. Disjunction: If φ1, ..., φn, n ≥ 0, are condition formulas then so is Or(φ1 ... φn), called a disjunctive formula. As a special case, Or() is permitted and is treated as a contradiction, i.e., a formula that is always false.
  4. Negation: If φ is a condition formula, then so is Not(φ), called a negative formula.
  5. Existentials: If φ is a condition formula and ?V1, ..., ?Vn, n>0, are variables then Exists ?V1 ... ?Vn(φ) is an existential formula.

In the definition of a formula, the component formulas φ and φi are said to be subformulas of the respective condition formulas that are built using these components.

The function Var(e) that maps a term, atomic or formula e to the set of its free variables is defined as follows:

Definition (Ground formula). A condition formula φ is a ground formula if and only if Varφ = {} and φ does not contain any existential subformula.

In other words, a ground formula does not contain any variable term.

2.1.1.4 Well-formed Formulas

The specification of RIF-PRD does not assign a standard meaning to all the formulas that can be serialized using its concrete XML syntax: formulas that can be meaningfully serialized are called well-formed. Not all formulas are well-formed with respect to RIF-PRD: it is required that no constant appear in more than one context. What this means precisely is explained below.

The set of all constant symbols, Const, is partitioned into several subsets as follows:

Each predicate and function symbol has precisely one arity. For positional predicate and function symbols, an arity is a non-negative integer that tells how many arguments the symbol can take. For symbols that take named arguments, an arity is a set {s1 ... sk} of argument names (siArgNames) that are allowed for that symbol.

An important point is that neither the above partitioning of constant symbols nor the arity are specified explicitly. Instead, the arity of a symbol and its type is determined by the context in which the symbol is used.

Definition (Context of a symbol). The context of an occurrence of a symbol, s∈Const, in a formula, φ, is determined as follows:

Definition (Well-formed formula). A formula φ is well-formed iff:

Definition (RIF-PRD condition language). The RIF-PRD condition language consists of the set of all well-formed formulas that can be serialized using the RIF-PRD XML syntax.

2.1.2 Semantics of condition formulas

This section specifies the intended semantics of the condition formulas in a RIF-PRD document.

For compatibility with other RIF specifications (in particular, RIF data types and builtins), and to make the interoperability with RIF logic dialects (in particular RIF-Core and RIF-BLD), the intended semantics for RIF-PRD condition formulas is specified in terms of a model theory.

2.1.2.1 Semantic Structures

The key concept in a model-theoretic semantics of a logic language is the notion of a semantic structure [Enderton01, Mendelson97].

Definition (Semantic structure). A semantic structure, I, is a tuple of the form <TV, DTS, D, Dind, IC, IV, IP, INP, Iframe, Isub, Iisa, I=, Iexternal, Itruth>. Here D is a non-empty set of elements called the domain of I, and Dind is a nonempty subset of D. Dind is used to interpret the elements of Const that are individuals. As before, Const denotes the set of all constant symbols and Var the set of all variable symbols. TV denotes the set of truth values that the semantic structure uses and DTS is a set of identifiers for primitive datatypes (please refer to Section Datatypes of [RIF-DTB] for the semantics of datatypes).

As far as the assignement of a standard meaning to formulas in the RIF-PRD condition language is concerned, the set TV of truth values consists of just two values, t and f.

The other components of I are total mappings defined as follows:

For convenience, we also define the following mapping I from terms to D:

The effect of datatypes. The set DTS must include the datatypes described in Section Primitive Datatypes of [RIF-DTB].

The datatype identifiers in DTS impose the following restrictions. Given dtDTS, let LSdt denote the lexical space of dt, VSdt denote its value space, and Ldt: LSdtVSdt the lexical-to-value-space mapping (for the definitions of these concepts, see Section Primitive Datatypes of [RIF-DTB]. Then the following must hold:

That is, IC must map the constants of a datatype dt in accordance with Ldt.

RIF-PRD does not impose restrictions on IC for constants in symbol spaces that are not datatypes included in DTS.

2.1.2.2 Interpretation of condition formulas

This section defines how a semantic structure, I, determines the truth value TValI(φ) of a condition formula, φ.

We define a mapping, TValI, from the set of all condition formulas to TV. Note that the definition implies that TValI(φ) is defined only if the set DTS of the datatypes of I includes all the datatypes mentioned in φ and Iexternal is defined on all externally defined functions and predicates in φ.

Definition (Truth valuation). Truth valuation for well-formed condition formulas in RIF-PRD is determined using the following function, denoted TValI:

2.1.2.3 Satisfaction of a condition

We now define what it means for a set of ground formulas to satisfy a condition formula. The satisfaction of condition formulas by a set of ground formulas provides formal underpinning to the operational semantics of rulesets interchanged using RIF-PRD.


Definition (Models). A semantic structure I is a model of a condition formula, φ, written as I |= φ, iff TValI(φ) = t.

Definition (Logical entailment). Let φ and ψ be formulas. We say that φ entails ψ, written as φ |= ψ, if and only if for every semantic structure, I, for which both TValI(φ) and TValI(ψ) are defined, I |= φ implies I |= ψ.

By extension, in this document, a set of formulas, Φ = {φ1, ..., φn}, n ≥ 1, is said to entail a formula ψ, written as Φ |= ψ, if and only if for every semantic structure, I, for which TValI(φ0), ..., TValI(φn), and TValI(ψ) are defined, I |= φ0 and ... and I |= φn implies I |= ψ.

Definition (Condition Satisfaction). Let Φ = {φ1, ..., φm}, m ≥ 1, be a set of ground formulas and ψ be a condition formula. We say that Φ satisfies ψ if and only if, for every semantic structure I that is a model of all the ground formulas φi in Φ: I |= φi, i= 1..m, there is at least one semantic structure I* such that:

  1. I* |= ψ, and
  2. I* is exactly like I, except that a mapping I*V is used instead of IV, such that   I*V is defined to coincide with IV on all variables except, possibly, on the variables ?v0 ... ?vn, n ≥ 0, that are free in ψ, that is, such that: Var(ψ) = {?v0 ... ?vn}.

In other words, a set of ground formulas Φ = {φ1, ..., φm}m ≥ 1 satisfies a condition formula ψ iff Φ |= Exists ?v0 ... ?vn (ψ), where {?v0, ..., ?vn}n ≥ 0 = Var(ψ).

2.1.2.4 Matching substitution

At the syntactic level, the interpretation of the variables by a valuation function IV is realized by a substitution. The matching substitution of constants to variables, as defined below, provides the formal link between the model-theoretic semantics of condition formulas and the operational semantics of rule sets in RIF-PRD.

Let Term be the set of the terms in the RIF-PRD condition language (as defined in section Terms).

Definition (Substitution). A substitution is a finitely non-identical assignment of terms to variables; i.e., a function σ from Var to Term such that the set {xVar | x ≠ σ(x)} is finite. This set is called the domain of σ and denoted by Dom(σ). Such a substitution is also written as a set such as σ = {ti/xi}i=0..n where Dom(σ) = {xi}i=0..n and σ(xi) = ti, i = 0..,n.

Definition (Ground Substitution). A ground substitution is a substitution σ that assigns only constants to the variables in Dom(σ): ∀ x Dom(σ), σ(x) ∈ Const.

Definition (Matching Substitution). Let ψ be a condition formula; let σ be a ground substitution for the free variables of ψ, that is, such that: Var(ψ) ⊆ Dom(σ); and let Φ be a set of ground formulas that satisfies ψ. We say that σ is matching Ψ to Φ (or simply, matching, when there is no ambiguity with respect to Ψ and Φ) if an only if, for every semantic structure I that is a model of all the ground formulas φi in Φ, there is at least one semantic structure I*, such that:

  1. I* is a model of ψ: I* |= ψ;
  2. I* is exactly like I, except that a mapping I*V is used instead of IV, such that   I*V is defined to coincide with IV on all variables except, possibly, on the variables ?v0 ... ?vn that are free in ψ, that is, such that: Var(ψ) = {?v0 ... ?vn};
  3. I*V(?xi) = IC(σ(?xi)), for all ?xi in Var(ψ).

In the definition of a matching substitution, conditions 1 and 2 are the same as in the definition of Condition Satisfaction, and they guarantee that the Φ-consistency of a substitution for the free variables in ψ is defined with respect to the same semantic structures that make Φ satisfy ψ. Condition 3 guarantees that Φ |= ψ[σ], where ψ[σ] denotes the ground condition formula obtained by substituting σ(?x) for every occurence of ?x in ψ, for every variable ?x in Var(ψ).

In other words, a formula ψ matches a ground formula And(φ1, ..., φn), n > 0, with respect to a ground substitution σ, in the usual sense of pattern matching algorithms, e.g. [REFERENCE], if and only if σ is a matching substitution for the free variables of ψ with respect to the set of ground formulas Φ = {φ1, ..., φn}.

2.2 Actions

This section specifies the actions that can be serialized using RIF-PRD, by specifying:

(See also: Proposed modified abstract syntax and semantics for option 3)

2.2.1 Abstract Syntax

For a production rule language to be able to interchange rules using RIF-PRD, its alphabet for expressing the action part of a rule must, at the abstract syntax level, consist of syntactic constructs to denote:

Editor's Note: ... and/or others. We are especially interested in feedback about actions that cannot be decomposed into a sequence of the above.

For the sake of readability and simplicity, this specification introduces a non-normative notation for these constructs. That notation is not intended to be a concrete syntax and it leaves out many details that are not needed for its purpose. The only normative concrete syntax for RIF-PRD is the XML syntax.

2.2.1.1 Atomic actions

Atomic action constructs take constructs from the RIF-PRD condition language as their arguments.

Definition (Atomic action). An atomic action can have several different forms and is defined as follows:

  1. Assert: If φ is a positional atom, an atom with named arguments, a frame, a membership atomic, or a subclass atomic in the RIF-PRD condition language, then Assert(φ) is an atomic action. φ is called the target of the action.
  2. Retract: If φ is a positional atom, an atom with named arguments, or a frame in the RIF-PRD condition language, then Retract(φ) is an atomic action. φ is called the target of the action.
  3. Retract object: If t is a term in the RIF-PRD condition language, then Retract(t) is an atomic action. t is called the target of the action.
2.2.1.2 Action variable bindings

Action variable bindings provide a limited mechanism to initialize local action variables. Action variables may be bound to newly created frame objects or to slot values of frames.

Definition (Action variable binding). An action variable binding can have two forms and is defined as follows:

  1. New: if ?o is a variable defined in an enclosing action block (described below), then New(?o) is an action variable binding.
  2. frame slot value: if f is a frame in the RIF-PRD condition language, then f is an action variable binding.
2.2.1.3 Action blocks

A sequence of zero or more variables followed by a sequence of zero or more action variable bindings followed by a sequence of one or more atomic actions is called an action block.

Definition (Action block). If v1, ..., vn1, n1 ≥ 0, are variables (sometimes called action variables) and b1, ..., bn2, n2 ≥ 0, are action variable bindings and a1, ..., an3, n3 ≥ 1, are atomic actions,

  1. if n1 = 0 then Do(a1 ... an3) is an action block.
  2. else Do v1 ... vn1(b1 ... bn2; a1 ... an3) is an action block.

Definition (Well-formed action block). An action block is well-formed if and only if:

Definition (Ground atomic action). An atomic action with target t is a ground atomic action (or, simply, a ground action) if and only if Var(t) ⊆ bv, where bv is the set of variables declared in an enclosing action block, if any.

2.2.1.4 RIF-BLD compatibility

If the then part of a rule consists of a single action Assert(φ) then that action is written as simply φ.

If the then part of a rule consists of the action block Do(Assert(φ1) ... Assert(φn)), n ≥ 2, then that action block is written as simply And(φ1 ... φn).

2.2.1.5 Well-formed actions

Definition (Well-formed action). An action α is well-formed if and only if:

Definition (RIF-PRD action language). The RIF-PRD action language consists of the set of all the well-formed actions.

2.2.2 Operational semantics of actions

This section specifies the intended semantics of the actions in a RIF-PRD document.

The effect intended of the ground actions in the RIF-PRD action language is to change the set of conditions that are satisfied before and after each action is implemented.

As a consequence, the intended semantics of the ground actions in the RIF-PRD action language determines a relation, called the RIF-PRD transition relation: →RIF-PRDP(W) × L × P(W), where W denotes the set of all the ground condition formulas in the RIF-PRD condition languages; where P(W) denotes the power set of W; and where L denotes the set of all the ground atomic actions in the RIF-PRD action language.

Definition (RIF-PRD transition relation). The intended semantics of RIF-PRD actions is completely specified by the transition relation →RIF-PRDP(W) × L × P(W). (w, α, w') ∈ →RIF-PRD if and only if wW, w'W, and one of the following is true:

  1. α is Assert(φ) and for every ground formula ψ in W, w' |= ψ if and only if And(w, φ) |= ψ
  2. α is Retract(φ) and for every ground formula ψW, w' |= ψ if and only if w |= ψ and ψ |≠ φ
  3. α is Retract(o) and o is a constant and f1, ..., fn, n ≥ 0, are ground frames where o is the object, and m1, ..., mn', n' ≥ 0, are ground member atomics where o is the object, and for every ground formula φW, w' |= φ if and only if w |= φ and φ |≠ Or(f1, ..., fn, m1, ..., mn')
  4. α is Do v1...vnv(b1...bnb; α1...αna) such that
    1. each variable vi is replaced everywhere in the actions α1...αna with constant ci, determined as follows. Let bj be the action variable binding that references vi, which is guaranteed to exist and be unique if α is well-formed:
      1. if bj is New(vi), then ci is a constant such that
        1. for every constant k in W, w |≠ ci#k and
        2. for every frame f in W, ci does not occur in the object position of f
      2. if bj is a frame, then ci comes from the substitution of vi as specified by the extractActions function.
    2. (w1, α1, w'1) ∈ →RIF-PRD and ... and (wna, αna, w'na) ∈ →RIF-PRD and w = w1 and wi+1 = w'i and w'na = w'

Rule 1 says that all the condition formulas that were satisfied before an assertion will be satisfied after, and that the condition formulas that are satisfied by the asserted ground formula will be satisfied after the assertion.

Rule 2 says that all the condition formulas that were satisfied before a retraction will be satisfied after, except if they are satisfied only by the retracted fact.

Rule 3 says that all the condition formulas that were satisfied before the removal of a frame object will be satisfied after, except if they are satisfied only by one of the frame or membership formulas about the removed object or a conjunction of such formulas.

Rule 4 says that the effect of a block of actions is the effect of executing each action one after the other.

2.3 Production rules and rulesets

This section specifies the rules and rulesets that can be serialized using RIF-PRD, by specifying:

In addition, this section specifies additional concrete XML syntax for wrapping a ruleset in a RIF-PRD document and for adding meta-data to elements in a RIF-PRD document.

2.3.1 Abstract syntax

For a production rule language to be able to interchange rules using RIF-PRD, in addition to the RIF-PRD condition and action languages, its alphabet must, at the abstract syntax level, contain syntactic constructs:

For the sake of readability and simplicity, this specification introduces a notation for these constructs. That notation is not intended to be a concrete syntax and it leaves out many details that are not needed for its purpose: the only concrete syntax for RIF-PRD is the XML syntax.

2.3.1.1 Rules

Definition (Rule). A rule can be either:

A rule If condition, Then action can be equivalently noted action :- condition, that is, using RIF-BLD logic programming notation. Indeed, the normative XML syntax is the same for a conditional assertion in RIF-BLD and for a conditional action in RIF-PRD. The use of RIF-BLD notation is especially useful if the condition formula, condition, contains no negation, and if action is an atomic conclusion or a conclusion block, to emphasize that such a rule has the same semantics in RIF-PRD and RIF-BLD.

Notice that the notation for a rule with bound variables uses the keyword Forall for the same reasons, that is, to emphasize the overlap with RIF-BLD. Indeed, although Forall does not indicate the universal quantification of the declared variables, in RIF-PRD, but merely that the execution of the rule must be considered for all their bindings as constrained by the binding patterns, the semantics of a RIF-PRD rule with bound variables and the semantics of a RIF-BLD universally quantified rule coincide whenever they have the same RIF XML syntax.

2.3.1.2 Groups

Definition (Group). If strategy denotes a conflict resolution strategy, if priority is an integer, and if each rgj, 0 ≤ j ≤ n, is either a rule or a group, then any of the following is a group:

2.3.1.3 Well-formed rules and groups

The function Var(f), that has been defined for condition formulae and extended to actions, is further extended to rules, as follows:

Definition (Well-formed rule). A rule, r, is a well-formed rule if and only if it contains no free variable, that is, Var(r) = 0, and either:

Definition (Well-formed group). A well-formed group is either a group that contains only well-formed rules and well-formed groups, or a group that contains no rule or group (an empty group).

The set of the well-formed groups contains all the production rulesets that can be meaningfully interchanged using RIF-PRD.

2.3.2 Operational semantics of rules and rule sets

For the purpose of specifying the semantics of a RIF-PRD rule or group of rules, a production rule system PRS is defined as a labeled terminal transition system (e.g. PLO04).

Definition (labeled terminal transition system): A labeled terminal transition system is a structure {C, L, →, T}, where

A labeled transition system is a structure {C, L, →} (without a set T of final states).

The idea of describing a PRS as a labeled terminal transition system is that, given a set of production rules RS and a set of facts w0, the rules in RS that are satisfied, in some sense, in w0 determine an action a1, which execution results in a new set of facts w1; the rules in RS that are satisfied in w1 determine an action a2 to execute in w1, and so on, until the system reaches a final state and stops. The result is the set of facts wn when the system stops.

Example 3.1. Judicael, one follower of Joe the Hen Public's method, has four chickens, Joe, Jack, Joe and Julia, that own three potatoes (BigPotato, SmallPotato, UglyPotato) among them:

That is the initial set of facts w0. Paula's rule set contains one single rule, that is, Joe's CMP rule:

(* joe:ChickenAndMashedPotatoes *)
Forall ?chicken ?potato ?allowance ?age ?weight (
  Do( Execute(joe:mash(?potato)) 
      Retract(?chicken[joe:allowance->?allowance])
      ?chicken[joe:allowance->External(func:numeric-multiply(?allowance 1.1))]
      Retract(joe:owns(?chicken ?potato)) )
  :-
  And( ?chicken#joe:Chicken 
       ?chicken[joe:age->?age joe:allowance->?allowance]
       External(pred:numeric-greater-than(?age, 8))
       ?potato#joe:Potato 
       ?potato[joe:weight->?weight]
       joe:owns(?chicken ?potato)
       External(pred:numeric-greater-than(?weight External(func:numeric-divide(?age 2))))
       External(pred:string-not-equals(External(joe:today()), "Tuesday"))
       Not(External(joe:foxAlarm())) ))

When the rule is applied to w0:

Suppose that Judicael's implementation of today() returns Monday and that the foxAlarm() is false when the CMP rule is applied: the condition is satisfied, and the actions in the conclusion are executed with BigPotato substituted for ?potato, Joe substituted for ?chicken, and 10 substituted for ?allowance. This results in the following changes in the set of facts:

The resulting set of facts w1 is thus:

When the CMP rule in applied to w1, the first External predicate still selects {Joe/?chicken, Jack/?chicken, Julia/?chicken} as possible values for variable ?chicken, but the joe:own relation and the second External predicate do not select any possible substitution for the couple (?chicken, ?potato) anymore: the rule cannot be satisfied, and the system, having detected a final state, stops.

The result of the execution of the system is w1.

In the remainder of this section, as in the section on the operational semantics of actions, W denotes the set of all the ground condition formulas in the RIF-PRD condition languages, and L denotes the set of all the ground atomic actions in the RIF-PRD action language. In addition, LC denotes the set of the formulas in the RIF-PRD condition language, and R denotes the set of all the rules in the RIF-PRD rule language. Finally, given a set X, P(X) will denote the power set of X and S(X), the set of all the finite sequences of elements of X.

For the purpose of this section, an instance of a rule, r ∈ R, is defined as a couple (rid, σ), where rid uniquely identifies r and σ is a ground substitution such that Var(r)Dom(σ). Given a rule instance ri = (rid, σ), rule(ri) denotes the rule that is uniquely identified by rid, and substitution(ri) denotes σ.

Similarly, an instance of a rule set RS is a set of rule instances rii, where ∀ i, rule(rii)RS. Given a rule set RS, Inst(RS) denotes the set of all the possible instances of RS.

A RIF-PRD production rule system is defined as a labelled terminal transition system: given a rule set RS ⊆ R, let CRS ⊆ P(W) × S(Inst(RS)) be a set of states, where a state is a pair c = (w, ric), such that w ⊆ W is a set of facts, and ric ∈ S(Inst(RS)) is an ordered instance of RS. Given a state c = (w, ric), let facts(c) denote the first element, the set of facts w; and let picked(c) denote the second element, the ordered ruleset instance, ric.

The idea is that a state, c, is made of a set, w, of ground FORMULAe that represent a state of facts; and of the ordered list, ric, of all the instances of the rules in the considered ruleset RS that are fired, in some sense to be further specified, in that state of facts.

Further, let HRS ⊆ S(CRS) be a set of histories, where a history, h, is an ordered list of states ci: h = (cn...c1), n≥ 0. Given a history, h ∈ HRS, current(h) will be used to denote the first element of h and history(h) will be used to denote h minus current(h): if h = (cn...c1), n≥ 1, current(h) denotes cn and history(h) denotes the ordered list (cn-1...c1), n≥ 1. If h = () is the empty list, current(h) = history(h) = ∅.

The idea is that a history, h, represents the stack of the states that have been successively traversed by a production rule system, in the current run, from its initial state to the current state: current(h) represents the current state of the system; history(h) represents its history, that is, the states of facts that held and the instances that were fired in the previous cycles, ordered from most recent to initial.

Let further assume three functions:

Let extractActions: S(Inst(R))S(L), be a helper function that, given an ordered set, ori, of rule instances, returns the sequence of ACTIONs that is the concatenation, preserving the order in ori, of the sequences of ground actions determined by each of the rule instances in ori.

Editor's Note: extractActions is underdefined. Need be fixed at some point.

Given a ruleset RS and the associated conflict resolution strategy LS, a RIF-PRD production rule system is defined as a labelled terminal transition system PRSRS,LS = {HRS, S(L), →RS,LS, TRS,LS}, where :

Intuitively, the first condition in the definition of the transition relation →RS,LS says that a RIF-PRD production rule system can transition from one history to another only if the implementation of the actions picked in the current state of the former history produce the state of facts in the current state of the latter, according to the semantics of the individual actions, as specified in the relation →RIF-PRD. Condition 2 guarantees that only the selection strategy and the specification of the function PICK determine which are the allowed transition paths out of a given state. And condition 3 guarantees that the system halts as soon as it encounters a terminal state.

The input function is defined as:
Eval(RS, LS, w) →RS,LS h ∈ HRS, where facts(current(h)) = w, picked(current(h)) = PICK(w, ∅, RS, LS) and history(h) = ∅
The output function is defined as:
h' ∈ TRS,LSRS,LS facts(current(h')) = w'

Or, using →*RS,LS to denote the transitive closure of the transition relation:

Eval(RS, w) →*RS,LS w'

Given the specification of PRSRS,LS, the intended operational semantics of a production ruleset represented by a RIF-PRD Group RS is completely specified by the specification of the three functions INSTANTIATE, PICK and FINAL.

2.3.2.1 Rules instantiation: INSTANTIATE

The evaluation of the function INSTANTIATE corresponds to the step that is often called matching in the description of production rule systems (e.g. PRR07). Given a collection of rules, it considers all possible ground rule instances, obtained by assigning ground terms to the variables occuring in them. Its semantics is defined, in accordance with the semantics of the RIF-PRD condition language.

Let ExtractCONDITIONS: R → LC be a function that, given a rule, r ∈ R, returns a well-formed condition formula defined recursively as follows:

Let InstantiateRULE: P(W) × R → P(Inst(R)), be a function that, given a set of facts wW and a rule rR, returns the set, irInst(R), of all the instances of r that are satisfied in w, where a rule instance ri = (rid, σ) satisfies a set of fact w if and only if σ matches ExtractCONDITIONS(rule(rid)) to w.

The evaluation of the function INSTANTIATE(w, RS), where wW and RSR, can now be specified as a simple terminal transition system where:

The input function is defined as:

INSTANTIATE(w, RS) → (w, RS, ∅)

The output function is defined as:

(w, ∅, ri) → ri


Example 3.4. TBD

2.3.2.2 Instances selection: PICK

A rule instance determines a sequences of ground actions, by application of the associated substitution to the variables in the ACTIONs in the then component of the instantiated rule. The decision to implement the sequence of actions that a rule instance determines is often called: firing the rule instance.

More than one rule from a rule set may be instantiated in a given state of facts, and, for a given rule, there may be several different instances. The set of all the rule instances that are satisfied in a given state is often called: the conflict set; and the process of selecting one or more rule instances from the conflict set for firing is often called: conflict resolution.

In RIF-PRD the conflict resolution algorithm (or conflict resolution strategy) that is intended for a set of rules is denoted by a keyword or a set of keywords that is attached to the rule set. In this version of the RIF-PRD specification, a single conflict resolution strategy is specified normatively: it is denoted by the RIF-PRD keyword rif:standardForward, for it accounts for a common conflict resolution strategy used in most forward-chaining production rule systems.

Editor's Note: Name of the standard CR strategy to be discussed and agreed upon... standardForward used here as a placeholder.

Future versions of the RIF-PRD specification may specify normatively the intended conflict resolution strategies to be attached to additional keywords. In addition, RIF-PRD documents may include non-standard keywords: it is the responsability of the producers and consumers of such document to agree on the intended conflict resolution strategies that are denoted by such non-standard keywords.

2.3.2.2.1 Conflict resolution: rif:standardForward

Most existing production rule systems implement conflict resolution algorithms that are a combination of the following elements (under these or other, idiosyncratic names; and possibly combined with additional, idiosyncratic rules):

The RIF-PRD keyword rif:standardForward denotes the common conflict resolution strategy that can be summarized as follows: given a conflict set, as returned by the function INSTANTIATE

  1. Refraction is applied to the conflict set, that is, all the refracted rule instances are removed from the conflict set;
  2. The remaining rule instances are ordered by decreasing priority, and only the rule instances with the highest priority are kept in the conflict set;
  3. The remaining rule instances are ordered by decreasing recency, and only the most recent rule instances are kept in the conflict set;
  4. Any remaining tie is broken arbitrarily, and a single rule instance is kept for firing.

Accordingly, given a state of fact, w ∈ W, a history, h ∈ HRS, and a rule set RS, the function PICK(w, h, RS, rif:standardForward) returns a list that contain a single rule instance, selected from the conflict set generated by INTANTIATE(w, RS) as specified below.

As specified earlier, picked(c) denotes the ordered list of the rule instances that were picked in state c. Under the conflict resolution strategy denoted by rif:standardForward, the list denoted by picked(c) contains a single rule instance, for any given state, c.

For the purpose of this specification, an extended test, inst, is specified for the membership of a rule instance in a set of rule instances: given a rule instance, ri ∈ Inst(RS), and a set of rule instance, RI ⊆ Inst(RS), ri ∈inst RI if and only if there is a rule instance, ri' ∈ RI such that rule(ri) = rule(ri') and, for each variable ?v ∈ Var(rule(ri)), σ(?v) = σ'(?v), where σ = substitution(ri) and σ' = substitution(ri').

Furthermore, let recency: Inst(RS) × HRS → N, where N denotes the set of the positive integers, be an integer function that, given a rule instance, ri, and a history, h, returns the number of states in h, starting from the first one, in which ri is continuously satisfied: if h is the history of the current state, recency(ri, h) provides a measure of the recency of the rule instance ri. The function is specified recursively as follows: for all rule instances ri ∈ Inst(RS), and forall history h ∈ HRS,

  1. if h is empty, recency(ri, ∅) = 0;
  2. if h is not empty,
    1. if ri ∈inst INSTANTIATE(facts(current(h)), RS), recency(ri, h) = 1 + recency(ri, history(h));
    2. if ri ∉inst INSTANTIATE(facts(current(h)), RS), recency(ri, h) = 1.

And let lastPicked: Inst(RS) × HRS → N, where N denotes the set of the positive integers, be an integer function that, given a rule instance, ri, and a history, h, returns the number of states in h, starting from the first one, since ri has been last fired. The function is specified recursively as follows: for all rule instances ri ∈ Inst(RS), and forall history h ∈ HRS,

  1. if ri ∈inst picked(current(h)), lastPicked(ri, h) = 1;
  2. if ri ∉inst picked(current(h)), lastPicked(ri, h) = 1 + lastPicked(ri, history(h)).

Finally, given a rule instance, ri ∈ Inst(RS), let priority(ri) denote the priority that is associated to rule(ri) in RS, or zero, if no priority is associated to rule(ri) in RS. If rule(ri) is inside nested Groups in RS, priority(ri) denotes the priority that is associated with the innermost Group to which a priority is explicitely associated, or zero.

Given a state of facts, w ∈ W, a history, h ∈ HRS, and a rule set, RS, PICK(w, h, RS, rif:standardForward ) can now be defined with the help of a terminal transition system {A, →sF, TsF}, where:

The input function is defined as:
PICK(w, h, RS; rif:standardForward) →sF a = INSTANTIATE(w, RS)
The output function is defined as:
a' ∈ TsFsF keepOneFrom(a')

where keepOneFrom breaks any remaining tie by removing arbirarily all the elements but one from its argument list.

2.3.2.3 Halting test: FINAL

Editor's Note: This section is still under discussion (see ISSUE-65). This version specifies a single, default halting test: future version of this draft may specify additional halting tests, and/or a different default. The Working Group seeks feedback on which halting tests and which combinations of tests should be supported by RIF-PRD and/or required from RIF-PRD implementations; and which halting test should be the default, if any.

By default, the specification for a terminal state that is intended for a set of production rules, when no halting test is explicitely associated to its representation as a RIF-PRD Ruleset, is when no rule instance is fireable: this is the case when INSTANTIATE returns an empty set of rule instances, or when all the rule instances that are satisfied in the state, according to the semantics of INSTANTIATE, have already been fired in a state that has not since changed significantly. That latter condition guarantees, in particular, that the system halts when it reaches a fixpoint.

Formally, ∀ RS ⊆ R, ∀ c ∈ CRS, PICK(c, RS) = true if and only if instance(c) - history(c) = ∅. Otherwise, PICK(c, RS) = false.

3 XML Syntax

This section specifies a common concrete XML syntax to serialize any production rule set written in a language that share the abstract syntax speicifed in section 4.1, provided that its intended semantics agrees with the semantics that is described in section 4.2.

In the following, after the notational conventions are introduced, we specify the RIF-PRD XML constructs that carry a normative semantics with respect to the intended interpretation of the interchanged rules. They are specified with respect to the abstract syntax, and their specification is structured according to the specification of the abstract syntax in sections 2.1, 3.1 and 4.1.

The root element of any RIF XML document, Document and other XML constructs that do not carry a normative semantics with respect to the intended interpretation of the interchanged rules are specified in the last sub-section.

3.1 Notational conventions

3.1.1 Namespaces

Throughout this document, the xsd: prefix stands for the XML Schema namespace URI http://www.w3.org/2001/XMLSchema#, the rdf: prefix stands for http://www.w3.org/1999/02/22-rdf-syntax-ns#, and rif: stands for the URI of the RIF namespace, http://www.w3.org/2007/rif#.

Syntax such as xsd:string should be understood as a compact URI (CURIE) -- a macro that expands to a concatenation of the character sequence denoted by the prefix xsd and the string string. The compact URI notation is used for brevity only, and xsd:string should be understood, in this document, as an abbreviation for http://www.w3.org/2001/XMLSchema#string.

3.1.2 BNF pseudo-schemas

The XML syntax of RIF-PRD is specified for each component as a pseudo-schema, as part of the description of the component. The pseudo-schemas use BNF-style conventions for attributes and elements: "?" denotes optionality (i.e. zero or one occurrences), "*" denotes zero or more occurrences, "+" one or more occurrences, "[" and "]" are used to form groups, and "|" represents choice. Attributes are conventionally assigned a value which corresponds to their type, as defined in the normative schema. Elements are conventionally assigned a value which is the name of the syntactic class of their content, as defined in the normative schema.

<!-- sample pseudo-schema -->
    <defined_element
          required_attribute_of_type_string="xs:string"
          optional_attribute_of_type_int="xs:int"? >
      <required_element />
      <optional_element />?
      <one_or_more_of_these_elements />+
      [ <choice_1 /> | <choice_2 /> ]*
    </defined_element>

3.1.3 Syntactic components

Three kinds of syntactic components are used to specify RIF-PRD:

3.2 Conditions

This section specifies the XML constructs that are used in RIF-PRD to serialize condition formulae.

3.2.1 TERM

The TERM class of constructs is used to serialize terms, be they simple terms, that is, constants and variables; or positional terms or terms with named arguments, both being, per the definition of a well-formed formula, representations of externally defined functions.

As an abstract class, TERM is not associated with specific XML markup in RIF-PRD instance documents.

    [ Const | Var | External ]
3.2.1.1 Const

In RIF, the Const element is used to serialize a constant.

The Const element has a required type attribute and an optional xml:lang attribute:

The content of the Const element is the constant's litteral, which can be any Unicode character string.

    <Const type=xsd:anyURI [xml:lang=xsd:language]? >
        Any Unicode string
    </Const>

\{\{EdNote|text=The case of non-standard data types, that is, of constants that do not belong or cannot be cast in one of RIF builtin types for interchange purposes, is still under discussion in the WG. The WG seeks feedback on whether they should be allowed and why.\}\}

Example 2.1. In each of the examples below, a constant is first described, followed by its serialization in RIF-PRD XML syntax.

a. A constant with builtin type xsd:integer and value 123:

<Const type="xsd:integer">123</Const>

b. A constant which symbol today is defined in Joe the Hen Public's namespace http://rif.examples.com/2008/joe#. The type of the constant is rif:iri:

<Const type="rif:iri">
   http://rif.examples.com/2008/joe#today
</Const>

c. A constant with symbol BigPotato that is local to the set of rules where it appears (e.g. a RuleSet specific to Paula's farm). The type of the constant is rif:local:

<Const type="rif:local">BigPotato</Const>

d. A constant with non-builtin type xsd:int and value 123:

<Const type="xsd:int">123</Const>


3.2.1.2 Var

In RIF, the Var element is used to serialize a variable.

The content of the Var element is the variable's name, serialized as an Unicode character string.

    <Var> any Unicode string </Var>

Example 2.2. The example below shows the XML serialization of a reference to a variable named: ?chicken.

<Var> chicken <Var>
3.2.1.3 External

As a TERM, the External element is used to serialize a positional term or a term with named arguments. In RIF-PRD, a positional or a named-argument term represents always a call to an externally specified function, e.g. a builtin, a user-defined function, a query to an external data source...

The External element contains one content element, which in turn contains one Expr element that contains one op element, followed zero or one args element or zero of more slot elements:

    <External>
       <content>
          <Expr>
             <op> Const </op>
             [ <args rif:ordered="yes"> TERM* </args>?
               |
               <slot rif:ordered="yes">
                  <Name> Any Unicode string </Name>
                  TERM
               <slot>* ]
          </Expr>
       </content>
    </External>

Editor's Note: The slotted, or named arguments form of the External TERM construct is still under discussion (see also ISSUE-68). The working group seeks feedback on whether or not it should be included in PRD.

Example 2.3.

a. The first example below shows one way to serialize, in RIF-PRD, the sum of integer 1 and a variable ?x, where the addition conforms to the specification of the builtin fn:numeric-add.

The prefix fn is associated with the namespace http://www.w3.org/2007/rif-builtin-function#.

<External>
   <content>
      <Expr>    
         <op> <Const type="rif:iri"> fn:numeric-add </Const> </op>
         <args rif:ordered="yes"> 
            <Const type="xsd:integer"> 1 </Const>
            <Var> x </Var>
         </args>
      </Expr>
   </content>
</External>

b. Another example, that shows the RIF XML serialization of a call to the application-specific nullary function today(), which symbol is defined in the example's namespace http://rif.examples.com/2008/joe#:

<External>
   <content>
      <Expr>    
         <op>
            <Const type="rif:iri">
               http://rif.examples.com/2008/joe#today
            </Const>
         </op>
      </Expr>
   </content>
</External>

3.2.2 ATOMIC

The ATOMIC class is used to serialize atomics: positional and named-arguments atoms, equality, membership and subclass atomics, frame atomics and externally defined atomics..

As an abstract class, ATOMIC is not associated with specific XML markup in RIF-PRD instance documents.

    [ Atom | Equal | Member | Subclass | Frame | External ]
3.2.2.1 Atom

In RIF, the Atom element is used to serialize a positional atomics or an atomic with named arguments.

The Atom element contains one op element, followed by zero or one args element or zero or more slot arguments:

    <Atom>
       <op> Const </op>
       [ <args rif:ordered="yes"> TERM* </args>?
         |
         <slot rif:ordered="yes">
            <Name> Any Unicode string </Name>
            TERM
         <slot>* ]
    </Atom>

Editor's Note: The slotted, or named arguments form of the Atom construct is still under discussion (see also ISSUE-68). The working group seeks feedback on whether or not it should be included in PRD.

Example 2.4. The example below shows the RIF XML serialization of the positional atomicsowns(?c ?p), where the predicate symbol owns is defined in the example namespace http://rif.examples.com/2008/joe#.

<Atom>
   <op>
      <Const type="rif:iri">
         http://rif.examples.com/2008/joe#owns
      </Const>
   </op>
   <args rif:ordered="yes">
      <Var> c </Var>
      <Var> p </Var>
   </args>
</Atom>
3.2.2.2 Equal

In RIF, the Equal element is used to serialize equality atomics.

The Equal element must contain one left sub-element and one right sub-element. The content of the left and right elements must be a construct from the TERM abstract class. The order of the sub-elements is not significant.

    <Equal>
       <left> TERM </left>
       <right> TERM </right>
    </Equal>
3.2.2.3 Member

In RIF, the Member element is used to serialize membership atomics.

The Member element contains two unordered sub-elements:

    <Member>
       <instance> TERM </instance>
       <class> TERM </class>
    </Member>

Example 2.5. The example below shows the RIF XML serialization of a boolean expression that tests whether the individual denoted by the variable ?c is a member of the class Chicken that is defined in the example namespace http://rif.examples.com/2008/joe#.

<Member>
   <instance> <Var> c </Var> </instance>
   <class>
      <Const type="rif:iri">
         http://rif.examples.com/2008/joe#Chicken
      </Const>
   </class>
</Member>
3.2.2.4 Subclass

In RIF, the Subclass element is used to serialize subclass atomics.

The Subclass element contains two unordered sub-elements:

    <Subclass>
       <sub> TERM </sub>
       <super> TERM </super>
    </Subclass>
3.2.2.5 Frame

In RIF, the Frame element is used to serialize frame atomics.

Accordingly, a Frame element must contain:

    <Frame>
       <object> TERM </object>
       <slot rif:ordered="yes"> TERM TERM </slot>*
    </Frame>

Example 2.6. The example below shows the RIF XML syntax that serializes an expression that states that the object denoted by the variable ?c has the value denoted by the variable ?a for the property Chicken/age that is defined in the example namespace http://rif.examples.com/2008/joe#.

<Frame>
   <object> <Var> c </Var> </object>
   <slot rif:ordered="yes"> 
      <Const type="rif:iri">
         ttp://rif.examples.com/2008/joe#Chicken/age
      </Const>
      <Var> a </Var>
   </slot>
</Frame>

Editor's Note: The example uses an XPath style for the key. How externally specified data models and their elements should be referenced is still under discussion (see ISSUE-37).

3.2.2.6 External

In RIF-PRD, the External element is also used to serialize an externally defined atomic.

When it is a ATOMIC (as opposed to a TERM; that is, in particular, when it appears in a place where an ATOMIC is expected, and not a TERM), the External element contains one content element that contains one Atom element. The Atom element serializes the externally defined atom properly said:

    <External>
       <content>
          Atom
       </content>
    </External>

The op Const in the Atom element must be a symbol of type rif:iri that must uniquely identify the externally defined predicate to be applied to the args TERMs. It can be one of the builtin predicates specified for RIF dialects, as listed in section List of RIF Builtin Predicates and Functions of the RIF data types and builtins document, or it can be application specific. In the latter case, it is up to the producers and consumers of RIF-PRD rulesets that reference non-builtin predicates to agree on their semantics.

Example 2.7. The example below shows the RIF XML serialization of an externally defined atomic that tests whether the value denoted by the variable named ?a (e.g. the age of a chicken) is greater than the integer value 8, where the test is intended to behave like the builtin predicate op:numeric-greater-than as specified in XQuery 1.0 and XPath 2.0 Functions and Operators.

In the example, the prefix op: is associated with the namespace http://www.w3.org/2007/rif-builtin-predicate#.

<External>
   <content>
      <Atom>    
         <op> <Const type="rif:iri"> op:numeric-greater-than </Const> </op>
         <args rif:ordered="yes">
            <Var> ?a </Var>
            <Const type="xsd:decimal"> 8 </Const>
         </args>
      </Atom>
   </content>
</External>

3.2.3 FORMULA

The FORMULA class is used to serialize condition formulas, that is, atomic formulas, conjunctions, disjunctions, negations and existentials.

As an abstract class, FORMULA is not associated with specific XML markup in RIF-PRD instance documents.

    [ ATOMIC | And | Or | NmNot | Exists ]
3.2.3.1 ATOMIC

An atomic formula is serialized using a single ATOMIC statement. See specification of ATOMIC, above.

3.2.3.2 And

A conjunction is serialized using the And element.

The And element contains zero or more formula sub-elements, each containing an element of the FORMULA group.

    <And>
       <formula> FORMULA </formula>*
    </And>


3.2.3.3 Or

A disjunction is serialized using the Or element.

The Or element contains zero or more formula sub-elements, each containing an element of the FORMULA group.

    <Or>
       <formula> FORMULA </formula>*
    </Or>
3.2.3.4 NmNot

A negation is serialized using the NmNot element.

The NnNot element contains exactly one formula sub-element. The formula element contains an element of the FORMULA group, that serializes the negated statement.

    <NmNot>
       <formula> FORMULA </formula>
    </NmNot>

Editor's Note: The name of that construct may change, including the tag of the XML element.

3.2.3.5 Exists

An existentially quantified formula is serialized using the Exists element.

The Exists element contains:

    <Exists>
       <declare> Var </declare>+
       <formula> FORMULA </formula>
    </Exists>

Example 2.8. The example below shows the RIF XML serialization of a boolean expression that tests whether the chicken denoted by variable ?c is older than 8 months, by testing the existence of a value, denoted by variable ?a, that is both the age of ?c, as serialized as a Frame element, as in example 2.6, and greater than 8, as serialized as an External ATOMIC, as in example 2.7.

<Exists>
   <declare> <Var> a </Var> </declare>
   <formula>
      <And>
         <Frame>
            <object> <Var> c </Var> </object>
            <slot rif:ordered="yes"> 
               <Const type="rif:iri">
                  http://rif.examples.com/2008/joe#Chicken/age
               </Const>
               <Var> a </Var>
            </slot>
         </Frame>
         <External>
            <content>
               <Atom>    
                  <op> <Const type="rif:iri"> op:numeric-greater-than </Const> </op>
                  <args rif:ordered="yes">
                     <Var> a </Var>
                     <Const type="xsd:decimal"> 8 </Const>
                  </args>
               </Atom>
            </content>
         </External>
      </And>
   </formula>
</Exists>

3.3 Actions

This section specifies the XML syntax that is used to serialize the action part of a rule supported by RIF-PRD.

3.3.1 ACTION

The ACTION class of constructs is used to represent the actions in the action part of a production rule.

As an abstract class, ACTION is not associated with specific XML markup in RIF-PRD instance documents.

    [ ATOMIC_CONCLUSION | ATOMIC_ACTION | ACTION_BLOCK | CONCLUSION_BLOCK ]
3.3.1.1 ATOMIC_CONCLUSION

The ATOMIC_CONCLUSION class of constructs is used to represent the targets of the Assert construct and is also used for compatibility with RIF-Core.

    [ Atom | Frame | Member | Subclass ]
3.3.1.2 ATOMIC_ACTION

The ATOMIC_ACTION class of constructs is used to represent the primitive actions assert and retract.

    [ Assert | Retract ]
3.3.1.2.1 Assert

An Assert construct is used to represent actions that result in asserting an ATOMIC_CONCLUSION.

    <Assert>
         <target> ATOMIC_CONCLUSION </target>
    </Assert>
3.3.1.2.2 Retract

The Retract construct is used to represent actions that result in removing facts from working memory.

An Atom, a Frame, or a frame object may be retracted. A frame object is denoted using a TERM. A frame object is retracted by removing it from the Member relation and removing all its Frames.

The Retract element has one target sub-element that contains an Atom, a Frame, or a TERM construct that represents the facts to be removed on implementing the action.

    <Retract>
       <target> [ Atom | Frame | TERM ] </target>
    </Retract>

Example 2.10. The example below shows the RIF XML representation of an action that updates the chicken-potato ownership table by removing the predicate that states that the chicken denoted by variable ?c owns the potato denoted by variable ?p. The predicate is represented as in example 2.4.

<Retract>
   <target>
      <Atom>
         <op>
            <Const type="rif:iri">
               http://rif.examples.com/2008/joe#owns
            </Const>
         </op>
         <args rif:ordered="yes">
            <Var> c </Var>
            <Var> p </Var>
         </args>
      </Atom>
   </target>
</Retract>


3.3.1.3 ACTION_BLOCK

An ACTION_BLOCK construct is used to represent optional local variables and their bindings plus several ATOMIC_ACTIONs.

    <Do rif:ordered="yes">
       <declare> Var </declare>*
       <binding> [ New | Frame ] </binding>*
       <action> ATOMIC_ACTION  </action>+
    </Do>


3.3.1.3.1 New

The New construct is used to create a new frame object.

The New element has an instance sub-element that contains a Var. A new object is created and bound to the instance variable.

    <New>
       <instance> Var </instance>?
    </New>


Example 2.9. The example below shows the RIF XML representation of an action block that asserts a new 100 decigram potato.

<Do rif:ordered="yes">
   <declare><Var>p</Var></declare>
   <binding>
      <New>
         <instance><Var>p</Var></instance>
      </New>
   </binding>
   <action>
      <Assert>
         <target>
            <Member>
               <instance><Var>p</Var></instance>
               <class>
                  <Const type="rif:iri">http://rif.examples.com/2008/joe#Potato</Const>
               </class>
            </Member>
         </target>
      </Assert>
   </action>
   <action>
      <Assert>
         <target>
            <Frame>
               <object><Var>p</Var></object>
               <slot rif:ordered="yes">
                  <Const type="rif:iri">http://rif.examples.com/2008/joe#weight</Const>
                  <Const type="xsd:decimal">100</Const>
               </slot>
            </Frame>
         </target>
      </Assert>
   </action>
</Do>
3.3.1.4 CONCLUSION_BLOCK

A CONCLUSION_BLOCK construct is used to represent several ATOMIC_CONCLUSIONs in a way that is compatible with RIF-Core.

    <And>
       <formula> ATOMIC_CONCLUSION </formula>+
    </And>

3.4 Rules and Groups

This section specifies the XML constructs that are used, in RIR-PRD, to serialize rules and groups.

3.4.1 RULE

In RIF-PRD, the RULE class of constructs is used to serialize rules, that is, unconditional as well as conditional actions, or rules with bound variables.

As an abstract class, RULE is not associated with specific XML markup in RIF-PRD instance documents.

    [ Implies | Forall | ACTION ]
3.4.1.1 ACTION

An unconditional action block is serialized, in RIF-PRD XML, using the ACTION class of construct.

Editor's Note: To be updated based according ot the uptodate version of the XML syntax for actions.

3.4.1.2 Implies

Conditional actions are serialized, in RIF-PRD, using the XML element Implies.

The Implies element contains an optional if sub-element and a then sub-element:

Editor's Note: To be updated based according ot the uptodate version of the XML syntax for actions.

    <Implies>
       <if> FORMULA </if>?
       <then rif:ordered="yes">
          ACTION
          ACTION*
        </then>
     </Implies>
3.4.1.3 Forall

The Forall construct is used, in RIF-PRD, to represent rules with bound variables.

The Forall element contains:

    <Forall>
       <declare> Var </declare>+
       <pattern> FORMULA </pattern>*
       <formula> RULE </formula>
    </Forall>

Editor's Note: Nested Foralls make explicit the scope of the declared variables, and, thus, impose an order on the evaluation of the pattern and if FORMULAe in a rule. That ordering and the use of patterns to constrain the binding of variables may be of practical significance for some production rule systems, but they are irrelevant with respect to the intended semantics of the rules being interchanged (although they would be relevant if RIF-PRD was to be extended to support some kind of "else" or "case" construct). In addition, RIF-BLD does not allow nested Forall and does not support the association of contraining patterns to declared variables. The working group seeks feedback regarding whether nested Forall and constrainting pattern should be supported in RIF-PRD, to the cost of reducing the interoperability with RIF-BLD.

Example 2.10. The example below shows how the CMP rule extract: "if a chicken owns a potato and ..." could be serialized using a binding pattern FORMULA:

<Forall>
   <declare><Var>chicken</Var></declare>
   <formula>
      <Forall>
         <declare><Var>potato</Var></declare>
         <pattern>
            <External>
               <content>
                  <Atom>
                     <Const type="rif:iri">
                        http://rif.examples.com/2008/joe#owns
                     </Const>
                     <Args rif:ordered="yes">
                        <Var>chicken</Var>
                        <Var>potato</Var>
                     </Args>
                  </Atom>
               </content>
            </External>
         </pattern>
         <formula>
            ...
         </formula>
      </Forall>
   </formula>
</Forall>

3.4.2 Group

The Group construct is used to serialize a group.

The Group element has zero or one behavior sub-element and zero or more sentence sub-elements:

    <Group>
       <behavior>
          <ConflictResolution> xsd:anyURI </ConflictResolution>?
          <Priority> -10,000 ≤ xsd:int ≤ 10,000 </Priority>?
       </behavior>?
       <sentence> [ RULE | Group ] </sentence>*
    </Group>

3.5 Non-semantic carrying constructs

3.5.1 Document

The Document is the root element in a RIF-PRD instance document.

The Document contains zero or one payload sub-element, that must contain a Group element.

    <Document>
       <payload> Group </payload>?
    </Document>

3.5.2 Metadata

Metadata can be associated with any concrete class element in RIF-PRD: those are the elements with a CamelCase tagname starting with an upper-case character:

    CLASSELT = [ TERM | ATOMIC | FORMULA | ACTION | RULE | Group | Document ]

An identifier can be associated to any instance element of the abstract CLASSELT class of constructs, as an optional id sub-element that MUST contain a Const of type rif:local or rif:iri.

Metadata can be included in any instance of a concrete class element using the meta sub-element.

The RIF-PRD Frame construct is used to serialize metadata: the content of the Frame's object sub-element identifies the object to which the metadata is associated:, and the Frame's slots represent the metadata properly said as property-value pairs.

If the all the metadata is related to the same object, the meta element can contain a single Frame sub-element. If metadata related to several different objects need be serialized, the meta role element can contain an And element with zero or more formula sub-elements, each containing one Frame element.

   <CLASSELT>
       <id> Const </id>?
       <meta>
          [ Frame 
            |
            <And>
               <formula> Frame </formula>*
            </And>
          ]
       </meta>?
       other CLASSELT content
    </CLASSELT>

Notice that the content of the meta sub-element of an instance of a RIF-PRD class element is not necessarily associated to that same instance element: only the content of the object sub-element of the Frame that represents the metadata specifies what the metadata is about, not where it is included in the instance RIF document.

It is suggested to use Dublin Core, RDFS, and OWL properties for metadata, along the lines of http://www.w3.org/TR/owl-ref/#Annotations -- specifically owl:versionInfo, rdfs:label, rdfs:comment, rdfs:seeAlso, rdfs:isDefinedBy, dc:creator, dc:description, dc:date, and foaf:maker.

Example 2.11. TBC

4 Presentation syntax

This section specifies a presentation syntax for RIF-PRD. The presentation syntax is not normative: its main purpose is to help make the normative specification of the semantics easier to read.

The presentation syntax is designed to be very close to RIF-BLD. A line by line comparison of the EBNF will show these few differences:

  1. the addition of Not
  2. the removal of Expr, the syntactic class of logical functions,
  3. the replacement of ATOMIC in rule conclusions with ACTION, and the addition of Do(ACTION*) and And(ASSERT*) instead of And(ATOMIC*) in rule conclusions.
  4. definition of Assert, New, Retract, and Do actions.

It is intended that the syntax and semantics of RIF-BLD and RIF-PRD are the same when the rule conclusion contains a only Atoms and Frames, "Not" is not used, and logical functions are not used.

The following EBNF is from RIF-BLD, with lines prefixed with ! indicating a change for RIF-PRD:

  FORMULA        ::= 'And' '(' FORMULA* ')' |
                     'Or' '(' FORMULA* ')' |
                     'Exists' Var+ '(' FORMULA ')' |
                      ATOMIC |
                     'External' '(' Atom | Frame ')' |
!                    'Not' '(' FORMULA ')'
  ATOMIC         ::= Atom | Equal | Member | Subclass | Frame
  Atom           ::= UNITERM
  UNITERM        ::= Const '(' (TERM* <| (Name '->' TERM)*) ')'
  Equal          ::= TERM ' = ' TERM
  Member         ::= TERM '#' TERM
  Subclass       ::= TERM '##' TERM
  Frame          ::= TERM '[' (TERM '->' TERM)* ']'
! TERM           ::= Const | Var | 'External' '(' Expr ')'
  Expr           ::= UNITERM
  Var            ::= '?' UNICODESTRING

The following EBNF is taken from RIF-DTB and is unchanged for PRD. Its purpose is to provide shortcuts for constants.

  ANGLEBRACKIRI  ::= '<' IRI_REF '>'
  STRING         ::= '"' UNICODESTRING '"'
  CURIE          ::=  PNAME_LN | PNAME_NS   → see RIF-DTB
  Const          ::= STRING '^^'ANGLEBRACKIRI
                   | STRING '^^' CURIE
                   | ANGLEBRACKIRI     → shortcut for rif:iri
                   | CURIE             → shortcut for rif:iri
                   | STRING            → shortcut for xsd:string
                   | NumericLiteral    → shortcut for xsd:integer,xsd:decimal,xsd:double
                   | '_' LocalName     → shortcut for rif:local

The following EBNF is from RIF-BLD and defines rules, groups of rules, and the containing document. Changed lines are prefixed with !. Metadata can be associated with Document, Group, and RULE constructs.

! Document     ::= IRIMETA? 'Document' '('  Group? ')'
  Group        ::= IRIMETA? 'Group' '(' (RULE | Group)* ')'
! RULE         ::= (IRIMETA? 'Forall' Var+ '(' Implies ')') | Implies | INITIAL_FACT
! INITIAL_FACT ::= ASSERT | Member
! Implies      ::= IRIMETA? ACTION ':-' FORMULA
  IRIMETA      ::= '(*' Const? (Frame | 'And' '(' Frame* ')')? '*)'
  IRI          ::= UNICODESTRING
  Profile      ::= UNICODESTRING

Finally, the following EBNF describes the syntax of PRD actions.

  ACTION             ::= ATOMIC_CONCLUSION | ATOMIC_ACTION | ACTION_BLOCK | CONCLUSION_BLOCK 
  ATOMIC_CONCLUSION  ::= Atom | Frame | Member | Subclass
  ATOMIC_ACTION      ::= Assert | Retract
  Assert             ::= 'Assert' '(' ATOMIC_CONCLUSION ')'
  Retract            ::= 'Retract' '(' Atom | Frame | TERM ')'
  ACTION_BLOCK       ::= 'Do' Var* '(' ( ACTION_VAR_BINDING+ ';' )? ATOMIC_ACTION+ ')' 
  ACTION_VAR_BINDING ::= New | Frame
  New                ::= 'New' '(' Var ')'
  CONCLUSION_BLOCK   ::= 'And' '(' ATOMIC_CONCLUSION ATOMIC_CONCLUSION+ ')' 

5 References

[CIR04]
Production Systems and Rete Algorithm Formalisation, Cirstea H., Kirchner C., Moossen M., Moreau P.-E. Rapport de recherche n° inria-00280938 − version 1 (2004).

[CURIE]
CURIE Syntax 1.0 - A compact syntax for expressing URIs, W3C note 27 October 2005, M. Birbeck (ed.).

[HAK07]
Data Models as Constraint Systems: A Key to the Semantic Web, Hassan Ait-Kaci, Constraint Programming Letters, 1:33--88, 2007.

[PLO04]
A Structural Approach to Operational Semantics, Gordon D. Plotkin, Journal of Logic and Algebraic Programming, Volumes 60-61, Pages 17-139 (July - December 2004).

[PRR07]
Production Rule Representation (PRR), OMG specification, version 1.0, 2007.

[RDF-CONCEPTS]
Resource Description Framework (RDF): Concepts and Abstract Syntax, Klyne G., Carroll J. (Editors), W3C Recommendation, 10 February 2004, http://www.w3.org/TR/2004/REC-rdf-concepts-20040210/. Latest version available at http://www.w3.org/TR/rdf-concepts/.

[RDF-SCHEMA]
RDF Vocabulary Description Language 1.0: RDF Schema, Brian McBride, Editor, W3C Recommendation 10 February 2004, http://www.w3.org/TR/2004/REC-rdf-schema-20040210/. Latest version available at http://www.w3.org/TR/rdf-schema/.

[RFC-3066]
RFC 3066 - Tags for the Identification of Languages, H. Alvestrand, IETF, January 2001, http://www.isi.edu/in-notes/rfc3066.txt.

[RFC-3987]
RFC 3987 - Internationalized Resource Identifiers (IRIs), M. Duerst and M. Suignard, IETF, January 2005, http://www.ietf.org/rfc/rfc3987.txt.

[XDM]
XQuery 1.0 and XPath 2.0 Data Model (XDM), W3C Recommendation, World Wide Web Consortium, 23 January 2007. This version is http://www.w3.org/TR/2007/REC-xpath-datamodel-20070123/. Latest version available at http://www.w3.org/TR/xpath-datamodel/.

[XML-SCHEMA2]
XML Schema Part 2: Datatypes Second Edition, W3C Recommendation, World Wide Web Consortium, 28 October 2004, http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/. Latest version available at http://www.w3.org/TR/xmlschema-2/.

[XPath-Functions]
XQuery 1.0 and XPath 2.0 Functions and Operators, W3C Recommendation, World Wide Web Consortium, 23 January 2007, http://www.w3.org/TR/2007/REC-xpath-functions-20070123/. Latest version available at http://www.w3.org/TR/xpath-functions/.


6 Appendix: XML Schema for RIF-PRD

TBD

7 Appendix: Compatibility with RIF-BLD

7.1 Syntactic compatibility between RIF-PRD and RIF-BLD

RIF-PRD and RIF-BLD share essentially the same presentation syntax and XML syntax.

The syntactic differences between the two dialects are summarized below:

Below is a complete, construct by construct, comparison table of RIF-PRD and RIF-BLD presentation and XML syntaxes. A construct is tagged "BLD" or "PRD" if it is specific to the dialect, or tagged "Core" if it is common to both.

Editor's Note: RIF-Core will be equal to or included in the intersection of RIF-PRD and RIF-BLD. The exact scope of RIF-Core is still under discussion. Until RIF-Core is specified more precisely, this document assumes that it will be equal to the intersection of RIF-PRD and RIF-BLD.

Presentation syntax XML syntax
TERM ::=
BLD
[Const | Var | Expr | External]
PRD
[Const | Var | External]
Const ::=
Core
'"' UNICODESTRING '"^^' SYMSPACE
<Const type=xsd:anyURI [xml:lang=xsd:language]? >
   Any Unicode string
</Const>
Var ::=
Core
'?' Any Unicode string
<Var>
   Any Unicode string
</Var>
Expr ::=
BLD
Const '(' (TERM* | (Name '->' TERM)*) ')'
<Expr>
   <op> Const </op>
   [
    <args rif:ordered="yes"> TERM* </args>?
    |
    <slot rif:ordered="yes">
       <Name> Any Unicode string </Name>
       TERM
    </slot>*
   ]
</Expr>
PRD
Undefined except when wrapped in an External (as TERM), as follows.
External (as TERM) ::=
Core
'External' '(' Expr ')'
<External>
   <content>
      Expr
   </content>
</External>
ATOMIC ::=
Core
[Atom | Equal | Member | Subclass | Frame]
Atom ::=
Core
Const '(' (TERM* | (Name '->' TERM)*) ')'
<Atom>
   <op> Const </op>
   [
    <args rif:ordered="yes"> TERM* </args>?
    |
    <slot rif:ordered="yes">
       <Name> Any Unicode string </Name>
       TERM
    </slot>*
   ]
</Atom>
Equal ::=
Core
TERM = TERM
<Equal>
   <left> TERM </left>
   <right> TERM </right>
</Equal>
Member ::=
Core
TERM # TERM
<Member>
   <instance> TERM </instance>
   <class> TERM </class>
</Member>
Subclass ::=
Core
TERM ## TERM
<Subclass>
   <sub> TERM </sub>
   <super> TERM </super>
</Subclass>
Frame ::=
Core
TERM ' [ ' (TERM ' -> ' TERM)* ' ] '
<Frame>
   <object> TERM </object>
   <slot rif:ordered="yes"> TERM TERM </slot>*
</Frame>
FORMULA ::=
BLD
[ATOMIC | External | And | Or | Exists]
PRD
[ATOMIC | External | And | Or | NmNot | Exists]
External (as FORMULA) ::=
Core
'External '(' [Atom | Frame] ')'
<External>
   <content>
      [ Atom | Frame ]
   </content>
</External>
And ::=
Core
'And' '(' FORMULA* ')'
<And>
   <formula> FORMULA </formula>*
</And>
Or ::=
Core
'Or' '(' FORMULA* ')'
<Or>
   <formula> FORMULA </formula>*
</Or>
NmNot ::=
BLD
Undefined
PRD
'Not' '(' FORMULA ')'
<NmNot>
   <formula> FORMULA </formula>
</NmNot>
Exists ::=
Core
'Exists' Var+ '(' FORMULA ')'
<Exists>
   <declare> Var </declare>+
   <formula> FORMULA </formula>
</Exists>
ACTION ::=
BLD
Undefined
PRD
[ ASSERT | Retract ]
ASSERT ::=
BLD
Undefined
PRD
[ Atom | Frame ]
Retract ::=
BLD
Undefined
PRD
'Retract' '(' Atom | Frame ' ) '
<Retract>
   <target>
      [ Atom | Frame ]
   </target>
</Retract>
RULE ::=
BLD
[ Forall | Implies | ATOMIC ]
PRD
[ Forall | Implies | ACTION ]
Forall ::=
BLD
' Forall ' Var+ ' ( ' [Implies | ATOMIC] ' ) '
<Forall>
   <declare> Var </declare>+
   <formula>
       [Implies | ATOMIC ] 
   </formula>
</Forall>
PRD
' Forall ' Var+ (' ( ' FORMULA ' ) ')* ' ( ' RULE ' ) '
<Forall>
   <declare> Var </declare>+
   <pattern> FORMULA </pattern>*
   <formula> RULE </formula>
</Forall>
Implies ::=
BLD
(ATOMIC | 'And' '(' ATOMIC* ')') ':-' FORMULA
<Implies>
   <if> FORMULA </if>
   <then>
      [ ATOMIC
        |
        <And>
           <formula>
              ATOMIC
           </formula>*
        </And>
      ]
   </then>
</Implies>
PRD
(ACTION | 'Do' '(' ACTION* ')') ':-' FORMULA
<Implies>
   <if> FORMULA </if>
   <then>
      ACTION
      ACTION*
   </then>
</Implies>
Group ::=
Core
METADATA? 'Group' '(' ([RULE | Group])* ')'
<Group>
   <sentence> [ RULE | Group ] </sentence>*
</Group>
Import ::=
BLD
'Import' '(' IRI Profile? ')'
<Import>
   <location>lAny Unicode string</location>
   <profile><Profile>Any Unicode String1</Profile></profile>
</Import>
PRD
Undefined in this version of the draft
Document ::=
BLD
METADATA? 'Document' '(' [Import | Prefix | Base]* Group? ')'
<Document>
  <directive>
     [ Import | Prefix | Base]*
  </directive>
  <payload> Group </payload>?
</Document>
PRD
METADATA? 'Document' '(' Group? ')'
<Document>
  <payload> Group </payload>?
</Document>
METADATA ::=
Core
'(*' Const? (Frame | 'And' '(' Frame* ')')? '*)'
<AnyClassTag>
   <id> Const </declare>?
   <meta>
      [ Frame 
        |
        <And>
           <formula> Frame </formula>
        </And>
       ]
   </meta>?
   other content of AnyClassTag
</AnyClassTag>

7.2 Semantic compatibility between RIF-PRD and RIF-BLD

The intended semantics of any RIF XML document which is both a syntactically valid RIF-PRD document and a syntactically valid RIF-BLD document is the same whether it is considered a RIF-PRD or a RIF-BLD document. For any input set of facts, the set of rules contained in the document must produce the same output set of facts whether it is consumed as a RIF-PRD or a RIF-BLD document.

Proof. TBC