Logic, Propositional, Predicate
Logic, Propositional, Predicate
.c
le
ra
ai
Connect with me:
Youtube: Piyush Wairale IITM
Linkedin: Piyush Wairale
w
om
1. Humans' intelligence relies on reasoning processes that operate on internal
representations of knowledge, as exemplified by knowledge-based agents in AI.
2. Problem-solving agents, while knowledgeable in limited, domain-specific ways, can
.c
benefit from more flexible and domain-independent knowledge representations, such as
logic.
3. Logic serves as a general class of representations for knowledge-based agents, enabling
le
them to combine and adapt information for various purposes.
4. Propositional logic, though less expressive than first-order logic, offers fundamental
ra
concepts and powerful inference technologies for building knowledge-based agents.
These sentences are expressed according to the syntax of the representation language, which
ai
specifies all the sentences that are well formed. The notion of syntax is clear enough in ordinary
arithmetic: “x + y = 4” is a well-formed sentence, whereas “x4y+ =” is not.
w
A logic must also define the semantics or meaning of sentences. The semantics define the truth
of each sentence with respect to each possible world. For example, the semantics for arithmetic
specify that the sentence “x + y = 4” is true in a world where x is 2 and y is 2, but false in a
sh
world where x is 1 and y is 1. In standard logics, every sentence must be either true or false in
each possible world—there is no “in between.”1
yu
1. Syntax and Semantics: Logic involves two key aspects - syntax, which defines the
structure and grammar of sentences, and semantics, which determines the truth or
falsehood of sentences in different possible worlds.
pi
2. Entailment and Inference: Entailment is the idea that one sentence logically follows
from another. Inference processes, like model checking, help derive conclusions from a
knowledge base (KB) while ensuring the soundness of the derived statements.
3. Soundness and Completeness: Sound inference procedures ensure that derived
conclusions are always true if the premises are true. Completeness is the ability to derive
any entailed sentence, which is crucial when dealing with infinite knowledge bases.
4. Grounding Knowledge: The connection between logical reasoning processes and the
real world is established through sensors and learning. Sensors create sentences based on
perceptual input, while learning helps derive general rules from experiences, connecting
the KB to the real environment.
5. Real-World Correspondence: Logical reasoning processes should ensure that derived
conclusions represent aspects of the real world that logically follow from the aspects
represented by the premises, bridging the gap between representations and reality.
om
1.PROPOSITIONAL LOGIC
We now present a simple but powerful logic called propositional logic. We cover the syntax of
propositional logic and its semantics—the way in which the truth of sentences is determined.
Then we look at entailment—the relation between a sentence and another sentence that follows
.c
from it—and see how this leads to a simple algorithm for logical inference.
le
Syntax
The syntax of propositional logic defines the allowable sentences. The atomic sentences consist
ra
of a single proposition symbol. Each such symbol stands for a proposition that can be true or
false.
ai
w
sh
yu
pi
Important Points:
● Propositional logic is also called Boolean logic as it works on 0 and 1.
● In propositional logic, we use symbolic variables to represent the logic, and we can use
om
any symbol for a representing a proposition, such A, B, C, P, Q, R, etc.
● Propositions can be either true or false, but it cannot be both.
● Propositional logic consists of an object, relations or function, and logical connectives.
These connectives are also called logical operators.
.c
● The propositions and connectives are the basic elements of the propositional logic.
● A proposition formula which is always true is called tautology, and it is also called a
valid sentence.
le
● A proposition formula which is always false is called Contradiction.
● Statements which are questions, commands, or opinions are not propositions such as
ra
"Where is Rohini", "How are you", "What is your name", are not propositions.
● Connectives can be said as a logical operator which connects two sentences.
ai
The syntax of propositional logic defines the allowable sentences for the knowledge
representation. There are two types of Propositions:
w
Atomic Propositions:
Atomic propositions are the simple propositions. It consists of a single proposition symbol.
These are the sentences which must be either true or false.
sh
Compound propositions:
Compound propositions are constructed by combining simpler or atomic propositions, using
parenthesis and logical connectives.
yu
pi
om
.c
le
ra
Semantics:
The semantics defines the rules for determining the truth of a sentence with respect to a
ai
particular model. In propositional logic, a model simply fixes the truth value—true or false—for
every proposition symbol. For example, if the sentences in the knowledge base make use of the
proposition symbols P1,2, P2,2, and P3,1, then one possible model is
w
● For complex sentences, we have five rules, which hold for any subsentences P and Q in
any model m (here “iff” means “if and only if”):
• ¬P is true iff P is false in m.
yu
The rules can also be expressed with truth tables that specify the truth value of a complex
sentence for each possible assignment of truth values to its components. Truth tables for the five
connectives are given-
om
.c
le
ra
ai
w
sh
yu
pi
Implication (→) represents a structure of “if P then Q.” For example, if P: “It is raining” and Q:
“I’m indoors”, then P → Q means “If it is raining, then I’m indoors.” In the case of P implies Q
(P → Q), P is called the antecedent and Q is called the consequent.
● When the antecedent is true, the whole implication is true in the case that the consequent
is true (that makes sense: if it is raining and I’m indoors, then the sentence “if it is
raining, then I’m indoors” is true).
● When the antecedent is true, the implication is false if the consequent is false (if I’m
outside while it is raining, then the sentence “If it is raining, then I’m indoors” is false).
● However, when the antecedent is false, the implication is always true, regardless of the
consequent. This can sometimes be a confusing concept.
● Logically, we can’t learn anything from an implication (P → Q) if the antecedent (P) is
false. Looking at our example, if it is not raining, the implication doesn’t say anything
about whether I’m indoors or not. I could be an indoors type and never walk outside,
om
even when it is not raining, or I could be an outdoors type and be outside all the time
when it is not raining. When the antecedent is false, we say that the implication is
trivially true.
.c
le
ra
ai
w
sh
yu
pi
Bidirectional (⇔)is an implication that goes both directions. You can read it as “if and only if.”
P ⇔ Q is the same as P → Q and Q → P taken together.
For example, if P: “It is raining.” and Q: “I’m indoors,” then P ⇔ Q means that “If it is raining,
om
then I’m indoors,” and “if I’m indoors, then it is raining.” This means that we can infer more
than we could with a simple implication. If P is false, then Q is also false; if it is not raining, we
know that I’m also not indoors.
.c
le
ra
ai
w
sh
yu
pi
Tautology and Logically Equivalent
om
.c
le
ra
ai
w
sh
yu
pi
pi
yu
sh
w
ai
ra
le
.c
om
pi
yu
sh
w
ai
ra
le
.c
om
pi
yu
sh
w
ai
ra
le
.c
om
om
Model
The model is an assignment of a truth value to every proposition. To reiterate, propositions are
.c
statements about the world that can be either true or false. However, knowledge about the world
is represented in the truth values of these propositions. The model is the truth-value assignment
le
that provides information about the world.
For example, if P: “It is raining.” and Q: “It is Tuesday.”, a model could be the following
ra
truth-value assignment: {P = True, Q = False}. This model means that it is raining, but it is not
Tuesday. However, there are more possible models in this situation (for example, {P = True, Q =
True}, where it is both raining an a Tuesday). In fact, the number of possible models is 2 to the
ai
power of the number of propositions. In this case, we had 2 propositions, so 2²=4 possible
models.
w
The knowledge base is a set of sentences known by a knowledge-based agent. This is knowledge
that the AI is provided about the world in the form of propositional logic sentences that can be
used to make additional inferences about the world.
yu
Entailment (⊨)
For example, if α: “It is a Tuesday in January” and β: “It is January,” then we know that α ⊨ β. If
it is true that it is a Tuesday in January, we also know that it is January. Entailment is different
from implication. Implication is a logical connective between two propositions. Entailment, on
the other hand, is a relation that means that if all the information in α is true, then all the
information in β is true.
Inference.
Model Checking is not an efficient algorithm because it has to consider every possible model
before giving the answer (a reminder: a query R is true if under all the models (truth
assignments) where the KB is true, R is true as well). Inference rules allow us to generate new
om
information based on existing knowledge without considering every possible model.
Inference rules are usually represented using a horizontal bar that separates the top part, the
.c
premise, from the bottom part, the conclusion.
The premise is whatever knowledge we have, and the conclusion is what knowledge can be
le
generated based on the premise.
Modus Ponens
ra
The type of inference rule we use in this example is Modus Ponens, which is a fancy way of
ai
saying that if we know an implication and its antecedent to be true, then the consequent is true as
well.
w
sh
yu
And Elimination
pi
If an And proposition is true, then any one atomic proposition within it is true as well.
For example, if we know that Harry is friends with Ron and Hermione, we can conclude that
Harry is friends with Hermione.
om
.c
A proposition that is negated twice is true.
le
For example, consider the proposition “It is not true that Harry did not pass the test”. We can
parse it the following way: “It is not true that (Harry did not pass the test)”, or “¬(Harry did not
ra
pass the test)”, and, finally “¬(¬(Harry passed the test)).”
The two negations cancel each other, marking the proposition “Harry passed the test” as true.
ai
Implication Elimination
w
sh
yu
Biconditional Elimination
om
A biconditional proposition is equivalent to an implication and its inverse with an And
connective.
.c
For example, “It is raining if and only if Harry is inside” is equivalent to (“If it is raining, Harry
is inside” And “If Harry is inside, it is raining”).
le
De Morgan’s Law
ra
ai
w
sh
From this, it is possible to conclude that “It is not true that Harry passed the test” Or “It is not
true that Ron passed the test.”
That is, for the And proposition earlier to be true, at least one of the propositions in the Or
pi
Distributive Property
om
A proposition with two elements that are grouped with And or Or connectives can be distributed,
or broken down into, smaller units consisting of And and Or.
.c
Resolution
Resolution is a powerful inference rule that states that if one of two atomic propositions in an Or
le
proposition is false, the other has to be true. For example, given the proposition “Ron is in the
Great Hall” Or “Hermione is in the library”, in addition to the proposition “Ron is not in the
Great Hall,” we can conclude that “Hermione is in the library.”
ra
More formally, we can define resolution the following way:
ai
w
sh
yu
Resolution can be further generalized. Suppose that in addition to the proposition “Ron is in the
Great Hall” Or “Hermione is in the library”, we also know that “Ron is not in the Great Hall” Or
“Harry is sleeping.” We can infer from this, using resolution, that “Hermione is in the library” Or
“Harry is sleeping.”
pi
.c
Thus, inference algorithms locate complementary literals to generate new knowledge.
le
A Clause is a disjunction of literals (a propositional symbol or a negation of a propositional
ra
symbol, such as P, ¬P). A disjunction consists of propositions that are connected with an Or
logical connective (P ∨ Q ∨ R). A conjunction, on the other hand, consists of propositions that
are connected with an And logical connective (P ∧ Q ∧ R). Clauses allow us to convert any
ai
logical statement into a Conjunctive Normal Form (CNF), which is a conjunction of clauses,
for example: (A ∨ B ∨ C) ∧ (D ∨ ¬E) ∧ (F ∨ G).
w
sh
yu
pi
At this point, we can run an inference algorithm on the conjunctive normal form. Occasionally,
through the process of inference by resolution, we might end up in cases where a clause contains
the same literal twice. In these cases, a process called factoring is used, where the duplicate
literal is removed. For example, (P ∨ Q ∨ S) ∧ (¬P ∨ R ∨ S) allow us to infer by resolution
that (Q ∨ S ∨ R ∨ S). The duplicate S can be removed to give us (Q ∨ R ∨ S).
om
Resolving a literal and its negation, i.e. ¬P and P, gives the empty clause (). The empty clause is
always false, and this makes sense because it is impossible that both P and ¬P are true. This fact
is used by the resolution algorithm.
.c
le
ra
ai
Proof by contradiction is a tool used often in computer science. If our knowledge base is true,
and it contradicts ¬α, it means that ¬α is false, and, therefore, α must be true. More technically,
the algorithm would perform the following actions:
w
sh
To determine if KB ⊨ α:
yu
om
2.FIRST-ORDER LOGIC (Predicate Logic)
.c
le
ra
ai
w
sh
yu
pi
om
.c
le
ra
● First-order logic (FOL) is foundational in mathematics, philosophy, and artificial
intelligence due to its ability to represent objects, relations, and general laws or rules.
ai
● FOL differs from propositional logic in its ontological commitment, as it assumes that the
world consists of objects with specific relations among them.
w
● The formal models in FOL are more complex than those in propositional logic, reflecting
the richer ontology it assumes.
sh
● FOL is strictly less expressive than higher-order logic, as some sentences in the latter
cannot be expressed using any finite number of FOL sentences.
● A logic's epistemological commitment refers to the possible states of knowledge
pi
regarding a fact. In both propositional and FOL, knowledge can be in three states:
believing a sentence to be true, believing it to be false, or having no opinion.
Predicate logic, also known as first-order logic or predicate calculus, is a formal system in
mathematical logic and philosophy. It extends propositional logic by introducing variables,
quantifiers, and predicates to enable more complex and expressive representations of statements
and relationships.
Syntax: First-order logic (FOL), also known as first-order predicate logic, has a well-defined
syntax that consists of various elements and rules for constructing valid statements. Here are the
key components of the syntax of FOL:
Object: Richard the Lionheart, King of England from 1189 to 1199; his younger brother, the evil
King John, who ruled from 1199 to 1215; the left legs of Richard and John; and a crown.
om
.c
le
ra
ai
w
sh
1. Variables: Predicate logic introduces variables (e.g., x, y) that can represent objects or
yu
objects or variables. They are often represented by symbols or words (e.g., P(x), Q(x, y)).
Predicates can be true or false depending on the values assigned to their variables.
We can go through each function and predicate, writing down what we know in terms of
the other symbols. For example, one’s mother is one’s female parent:
∀ m, c Mother (c) = m ⇔ Female(m) ∧ Parent(m, c) .
One’s husband is one’s male spouse:
∀ w, h Husband(h, w) ⇔ Male(h) ∧ Spouse(h, w) .
Male and female are disjoint categories:
∀ x Male(x) ⇔ ¬Female(x) .
Parent and child are inverse relations:
∀ p, c Parent(p, c) ⇔ Child(c, p) .
A grandparent is a parent of one’s parent:
∀ g, c Grandparent(g, c) ⇔ ∃ p Parent(g, p) ∧ Parent(p, c) .
A sibling is another child of one’s parents:
∀ x, y Sibling(x, y) ⇔ x = y ∧ ∃ p Parent(p, x) ∧ Parent(p, y) .
om
3. Quantifiers:
Quantifiers in first-order logic allow us to express properties of entire collections of
objects, making it possible to state general rules and assertions. Predicate logic uses
quantifiers to express statements about the scope of variables. First-order logic contains
.c
two standard quantifiers, called universal and existential.
a. Universal Quantifier (∀): Represents "for all" or "for every." For example,
le
∀x P(x) means "P(x) is true for all values of x."
For Example:“All kings are persons,” is written in first-order logic as
ra
∀ x King(x) ⇒ Person(x)
∀ is usually pronounced “For all ...”. (Remember that the upside-down A stands
for “all.”) Thus, the sentence says, “For all x, if x is a king, then x is a person.”
ai
The symbol x is called a variable. By convention, variables are lowercase letters.
A variable is a term all by itself, and as such can also serve as the argument of a
w
om
Universal quantification makes statements about every object. Similarly, we can
make a statement about some object in the universe without naming it, by using
an existential quantifier. To say, for example, that King John has a crown on his
head, we write
.c
∃ x Crown(x) ∧ OnHead(x, John) .
∃x is pronounced “There exists an x such that ...” or “For some x...”.
Intuitively, the sentence ∃ x P says that P is true for at least one object x. More
le
precisely, ∃ x P is true in a given model if P is true in at least one extended
interpretation that assigns x to a domain element. That is, at least one of the
rafollowing is true:
Richard the Lionheart is a crown ∧ Richard the Lionheart is on John’s
head;
ai
King John is a crown ∧ King John is on John’s head;
Richard’s left leg is a crown ∧ Richard’s left leg is on John’s head;
w
sentence is true in the model. Notice that, by our definition, the sentence would
also be true in a model in which King John was wearing two crowns. This is
entirely consistent with the original sentence “King John has a crown on his
yu
head.”
Just as ⇒ appears to be the natural connective to use with ∀, ∧ is the natural
connective to use with ∃. Using ∧ as the main connective with ∀ led to an
pi
overly strong statement in the example in the previous section; using ⇒ with ∃
usually leads to a very weak statement, indeed. Consider the following sentence:
∃ x Crown(x) ⇒ OnHead(x, John) .
4. Functions: Predicate logic allows the use of functions to denote operations that produce
values based on input arguments. Functions can be used in expressions and predicates
(e.g., f(x) = y).
5. Connectives: Similar to propositional logic, predicate logic uses logical connectives
(e.g., ∧ for AND, ∨ for OR, ¬ for NOT) to form complex statements from simpler ones.
6. Constants: Constants are specific objects or values in the domain. They are treated as
fixed and do not vary like variables.
om
.c
le
ra
ai
w
sh
yu
pi
7. Terms:
● Terms are expressions that represent objects in the domain of discourse.
● They can be variables, constants, or functions applied to arguments (e.g., f(x),
John).
● Function symbols, like "LeftLeg," are used to represent relationships or properties
of objects without the need for separate constant symbols for each object.
● The semantics of terms is straightforward: a term like f(t1, ..., tn) refers to the
result of applying the function represented by f to objects represented by t1, ..., tn.
8. Complex Formulas:
● Complex formulas are built using connectives, quantifiers, and atomic formulas.
● They can be constructed by combining atomic formulas with connectives (e.g., P(x) ∧
om
Q(y)) or by quantifying variables over formulas (e.g., ∀x P(x)).
For example: Richard the Lionheart, King of England from 1189 to 1199; his younger
brother, the evil King John, who ruled from 1199 to 1215; the left legs of Richard and
John; and a crown.
.c
¬Brother (LeftLeg(Richard), John)
Brother (Richard, John) ∧ Brother (John, Richard)
King(Richard) ∨ King(John)
le
¬King(Richard) ⇒ King(John) .
ra
9. Atomic sentences:
An atomic sentence (or atom for short) is formed from a predicate symbol optionally
ai
followed by a ATOM parenthesized list of terms, such as
Brother (Richard, John).
w
This states, under the intended interpretation given earlier, that Richard the Lionheart is
the brother of King John. Atomic sentences can have complex terms as arguments. Thus,
Married(Father (Richard), Mother (John))
sh
states that Richard the Lionheart’s father is married to King John’s mother (again, under a
suitable interpretation).
An atomic sentence is true in a given model if the relation referred to by the predicate
yu
Quantifier Negation:
pi
om
.c
le
ra
ai
w
sh
yu
Nested Quantifiers
pi
om
.c
le
Order Matters:
ra
ai
w
sh
yu
pi
Scope Matters:
om
.c
le
ra
References:
1. CS 50: Introduction to AI course (Harvard University)
ai
2. First course in Artificial Intelligence by Prof Deepak Khemani
3. Artificial Intelligence: A Modern Approach Textbook by Peter Norvig
w
5. Javatpoint. com
yu
pi