Herbrand Logic
 
Deductive databases, constraint satisfaction, Prolog, and formal verification are often defined as special cases of firstorder logic. Here we define their simplest incarnations from the perspective of Herbrand logic, where the resulting definitions are identical to those usually given in for example Ullman's Database and Knowledgebase Systems or Lloyd's Foundations of Logic Programming book. Because Herbrand semantics is simpler to teach and understand than firstorder logic, we hope our introduction to the foundations of these three applications are more accessible than the firstorder introduction to those not familiar with logic. Bilevel ReasoningAll four applications of Herbrand logic can be defined in a common framework: Bilevel Reasoning (BR). Bilevel reasoning focuses on reasoning about a pair <Γ, M>, where M is a model and Γ is a set of axioms. Γ conservatively extends the model M. The idea is that the model M picks out one world in the vocabulary V and the axioms Γ extend the theory defined by M to some theory in vocabulary V', which is larger than V. Definition (Bilevel Pair): A bilevel pair is <Γ, M>, where M is a Herbrand model, Γ is a set of axioms, and vocabulary[Γ]∪vocabulary[M] is a vocabulary, denoted vocabulary[<Γ,M>]. Satisfaction for bilevel pairs can be defined using the notion of a model's reduct, which is just a way of talking about the portion of a model in a shrunken vocabulary. Definition (Reduct): The reduct of model M wrt vocabulary V, written Reduct[M,V] is the intersection of M and the ground atoms of V. Definition (Bilevel Satisfaction): Let <Γ, M> be a bilevel pair, where Γ consists of closed sentences. Let N be a model in the vocabulary V = vocabulary[Γ] ∪ vocabulary[M]. N satisfies the pair exactly when N satisfies Γ wrt V and the portion of N corresponding to the vocabulary of M is the same as M. Just as the set of models for an axiomatization Δ is usually denoted Mod[Δ], we can use Mod[<Γ,M>] to denote the set of models that satisfy the bilevel pair <Γ,M>. Entailment in bilevel reasoning can therefore be defined follows. Definition (Bilevel Entailment): Let P be a bilevel pair and φ a closed sentence. P entails φ exactly when every model that satisfies P satisfies φ. This splitting of axioms and data is convenient, but often it is equivalent to a normal set of sentences in Herbrand logic. Theorem (Finite Bilevel Equivalent to Herbrand Logic): Let <Γ,M> be a bilevel pair, where M is finite. Then there is a sentence set Δ in Herbrand logic such that Mod[Δ] = Mod[<Γ,M>].
Start out by including in Δ every sentence in Γ. Then for each relation r in M, perform the following. Let {t_{1},...,t_{n}} be the set of ground tuples for which r is satisfied in M. Note this is a finite set. Include the sentence, ∀xbar.r(xbar) ⇔ xbar=t_{1} ∨ xbar=t_{2} ∨ ... ∨ xbar=t_{n}. To show: =_{N} <Γ,M> if and only if =_{N} Δ. Since Γ is included in Δ, we can remove it from both sides. Using the definition of bilevel pair satisfaction, we need now show that M = Reduct[N,vocab[M]] if and only if =_{N} ∀xbar. r_{i}(xbar) ⇔ xbar=t_{1} ∨ xbar=t_{2} ∨ ... ∨ xbar=t_{n} for all relations r_{i} in vocab[M]. (⇒) Suppose M = Reduct[N,vocab[M]] but for the purpose of contradiction there is some r_{i} such that #_{N} ∀xbar. r_{i}(xbar) ⇔ xbar=t_{1} ∨ xbar=t_{2} ∨ ... ∨ xbar=t_{n}. That is, there is some tbar such that #_{N} r_{i}(tbar) ⇔ tbar=t_{1} ∨ tbar=t_{2} ∨ ... ∨ tbar=t_{n}. That is, there is either some tbar in r_{i} in the reduct that is not in {t_{1},...,t_{n}} or there is some tbar not in r_{i} in the reduct but in {t_{1},...,t_{n}}. But in both cases, because the reduct of N is M, and {t_{1},...,t_{n}} was constructed to be exactly that set of ground terms in r_{i} in M, neither of these can be the case. Contradiction. (⇐) Suppose N satisfies ∀xbar. r_{i}(xbar) ⇔ xbar=t_{1} ∨ xbar=t_{2} ∨ ... ∨ xbar=t_{n} for all relations r_{i} in vocab[M], but for the purpose of contradiction M \ne Reduct[N,vocab[M]]. That is there is some r(ubar) extra in N or missing in N. Suppose the former, that r(ubar) is in Reduct[N,vocab[M]] but not M, i.e. ubar is not in {t_{1},...,t_{n}}. Then N could not satisfy ∀xbar. r(xbar) ⇔ xbar=t_{1} ∨ xbar=t_{2} ∨ ... ∨ xbar=t_{n} since ubar is none of the t_{i}. Likewise, if r(ubar) is in M but missing from Reduct[N,vocab[M]] then again N cannot satisfy ∀xbar. r(xbar) ⇔ xbar=t_{1} ∨ xbar=t_{2} ∨ ... ∨ xbar=t_{n} since this sentence entails r(ubar). Contradiction. ∎ Clearly then every finite bilevel pair can be encoded as a finite set of Herbrand logic sentences. However, as we shall see, deductive databases and to a lesser extent formal verification take advantage of this separation. They along with CSPs and logic programming can be defined as subsets of a very special class of bilevel pairsthose with exactly one satisfying model. In firstorder logic, a set of axioms whose models are all elementarily equivalent, i.e. indistinguishable wrt firstorder sentences, is said to be axiomatically complete. This means every sentence in the language or its negation is entailed by the axioms. Definition (Axiomatic Completeness): Let L be a language and Δ a set of sentences. Δ is axiomatically complete if and only if for every closed sentence s in L, Δ entails s or Δ entails ¬s or both. In Herbrand logic, if a set of sentences is axiomatically complete, those sentences are satisfied by exactly one model. (The fact that axiomatic completeness in Herbrand logic has different modeltheoretic properties than firstorder logic stems from the fact that Herbrand logic fixes the equality relation, whereas firstorder logic does not.) Likewise, we will say that a bilevel pair is (axiomatically) complete if and only if it has a single model. Definition (Complete Bilevel Pair): A bilevel pair P is complete if and only if Mod[P] is either a singleton set or the empty set. Definition (Complete Bilevel Axioms): A set of bilevel axioms Γ is complete wrt vocabulary V if and only if for every model M in V such that P=<Γ,M> is satisfiable, P is a complete bilevel pair. It is sometimes natural to think of Γ as simply extending the theory defined by M, a small wrinkle on the notion of a conservative extension to a logical theory. Definition (Conservative Pair): A pair P=<Γ,M> is conservative exactly when every sentence in Cn[P] that is in vocabulary[M] is a consequence of M itself, i.e. when it is in Th[M]. Definition (Conservative Bilevel Axioms): A set of axioms Γ is conservative wrt vocabulary V if and only if for every model M in V, <Γ,M> is a conservative pair. Deductive databases, constraint satisfaction, logic programming, and formal verification can all be defined as complete bilevel pairs.
Deductive DatabasesA database is complete bilevel pair where the model that satisfies the pair is finite. Two standard options exist for defining the set of object constants in the vocabulary: (1) it consists of those object constants that appear in P or (2) it is the set of all object constants, i.e. it includes infinitely many object constants. We will assume the former: that the set of object constants is just those that appear in P. Let <Γ,M> be a database. Using the conventional database terminology, the set of relations defined in M is the set of extensional database predicates (EDBs), i.e. the base tables, and the remaining relations comprise the set of intensional database predicates (IDBs), i.e. the views. When there are no IDBs, a database is just a Herbrand model, and there is always at least one EDB in every database. A database query always takes the following form: find all the x_{1},...,x_{n} such that the database satisfies the query φ(x_{1},...,x_{n}). Various languages exist for expressing that query; here we discuss Datalog with negation, which is often used to define IDBs. Because a database is a complete pair, Datalog has been designed so that the negative consequences need not be written down (just like in a Herbrand model) but at the same time every set of Datalog rules can always be assigned a unique model. This turns out to be a little tricky with negation. As we shall see, this allows us to define a database as a bilevel pair in a fairly straightforward way: the model is the set of EDB predicates and the axiom set defines the IDB predicates with Datalog. The rest of this section defines Datalog with negation and discusses how to ensure a set of Datalog rules can be assigned a unique model. Definition (Datalog Rule): A Datalog rule is an implication (where traditionally : is used instead of ⇐ and , is used in place of ∧).
 The head, h, is an atomic sentence.  Each element in the body, b_{i}, is a literal.  There are no function constants.  Safety: if a variable appears in the head or in a negative literal, it must appear in a positive literal in the body. (Usually, Datalog allows various arithmetic operations in the body of rules, e.g. addition and multiplication, but we ignore those operations here. Also, the above definition is usually called datalog^{¬}.) Datalog is usually viewed as a language for defining a larger database from a smaller one. It defines the contents of new relations based on the contents of the original relations, in the end producing a single model/database. Because Herbrand semantics allows multiple models to satisfy a particular set of sentences, as stated it is inappropriate for defining the semantics of Datalog rules. Three variations on Herbrand semantics are often used as the semantics for Datalog: minimal Herbrand semantics with stratified negation, stable model semantics, and wellfounded semantics. We leave discussion of stable model semantics to the section on Prolog; wellfounded semantics relies on 3valued logic, which we do not address. If a set of Datalog rules has no negation, i.e. when every literal in the body of every rule is an atom, it is Horn. It is wellknown that Horn rules have a welldefined minimal model (as measured by the number of ground atoms in the Herbrand model), and the semantics for such a set of rules is defined to be that model. When the rules do include negation, the minimal model is not necessarily welldefined. For example, the sentence
While negation does present some problems for the notion of a minimal Herbrand semantics, certain forms of negation do have welldefined minimal models. Stratification is one such form. It is defined in terms of a dependency graph. Definition (Dependency graph): Let Δ be a set of Datalog rules. The nodes of the dependency graph for Δ are the relation constants in the vocabulary. There is an edge from r_{2} to r_{1} whenever there is a rule with r_{1} in the head and r_{2} in the body. That edge is labeled with ¬ whenever r_{2} is in a negative literal. Definition (Datalog Stratification): A set of Datalog rules are stratified when its dependency graph contains no cycle through a negative edge. Stratum 0 is the set of all nodes without incoming edges. Stratum 1 is the set of all nodes adjacent to a node in stratum 0; stratum i+1 is the set of all nodes adjacent to a node in stratum i that are not in stratum i. Clearly, if there is no negation, the graph has no ¬ edges, which means it has a single stratum and is stratified. When a set of Datalog rules is stratified, we can always choose a single Herbrand model as its semantics. Stratum 0 contains no negation; thus it has a minimal model. The minimal model for stratum i+1 is constructed by extending the minimal model for stratum i by evaluating the body of all rules in stratum i+1 in the minimal model of stratum i. Definition (Stratified Datalog Semantics): Let S be a set of stratified Datalog rules. Let M_{0} be the minimal models that satisfies all the rules in stratum 0. To compute M_{i}, where i > 0, initialize M_{i} to M_{i1}. Perform the following operations, adding the result to M_{i} until no changes occur.
For example, consider the following stratified rules. (Traditionall not is used in place of ¬.)
q(b) ⇐ not t(b) t(c)
Variables in negative literals can be problematic. Consider the rule set
q(a) The definition for a Datalog rule includes a statement that says for an implication to be a Datalog rule, it must obey the following constraint: if a variable appears in the head of the rule or a variable appears in a negative literal, that variable must also appear in a positive literal in the body. Now that the semantics have been defined, the reason for this constraint can be explained. Suppose we were to write a rule with a variable in the head that does not occur in the body or a rule with a variable in a negative literal that does not occur in the body.
s(a) ⇐ ¬ r(y) In the second rule above, it is unclear how to interpret what the rule is supposed tomean. Does it mean that if there is some y for which r is false that s(a) is true? Or does it mean that if r(t) for every ground term t is false that s(a) is true? the constraint on Datalog rules removes this ambiguity by requiring every variable in a negative literal to also occur in a positive literal in the body; by first evaluating the poositive literal, every negative literal can be ground before evaluating it using negation as failure. Now that the syntax and semantics of Datalog have been covered, we can return to the earlier promise of defining a database in terms of a bilevel pair. Observation (Database as a Bilevel pair): A database is a bilevel pair <Γ,M>, where Γ is a finite set of Datalog rules that has no EDB predicate in the head of any rule. We now turn to some decidability results. Because Datalog does not allow function constants, the number of Herbrand models for any finite vocabulary is finite. Regardless which semantics are used, as long as the semantics assigns some subset of all Herbrand models over a finite vocabulary to a set of sentences and checking satisfaction in one of those models is decidable, entailment is decidable. Theorem (Datalog is Decidable): Let Δ be a finite set of Datalog rules. Let S be a semantics for Datalog that chooses some subset of the Herbrand models over the vocabulary induced by Δ, where checking whether a model satisfies Δ is decidable. Let φ be the query. Proof: Since Δ itself is finite, the vocabulary and therefore the number and size of all Herbrand models over that vocabulary is finite. Because satisfaction in S is decidable, to check entailment, enumerate each model for the vocabulary and when it satisfies Δ check whether it satisfies φ. If every model that satisfies Δ satisfies φ, Δ = φ. Otherwise Δ # φ. ∎ Unlike theorem proving, answering a query in a database usually means finding all the tuples for which the query is satisfied. We call this materializing the query. Definition (Materialization): Let Δ be a set of sentences and φ(x_{1},...,x_{n}) be a query with free variables x_{1},...,x_{n}. The materialization of the query for Δ is the set of all <t_{1},...,t_{n}> such that Δ = φ(t_{1},...,t_{n}), where each t_{i} is ground. Corollary (Materializing Datalog is Decidable): Same conditions as the last theorem. φ has the free variables x_{1},...,x_{n}. Materializing φ for Δ is decidable.
Completeness and NAF implementationWhen a theory in a complete logic, i.e. a logic with a complete proof procedure, is axiomatically complete and has a recursively enumerable axiomatization, the theory is decidable: for any query φ, interleave proof attempts for φ and ¬ φ. One of them is entailed, and because the logic is complete, the proof will be found. In such a theory, negation as failure (NAF) is monotonic: failing to prove φ ensures that ¬ φ is entailed. Definition (Negation as Failure): Negation as failure is the following inference rule:
NAF is monotonic whenever Δ entails either the query in question or its negation, i.e. Δ is complete for the language that includes either the query or its negation. Theorem (Monotonic NAF): NAF is monotonic for a particular query φ if and only if the theory is complete wrt the language {φ}.
⇔ ¬ (Δ = φ) ⇒ Δ = ¬φ (Logical equivalence of p ∨ q and ¬ p ⇒ q) ⇔ Δ # φ ⇒ Δ = ¬φ (Every query is either entailed or not entailed)∎ Because the Stratified Datalog semantics assigns a single model to a set of rules, it ensures every theory is axiomatically complete. The above theorem ensures NAF is monotonic for every query. One benefit to these semantics is that there need be no rules with negative literals in the head, which is reflected in the definition of Datalog rules. Since the negative portion of the theory is never explicitly written, a proof system for Datalog must rely on NAF. The definition of Stratified Semantics can be implemented directly, causing the proof system to construct the minimal model by constructing one stratum after another in a bottomup fashion. Some implementations, on the other hand, start with the query and use the rules backwards. They evaluate negative literals in rule bodies with NAF: attempt to prove the positive version of the literal, and if that fails, conclude that the negative version must be true. If done naively, the proof procedure can fail to find a proof even when one exists. For example, consider the following ruleset.
q(a) ⇐ not p(a,a) q(a)
p(a,a) can be proven if p(a,z) and p(z,a) can be proven p(a,z) can be proven if p(a,w) and p(w,z) can be proven ... This example illustrates a fundamental feature of the topdown approach: while answering a Datalog query is decidable, the naive topdown approach does not always decide it whereas the naive bottomup approach will. For example, the query p(a,a) may run forever. Moreover, it is hard to make the topdown approach decide such queries efficiently, even with sophisticated methods.
Constraint Satisfaction ProblemsFinite constraint satisfaction problems turn out to be a subclass of database queries. Infinite constraint satisfaction problems would also fall into a subclass of database queries if databases were allowed to be infinitely large. However, instead of finding all solutions to the query as is done in databases, a constraint satisfaction problem is solved once any one solution is found. Definition (Constraint Satisfaction Problem): A constraint satisfaction problem is a threetuple <V,D_{V},C_{V}>:
D_{V}: for each variable, a set of values, i.e. its domain C_{V}: a set of constraints that say which combinations of variables can be assigned which combinations of values Mathematically, the constraints in a CSP can be defined as tables of the allowed values. For example if variables v_{1} and v_{2} have the same domain {a,b,c} but some constraint says those variables can only be assigned different values, that constraint is mathematically equivalent to the following table.
A set of constraints is then a set of tables, where each column is labeled with a variable name. In the context of databases, these tables labeled C_{i} is correspond to the EDBs. In logic, we encode the table for constraint C_{i} as the set of all ground atoms of the form C_{i}(t_{1},...,t_{n}), where n is the number of columns and t_{1},...,t_{n} is some tuple in the table. The CSP is solved by a variable assignment that satisfies all the constraints. The set of all such variable assignments is defined by the following conjunction. For each table C_{i} with columns labeled v_{1},...,v_{m}, include the conjunct C_{i}(v_{1},...,v_{m}). This is a special kind of database querya conjunctive query or equivalently a selectprojectjoin query. Or equivalently, the query is just the natural join on all the tables. For example, suppose there were two of the tables as shown above: C_{1} and C_{2}, the first labeled the same as above, v_{1} on the left and v_{2} on the right, and the second labeled differently, v_{2} on the left and v_{3} on the right. The constraint satisfaction problem would be asking for an assignment v_{1}/t_{1}, v_{2}/t_{2}, and v_{3}/t_{3} so that <t_{1},t_{2}> is a tuple in the C_{1} table and <t_{2},t_{3}> is a tuple in the C_{2} table. The corresponding conjunctive query would be C_{1}(v_{1},v_{2}) ∧ C_{2}(v_{2},v_{3}). All solutions to that query over those tables is the following, which is equivalent to the natural join of C_{1} and C_{2}.
The constraints in a CSP are often stated more compactly, in Datalog. At first, this equivalence of CSPs with a subset of databases is disconcerting since solving a CSP is wellknown to be NPComplete and answering queries in databases is often considered to be polynomial. To rectify this seeming contradiction, it is sufficient to note that solving a CSP is NPhard in terms of the number of variables. Solving a database query is polynomial in terms of the data, i.e. in terms of the size of the model; it is exponential in the number of variables in the query. Thus, database queries are in practice usually polynomial because the size of the data vastly exceeds the size of the querythe major cost in answering a database query is in manipulating the data. Not independently, the number of answers to a query is often much larger than the number of variables in the problem, which gives further support for ignoring the number of variables, as is often done in the database community. Observation (CSP as a Bilevel pair): In the context of bilevel reasoning, a CSP is a bilevel pair <Γ,M>, where Γ is empty, and the only query of interest is the natural join over all the relations in M (if we gave names to each argument of each relation).
Logic ProgrammingThis section is entitled Logic Programming, though with some apprehension. Truly this section is about Prolog and variants of ita family of languages that were developed to program computers where all the logic is in rule form, and negation as failure is prevalent. Logic programming on the other hand is the far more general paradigm of programming a computer using formal logic itself, regardless the syntax or semantics. It is noteworthy that Prolog and its variants have become so popular that they have become synonymous with the term logic programming. Prolog can be seen as a generalization of Datalog, and in the context of Bilevel reasoning, it is a complete bilevel pair <Γ,M>, where M can be empty. Function constants come into the picture, certain restrictions are removed, and a more general rule form is often allowed. The Declarative Logic Program (see, for example Alsac and Baral's comparison of DLP and Description logic) is one of the most general forms of logic programming. Definition (Declarative Logic Program Rule): A Declarative Logic Program rule is an implication (where traditionally : is used instead of ⇐ and , is used in place of ∧).
 each h_{i} is a classical literal, e.g. p(a) or ¬p(a).  each b_{i} is a classical literal.  each not b_{j} is a NAF literal, e.g. not p(a) or not ¬ p(a) ∎ When compared to the definition of a Datalog Rule, (1) disjunction is allowed in the head, (2) classical negation is allowed everywhere , (3) variables are unrestricted, and (4) function constants are allowed. The most widelyused form of logic programming, Prolog, does not allow (1) or (2). It is this version of logic programming we assume from this point on, making the definition as follows. Definition (Prolog): A Prolog is an implication.
 h is an atom.  each b_{i} is a NAF literal, e.g. p(a) or not p(a). ∎ Just as with Datalog, a set of Prolog sentences without negation can be assigned a single, minimal model; that model happens to be the intersection of all the Herbrand models of those sentences. Negation presents difficulties in Prolog just like it did with Datalog. The Stratified Datalog semantics works equally well with function constants, but researchers have found stratification sometimes too restrictive; two definitions for the semantics of Prolog rules with negation stand out. [Gelfond and Lifschitz 1988] introduced Stable Model Semantics, and [Gelder, Ross, and Schlipf 1991] introduced Wellfounded semantics. Stable model semantics are closer to Herbrand semantics than minimal Herbrand semantics: a Prolog theory under stable model semantics is not necessarily axiomatically complete, i.e. instead of assigning a single model to a set of sentences, it assigns multiple models. Wellfounded semantics relies on a 3valued logic, which in some sense compresses multiple models into a single one. Here we discuss only stable model semantics. These semantics do not naturally fit into the complete bilevel pair formalism, the stratified semantics do. Propositional stable model semantics relies on the notion of a stable model, which in turn relies on the GelfondLifschitz transformation. Definition (GelfondLifschitz Transformation): Let Δ be a set of ground Prolog rules and M a Herbrand model in the vocabulary of Δ. The GelfondLifschitz transformation of Δ with respect to M is defined as follows.
The result of this transformation with respect to a model M is a set of rules without negation. If M is minimal, it is a stable model. Definition (Stable Model): Let Δ be a set of ground Prolog rules and M a Herbrand model in the vocabulary of Δ. M is a stable model of Δ if and only if M is the minimal satisfying model of GL[Δ,M]. There will always be exactly one minimal model of GL[Δ,M] since it is Horn. Definition (Propositional Stable Model Semantics): Let Δ be a set of ground Prolog rules. Δ = φ if and only if every stable model of P satisfies φ. Definition (Stable Model Semantics): Let Δ be a set of Prolog rules. Let Δ' be all ground instantiations of the rules in Δ. Δ = φ if and only if Δ' = φ. Regardless which semantics are chosen, a query in Prolog is a single atomic sentence. If the query φ = p(t_{1},...,t_{n}) has variables, four options arise for answering the query: (1) return T if ∃*φ is entailed by the Prolog rules, (2) return some variable assignment σ such that the rules entail φ.σ, (3) return a function that iteratively returns such variable assignments, or (4) return all such variable assignments. Part of the reason (3) and (4) are not considered in Datalog is that every Datalog query has finitely many answers, whereas in Prolog there may be infinitely many answers. Recall that answering entailment queries in Datalog is decidable, as is finding all answers to Datalog queries. The addition of functions ensures that undecidable problems can be embedded in Prolog, even without employing negation (see the comments about encoding Diophatine equations on Proof and Model Theory). That is, entailment queries for recursive Horn rules with functions is undecidable. Removing either functions or recursion regains decidability. Theorem: Entailment for Horn Prolog is undecidable. Theorem: Entailment for nonrecursive Horn Prolog is decidable. Theorem: Entailment for functionfree Horn Prolog is decidable. For more information on the semantics of Prolog and its variants, Lifschitz's paper entitled Foundations of Logic Programming surveys various semantic definitions and their computational consequences. It focuses on rules that include classical negation and on stable model semantics, closely connected to answer set programming.
Formal VerificationFormal verification at a very high level involves defining how a system works and asking whether that system obeys some property. For example, given a computer program written in C, does it ever access an element of an array before allocating the memory for that array? Here we consider a very simple class of systems: finite state machines that run forever. While this class is simple, it should be noted that it is complex enough to model the workings of any modernday computer. First we show how to use a bilevel pair to define a system, and then we show how to phrase queries about that system. Definition (Finite State Machine): A finite state machine (FSM) is a tuple <S, Σ, S_{0}, S_{f}, δ>. S: set of states Σ: input vocabulary S_{0}: the initial state  S_{0} ∈ S S_{f}: the final states  S_{f} ∈ S δ: the transition function: SxΣ \rightarrow S. <∈dent> It turns out to be convenient to use Vanilla Prolog with stratified semantics, i.e. Datalog with function constants, for encoding the FSM. Now we explain how to describe a finite state machine as a bilevel pair <Γ,M>. Representing a FSM as a shown above may require a large amount of space; simply because the set of states may be very large. Often, though, the states in a system need not be described as monolithyic states but rather can be described using a set of propositions, where a state is defined as the set of propositions true in the state. Those propositions will be represented by ground terms. The model M defines the propositions true in the initial state, S0. If for example the propositions p, q, and r are true in the intial state, and only those are true in the initial state, then the model is.
init(q) init(r) The dynamics of most systems are the same regardless what the initial state is. Those dynamics (δ) tell us for a given state and a given input what the next state will be. To represent that proposition p is true in state s, we write
To represent names for states, we will borrow from situation calculus. Each state may have many names; each name encodes the history of actions required to reach that state from the initial state. This reflects the fact that even though there are a finite set of states in a FSM, any one state may be reached arbitrarily many times by performing longer and longer sequences of actions from the initial state. Thus, actions too take the form of propositions, and when encoded in logic the form of ground terms. If the proposition p is true in the state resulting from executing actions a,b,c from the initial state, we can express this as follows.
To tie the initial state to the state name s0, we need a single rule.
Using simple implications, we can encode how certain actions affect the state of the world. Blocks world is a simple example. If blocks x and y are clear in state s (all of which are variables) then by executing the action stack(x,y) in s, the resulting state includes the proposition on(x,y).
legal(stack(x,y), s) ⇐ true(clear(x),s) ^{ }true(clear(y),s) Frame axioms, sentences that say what things do not change as a result of an action, must also be encoded. For example, if block x is on block y then performing the stack action does not change that fact. (Conditioning the rule on x and y being clear ensures the action is not executed unless it is legal to do so.
Datalog is useful here since it ensures that every proposition that cannot be proven true in a state is in fact false in that state, without having to write down all the rules that say so. The set of all rules that define the transition function δ also define the input vocabulary Σ. Σ is the set of all ground action names. The remaining element of a FSM that must still be defined is the set of final states, Sf. To do that, we use a distinguished unary relation terminal. Whenever terminal holds in a state, the state is a terminal state, i.e. a member of Sf. For example, to say the system is terminal when block a is on b and block b is on c, we could write the following.
To be faithful to the FSM notion of a terminal state, the rules for terminal should never distinguish states based on the state names, i.e. on the action taken to reach the current state. In other words, terminal(s) should always be at the head, and no action should ever be mentioned in the body. The examples define a transition function as one would expect: given a state and an action, the rules say what the subsequent state looks like. But one could write more interesting rules where the state an arbitrary number of steps in the future determines what must have happened in the past.
Such rules can easily lead to inconsistency, and are never necessary for defining a finite state machine (though sometimes such rules are convenient). In the case that it is desirable to force a system description where the transition function is expressed only as the effects of an action on a current state, i.e. a Markov version of what is shown above, there is a language called GDL. It ensures decidability and finiteness, and can be easily translated into the form seen here. Formal Verification QueriesThe discussion above illustrates how to construct a bilevel pair that defines the system we might like to verify. Some kinds of formal verification can be seen as just answering entailment questions about that bilevel pair.For example, let's say we want to ask whether in every state reachable from the initial state the action a is legal. First, we need to define which states are reachable. Again, we use Datalog to ensure we know which states are reachable and which states are not reachable.
reachable(do(x,s)) <= legal(x,s) ^{ }reachable(s)
Is there a legal move in each reachable state?
Not every formal verification query can be phrased as a finite axiom about a bilevel pair. without extending the set of ground terms (and therefore the set of models. For example, does some property p hold over every subset of reachable states? Because the set of states can be arbitrarily large (depending on the model M), any relation of fixed arity will not be able to define any subset with more elements than the arity. Even if we were to extend the language with function constants to allow lists, the set of reachable state names could be countably large, which ensures the set of all subsets is uncountable. Clearly we cannot represent uncountably large sets in Herbrand logic since every model has only countably many elements. (Of course, if we were only interested in all the finite subsets of the reachable states, that set is still countable, and we could express it in Herbrand logic.)
© Copyright 2006 by
and the Stanford Logic Group
