371CPE Lectures Part1
371CPE Lectures Part1
Student Name
Student ID
References
• Adrian A. Hopgood, Intelligent Systems for Engineers and Scientists: A
Practical Guide to Artificial Intelligence, 4th edition, CRC Press, 2021.
ISBN-13:978-0367336165.
• C. Grosan and A. Abraham, Intelligent Systems: A Modern Approach,
Springer, 2011, e-ISBN 978-3-642-21004-4.
Marks Distribution
Quizzes Assignments Mid Exam 1 Lab Final
15 5 20 20 40
Table of Contents
Chapter 0: Discrete Structures: Revisited
0.1 Data Structures: Revisited
0.2 Blind Search Algorithms: Revisited
0.3 Heuristic Search Algorithms: Revisited
0.4 Propositional Logic: Revisited
0.5 Predicate Logic: Revisited
0.6 Inference (Reasoning): Revisited
Chapter 1:
1.1 Intelligent Systems: An Introduction
1.2 Machine Learning: An Introduction
Chapter 2:
2.1 Knowledge-Based Systems
2.2 Decision Trees
Chapter 3:
3.1 Intelligent Agent
3.2 Goal-based Problem-Solving Agent
Chapter 4:
4.1 Fuzzy Sets and Fuzzy Logic
4.2 Fuzzy Expert Systems
Chapter 5:
5.1 Neural Networks
5.2 Deep Learning: An Introduction
Chapter 6:
6.1 Interpretation and Diagnosis Intelligent Systems
6.2 Design and Selection Intelligent Systems
6.3 Planning Intelligent Systems
6.4 Control Intelligent Systems
Intelligent Systems, 2024 Chapter 0.1 Dr. Mohammad Alshamri
5. Linear queue
Binary Trees
A binary tree is a tree data structure in
which each node has at the most two
children, which are referred to as the left
child and the right child.
Tree Traversal
We have two options here:
• Depth-First Search (DFS): It starts at the root and explores as far as possible along
each branch before backtracking.
• Breadth-First Search (BFS): It starts at the tree root and explores the neighbor
nodes first, before moving to the next level neighbors.
Inorder Traversal
Visit the nodes in the left subtree of a node, then visit the node, and then visit the nodes
in the right subtree of the node.
Postorder Traversal
Visit the nodes in the left subtree of a node, then visit the nodes in the right subtree of the
node, and then visit the node.
Preorder Traversal
Visit a node, then visit the nodes in the left subtree of that node, and then visit the nodes
in the right subtree of the node.
Example 1
Example2
Example 3
Expanding a Node
Expanding a node means:
✓ generating all the successor nodes of it, and
✓ adding them and their associated vertices to the state space graph.
Example 4
The following shows how to expand nodes
Arad and Sibiu.
Example 5 (DFS)
Example 6 (BFS)
To avoid processing a node more than once, we use a Boolean visited array.
No information about the problem other than its Some guidance on where to look for solutions is
definition is given. given.
Important Terms
Branching factor (𝒃): it is the maximum number of successors of any node.
Breadth-First Search
BFS expands all the nodes at a given depth in the search tree before any nodes at the next
level are expanded.
Answer 3
Example 4
What BFS search output of the following graph
if the start node is A and Goal node is G?
Answer 4
Visited
A B C D E F G H I G
QUEUE
Example 5
What is the DFS tree of the following graph
if the starting node is A?
Answer 5
Example 6
What is the DFS search output of the following
graph if the start node is A and the goal node is G?
Answer 6
Visited
A B C D E F G H I G
STACK
Example 7
What are the DFS and BFS trees of the
following graph if the starting node is 0?
Answer 7
Example 8
What are the DFS and BFS trees of the
following directed graph if the starting
node is 0?
Answer 8
Example 9
What is the time complexity for BFS of a uniform tree where every state has 𝑏
successors?
Answer 9
L1: The root of the search tree generates 𝑏 nodes.
L2: Each node generates 𝑏 more nodes, for a total of 𝑏 2 .
L3: Each node generates 𝑏 more nodes, yielding 𝑏 3 .
Then the total number of nodes generated is:
1 + 𝑏 + 𝑏 2 + 𝑏 3 + 𝑏 4 + ⋯ + 𝑏 𝑑 = 𝑂(𝑏 𝑑 )
Complexity: complexity is like the time complexity plus the root node
Example 10
BFS is implemented on 1MHZ processor for a problem with 𝑏 = 110, and 𝑑 = 2. Each
node requires 1000 bytes of storage.
1. What is the time complexity?
2. What is the consumed time?
3. What is space complexity?
4. What is the required memory in KB?
Answer 10
Example 11
Repeat Example 10 if 𝑏 = 1000, and 𝑑 = 12?
Example 12
What is the space complexity for DFS with branching factor 𝑏 and maximum depth 𝑚?
Answer 12
The depth-first search requires storage of only 𝑂(𝑏𝑚) nodes.
▪ UCS will get stuck in an infinite loop if there is a path with an infinite sequence of
zero-cost actions—for example, a sequence of NoOp actions.
▪ When all step costs are the same, UCS is similar to BFS, except that the latter stops
as soon as it generates a goal, whereas UCS examines all the nodes at the goal’s
depth to see if one has a lower cost; thus, UCS does strictly more work by
expanding nodes at depth 𝑑 unnecessarily.
Example 13
What is the UCS tree if the start state is Frankfurt?
PQUEUE Visited
F M W K Kar A Mu E N S
Example 14
What is the UCS search output if the start state is Frankfurt and goal state is Munchen?
Answer 14
The output is Frankfurt – Wurzburg – Nurnberg – Munchen. The cost is 487Km.
Example 15
What is the UCS search output if the start state is Sibiu and goal state is Bucharest?
Visited
PQUEUE B/310 S F R P B
← S/0 R/80 F/99 P/177
B/278
←
The output is Sibiu – Rimnicu Vilcea – Pitesti – Bucharest. The cost is 278Km
Example 16
What is the time complexity of UCS?
Answer 16
𝐶∗ 𝐶∗
1+⌊ ⌋ ⌊ ⌋
𝑂 (𝑏 𝜖 ) ≈ 𝑂 (𝑏 𝜖 )
a
𝑏: is the branching factor. complete if 𝑏 is finite.
𝑑: is the depth of the shallowest solution. b
complete if step costs ≥ 𝜖 for positive 𝜖.
𝑚: is the maximum depth of the search tree. c
optimal if step costs are all identical.
𝑙: is the depth limit.
DFS BFS
Advantages ✓ requires less memory ✓ If there are multiple solutions, BFS
✓ faster in execution finds the shortest path.
✓ If there is a solution BFS guarantee
to find it. (Optimal)
Disadvantage there is no guarantee of ✓ takes more memory
solution (not optimal) ✓ slow
Example1
Consider 8-puzzle problem with the following current and goal states. Find the heuristic
function, ℎ(𝑛), output if it is defined as:
1. Number of misplaced tiles in the current state relative to the goal state.
2. Sums of the Manhattan distances for each tile in the puzzle (Manhattan distance of a
tile represents the number of squares from the desired location).
Answer1
ℎ1 (𝑛) = 3
because tiles 1, 4, and 7 are out of place.
ℎ2 (𝑛) = 1 + 0 + 0 + 1 + 0 + 0 + 1 + 0 = 3
Both functions estimate the number of moves we will
have to make to reach a goal state.
Example 2
Find the city-block distance of the following?
Answer 2
ℎ3 (𝑛) = 3 + 1 + 2 + 2 + 2 + 3 + 3 + 2 = 18
Example 3
Find ℎ(𝑛) of Pac Man problem if the
heuristic function is defined as the:
1. Manhattan distance between the
current and goal state.
2. Euclidean distance between the
current and goal state.
Answer 3
ℎ2 (𝑛) = 10 + 5 = 15
Greedy Search
▪ The idea is to expand the node with the smallest estimated cost to reach the goal
(the node which appears to be closest to the goal).
▪ It is called “greedy” because at each step it tries to get as close to the goal as it can.
▪ The heuristic function, ℎ(𝑛), estimates the remaining distance to a goal.
▪ Greedy search is simple and finds a solution quickly.
▪ The time and space complexity for the tree version of greedy search is 𝑂(𝑏𝑚).
However, with a good heuristic function, the complexity can be reduced
substantially.
▪ Greedy algorithm is neither complete nor optimal. It is susceptible to false start.
Example 4
Apply greedy search for
the 8-puzzle problem
using the number of
misplaced tiles as the
heuristic function?
Answer 4
The goal state is reached
in the optimal way.
The same tree will be
obtained if we use
Manhattan distance
Example 5
The distance between any two cities and direct distances from each city to Bucharest are
given below.
1. Find the shortest path from Barcelona to Bucharest using the greedy algorithm.
2. Find the complete path cost.
Answer 5
• For this problem, the direct distances
from a city to Bucharest will be used
as the heuristic function.
• The complete path is:
Barcelona – Rome – Palermo – Athens
– Bucharest
• The path cost is:
𝑃𝑐𝑜𝑠𝑡 = 1471 + 1043 + 907 + 1300
= 4,721𝐾𝑚
A* Search
▪ The A* algorithm combines the UCS and the Greedy search to determinate the
ordering.
▪ The evaluation function 𝑓 is given by:
𝑓(𝑛) = ℎ(𝑛) + 𝑔(𝑛)
o ℎ(𝑛) is a heuristic function that estimates the cost from the node 𝑛 to the goal
o 𝑔(𝑛) is the cost so far to reach 𝑛.
▪ A* search is complete, optimal and speedy.
▪ 𝑓(𝑛) estimates total cost of path through the node 𝑛 to goal.
▪ The queue will be sorted based on estimates of full path costs (not just the cost so
far, and not just the estimated remaining cost, but the two together).
Example 6
Find the
shortest
path from
X to Y
using A*
algorithm.
Example 7
Find the
shortest path
from S to E
using A*
algorithm.
Example 8
Find the shortest path from Barcelona to Bucharest using A* algorithm.
The distance between any two cities and direct distances from each city to Bucharest are
given. Assume the following:
1. 𝒉(𝒏): the direct distance to Bucharest from the node 𝑛.
2. 𝒈(𝒏): the cost of the path so far (i.e., the sum of all costs in the path from Barcelona to
the current node).
Answer 8
• Barcelona is the starting point, so Barcelona will expand into 3 nodes: Madrid, Lyon
and Roma.
• Lyon will be expanded because it has the lowest 𝑓(𝑛) value among them.
Propositional Logic
Logic
▪ Logic describes what is TRUE and not how to solve problems.
▪ Logic consists of two parts:
1. Language: It has two aspects:
✓ Syntax.
✓ Semantics.
2. Method of reasoning.
Syntax
▪ Syntax specifies the symbols in the language and how they can be combined to
form sentences
▪ Syntax represents the:
1. Atomic symbols of the logical language, and
2. Symbol structures for constructing well-formed, non-atomic expressions of logic.
Sentence
• Sentence represents some simple or complex assertion about the world.
• Facts about the world are represented as sentences in logic.
• TRUE, FALSE or any proposition symbol is a sentence.
Axiom (Postulate)
▪ Axiom is a sentence taken as given without being derived from other sentences.
▪ Axiom serves as a premise or starting point for further reasoning and arguments
Semantics
▪ Semantics gives meaning to the atomic symbols of logic.
▪ Semantic specifies how you assign a truth value to a sentence based on its meaning
in the world.
Logical Systems
There are several logical systems with different syntax and semantics.
1. Propositional logic.
2. First-order predicate logic.
Proposition
The proposition is a statement about the world which is either True or False.
"Grass is green" proposition "Close the door" Not proposition
"2 + 5 = 5" proposition "Is it hot outside?" Not proposition
"x is greater than 2" Not proposition
Propositional Logic
▪ Propositional logic is the simplest logical system in which the user defines:
1. A set of propositional symbols, like P and Q.
2. The semantics of each of these symbols
▪ For example:
P: “Sunday is a holiday” Q: “Today is Sunday”
▪ Propositional logic:
1. Expresses knowledge in the form of propositions from the environment.
2. Represents knowledge in symbols that are used to represent the propositions.
▪ A knowledge base of propositional logic is a set of sentences.
Logical Operators
R: It is raining D: It is dark C: It is cold.
Sentence Types
▪ Simple sentence: It is a simple sentence (P, Q, R) that expresses ‘atomic''
propositions about the world.
Q: Today is Sunday. Q can be True or False
Example 1
IF it is raining AND it is dark THEN it is cold (R∧D) ⟹ C
Statement form Symbolic form
Example 2
Prove using truth table the following: ¬(𝑃 ∨ 𝑄) = (¬𝑃) ∧ (¬𝑄)
𝑃 𝑄 𝑃∨𝑄 ¬(𝑃 ∨ 𝑄) ¬𝑃 ¬𝑄 (¬𝑃) ∧ (¬𝑄)
T T T F F F F
T F T F F T F
F T T F T F F
F F F T T T T
Example 3
Prove using truth table the following: 𝑃 ∨ (𝑄 ∧ 𝑅) = (𝑃 ∨ 𝑄) ∧ (𝑃 ∨ 𝑅)
Example 4
Convert the statement to symbolic form and P: The Sun is hot
generate its truth table. Q: It is humid
The Sun is hot, but it is not humid 𝑃 ∧ (¬𝑄)
𝑃 𝑄 ¬𝑄 𝑃 ∧ (¬𝑄)
T T F F
T F T T
F T F F
F F T F
Example 6
Convert the statement to symbolic form and generate truth table.
Answer 6
P: Ali passed exam 𝑃 𝑄 𝑅 𝑄∨𝑅 𝑃 ⟹ (𝑄 ∨ 𝑅)
T T T T T
Q: Ali will get a job
T T F T T
R: Ali will get a car T F T T T
T F F F F
𝑃 ⟹ (𝑄 ∨ 𝑅) F T T T T
F T F T T
F F T T T
F F F F T
Example 7
Assume the following propositions, write symbolic forms of:
A: Angelo comes to the party C: Carlo comes to the party
B: Bruno comes to the party D: David comes to the party
1 IF David comes to the party, THEN Bruno AND Carlo come too 𝐷 ⟹𝐵∧𝐶
2 Carlo comes to the party ONLY IF Angelo AND Bruno do not come 𝐶 ⟹ ¬𝐴 ∧ ¬𝐵
3 David comes to the party IFF Carlo comes AND Angelo does not come 𝐷 ⇔ (𝐶 ∧ ¬𝐴)
IF David comes to the party, THEN IF Carlo does not come THEN Angelo
4 𝐷 ⟹ (¬𝐶 ⟹ 𝐴)
comes
Carlo comes to the party provided that David does not come BUT IF David
5 (¬𝐷 ⟹ 𝐶) ∧ (𝐷 ⟹ ¬𝐵)
comes THEN Bruno does not come
A necessary condition for Angelo coming to the party is that IF Bruno AND
6 𝐴 ⟹ ((¬𝐵 ∧ ¬𝐶) ⟹ 𝐷)
Carlo are not coming, David comes.
Angelo, Bruno, AND Carlo come to the party IFF David does not come BUT IF neither Angelo NOR Bruno
7 come THEN David comes ONLY IF Carlo comes
((𝐴 ∧ 𝐵 ∧ 𝐶) ⇔ ¬𝐷) ∧ ((¬𝐴 ∧ ¬𝐵) ⟹ (𝐷 ⇔ 𝐶))
Example 8
Consider the following propositional language
P: Ahmad is happy Q: Ahmad paints a picture R: Ali is happy
Tautology
It is a compound proposition
that is always TRUE
regardless of the value of
the variables.
Contradiction
It is a compound proposition that is always FALSE.
Example 9
Example 1
R: It is raining U: Joe takes his umbrella W: Joe gets wet
Predicate
Predicates are functions of zero or more arguments that return Boolean values.
U: Joe takes his umbrella U(x): x takes his umbrella Predicate with ONE argument
W: Jane is the mother of Mary W(x,y): x is the mother of y Predicate with TWO arguments
R: It is raining R: It is raining Predicate with ZERO argument
Example 2
R⟹W(x) For any individual x, IF it is raining, THEN x takes his or her umbrella
U(x)⟹ ¬W(x) No matter who you are, IF you take your umbrella, THEN you will not get wet
For any individual x, IF x takes an umbrella, THEN x will not get wet
¬R⟹ ¬W(x) IF it doesn’t rain, THEN nobody gets wet
For any individual x, IF it doesn’t rain, THEN x will not get wet
Atomic Formula
▪ An atomic formula is a predicate with zero or more arguments.
▪ For example, 𝑈(𝑥) is an atomic formula with predicate 𝑈 and one argument
occupied by the variable 𝑥.
▪ In general, an argument is either a variable or a constant.
Constant
• Constant represents a fixed knowledge and cannot be changed during the execution
of the knowledge-based system.
• Constant values can be integers, reals, or character strings (‘Ali’, ‘Omer’, ‘Mary’)
Variables
• Variables are symbols capable of taking on any constant as a value.
• Variables may take different values within a fixed domain.
• Variable values may change during the execution of the system from time to time.
Functions
Functions carry out processes and return a predefined value, not a Boolean value.
Example 3
Create ground and non-ground atomic formulas for Course-Student-Grade predicate.
Answer 3
csg(“CS101”, 12345, “A”) is asserting that the student with ID 12345 got an A in CS101.
Example 4
What is the universe of discourse for the following language?
1. Jane is Paul’s mother. The universe of discourse for this example
2. Jane is Mary’s mother. can be the people living in a particular
3. Any two persons having the same mother are siblings. house or on a particular block
4. Paul and Mary are siblings. Family = {′Jane′, ′Jack′, ′Paul′, ′Mary′}
Arity Number
▪ It indicates the number of elements in the argument list of a predicate.
▪ A predicate with arity 𝑛 is often called an 𝑛-place predicate.
▪ The predicates indicate relations between objects.
Statement Predicate Argument List Arity Number
Tom is a cat C: "is a cat" C(‘Tom’) ‘Tom’ one-place 1
Jane is the mother of
"is the mother of" mother(‘Jane’,‘Mary’) ‘Jane’, ‘Mary’ two-place 2
Mary
The sum of 2 and 3 is 6 "is the sum of" sum(2,3,6) 2,3,6 three-place 3
Mary and Paul are
"are siblings". sibling(‘Mary’, ‘Paul’) ‘Mary’, ‘Paul’ two-place 2
siblings
Closed Formula
Closed formula constitutes a proposition and thus can have a truth value.
Open Formula
• Open formula is a formula that contains at least one free variable. Hence, it does
not have a truth value assigned to it before knowing the variable value.
• Open formula can be transformed into a closed formula by applying a quantifier
for each free variable to make them bound variables.
Example 5
IF 𝑥 is a cat THEN 𝑥 has a tail 𝐶(𝑥): 𝑥 is a cat 𝑇(𝑥): 𝑥 has a tail
Open formula Closed formula
𝐶(𝑥) ⇒ 𝑇(𝑥) C(‘Tom’) ⇒T(‘Tom’).
Example 6
The formula "𝑥 + 2 > 𝑦" is open since it contains the free variables 𝑥 and 𝑦.
In contrast, the formula "∃𝑦 ∀𝑥: 𝑥 + 2 > 𝑦" is closed and has truth value true.
Scope of a Quantifier
▪ Scope is the range in the formula where the quantifier "engages in"
▪ Assume we have: ∀𝑥 𝐴. Here 𝐴 is called the scope of the quantifier.
Example 17
Assume 𝑃(𝑥): 𝑥 is living 𝑄(𝑥): 𝑥 is dead
Example 7
Generalize the statement “I like chocolate” using quantifiers.
Answer 7
“Everyone likes chocolate” ∀𝑥 𝑃(𝑥) ⇒ 𝐿(𝑥, 𝑐)
“There exists 𝑥 such that 𝑥 likes chocolate” ∃𝑥 𝐿(𝑥, 𝑐)
Example 8
Write the predicate of “My brother likes chocolate”
L(B(me), ‘chocolate’)
b(x) means the brother of x (a function).
Example 9
Express "Everyone gets a break once in a while" in predicate logic?
Answer 9
▪ The predicate is: B: "gets a break once in a while"
▪ 𝐵(𝑥): “𝑥 gets a break once in a while”
▪ The word "everyone" indicates that is true for all 𝑥. Hence, ∀𝑥 𝐵(𝑥)
Example 10
Express "All cats have tails" in predicate logic.
Answer 10
We first have to find the scope of the universal quantifier, which is:
"IF 𝑥 is a cat, THEN 𝑥 has tails" 𝐶(𝑥): 𝑥 is a cat 𝑇(𝑥): 𝑥 has a tail
Example 11
Express "There is somebody who knows everyone" in predicate logic?
Answer 11
1. ∃𝑥(𝑥 knows everybody) 3. ∀𝑦 𝐾(𝑥, 𝑦): 𝑥 knows everybody.
2. 𝐾(𝑥, 𝑦): 𝑥 knows 𝑦. 4. ∃𝑥 ∀𝑦 𝐾(𝑥, 𝑦)
Example 12
Express "Everybody has somebody who is his or her mother" in predicate logic?
Answer 12
1. 𝑀(𝑥, 𝑦): " 𝑥 is the mother of 𝑦".
2. ∃𝑥 𝑀(𝑥, 𝑦): "Someone is the mother of 𝑦"
3. Add the universal quantifier: ∀𝑦 ∃𝑥 𝑀(𝑥, 𝑦).
Example 13
Express "Nobody is perfect" in predicate logic?
Answer 13
• "nobody" is a quantifier that indicates the absence of an individual with a certain
property.
• To express the fact that there is no x for which an expression 𝐴 is true, one can
either use:
¬∃𝑥 𝐴: "It is not the case that there is somebody who is perfect"
∀𝑥 ¬𝐴: "For everyone, it is not the case that he or she is perfect".
• The two methods are logically equivalent, i.e., ¬∃𝑥 𝐴 ⟺ ∀𝑥 ¬𝐴.
Example 14
Express "All dogs are mammals" in predicate logic.
Answer 14
Since the quantifier should be restricted to dogs, one should rephrase the statement to be:
"IF 𝑥 is a dog, THEN 𝑥 is a mammal"
This immediately leads to
Example 15
Express "Some dogs are brown" in predicate logic.
Answer 15
▪ This statement means that there are some animals that are dogs and that are brown.
▪ Of course, the statement "x is a dog and x is brown" can be translated as
dog(𝑥)∧brown(𝑥)
▪ "There are some brown dogs" can now be translated as:
Example 16
Express "only dogs bark" in predicate logic?
Answer 16
▪ This statement must be reworded as:
"It barks ONLY IF it is a dog", or, equivalently,
"IF it barks, THEN it is a dog".
▪ ∀𝑥(barks(𝑥) ⇒ dog(𝑥))
Precedence of Operators
1. Quantifiers 4. OR
2. NOT 5. ⟹, ⟺
3. AND
Example 17
Assume 𝑃(𝑥): 𝑥 is living 𝑄(𝑥): 𝑥 is dead
What is the meaning of:
∀𝑥(𝑃(𝑥) ∨ 𝑄(𝑥)) everything is either living or dead.
∀𝑥 𝑃(𝑥) ∨ 𝑄(𝑥) everything is living or 𝑥 is dead.
Example 18
Illustrate the precedence of the operators through brackets.
∀𝑥 ¬ ∃𝑦 𝑃(𝑥, 𝑦)
Answer 18
∀𝑥 (¬ ∃𝑦 𝑃(𝑥, 𝑦))
This means “For all 𝑥 there is no 𝑦 such that 𝑃(𝑥, 𝑦) is TRUE”
“There is no pair of values for 𝑥 and 𝑦 that makes 𝑃(𝑥, 𝑦) TRUE”.
Example 19
Sentence John likes cricket OR football
Predicate(s) 𝑃(𝑥, 𝑦): 𝑥 likes 𝑦
Variables 𝑥: a person - 𝑦: a sport
Constants John, cricket, football
General Symbolic form 𝑃(𝑥, 𝑦)
Sentence Symbolic form 𝑃(“𝐽𝑜ℎ𝑛”, “𝑐𝑟𝑖𝑐𝑘𝑒𝑡”) ∨ 𝑃(“𝐽𝑜ℎ𝑛”, “𝑓𝑜𝑜𝑡𝑏𝑎𝑙𝑙”)
Sentence John lives in a house AND the color of the house is green
Predicate(s) 𝑃(𝑥, 𝑦): 𝑥 lives in 𝑦
𝑄(𝑦, 𝑧): color of 𝑦 is 𝑧
Variables 𝑥: a person - 𝑦: a residence place - 𝑧: color
Constants John, house and green
John introduced
Tautology
▪ An expression 𝐸 is called a tautology if for every interpretation of 𝐸, the value of
𝐸 is true.
▪ An example of a tautology is: 𝑃(𝑥) ∨ ¬ 𝑃(𝑥)
▪ Here, it does not matter what interpretation we use for predicate 𝑃, or what value
we assign to the free variable 𝑥.
Expression Tree
• The predicates are the leaves.
• The operators are ordered based on their precedence.
• The higher precedence operators are close to the predicates and therefore the least precedent one
is the root of the tree.
Inference (Reasoning)
▪ Inference is the mechanism for deriving new sentences from old ones.
▪ Inference consists of the rules for determining a subset of logical expressions,
called theorems of logic.
▪ Inference must obey the primary requirement that the new sentences should follow
logically from the previous ones.
Important Definitions
1. Premises (Hypothesis): They are all propositions except the final proposition.
2. Argument: It is a sequence of propositions.
3. Conclusion: It is the final proposition.
4. Argument form: It is a sequence of compound propositions involving
propositional variables.
Argument Form
Premise (hypothesis) 𝑃1
Argument
Premise (hypothesis) 𝑃2
Premise (hypothesis) 𝑃3
Premise (hypothesis) 𝑃4
conclusion 𝑄
5. Valid argument: An argument is valid if the truth of all its premises implies that
the conclusion is true.
Example 1
Use inference to generate a new sentence:
1. All ravens fly 1. Jane is Paul’s mother.
2. Peter is a raven 2. Jane is Mary’s mother.
3. Any two persons having the same mother
are siblings.
Peter flies Paul and Mary are siblings.
Modus ponens (MP): This rule states that if a conditional statement (‘𝑝 ⇒ 𝑞’) is accepted, and the
antecedent (p) holds, then the consequent (q) may be inferred.
Contraposition is an inference that says that a conditional statement is logically equivalent to
its contrapositive.
Example 2
Use contrapositive for the proposition "All cats are mammals".
Answer 2
• The proposition can be restated as the conditional
"IF something is a cat, THEN it is a mammal"
• The law of contraposition says that statement is identical to the contrapositive
"IF something is not a mammal, THEN it is not a cat"
Example 3
Which rule of inference is used in each argument below:
Alice is a math major.
Addition
Therefore, Alice is either a math major OR a CSI major.
Jerry is a math major AND a CSI major. Therefore, Jerry is a math major. Simplification
IF it is rainy, THEN the pool will be closed. Modus
It is rainy. Therefore, the pool is closed. ponens
IF it snows today, THEN the university will close. Modus
The university is not closed today. Therefore, it did not snow today Tollens
IF I go swimming, THEN I will stay in the sun too long.
Hypothetical
IF I stay in the sun too long, THEN I will sunburn.
syllogism
Therefore, IF I go swimming, THEN I will sunburn.
I go swimming OR eat ice cream. Disjunctive
I did not go swimming. Therefore, I eat an ice cream. syllogism
Formal Proof
▪ Formal proof of a conclusion 𝑄 given hypotheses 𝑃1 , 𝑃1 , . . . , 𝑃𝑛 is a sequence of
steps, each of which applies some inference rule to hypotheses or previously
proven statements (antecedents) to yield a new true statement (consequent).
▪ Formal proof demonstrates that if the premises are TRUE, then the conclusion is
TRUE.
▪ Formal proof is based simply on symbol manipulation (NO need of thinking, just
apply rules)
Example 4
Answer 4
Example 5
Example 6
Show that the premises:
▪ All computer science students like programming.
▪ All computer science students.
imply the conclusion
▪ All like programming.
Answer 6
Domain: All computer science students.
P(x): "x is a computer science student" Q(x): "x likes programming"
The premises are:
▪ All computer science students like programming - ∀𝑥(𝑃(𝑥) ⇒ 𝑄(𝑥))
▪ All computer science students - ∀𝑥 𝑃(𝑥)
The conclusion is:
▪ All like programming - ∀𝑥 𝑄(𝑥)
Step Reason
1. ∀𝑥 𝑃(𝑥) Hypothesis 1
2. ∀𝑥(𝑃(𝑥) ⇒ 𝑄(𝑥)) Hypothesis 2
3. 𝑃(𝑐) Universal Instantiation from (1)
4. 𝑃 (𝑐 ) ⇒ 𝑄 (𝑐 ) Universal Instantiation from (2)
5. 𝑄(𝑐) Modus Ponens from (3) and (4)
6. ∀𝑥 𝑄(𝑥) Universal Generalization from (5)