0% found this document useful (0 votes)
8 views102 pages

Aifl SPV Unit1

The document provides an introduction to Artificial Intelligence (AI) and its applications across various sectors such as healthcare, finance, and education. It discusses the need for AI, its benefits, drawbacks, and various search algorithms used in problem-solving, including uninformed and informed search techniques. Additionally, it covers specific algorithms like Breadth-First Search (BFS), Depth-First Search (DFS), A* search, and their advantages and disadvantages.

Uploaded by

algocode55
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views102 pages

Aifl SPV Unit1

The document provides an introduction to Artificial Intelligence (AI) and its applications across various sectors such as healthcare, finance, and education. It discusses the need for AI, its benefits, drawbacks, and various search algorithms used in problem-solving, including uninformed and informed search techniques. Additionally, it covers specific algorithms like Breadth-First Search (BFS), Depth-First Search (DFS), A* search, and their advantages and disadvantages.

Uploaded by

algocode55
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 102

SAIESH N.

Digitally signed by SAIESH


N. PRABHU VERLEKAR
DN: cn=SAIESH N. PRABHU

PRABHU VERLEKAR, o=SRIEIT, ou=IT,


email=SAIESH.PRABHUVER
[email protected], c=IN
VERLEKAR Date: 2025.02.22 15:12:49
+05'30'

INTRODUCTION TO AI AND
KNOWLEDGE
REPRESENTATION

1 Saiesh N. Prabhu Verlekar


Department of Information Technology
SRIEIT, Shiroda - Goa
INTRODUCTION
- Artificial Intelligence (AI) refers to the simulation of human
intelligence in machines that are programmed to think and
act like humans.
- It involves the development of algorithms and computer
programs that can perform tasks that typically require
human intelligence such as visual perception, speech
recognition, decision-making, and language translation.

2
USES OF ARTIFICIAL INTELLIGENCE

 Healthcare: AI is used for medical diagnosis, drug


discovery, and predictive analysis of diseases.

 Finance: AI helps in credit scoring, fraud detection, and


financial forecasting.

 Retail: AI is used for product recommendations, price


optimization, and supply chain management.

 Manufacturing: AI helps in quality control, predictive


maintenance, and production optimization.

3
 Transportation: AI is used for autonomous vehicles,
traffic prediction, and route optimization.
 Customer service: AI-powered chatbots are used for
customer support, answering frequently asked questions,
and handling simple requests.

 Security: AI is used for facial recognition, intrusion


detection, and cybersecurity threat analysis.

 Marketing: AI is used for targeted advertising, customer


segmentation, and sentiment analysis.

 Education: AI is used for personalized learning, adaptive


testing, and intelligent tutoring systems.
4
NEED FOR ARTIFICIAL INTELLIGENCE

 To create expert systems that exhibit intelligent behavior


with the capability to learn, demonstrate, explain, and
advise its users.

 Helping machines find solutions to complex problems like


humans do and applying them as algorithms in a
computer-friendly manner.

 Improved efficiency: Artificial intelligence can automate


tasks and processes that are time-consuming and require a
lot of human effort.

 Better decision-making: Artificial intelligence can analyze 5


large amounts of data and provide insights that can aid in
decision-making.
 Enhanced accuracy: Artificial intelligence algorithms can
process data quickly and accurately, reducing the risk of
errors that can occur in manual processes. This can
improve the reliability and quality of results.

 Personalization: Artificial intelligence can be used to


personalize experiences for users, tailoring
recommendations, and interactions based on individual
preferences and behaviors. This can improve customer
satisfaction and loyalty.

 Exploration of new frontiers: Artificial intelligence can be


used to explore new frontiers and discover new knowledge
6
that is difficult or impossible for humans to access.
DRAWBACKS OF ARTIFICIAL INTELLIGENCE

 Bias and unfairness: AI systems can perpetuate and


amplify existing biases in data and decision-making.

 Lack of transparency and accountability: Complex AI


systems can be difficult to understand and interpret,
making it challenging to determine how decisions are being
made.

 Job displacement: AI has the potential to automate


many jobs, leading to job loss and a need for reskilling.

 Security and privacy risks: AI systems can be


vulnerable to hacking and other security threats, and may 7
also pose privacy risks by collecting and using personal
data.
 Ethical concerns: AI raises important ethical questions
about the use of technology for decision-making, including
issues related to autonomy, accountability, and human
dignity.

8
SOLVING PROBLEMS BY SEARCHING
 Search is the systematic examination of states to find path
from the start/root state to the goal state.
 The process of problem-solving using searching consists of
the following steps:
- Define the problem
- Analyze the problem
- Identification of possible solutions
- Choosing the optimal solution
- Implementation

9
UNINFORMED SEARCH ALGORITHMS

- The uninformed search algorithm does not have any


domain knowledge such as closeness, location of the goal
state, etc. it behaves in a brute-force way.
- It only knows the information about how to traverse the
given tree and how to find the goal state. This algorithm is
also known as the Blind search algorithm or Brute -Force
algorithm.

10
UNINFORMED SEARCH
 Breadth First Search (BFS)
- It generally starts from the root node and examines the
neighbor nodes and then moves to the next level.
- It uses First-in First-out (FIFO) strategy as it gives the
shortest path to achieving the solution.
- BFS is used where the given problem is very small.

11
- let’s take node A as the start state and node F as the goal
state.
- The BFS algorithm starts with the start state and then goes
to the next level and visits the node until it reaches the goal
state.
- In this example, it starts from A and then travel to the next
level and visits B and C and then travel to the next level and
visits D, E, F and G.
- Here, the goal state is defined as F. So, the traversal will
stop at F.
- The path of traversal is:
A —-> B —-> C —-> D —-> E —-> F
12
 Advantages of BFS
- BFS will never be trapped in any unwanted nodes.
- If the graph has more than one solution, then BFS will
return the optimal solution which provides the shortest path.

 Disadvantages of BFS
- BFS stores all the nodes in the current level and then go to
the next level. It requires a lot of memory to store the nodes.
- BFS takes more time to reach the goal state which is far
away.

13
EXAMPLE

14
15
16
EXAMPLE (ROUTING PROBLEM)

1 10
S G
B
5 5

15 5

17
SOLUTION OF THE ROUTING PROBLEM
USING BREADTH FIRST SEARCH
S S
Sol= {S,A,G} &
Cost = 11
A B C A B C
1 5 15 1 5 15

G
11

18
New solution found
better than the current S

Sol= {S,B,G} &


Cost = 10
A B C
1 5 15

G G
11 10 New solution found S
but not better than
what we have
Sol= {S,B,G} &
A B C
Cost = 10 1 5 15

G G G
11 10 20

19
DEPTH FIRST SEARCH (DFS)
- The depth-first search uses Last-in, First-out (LIFO)
strategy.
- DFS uses backtracking. That is, it starts from the initial
state and explores each path to its greatest depth before it
moves to the next path.
- DFS will follow
Root node —-> Left node —-> Right node

20
- It starts from the start state A and then travels to B and
then it goes to D.
- After reaching D, it backtracks to B. B is already visited,
hence it goes to the next depth E and then backtracks to B. as
it is already visited, it goes back to A. A is already visited.
- So, it goes to C and then to F. F is our goal state and it
stops there.
- The path of traversal is:
A —-> B —-> D —-> E —-> C —-> F

21
 Advantages of DFS
- It takes lesser memory as compared to BFS.
- The time complexity is lesser when compared to BFS.
- DFS does not require much more search.

 Disadvantages of DFS
- DFS does not always guarantee to give a solution.
- As DFS goes deep down, it may get trapped in an infinite
loop.

22
EXAMPLE

23
24
25
26
27
28
29
ITERATIVE DEEPENING SEARCH
- Iterative deepening depth-first search is a combination of
depth-first search and breadth-first search.
- IDDFS find the best depth limit by gradually adding the
limit until the defined goal state is reached.

30
- Consider, A as the start node and E as the goal node. Let
the maximum depth be 2.
- The algorithm starts with A and goes to the next level and
searches for E.
- If not found, it goes to the next level and finds E.
- The path of traversal is
A —-> B —-> E

31
 Advantages of IDDFS
- IDDFS has the advantages of both BFS and DFS.
- It offers fast search and uses memory efficiently.

 Disadvantages of IDDFS
- It does all the works of the previous stage again and again.

32
INFORMED SEARCH
- The informed search algorithm is also called heuristic
search or directed search. In contrast to uninformed search
algorithms, informed search algorithms require details such
as distance to reach the goal, steps to reach the goal, cost of
the paths which makes this algorithm more efficient.
- Here, the goal state can be achieved by using the heuristic
function.
- The heuristic function is used to achieve the goal state with
the lowest cost possible. This function estimates how close a
state is to the goal.

33
HEURISTIC FUNCTION FORMULA

 f(n)= g(n) + h(n), where

 g(n) = cost to reach node n from the start state.

 h(n) = cost to reach from node n to goal node.

 f(n) = estimated cost of the cheapest solution.

34
GREEDY BEST-FIRST SEARCH
- Greedy best-first search uses the properties of both depth-
first search and breadth-first search.
- Greedy best-first search traverses the node by selecting the
path which appears best at the moment.
- The closest path is selected by using the heuristic function.

35
- A is the start node and H is the goal node.
- Greedy best-first search first starts with A and then
examines the next neighbour B and C. Here, the heuristics of
B is 12 and C is 4.
- The best path at the moment is C and hence it goes to C.
- From C, it explores the neighbours F and G. the heuristics
of F is 8 and G is 2.
- Hence it goes to G. From G, it goes to H whose heuristic is 0
which is also our goal state.
- The path of traversal is
A —-> C —-> G —-> H

36
 Advantages of Greedy best-first search
- Greedy best-first search is more efficient compared with
breadth-first search and depth-first search.

 Disadvantages of Greedy best-first search


- There are some possibilities for greedy best-first to get
trapped in an infinite loop.
- The algorithm is not an optimal one.

37
EXAMPLE

38
39
40
41
A* SEARCH
- A* search algorithm is a combination of both uniform cost
search and greedy best-first search algorithms.
- It uses the advantages of both with better memory usage.
- It uses a heuristic function to find the shortest path.
- A* search algorithm uses the sum of both the cost and heuristic
of the node to find the best path.

42
- Let A be the start node and H be the goal node.
- First, the algorithm will start with A. From A, it can go to
B, C, H.
- Note the point that A* search uses the sum of path cost and
heuristics value to determine the path.
- Here, from A to B, the sum of cost and heuristics is 1 + 3 =
4.
From A to C, it is 2 + 4 = 6.
From A to H, it is 7 + 0 = 7.
- Here, the lowest cost is 4 and the path A to B is chosen. The
other paths will be on hold.
- Now, from B, it can go to D or E.
43
- From A to B to D, the cost is 1 + 4 + 2 = 7.
- From A to B to E, it is 1 + 6 + 6 = 13.
- The lowest cost is 7. Path A to B to D is chosen and
compared with other paths which are on hold.
- Here, path A to C is of less cost. That is 6.
- Hence, A to C is chosen and other paths are kept on hold.
- From C, it can now go to F or G.
- From A to C to F, the cost is 2 + 3 + 3 = 8.
- From A to C to G, the cost is 2 + 2 + 1 = 5.
- The lowest cost is 5 which is also lesser than other paths
which are on hold. Hence, path A to G is chosen.
- From G, it can go to H whose cost is 2 + 2 + 2 + 0 = 6.
- Here, 6 is lesser than other paths cost which is on hold.
- Also, H is our goal state. The algorithm will terminate here. 44
- The path of traversal is
A —-> C —-> G —-> H
 Advantages of A* search algorithm
- This algorithm is best when compared with other
algorithms.
- This algorithm can be used to solve very complex problems
also it is an optimal one.

 Disadvantages of A* search algorithm


- The A* search is based on heuristics and cost. It may not
produce the shortest path.
- The usage of memory is more as it keeps all the nodes in
the memory.

45
EXAMPLE

46
47
48
49
50
51
ITERATIVE DEEPENING A* (IDA*)

52
- We want to find the optimal path from node A to node F using
the IDA* algorithm.
- The first step is to set an initial cost limit. Let's use the
heuristic estimate of the optimal path, which is 7 (the sum of the
costs from A to C to F).
- Set the cost limit to 7.
- Start the search at node A.
- Expand node A and generate its neighbors, B and C.
- Evaluate the heuristic cost of the paths from A to B and A to C,
which are 5 and 6 respectively.
- Since the cost of the path to B is less than the cost limit,
continue the search from node B.
- Expand node B and generate its neighbors, D and E. 53
- Evaluate the heuristic cost of the paths from A to D and A to E,
which are 10 and 9 respectively.
- Since the cost of the path to D exceeds the cost limit, backtrack
to node B.
- Evaluate the heuristic cost of the path from A to C, which is 6.
- Since the cost of the path to C is less than the cost limit,
continue the search from node C.
- Expand node C and generate its neighbor, F.
- Evaluate the heuristic cost of the path from A to F, which is 7.
- Since the cost of the path to F is less than the cost limit, return
the optimal path, which is A - C - F.

54
HEURISTIC FUNCTION
- A heuristic function estimates the approximate cost of
solving a task.
- Determining the shortest driving distance to a particular
location can be one example.
- Informed Search uses a heuristic function to identify the
most feasible path.
- It estimates how far away the agent is from the goal using
the agent's current condition as input.
 Types of heuristic functions in AI are:

- Breadth-First Search (BFS) and Depth First Search (DFS),


Bidirectional Search, A* search Simulated Annealing, Hill
Climbing, Best First search.
55
HILL CLIMBING
- Hill climbing is a simple optimization algorithm used in
Artificial Intelligence (AI) to find the best possible solution for a
given problem.
- It belongs to the family of local search algorithms and is often
used in optimization problems where the goal is to find the best
solution from a set of possible solutions.
- In Hill Climbing, the algorithm starts with an initial solution
and then iteratively makes small changes to it in order to
improve the solution.
- These changes are based on a heuristic function that
evaluates the quality of the solution.
- The algorithm continues to make these small changes until it
reaches a local maximum, meaning that no further
improvement can be made with the current set of moves. 56
- One of the widely discussed examples of Hill climbing
algorithm is Traveling-salesman Problem in which we need to
minimize the distance traveled by the salesman.

57
 Step 1: Start with an initial state.
 Step 2: Check if the initial state is the goal. If so, return
success and exit.
 Step 3: Enter a loop to search for a better state
continuously.
 Select a neighboring state within the loop by applying an
operator to the current state.
 Evaluate this new state:
 If it’s the goal state, return success and exit.
 If it’s better than the current state, update the current
state to this new state.
 If it’s not better, discard it and continue the loop.
 Step 4: End the process if no better state is found and the 58

goal isn’t achieved.


MIN-MAX ALGORITHM
- It is a recursive or back tracking algorithm which is use in
game theory and decision making.
- It is mostly used for game playing in AI such as chess, tic
tac toe, checkers etc.
- There are 2 types of players : MIN and MAX.
- MAX for maximized value and MIN for minimized value.

59
1 A
MAX

1 B -3 C

MIN

4 D 1 E 2 F -3 G
MAX

H I J K L M N O

4 -5 -5 1 -7 2 -3 -8

60

= agent = opponent
ALPHA – BETA PRUNING
 Alpha-Beta is a procedure which can prune large parts of
the search tree and allow search to go deeper.

61
CONSTRAINT SATISFACTION PROBLEM
- Variables WA, NT, Q, NSW, V, SA, T

- Domains Di = {red,green,blue}

- Constraints: adjacent regions must have different colors


 e.g., WA ≠ NT

- Solutions : e.g., WA = red, NT = green, Q = red, NSW = green, V


= red, SA = blue, T = green

62
CRYPT ARITHMETIC PROBLEMS
Rules:
No two letters have same value.
Sum of digits must be as shown in the problem.
There should be only one carry forward.
Digits to be assigned is from 0-9.

1) TO Soln: Letter Digit


GO T 2
OUT O 1
G 8
63
U 0
2+G =U+10 try : 2+9=11 or 2+8=10
SOLVE EXAMPLES
2) C R O S S 3) B A S E
R O A D S B A L L
D A N G E R G A M E S

4) S E N D 5) E A T
M O R E T H A T
M O N E Y A P P L E

6) S O M E 7) L O G I C
T I M E L O G I C 64
S P E N T P R O L O G
PROPOSITIONAL LOGIC IN ARTIFICIAL
INTELLIGENCE

- Propositional logic (PL) is the simplest form of logic where


all the statements are made by propositions.
- A proposition is a declarative statement which is either true
or false
 Example:

a) It is Sunday.
b) The Sun rises from West (False proposition)
c) 3+3= 7(False proposition)
d) 5 is a prime number.

65
SOME BASIC FACTS ABOUT
PROPOSITIONAL LOGIC
- 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 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.
- Connectives can be said as a logical operator which
connects two sentences.
66
- A proposition formula which is always true is
called tautology, and it is also called a valid sentence.
- A proposition formula which is always false is
called Contradiction.
- Statements which are questions, commands, or opinions are
not propositions such as "Where is Rohini", "How are you",
"What is your name", are not propositions.

67
SYNTAX OF PROPOSITIONAL LOGIC:

- The syntax of propositional logic defines the allowable


sentences for the knowledge representation.
- There are two types of Propositions:
 Atomic Propositions

 Compound propositions

 Atomic Proposition:
- Atomic propositions are the simple propositions.
- These are the sentences which must be either true or false.
Eg:
a) 2+2 is 4, it is an atomic proposition as it is a true fact.
b) "The Sun is cold" is also a proposition as it is a false fact. 68
 Compound proposition:
- Compound propositions are constructed by combining
simpler or atomic propositions, using parenthesis and logical
connectives.
 Eg:

a) "It is raining today, and street is wet."


b) "Ankit is a doctor, and his clinic is in Mumbai."

69
LOGICAL CONNECTIVES

- Logical connectives are used to connect two simpler propositions


or representing a sentence logically. There are mainly five
connectives, which are given as follows:
 Negation: A sentence such as ¬ P is called negation of P. A
literal can be either Positive literal or negative literal.
 Conjunction: A sentence which has ∧ connective such as, P ∧
Q is called a conjunction.
Eg: Rohan is intelligent and hardworking. It can be written as
P∧ Q.
P= Rohan is intelligent,
Q= Rohan is hardworking.

 Disjunction: A sentence which has ∨ connective, such as P ∨ Q.


is called disjunction, where P and Q are the propositions.
70
Eg: "Ritika is a doctor or Engineer"
Here P= Ritika is Doctor. Q= Ritika is Engineer, so we can write
it as P ∨ Q.
 Implication: A sentence such as P → Q, is called an
implication. Implications are also known as if-then rules.
- It can be represented as
If it is raining, then the street is wet.
- Let P= It is raining, and Q= Street is wet, so it is represented
as P → Q

 Biconditional: A sentence such as P⇔ Q is a Biconditional


sentence,
- Eg: If I am breathing, then I am alive
P= I am breathing, Q= I am alive, it can be represented
as P ⇔ Q.

71
PROPOSITIONAL LOGIC CONNECTIVES

72
73
Limitations of Propositional logic:
•We cannot represent relations like ALL, some, or none with
propositional logic. Example:
• All the girls are intelligent.
• Some apples are sweet.
•Propositional logic has limited expressive power. 74
 Inference:
- In artificial intelligence, we need intelligent computers
which can create new logic from old logic or by evidence, so
generating the conclusions from evidence and facts is termed
as Inference.
- Inference rules are applied to derive proofs in artificial
intelligence, and the proof is a sequence of the conclusion that
leads to the desired goal.

75
INFERENCE RULES

 Implication: It is one of the logical connectives which can


be represented as P → Q. It is a Boolean expression.

 Converse: The converse of implication, which means the


right-hand side proposition goes to the left-hand side and
vice-versa. It can be written as Q → P.

 Contrapositive: The negation of converse is termed as


contrapositive, and it can be represented as ¬ Q → ¬ P.

 Inverse: The negation of implication is called inverse. It


can be represented as ¬ P → ¬ Q.
76
Hence from the above truth table, we can prove that P → Q is equivalent
to ¬ Q → ¬ P, and Q→ P is equivalent to ¬ P → ¬ Q. 77
TYPES OF INFERENCE RULES

1) Modus Ponens:
- It states that if we have a conditional statement ("If P, then
Q") and we know that P is true, then we can conclude that Q
must also be true.
- It can be represented as:
If P, then Q.
P.
Therefore, Q.

78
.
 Statement -1 : "If I am sleepy then I go to bed" ==> P→ Q
Statement - 2 : "I am sleepy" ==> P
Conclusion: "I go to bed." ==> Q.

 We are given the logical statements:


 Statement-1 (Conditional Statement): "If I am sleepy, then
I go to bed."
 This can be written as: P → Q
 Where:
 P = "I am sleepy"

 Q = "I go to bed"

 Statement-2 (Premise): "I am sleepy." (P is true)


 Conclusion: "I go to bed." (Q must be true) 79
 Truth Table for Modus Ponens

P (I am sleepy) Q (I go to bed) P → Q (If P Valid


then Q) Conclusion (Q)
when P is true

(Modus Ponens
F (False) F (False) T (True)
does not apply)
F (False) T (True) T (True) (Modus Ponens
does not apply)
T (True) F (False) F (False) Invalid case
T (True) T (True) T (True) T (True)

80
2) Modus Tollens:
- It states that If P → Q (If P, then Q) is true and Q is false
(¬Q), Then P must also be false (¬P).
- It can be represented as:
If P, then Q.
Not Q.
Therefore, not P.

 Example of Modus Tollens


- Premise 1: If it is raining, then the ground is wet. (P → Q)
- Premise 2: The ground is not wet. (¬Q)
- Conclusion: Therefore, it is not raining. (¬P) 81
 Truth Table for Modus Tollens

P (It is Q (The P → Q (If P ¬Q (The Valid


raining) ground is then Q) ground is Conclusion
wet) NOT wet) (¬P, It is
NOT
raining)

F (False) F (False) T (True) T (True) T (True)

F (False) T (True) T (True) F (False) (Modus


Tollens does
not apply)
T (True) F (False) F (False) T (True) (Invalid
case)
T (True) T (True) T (True) F (False) (Modus 82
Tollens does
not apply)
 Statement -1: "If I am sleepy then I go to bed" ==> P→ Q
Statement -2: "I do not go to the bed."==> ¬Q
Statement-3: Which infers that "I am not sleepy" => ¬P
 Logical Statements Given:
 Statement-1 (Conditional Statement): "If I am sleepy,
then I go to bed."
 This can be written as: P → Q
 Where:
 P = "I am sleepy"

 Q = "I go to bed"

 Statement-2 (Premise): "I do not go to bed." (¬Q is true)


 Conclusion (By Modus Tollens): "I am not sleepy." (¬P) 83
P (I am Q (I go to P → Q (If P ¬Q (I do Valid
sleepy) bed) then Q) NOT go to Conclusion
bed) (¬P, I am
NOT
sleepy)

F (False) F (False) T (True) T (True) T (True)

F (False) T (True) T (True) F (False) (Modus


Tollens does
not apply)
T (True) F (False) F (False) T (True) (Invalid
case)
T (True) T (True) T (True) F (False) (Modus
Tollens does 84
not apply)
FIRST-ORDER LOGIC

- First-order logic is another way of knowledge representation in


artificial intelligence. It is an extension to propositional logic.
- First-order logic is also known as Predicate logic or First-order
predicate logic.
- The key components of FOL include constants, variables,
predicates, functions, quantifiers, and logical connectives.
 Constants: Constants represent specific objects within the
domain. For example, in a given domain, Alice, 2,
and NewYork could be constants.
 Variables: Variables stand for unspecified objects in the
domain. Commonly used symbols for variables include x, y,
and z.
 Predicates: Predicates are functions that return true or false,
representing properties of objects or relationships between 85
them. For example, Likes(Alice, Bob) indicates that Alice likes
Bob, and GreaterThan(x, 2) means that x is greater than 2.
 Functions: Functions map objects to other objects. For
instance, MotherOf(x) might denote the mother of x.
 Quantifiers: Quantifiers specify the scope of variables. The
two main quantifiers are:
 Universal Quantifier (∀): Indicates that a predicate
applies to all elements in the domain.
 For example, ∀x (Person(x) → Mortal(x)) means "All

persons are mortal."


 Existential Quantifier (∃): Indicates that there is at
least one element in the domain for which the predicate
holds.
 For example, ∃x (Person(x) ∧ Likes(x, IceCream)) means

"There exists a person who likes ice cream."


 Logical Connectives: Logical connectives include 86
conjunction (∧), disjunction (∨), implication (→), biconditional
(↔), and negation (¬).
BASIC ELEMENTS OF FIRST-ORDER
LOGIC
Name
Symbol

Constant 1, 6, A,W,New York, Elie, Dog...

Variables a, b, c, x, y, z...

Predicates <, >, brother, sister, father...

Equality ==

Function Sqrt, LessThan, Sin(θ)...

Quantifier ∀, ∃
87
Connectives ∧, ∨, ¬, ⇒, ⇔
ATOMIC AND COMPLEX SENTENCES IN
FOL

 Atomic sentences:
- Atomic sentences are the most basic sentences of first-order
logic.
- These sentences are formed from a predicate symbol
followed by a parenthesis with a sequence of terms.
- We can represent atomic sentences as Predicate (term1,
term2, ......, term n).
 Example:

- Ravi and Ajay are brothers: => Brothers(Ravi, Ajay).


Chinky is a cat: => cat (Chinky).

88
 Complex Sentences:
- Complex sentences are made by combining atomic
sentences using connectives.
- First-order logic statements can be divided into two parts:
- Subject: Subject is the main part of the statement.
- Predicate: A predicate can be defined as a relation, which
binds two atoms together in a statement.
 Example:

- Consider the statement: "x is an integer.―


- it consists of two parts, the first part x is the subject of the
statement and second part "is an integer," is known as a
predicate.
89
 Quantifiers in First-order logic:
- A quantifier is a language element which generates
quantification.
- There are two types of quantifier:
 Universal Quantifier, (for all, everyone,
everything)
 Existential quantifier, (for some, at least one).
 Universal Quantifier:

- Universal quantifier is a symbol of logical representation,


which specifies that the statement within its range is true for
everything or every instance of a particular thing.
- The Universal quantifier is represented by a symbol ∀,
which resembles an inverted A. 90
 If x is a variable, then ∀x is read as:
- For all x
- For each x
- For every x.
 Example:

- All man drink coffee.


∀x : man(x) → drink (x, coffee).
- It will be read as: There are all x where x is a man who
drink coffee.

91
 Existential Quantifier:
- Existential quantifiers are the type of quantifiers, which
express that the statement within its scope is true for at least
one instance of something.
- It is denoted by the logical operator ∃, which resembles as
inverted E. When it is used with a predicate variable then it
is called as an existential quantifier.
- If x is a variable, then existential quantifier will be ∃x or
∃(x). And it will be read as:
- There exists a 'x.'
- For some 'x.'
- For at least one 'x.'
 Example: 92

- Some boys are intelligent.


∃x: boys(x) ∧ intelligent(x)
 All birds fly.
 Some boys play cricket.
 Every man respects his parent.
 Not all students like both Mathematics and Science.

93
 ∀x : bird(x) →fly(x).
 ∃x : boys(x) ∧ play(x, cricket).
 ∀x : man(x) → respects (x, parent).
 ¬∀ (x) : [student(x) → like(x, Mathematics) ∧ like(x,
Science)]

94
UNIFICATION
 Unification in AI is a process used in logic and reasoning to
make different logical expressions identical by finding a
common substitution for variables.
 It is widely used in automated reasoning, natural language
processing, and logic.
 Unification depends on the substitution process.

 It takes two literals as input and makes them identical using


substitution.
 you have two statements:

Parent(x, John)
Parent(Mary, y)
 Here, x and y are variables. Unification finds a substitution
that makes both statements identical.
 To unify them: 95

- If x = Mary and y = John, both statements become


Parent(Mary, John).
ALGORITHM
 Check if the predicates are the same → If not,
unification fails.
 Compare arguments one by one:
 If both are the same constant → No substitution needed.
 If one is a variable → Replace it with the other term.
 If both are functions → Recursively unify their
arguments.
 If a variable occurs inside its own function (occurs check)
→ Fail (to avoid infinite loops).
 Repeat until all terms are matched or unification
fails.

96
 Eg: Unify: p(x, F(y)) and p(a, F(g(z)))
 Step 1

- Check predicate p → ✅ (same)


 Step 2

- Compare first arguments: x and a → Substituting x = a


 Step 3

- Compare second arguments: F(y) and F(g(z)) → ✅ (same function


F)
 Step 4

- Compare inside F: y and g(z) → Substituting y = g(z)


 Step 5

- Substitutions: x = a, y = g(z) → ✅ Successfully unified! 97


 Eg: p(x, F(y)) p(a, F(g(z))
 To unify the two predicates:

p(x, F(y))
p(a, F(g(z)))
 Step 1: Match Predicate Names

Both predicates are p, so we proceed.


 Step 2: Match First Arguments

x in the first expression


a in the second expression
To unify, we substitute x = a.
 Step 3: Match Second Arguments

F(y) in the first expression 98

F(g(z)) in the second expression


The function F is the same, so we match their arguments:
 y = g(z)
 Final Substitutions

 x = a

 y = g(z)

Therefore
 p(a, F(g(z)) p(a, F(g(z))

 Unified Successfully

99
CONDITIONS FOR UNIFICATION
 Compare predicates and ensure they match.
 Check arguments:

- Constants must be identical.


- Variables can be replaced with terms.
 If a valid substitution exists, the expressions are unified.

Eg: Prime (11), Prime (y)


Sub. y with 11 [(11|y)]

Prime (11), Prime (11)

- Successfully unified
100
 Eg: Q(a, g(x,a),f(y)) Q(a, g(f(b), a), x)
- sub. x with f(b) [f(b) |x]
- Q(a, g(f(b), a), f(y)) Q(a, g(f(b), a), f(b))
- sub y with b [b|y]
- Q(a, g(f(b), a), f(b)) Q(a, g(f(b), a), f(b))
- unified successfully

101
 Eg:
P(x,b) and P(a,b)
Q(F(x),y) and Q(F(a),b)
R(x,y,F(y)) and R(a,b,F(b))
S(a,x) and S(b,y)
T(x) and T(F(x))

102

You might also like