Let’s take a look at the syntax (how sentances are structured)
and semantics (how truth of sentances is determined)
of Propositional Logic
Then we’ll look at a simple algorithm of logical inference that implements entailment. From there, we’ll reason about the treacherous Wumpus World…
Syntax defines our allowable sentences.
Atomic sentences consist of a single proposition symbol.
Each proposition symbol can either be true or false. Example proposition symbols: \[ \mathbf{P,Q,R,W_{1,3}},FacingEast \]
The symbols could be anything, but are often mnemonic, e.g. \(W_{1,3}\) could mean that the Wumpus is in \([1,3]\).
Important: Symbols are atomic, the \([1,3]\) might as well be anything.
There are two fixed-meaning propositions: \(True\) and \(False\).
Complex sentences are built-up from from other sentences using \((\ )\) and logical connectives, of which we’ll introduce five:
Here is a formal grammar of propositional logic presented in BNF (augmented with operator precedence, to resolve ambiguity).
Bracus-Naur Form
With the syntax out of the way, we can now focus on meaning.
In propositional logic, a model just sets a truth value (true or false) for every proposition symbol. Example: \[ m_1 = \{P_{1,2}=false,P_{2,2}=false,P_{3,1}=true\} \]
With three proposition symbols, there are how many possible models? ::: {.incremental} - \(2^3=8\) ::: Exactly as seen in:
It’s important to note that these modes are purely mathematical objects that don’t necessarily relate to wumpus worlds. \(P_{1,2}\) is just a symbol which could just as well mean “There’s a pit in [1,2]” as I am pogchamp today and tomorrow.
Given a model, our semantics must specify how to compute the truth value of any sentence, given a model, (done recursively).
This requires us to specify how to compute atomic sentences and sentences formed with the five connectives.
First, atomic sentences: ::: {.incremental} - \(True\) is true in every model and \(False\) is false in every model. - The truth of every other proposition must be specified directly in the model. ::: For complex sentences, we have five rules, which hold for any subsentences \(P,Q\) in \(m\): ::: {.incremental} - \(\lnot P\) is true iff \(P\) is false in \(m\) - \(P \land Q\) is true iff both \(P\) or \(Q\) is true in \(m\) - \(P \lor Q\) is true iff either \(P\) or \(Q\) is true in \(m\) - \(P \implies Q\) is true unless \(P\) is true and \(Q\) is false in \(m\) - \(P \iff Q\) is true iff \(P\) and \(Q\) are both true or both false in \(m\) ::: The rules can be expressed by truth tables that specify the truth values to its components.
From these, the truth value of any sentence \(s\) may be computed with respect to any model \(m\) by recursive evaluation.
Let’s try!: not, (\(P\land Q\))
How about: \(\lnot P_{1,2}\land(P_{2,2}\lor P_{3,1})\)
Complete truth table for the five connectives:
Truth Table
One subtle point: \(P\lor Q\) is true if \(P\) is true or \(Q\) is true or both. “Exclusive or” or “xor” is another connective, which yields false when both disjuncts are true. You may see xor as: \(\lor,\neq,or\ \oplus\)
Another odd point is the fact that the following sentence is true under propositional logic:
"5 is odd implies Tokyo is the capital of Japan"
Does this strike anyone as odd :::{.incremental} - implication is not the same as causation or even relevance :::
Let’s think of “\(P\implies Q\)” as “If \(P\) is true, then I am claiming that \(Q\) is true; otherwise I am making no claim”.
Let’s start with the immutable aspects of the wumpus world (we’ll cover mutable aspects later). We need some symbols for each \([x,y]\) location:
These will be sufficient to derive \(\lnot P_{1,2}\) as was done before (informally). We’ll lable our sentences \(R_i\) so we can refer to them
These are true in all wumpus worlds!
Now… to include the breeze percepts for the first two squares visited in our specific world:
$R_4: \lnot B_{1,1}$
$R_5: B_{2,1}
Our goal is to decide whether \(KB\models \alpha\) (KB models alpha) for some sentence alpha.
Models are assignments of \(true\) or \(false\) to every proposition symbol.
In our Wumpus World, the relevant propositions are \(B_{1,1},B_{2,1},P_{1,1},P_{1,2},P_{2,1},P_{2,2},P_{3,1}\) With seven symbols we have \(128\) possible models… in three of them, \(KB\) is true.
In those three, \(\lnot P_{1,2}\) is true, therefore there is no pit in \([x,y]\). However, \(P_{2,2}\) is true in two, but false in one… so we can’t tell yet.
Our large truth table:
A general algorithm for deciding entailment in propositional logic is below.
Like our \(BacktrackingSearch\), \(TTEntails\) searches recursively over a finite space of assignments to symbols. It is both sound and complete… why?
Truth Table Enumeration
That said, “finite” is not always the same as “small”.
If \(KB\) and \(\alpha\) contain \(n\) symbols, then there are \(2^n\) models. Thus, the time complexity is \(O(2^n)\) (the space complexity is \(O(n)\) due to it being DFS).
Unfortunately, propositional entailment is co-NP-complete (probably no easier than NP-complete).