Logic gives a precise language in which to state knowledge, and clear rules for reasoning with it.

Propositional Logic

Propositional logic deals with statements that are either true or false, called propositions, such as It is raining. They are joined by the connectives NOT (¬), AND (∧), OR (∨), implies (→) and if and only if (↔). The truth of a compound statement is found from a truth table. An implication P → Q is false only when P is true and Q is false. A statement that is always true is a tautology, and one that is always false is a contradiction. Propositional logic is simple and has a complete method of proof, but it is weak, since it cannot speak of objects and their properties, or of all and some.

Predicate Logic

Predicate logic, or first-order logic, adds objects, predicates, functions and quantifiers. A predicate states a property or a relation, such as Student(Asha) or Teaches(Rao, AI). The universal quantifier ∀ means for all, and the existential quantifier ∃ means there exists. All students study is written ∀x (Student(x) → Studies(x)). Some student is absent is ∃x (Student(x) ∧ Absent(x)). Predicate logic is much more expressive than propositional logic.

Definition: Predicate logic. A formal language with objects, predicates, functions, connectives and quantifiers, used to state facts about objects and their relations and to reason about them.

Reasoning in Logic

In predicate logic, unification finds a substitution that makes two expressions the same, so that a rule can be applied. Resolution proves a statement by adding its negation to the knowledge and deriving a contradiction. The knowledge is first converted to clause form, which is a set of disjunctions of literals. Prolog is a programming language based on a form of predicate logic, and it uses backward chaining with unification. Logic is precise and has sound proofs, but it can be slow, and it cannot easily handle uncertainty.

Table 2.2: Propositional and predicate logic

Feature Propositional Predicate
Basic unit Whole statement Predicate with objects
Quantifiers None For all, exists
Expressive power Low High
Example P ∧ Q ∀x Student(x) → Studies(x)

Example 2.2: Truth table of an implication

Problem: Find the truth values of P → Q for all values of P and Q, and show that P → Q is the same as ¬P ∨ Q.

Solution:

  1. P true, Q true: P → Q is true.
  2. P true, Q false: P → Q is false.
  3. P false, Q true: true. P false, Q false: true.
  4. Check ¬P ∨ Q: true, false, true, true, which is the same list.

Result: P → Q is false only when P is true and Q is false, and it equals ¬P ∨ Q.

for p in (True, False):
    for q in (True, False):
        imp = (not p) or q
        print(p, q, imp)

Output

True True True
True False False
False True True
False False True

Common mistakes

  • Writing "all students study" as ∀x Student(x) ∧ Studies(x). It should use an implication.
  • Writing "some student is absent" with an implication instead of AND.
  • Thinking P → Q is true only when both P and Q are true.

Key takeaways

  • Propositional logic uses statements and connectives.
  • Predicate logic adds objects, predicates and quantifiers.
  • P → Q is false only when P is true and Q is false.
  • Resolution proves a statement by deriving a contradiction from its negation.

Practice questions

  1. What is a predicate?
  2. Name the two quantifiers.
  3. What is a tautology?

Answers to the practice questions

  1. A statement about a property of an object or a relation between objects, such as Student(Asha).
  2. The universal quantifier (for all) and the existential quantifier (there exists).
  3. A statement that is true for all values of its parts.

Sources

  • Official BCA syllabus Artificial Intelligence and Expert Systems, course code 25BCA405DS02, Unit II