foundations of computational agents
When a variable appears in a clause, the clause is true in an interpretation only if the clause is true for all possible values of that variable.
To formally define semantics of variables, a variable assignment, $\rho $, is a function from the set of variables into the domain $D$. Thus, a variable assignment assigns an element of the domain to each variable. Given interpretation $$ and variable assignment $\rho $, each term denotes an individual in the domain. If the term is a constant, the individual is given by $\varphi $. If the term is a variable, the individual is given by $\rho $. Given an interpretation and a variable assignment, each atom is either true or false, using the same definition as earlier. Thus, given an interpretation and a variable assignment, each clause is either true or false.
A clause is true in an interpretation if it is true for all variable assignments. The variables are said to be universally quantified in the scope of the clause. Thus, a clause is false in an interpretation means there is a variable assignment under which the clause is false.
The clause
$${p}{}{a}{}{r}{}{t}{}{\mathrm{\_}}{}{o}{}{f}{}{(}{X}{,}{Y}{)}{\leftarrow}{}{i}{}{n}{}{(}{X}{,}{Y}{)}{.}$$ |
is false in the interpretation of Example 13.5, because under the variable assignment with ${X}$ denoting Kim and ${Y}$ denoting Room 123, the clause’s body is true and the clause’s head is false.
The clause
$${i}{}{n}{}{(}{X}{,}{Y}{)}{\leftarrow}{}{p}{}{a}{}{r}{}{t}{}{\mathrm{\_}}{}{o}{}{f}{}{(}{Z}{,}{Y}{)}{\wedge}{}{i}{}{n}{}{(}{X}{,}{Z}{)}{.}$$ |
is true, because in all variable assignments where the body is true, the head is also true.
Logical consequence is defined in the same way as it was for propositional definite clauses in Section 5.1: ground body $g$ is a logical consequence of $KB$, written $KB\vDash g$, if $g$ is true in every model of $KB$.
Suppose the knowledge base ${K}{\mathit{}}{B}$ is
${i}{}{n}{}{(}{k}{}{i}{}{m}{,}{r}{}{123}{)}{.}$ | ||
${p}{}{a}{}{r}{}{t}{}{\mathrm{\_}}{}{o}{}{f}{}{(}{r}{}{123}{,}{c}{}{s}{}{\mathrm{\_}}{}{b}{}{u}{}{i}{}{l}{}{d}{}{i}{}{n}{}{g}{)}{.}$ | ||
${i}{}{n}{}{(}{X}{,}{Y}{)}{\leftarrow}$ | ||
${\mathrm{}}{\mathit{\hspace{1em}\hspace{1em}\u2006}}{p}{}{a}{}{r}{}{t}{}{\mathrm{\_}}{}{o}{}{f}{}{(}{Z}{,}{Y}{)}{\wedge}$ | ||
${\mathrm{}}{\mathit{\hspace{1em}\hspace{1em}\u2006}}{i}{}{n}{}{(}{X}{,}{Z}{)}{.}$ |
The interpretation defined in Example 13.5 is a model of ${K}{\mathit{}}{B}$, because each clause is true in that interpretation.
${K}{}{B}{\vDash}{i}{}{n}{}{(}{k}{}{i}{}{m}{,}{r}{}{123}{)}$, because this is stated explicitly in the knowledge base. If every clause of ${K}{\mathit{}}{B}$ is true in an interpretation, then ${i}{\mathit{}}{n}{\mathit{}}{\mathrm{(}}{k}{\mathit{}}{i}{\mathit{}}{m}{\mathrm{,}}{r}{\mathit{}}{\mathrm{123}}{\mathrm{)}}$ must be true in that interpretation.
${K}{}{B}{\vDash \u0338}{i}{}{n}{}{(}{k}{}{i}{}{m}{,}{r}{}{023}{)}$. The interpretation defined in Example 13.5 is a model of ${K}{\mathit{}}{B}$, in which ${i}{\mathit{}}{n}{\mathit{}}{\mathrm{(}}{k}{\mathit{}}{i}{\mathit{}}{m}{\mathrm{,}}{r}{\mathit{}}{\mathrm{023}}{\mathrm{)}}$ is false.
${K}{}{B}{\vDash \u0338}{p}{}{a}{}{r}{}{t}{}{\mathrm{\_}}{}{o}{}{f}{}{(}{r}{}{023}{,}{c}{}{s}{}{\mathrm{\_}}{}{b}{}{u}{}{i}{}{l}{}{d}{}{i}{}{n}{}{g}{)}$. Although ${p}{\mathit{}}{a}{\mathit{}}{r}{\mathit{}}{t}{\mathit{}}{\mathrm{\_}}{\mathit{}}{o}{\mathit{}}{f}{\mathit{}}{\mathrm{(}}{r}{\mathit{}}{\mathrm{023}}{\mathrm{,}}{c}{\mathit{}}{s}{\mathit{}}{\mathrm{\_}}{\mathit{}}{b}{\mathit{}}{u}{\mathit{}}{i}{\mathit{}}{l}{\mathit{}}{d}{\mathit{}}{i}{\mathit{}}{n}{\mathit{}}{g}{\mathrm{)}}$ is true in the interpretation of Example 13.5, there is another model of ${K}{\mathit{}}{B}$ in which ${p}{\mathit{}}{a}{\mathit{}}{r}{\mathit{}}{t}{\mathit{}}{\mathrm{\_}}{\mathit{}}{o}{\mathit{}}{f}{\mathit{}}{\mathrm{(}}{r}{\mathit{}}{\mathrm{023}}{\mathrm{,}}{c}{\mathit{}}{s}{\mathit{}}{\mathrm{\_}}{\mathit{}}{b}{\mathit{}}{u}{\mathit{}}{i}{\mathit{}}{l}{\mathit{}}{d}{\mathit{}}{i}{\mathit{}}{n}{\mathit{}}{g}{\mathrm{)}}$ is false. In particular, the interpretation which is like the interpretation of Example 13.5, but where
$$ |
is a model of ${K}{\mathit{}}{B}$ in which ${p}{\mathit{}}{a}{\mathit{}}{r}{\mathit{}}{t}{\mathit{}}{\mathrm{\_}}{\mathit{}}{o}{\mathit{}}{f}{\mathit{}}{\mathrm{(}}{r}{\mathit{}}{\mathrm{023}}{\mathrm{,}}{c}{\mathit{}}{s}{\mathit{}}{\mathrm{\_}}{\mathit{}}{b}{\mathit{}}{u}{\mathit{}}{i}{\mathit{}}{l}{\mathit{}}{d}{\mathit{}}{i}{\mathit{}}{n}{\mathit{}}{g}{\mathrm{)}}$ is false.
${K}{}{B}{\vDash}{i}{}{n}{}{(}{k}{}{i}{}{m}{,}{c}{}{s}{}{\mathrm{\_}}{}{b}{}{u}{}{i}{}{l}{}{d}{}{i}{}{n}{}{g}{)}$. If the clauses in ${K}{\mathit{}}{B}$ are true in interpretation ${I}$, it must be the case that ${i}{\mathit{}}{n}{\mathit{}}{\mathrm{(}}{k}{\mathit{}}{i}{\mathit{}}{m}{\mathrm{,}}{c}{\mathit{}}{s}{\mathit{}}{\mathrm{\_}}{\mathit{}}{b}{\mathit{}}{u}{\mathit{}}{i}{\mathit{}}{l}{\mathit{}}{d}{\mathit{}}{i}{\mathit{}}{n}{\mathit{}}{g}{\mathrm{)}}$ is true in ${I}$, otherwise, there is an instance of the third clause of ${K}{\mathit{}}{B}$ that is false in ${I}$ – a contradiction to ${I}$ being a model of ${K}{\mathit{}}{B}$.
The following example shows how the semantics treats variables appearing in a clause’s body but not in its head.
In Example 13.8, the variable ${Y}$ in the clause defining ${i}{\mathit{}}{n}$ is universally quantified at the level of the clause; thus, the clause is true for all variable assignments. Consider particular values ${{c}}_{{\mathrm{1}}}$ for ${X}$ and ${{c}}_{{\mathrm{2}}}$ for ${Y}$. The clause
${i}{}{n}{}{(}{{c}}_{{1}}{,}{{c}}_{{2}}{)}{\leftarrow}$ | ||
${\mathrm{}}{\mathit{\hspace{1em}\hspace{1em}\u2006}}{p}{}{a}{}{r}{}{t}{}{\mathrm{\_}}{}{o}{}{f}{}{(}{Z}{,}{{c}}_{{2}}{)}{\wedge}$ | ||
${\mathrm{}}{\mathit{\hspace{1em}\hspace{1em}\u2006}}{i}{}{n}{}{(}{{c}}_{{1}}{,}{Z}{)}{.}$ |
is true for all variable assignments to ${Z}$. If there exists a variable assignment ${{c}}_{{\mathrm{3}}}$ for ${Z}$ such that ${p}{\mathit{}}{a}{\mathit{}}{r}{\mathit{}}{t}{\mathit{}}{\mathrm{\_}}{\mathit{}}{o}{\mathit{}}{f}{\mathit{}}{\mathrm{(}}{Z}{\mathrm{,}}{{c}}_{{\mathrm{2}}}{\mathrm{)}}{\mathrm{\wedge}}{\mathit{}}{i}{\mathit{}}{n}{\mathit{}}{\mathrm{(}}{{c}}_{{\mathrm{1}}}{\mathrm{,}}{Z}{\mathrm{)}}$ is true in an interpretation, then ${i}{\mathit{}}{n}{\mathit{}}{\mathrm{(}}{{c}}_{{\mathrm{1}}}{\mathrm{,}}{{c}}_{{\mathrm{2}}}{\mathrm{)}}$ must be true in that interpretation. Therefore, you can read the last clause of Example 13.8 as “for all ${X}$ and for all ${Y}$, ${i}{\mathit{}}{n}{\mathit{}}{\mathrm{(}}{X}{\mathrm{,}}{Y}{\mathrm{)}}$ is true if there exists a ${Z}$ such that ${p}{\mathit{}}{a}{\mathit{}}{r}{\mathit{}}{t}{\mathit{}}{\mathrm{\_}}{\mathit{}}{o}{\mathit{}}{f}{\mathit{}}{\mathrm{(}}{Z}{\mathrm{,}}{Y}{\mathrm{)}}{\mathrm{\wedge}}{\mathit{}}{i}{\mathit{}}{n}{\mathit{}}{\mathrm{(}}{X}{\mathrm{,}}{Z}{\mathrm{)}}$ is true.”
The definite clause language makes universal quantification implicit. Sometimes it is useful to make quantification explicit. There are two quantifiers that are used in logic:
$\forall Xp(X)$, read “for all $X$, $p(X)$” means $p(X)$ is true for every variable assignment for $X$. $X$ is said to be a universally quantified.
$\exists Xp(X)$, read “there exists an $X$ such that $p(X)$” means $p(X)$ is true for some variable assignment for $X$. $X$ is said to be existentially quantified.
The clause $P(X)\leftarrow Q(X,Y)$ means
$$\forall X\forall Y(P(X)\leftarrow Q(X,Y))$$ |
which is equivalent to
$$\forall X(P(X)\leftarrow \exists YQ(X,Y)).$$ |
Thus, free variables that only appear in the body are existentially quantified in the scope of the body.
It may seem as though there is something peculiar about talking about a clause being true for cases where it does not make sense, as in the following example.
Consider the clause
${i}{}{n}{}{(}{c}{}{s}{}{422}{,}{l}{}{o}{}{v}{}{e}{)}{\leftarrow}$ | ||
${\mathrm{}}{\mathit{\hspace{1em}\hspace{1em}\u2006}}{p}{}{a}{}{r}{}{t}{}{\mathrm{\_}}{}{o}{}{f}{}{(}{c}{}{s}{}{422}{,}{s}{}{k}{}{y}{)}{\wedge}$ | ||
${\mathrm{}}{\mathit{\hspace{1em}\hspace{1em}\u2006}}{i}{}{n}{}{(}{s}{}{k}{}{y}{,}{l}{}{o}{}{v}{}{e}{)}{.}$ |
where ${c}{\mathit{}}{s}{\mathit{}}{\mathrm{422}}$ denotes a course, ${l}{\mathit{}}{o}{\mathit{}}{v}{\mathit{}}{e}$ denotes an abstract concept, and ${s}{\mathit{}}{k}{\mathit{}}{y}$ denotes the sky. Here, the clause is vacuously true in the intended interpretation according to the truth table for ${\mathrm{\leftarrow}}$, because the clause’s right-hand side is false in the intended interpretation.
As long as whenever the head is nonsensical, the body is also, the rule can never be used to prove anything nonsensical. When checking for the truth of a clause, you must only be concerned with those cases in which the clause’s body is true. The convention that a clause is true whenever the body is false, even if it strictly does not make sense, makes the semantics simpler and does not cause any problems.
The formal description of semantics does not tell us why semantics is interesting or how it can be used as a basis to build intelligent systems. The methodology for using semantics for propositional logic programs can be extended to Datalog:
Select the task domain or world to represent. This could be some aspect of the real world, for example, the structure of courses and students at a university or a laboratory environment at a particular point in time, some imaginary world, such as the world of Alice in Wonderland, or the state of the electrical environment if a switch breaks, or an abstract world, for example, the world of money, numbers and sets. Within this world, let the domain $D$ be the set of all individuals or things that you want to be able to refer to and reason about. Also, select which relations to represent.
Associate constants in the language with individuals in the world that you want to name. For each element of $D$ you want to refer to by name, assign a constant in the language. For example, you may select the name “$kim$” to denote a particular professor, the name “$cs322$” for a particular introductory AI course, the name “$two$” for the number that is the successor of the number one, and the name “$red$” for the color of stoplights. Each of these names denotes the corresponding individual in the world.
For each relation that you may want to represent, associate a predicate symbol in the language. Each $n$-ary predicate symbol denotes a function from ${D}^{n}$ into $\{\text{true},\text{false}\}$, which specifies the subset of ${D}^{n}$ for which the relation is true. For example, the predicate symbol “$teaches$” of two arguments (a teacher and a course) may correspond to the binary relation that is true when the individual denoted by the first argument teaches the course denoted by the second argument. These relations need not be binary. They could have any number of arguments (zero or more). For example, “$is\mathrm{\_}red$” may be a predicate that has one argument.
These associations of symbols with their meanings form an intended interpretation.
Write clauses that are true in the intended interpretation. This is often called axiomatizing the domain, where the given clauses are the axioms of the domain. If the person who is denoted by the symbol $kim$ actually teaches the course denoted by the symbol $cs322$, you can assert the clause $teaches(kim,cs322)$ as being true in the intended interpretation.
Ask queries about the intended interpretation. The system gives answers that you can interpret using the meaning assigned to the symbols.
Following this methodology, the knowledge base designer does not actually tell the computer anything until step 4. The first three steps are carried out in the head of the designer. Of course, the designer should document the denotations to make their knowledge base understandable to other people, so that they remember each symbol’s denotation, and so that they can check the truth of the clauses.
The world itself does not prescribe what the individuals are.
In one conceptualization of a domain, ${p}{\mathit{}}{i}{\mathit{}}{n}{\mathit{}}{k}$ may be a predicate symbol of one argument that is true when the individual denoted by that argument is pink. In another conceptualization, ${p}{\mathit{}}{i}{\mathit{}}{n}{\mathit{}}{k}$ may be an individual that is the color pink, and it may be used as the second argument to a binary predicate ${c}{\mathit{}}{o}{\mathit{}}{l}{\mathit{}}{o}{\mathit{}}{r}$, which says that the individual denoted by the first argument has the color denoted by the second argument. Alternatively, someone may want to describe the world at a level of detail where various shades of ${r}{\mathit{}}{e}{\mathit{}}{d}$ are not distinguished, and so the color ${p}{\mathit{}}{i}{\mathit{}}{n}{\mathit{}}{k}$ would not be included. Someone else may describe the world in more detail, and decide that ${p}{\mathit{}}{i}{\mathit{}}{n}{\mathit{}}{k}$ is too general a term, and use the terms ${c}{\mathit{}}{o}{\mathit{}}{r}{\mathit{}}{a}{\mathit{}}{l}$ and ${s}{\mathit{}}{a}{\mathit{}}{l}{\mathit{}}{m}{\mathit{}}{o}{\mathit{}}{n}$.
When the individuals in the domain are real physical things, it is usually difficult to give the denotation without physically pointing at the individual. When the individual is an abstract individual – for example, a university course or the concept of love – it is virtually impossible to write the denotation. However, this does not prevent the system from representing and reasoning about such concepts.
Example 5.7 represented the electrical environment of Figure 5.2 using propositions. Using individuals and relations can make the representation more intuitive, because the general knowledge about how switches work can be clearly separated from the knowledge about a specific house.
To represent this domain, the first step is to decide what individuals exist in the domain. In what follows, assume that each switch, each light, and each power outlet is an individual. Each wire between two switches and between a switch and a light is also an individual. Someone may claim that, in fact, there are pairs of wires joined by connectors and that the electricity flow must obey Kirchhoff’s laws. Someone else may decide that even that level of abstraction is inappropriate because we should model the flow of electrons. However, an appropriate level of abstraction is one that is useful for the task at hand. A resident of the house may not know the whereabouts of the connections between the individual strands of wire or even the voltage. Therefore, we assume a flow model of electricity, where power flows from the outside of the house through wires to lights. This model is appropriate for the task of determining whether a light should be lit or not, but it may not be appropriate for other tasks.
Next, give names to each individual to which we want to refer. This is done in Figure 5.2. For example, the individual ${{w}}_{{\mathrm{0}}}$ is the wire between light ${{l}}_{{\mathrm{1}}}$ and switch ${{s}}_{{\mathrm{2}}}$.
Next, choose which relationships to represent. Assume the following predicates with their associated intended interpretations:
${l}{}{i}{}{g}{}{h}{}{t}{}{(}{L}{)}$ is true if the individual denoted by ${L}$ is a light.
${l}{}{i}{}{t}{}{(}{L}{)}$ is true if the light ${L}$ is lit and emitting light.
${l}{}{i}{}{v}{}{e}{}{(}{W}{)}$ is true if there is power coming into ${W}$; that is, ${W}$ is live.
${u}{}{p}{}{(}{S}{)}$ is true if switch ${S}$ is up.
${d}{}{o}{}{w}{}{n}{}{(}{S}{)}$ is true if switch ${S}$ is down.
${o}{}{k}{}{(}{E}{)}$ is true if ${E}$ is not faulty; ${E}$ can be either a circuit breaker or a light.
${c}{}{o}{}{n}{}{n}{}{e}{}{c}{}{t}{}{e}{}{d}{}{\mathrm{\_}}{}{t}{}{o}{}{(}{X}{,}{Y}{)}$ is true if component ${X}$ is connected to ${Y}$ such that current would flow from ${Y}$ to ${X}$.
At this stage, the computer has not been told anything. It does not know what the predicates are, let alone what they mean. It does not know which individuals exist or their names.
Before anything about the particular house is known, the system can be told general rules such as
${l}{}{i}{}{t}{}{(}{L}{)}{\leftarrow}{}{l}{}{i}{}{g}{}{h}{}{t}{}{(}{L}{)}{\wedge}{}{l}{}{i}{}{v}{}{e}{}{(}{L}{)}{\wedge}{}{o}{}{k}{}{(}{L}{)}{.}$ |
Recursive rules let you state what is live from what is connected to what:
${l}{}{i}{}{v}{}{e}{}{(}{X}{)}{\leftarrow}{}{c}{}{o}{}{n}{}{n}{}{e}{}{c}{}{t}{}{e}{}{d}{}{\mathrm{\_}}{}{t}{}{o}{}{(}{X}{,}{Y}{)}{\wedge}{}{l}{}{i}{}{v}{}{e}{}{(}{Y}{)}{.}$ | ||
${l}{}{i}{}{v}{}{e}{}{(}{o}{}{u}{}{t}{}{s}{}{i}{}{d}{}{e}{)}{.}$ |
For the particular house and configuration of components and their connections, the following facts about the world can be told to the computer:
${l}{}{i}{}{g}{}{h}{}{t}{}{(}{{l}}_{{1}}{)}{.}$ | ||
${l}{}{i}{}{g}{}{h}{}{t}{}{(}{{l}}_{{2}}{)}{.}$ | ||
${d}{}{o}{}{w}{}{n}{}{(}{{s}}_{{1}}{)}{.}$ | ||
${u}{}{p}{}{(}{{s}}_{{2}}{)}{.}$ | ||
${o}{}{k}{}{(}{c}{}{{b}}_{{1}}{)}{.}$ | ||
${c}{}{o}{}{n}{}{n}{}{e}{}{c}{}{t}{}{e}{}{d}{}{\mathrm{\_}}{}{t}{}{o}{}{(}{{w}}_{{0}}{,}{{w}}_{{1}}{)}{\leftarrow}{}{u}{}{p}{}{(}{{s}}_{{2}}{)}{.}$ | ||
${c}{}{o}{}{n}{}{n}{}{e}{}{c}{}{t}{}{e}{}{d}{}{\mathrm{\_}}{}{t}{}{o}{}{(}{{w}}_{{0}}{,}{{w}}_{{2}}{)}{\leftarrow}{}{d}{}{o}{}{w}{}{n}{}{(}{{s}}_{{2}}{)}{.}$ | ||
${c}{}{o}{}{n}{}{n}{}{e}{}{c}{}{t}{}{e}{}{d}{}{\mathrm{\_}}{}{t}{}{o}{}{(}{{w}}_{{1}}{,}{{w}}_{{3}}{)}{\leftarrow}{}{u}{}{p}{}{(}{{s}}_{{1}}{)}{.}$ | ||
${c}{}{o}{}{n}{}{n}{}{e}{}{c}{}{t}{}{e}{}{d}{}{\mathrm{\_}}{}{t}{}{o}{}{(}{{w}}_{{3}}{,}{o}{}{u}{}{t}{}{s}{}{i}{}{d}{}{e}{)}{\leftarrow}{}{o}{}{k}{}{(}{c}{}{{b}}_{{1}}{)}{.}$ |
These rules and atomic clauses are all that the computer is told. It does not know the meaning of these symbols. However, it can now answer queries about this particular house.