0% found this document useful (0 votes)
18 views121 pages

Ai Unit 4

Knowledge representation is a key aspect of artificial intelligence that enables machines to understand and utilize information about the real world, allowing them to behave intelligently. It encompasses various types of knowledge, including declarative, procedural, meta, heuristic, and structural knowledge, which contribute to the reasoning capabilities of AI agents. Logical agents rely on knowledge bases to infer actions based on their perceptions and prior knowledge, utilizing inference rules and logical semantics to derive conclusions.

Uploaded by

aaryashanbhag6
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)
18 views121 pages

Ai Unit 4

Knowledge representation is a key aspect of artificial intelligence that enables machines to understand and utilize information about the real world, allowing them to behave intelligently. It encompasses various types of knowledge, including declarative, procedural, meta, heuristic, and structural knowledge, which contribute to the reasoning capabilities of AI agents. Logical agents rely on knowledge bases to infer actions based on their perceptions and prior knowledge, utilizing inference rules and logical semantics to derive conclusions.

Uploaded by

aaryashanbhag6
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/ 121

Knowledge Representation

What is knowledge representation?


● Humans are best at understanding, reasoning, and interpreting knowledge.
● Human knows things, which is knowledge and as per their knowledge they
perform various actions in the real world.
● But how machines do all these things comes under knowledge representation
and reasoning.
● Knowledge representation and reasoning (KR, KRR) is the part of Artificial
intelligence which concerned with AI agents thinking and how thinking
contributes to intelligent behavior of agents.
Knowledge representation

● It is responsible for representing information about the real


world so that a computer can understand and can utilize this
knowledge
● It is also a way which describes how we can represent
knowledge in artificial intelligence.
● Knowledge representation is not just storing data into some
database,but it also enables an intelligent machine to learn
from that knowledge and experiences so that it can behave
intelligently like a human.
Types of Knowledge
1. Declarative Knowledge:

● Declarative knowledge is to know about something.


● It includes concepts, facts, and objects.
● It is also called descriptive knowledge and expressed in declarative sentences.
● It is simpler than procedural language.
2. Procedural Knowledge

● It is also known as imperative knowledge.


● Procedural knowledge is a type of knowledge which is responsible for knowing how to
do something.
● It can be directly applied to any task.
● It includes rules, strategies, procedures, agendas, etc.
● Procedural knowledge depends on the task on which it can be applied.
Types of Knowledge

3. Meta-knowledge:
● Knowledge about the other types of knowledge is called Meta-knowledge.
● Some examples of meta knowledge include planning, learning.

4. Heuristic knowledge:

● Heuristic knowledge is representing knowledge of some experts in a field or


subject.
● Heuristic knowledge is rules of thumb based on previous experiences, awareness
of approaches.
Types of Knowledge

5. Structural knowledge:

● Structural knowledge is basic knowledge to problem-solving.


● It describes relationships between various concepts such as kind of, part of, and
grouping of something.
● It describes the relationship that exists between concepts or objects.
Relation between knowledge and intelligence:

Knowledge plays an important


role in demonstrating intelligent
behavior in AI agents.
An agent is only able to
accurately act on some input
when he has some knowledge
or experience about that input.
Logical Agents

• Knowledge-based agents – agents that have an explicit


representation of knowledge that can be reasoned with.

• These agents can manipulate this knowledge to infer new things


at the “knowledge level”
Knowledge Based Agents
• Both TELL and ASK operations may involve inference.
• Inference for deriving new sentences from old.
• Job of inference: Inference must obey the requirement that
when one ASKs a question of the knowledge base, the
answer should follow from what has been told (or TELLed)
to the knowledge base previously.
• Inference process should not make things up as it goes along.
Knowledge Based Agents
• Like all agents, it takes a percept as input and returns an action.
• The agent maintains a knowledge base, KB, which may initially contain
some background knowledge
• Each time the agent program is called, it does three things.
1. First, it TELLs the knowledge base what it perceives / input.
2. Second, it ASKs the knowledge base what action it should perform.
In the process of answering this query, extensive reasoning may be done
about the current state of the world, about the outcomes of possible
action sequences, and so on.
3. Third, the agent program TELLs the knowledge base which action
was chosen, and the agent executes the action.
Generic Knowledge-Based Agent
function KB-AGENT(percept ) returns an action
persistent: KB, a knowledge base
t , a counter, initially 0, indicating time (t is an time counter with initial value 0)
TELL(KB,MAKE-PERCEPT-SENTENCE(percept , t ))
action ←ASK(KB,MAKE-ACTION-QUERY(t ))
TELL(KB,MAKE-ACTION-SENTENCE(action, t ))
t ←t + 1
return action
• Given a percept, the agent adds the percept to its knowledge base, asks the knowledge
base for the best action, and tells the knowledge base that it has in fact taken that action.
Generic Knowledge-Based Agent
• The details of the representation language are hidden inside three functions.

• MAKE-PERCEPT-SENTENCE constructs a sentence asserting that the agent


perceived the given percept (Information) at the given time.

• MAKE-ACTION-QUERY constructs a sentence that asks what action should


be done at the current time.

• MAKE-ACTION-SENTENCE constructs a sentence asserting that the


chosen action was executed.

• The details of the inference mechanisms are hidden inside TELL and ASK.
A simple knowledge-based agent

• The agent must be able to:


• Represent states, actions, etc.

• Incorporate new percepts

• Update internal representations of the world

• Deduce hidden properties of the world

• Deduce appropriate actions


A Wumpus World
Wumpus World PEAS description
● Performance measure
○ gold +1000, death -1000
○ -1 per step, -10 for using the arrow
● Environment: 4 x 4 grid of rooms
○ Squares adjacent to wumpus are smelly
○ Squares adjacent to pit are breezy
○ Glitter iff gold is in the same square
○ Shooting kills wumpus if you are facing it
○ Shooting uses up the only arrow
○ Grabbing picks up gold if in same square
○ Releasing drops the gold in same square
● Sensors: Stench, Breeze, Glitter, Bump, Scream (shot Wumpus)
● Actuators: Left turn, Right turn, Forward, Grab, Release, Shoot
Wumpus world characterization
• Fully Observable No – only local perception
• Deterministic Yes – outcomes exactly specified
• Episodic No – sequential at the level of actions
• Static Yes – Wumpus and Pits do not move
• Discrete Yes
• Single-agent? Multi – (wumpus, eventually other agents)
Wumpus World
● Percepts given to the agent
1. Stench
2. Breeze
3. Glitter
4. Bumb (ran into a wall)
5. Scream (wumpus has been hit by arrow)

● Principle Difficulty: agent is initially ignorant of the


configuration of the environment – going to have to reason
to figure out where the gold is without getting killed!
Exploring the Wumpus World

Initial situation:

Agent in 1,1 and percept is


[None, None, None, None,
None]

From this the agent can infer


the neighboring squares are
safe (otherwise there would
be a breeze or a stench)
Sample Run
Sample Run
Sample Run
Sample Run
Sample Run
Sample Run
Sample Run
Sample Run
Sample Run
Now we look at

• How to represent facts / beliefs


✔ “There is a pit in (2,2) or (3,1)”
• How to make inferences
✔ “No breeze in (1,2), so pit in
(3,1)”
Logic + Reasoning + Inference
• The knowledge bases consist of sentences.
• These sentences are expressed according to the syntax of the
representation language
• Example, “x + y = 4” is a well-formed sentence, whereas “x4y+ =”
is not.
• A logic must also define the semantics or meaning of sentences.
• The semantics defines the truth of each sentence with respect to
each possible world.
• For example, the semantics for arithmetic specifies that the sentence
“x + y =4” is true in a world where x is 2 and y is 2, but false in a
world where x is 1 and y is 1.
• In standard logics, every sentence must be either true or false only.
Logic + Reasoning + Inference
• Sentence: Individual piece of knowledge • Semantics: Mapping from sentences to facts
- English sentence forms one piece of in the world
knowledge in English language - They define the truth of a sentence in a
- Statement in C++ forms one piece of “possible world”
knowledge in C++ programming language - Add the values of 2 and 3, store them in the
memory location indicated by variable a
• Syntax: Form used to represent sentences • In the language of arithmetic:
- Syntax of C indicates legal combinations x + 2 >= y is a sentence
of symbols x2 + y > is not a sentence
- a = 2 + 3; is legal x + 2 >= y is true in all worlds where
- a = + 2 3 is not legal the number x + 2 is no less than the number y
- Syntax alone does not indicate meaning x + 2 >= y is true in a world where
x = 7, y = 1
x + 2 >= y is false in a world where
x = 0, y = 6
Knowledge Representation Languages and Inference
• A KR language is specified by
• Syntax: The atomic symbols used in the language and
how they can be composed to formal legal sentences.
• Semantics: What fact about the world is represented by
a sentence in the language, which determines whether it is true or
false.
Knowledge Representation Languages and Inference
• Logical inference (deduction) derives new sentences in the language
from existing ones.
Socrates is a man.
All men are mortal.
--------------------------
Socrates is mortal.

Proper inference should only derive sound conclusions. (ones that are true assuming
the premises are true)
Propositional Logic Syntax
• Logical constants: True, False
• Propositional symbols: P, Q, etc. representing specific facts about the world.
• Constants and symbols are atomic, other sentences are complex.
• If S is a sentence, then (S) is a sentence
• If S and R are sentences then so are:
S ∧ R: conjunction, S and R are conjuncts
S ∨ R: disjunction, S and R are disjuncts
S ⇒ R: implication, S is a premise or antecedent,
R is the conclusion or consequent, also known as
a rule or if-then statement
• S ⇔ R: equivalence ( biconditional implication )
• ¬S: negation
• A literal is an atomic sentence or its negation (P, ¬S)
• Precedence of operators: ¬, ∧, ∨, ⇒, ⇔
Propositional Logic Semantics

• True and False indicate truth and falsity in


the world.
• A proposition denotes whatever fixed
statement about the world you want which
could be true or false.
• The semantics of complex sentences are
derived from the semantics of their parts
according to the following truth table.
Validity and Inference
• An interpretation is an assignment of True or False
to each atomic proposition.
• A sentence that is true under any interpretation is
valid (also called a tautology or analytic sentence).
• Validity can be checked by exhaustively exploring
each possible interpretation in a truth table:
Logical equivalence
• Two sentences are logically equivalent iff true in same models: α ≡ ß iff
α╞ β and β╞ α
Models and Entailment

• Entailment: the relation between a


sentence and another sentence that
follows from it and see how this leads
to a simple.
• Any interpretation in which a sentence
is true is called a model of the
sentence. (Venn Diagram)
Models and Entailment

• A sentence A entails a sentence B, (A |= B) if every model


of A is also a model of B. In this case, if A is true then B
must be true.
• Correct logical inference is characterized by entailment, we
want to be able to infer whether a statement S follows from a
knowledge base:

KB |= S
or
(KB -> S) is valid
Validity and Inference
• Inference can be performed by validity checking.
• If one has a set of sentences: {S1,... Sn} defining
one’s background knowledge, and one want to
know whether a conclusion C logically follows,
construct the sentence:
S1 ∧ S2 ∧... ∧ Sn ⇒ C
and check whether it is valid.
How many rows do we need to check?
Satisfiability and Complexity of Inference

● A sentence is satisfiable if it is true under some


interpretation.
● Means it has a model, otherwise the sentence is
unsatisfiable.
● A sentence is valid if and only if its negation is
unsatisfiable.
● Algorithms for either validity or satisfiability checking
are useful for logical inference.
● If there are n propositional symbols in a sentence, then
simple validity checking must enumerate 2n rows
Satisfiability and Complexity of Inference
• However, propositional satisfiability is the first problem to
be proven NP-complete, and therefore there is assumed to
be no polynomial-time algorithm.
• Therefore, sound and complete logical inference in
propositional logic is intractable in general.
• But many problems can be solved very quickly.
Validity and satisfiability
• A sentence is valid if it is true in all models,
e.g., True, A ∨¬A, A ⇒ A, (A ∧ (A ⇒ B)) ⇒ B
• Validity is connected to inference via the Deduction Theorem:
KB ╞ α if and only if (KB ⇒ α) is valid
• A sentence is satisfiable if it is true in some model
e.g., A∨ B, C
• A sentence is unsatisfiable if it is true in no models
e.g., A∧¬A
Rules of Inference

• As an alternative to checking all rows of a truth table, one can


use rules of inference to draw conclusions.
• A sequence of inference rule applications that leads to a desired
conclusion is called a logical proof.
• Entailment: A |- B denotes that B can be derived by some
inference procedure from the set of sentences A.
• Inference rules can be verified by the truth-table method and
then used to construct sound proofs.
• Finding a proof is simply a search problem with the inference
rules as operators and the conclusion as the goal.
• Logical inference can be more efficient than truth table
construction.
Sample Rules of Inference

Entailments Examples:
• Modus Ponens: {α ⇒ β, α} |− β
{α ⇒ β, α}
----------------
β
• And Elimination: {α ∧ β} |- α ; {α ∧ β} |− β
• And Introduction: {α, Β} |− α ∧ β
• Or introduction: {α} |− α ∨ β
• Double negation Elimination: {¬ ¬α} |− α
• Implication Elimination: {α ⇒ β} |− ¬α ∨ β
• Unit resolution: {α ∨ β, ¬β} |− α
Sample Proof

• If John is not married, he is a bachelor. (¬P ⇒ Q)


• John is not a bachelor. (¬Q)
• Therefore, he is married. (P)
¬P ⇒ Q
----------
¬¬P ∨ Q ; Implication élimination ({α ⇒ β} |− ¬α ∨ β)
-----------
P ∨ Q, ¬Q ; Double negation elimination ({¬ ¬α} |− α)
-------------------------
P : Unit resolution({α ∨ β, ¬β} |− α)
Logical equivalence
• Two sentences are logically equivalent iff true in same models: α ≡ ß iff
α╞ β and β╞ α
Rules of Inference
• As an alternative to checking all rows of a truth table, one can
use rules of inference to draw conclusions.
• A sequence of inference rule applications that leads to a desired
conclusion is called a logical proof.
• Entailment: A |- B denotes that B can be derived by some
inference procedure from the set of sentences A.
• Inference rules can be verified by the truth-table method and
then used to construct sound proofs.
• Finding a proof is simply a search problem with the inference
rules as operators and the conclusion as the goal.
• Logical inference can be more efficient than truth table
construction.
Sample Rules of Inference
Entailments Examples:
• Modus Ponens: {α ⇒ β, α} |− β
{α ⇒ β, α}
----------------
β
• And Elimination: {α ∧ β} |- α ; {α ∧ β} |− β
• And Introduction: {α, Β} |− α ∧ β
• Or introduction: {α} |− α ∨ β
• Double negation Elimination: {¬ ¬α} |− α
• Implication Elimination: {α ⇒ β} |− ¬α ∨ β
• Unit resolution: {α ∨ β, ¬β} |− α
• Resolution: {α ∨ β, ¬β ∨ γ} |− α ∨ γ. : Important
Sample Proof
• If John is not married, he is a bachelor. (¬P ⇒ Q)
• John is not a bachelor. (¬Q)
• Therefore, he is married. (P)
¬P ⇒ Q
----------
¬¬P ∨ Q ; Implication élimination ({α ⇒ β} |− ¬α ∨ β)
-----------
P ∨ Q, ¬Q ; Double negation elimination ({¬ ¬α} |− α)
-------------------------
P : Unit resolution({α ∨ β, ¬β} |− α)
Proof methods
• Proof methods divide into (roughly) two kinds:

• Application of inference rules


• Legitimate (sound) generation of new sentences from old
• Proof = a sequence of inference rule applications
Can use inference rules as operators in a standard
search algorithm
• Typically require transformation of sentences into a
normal form
Proof methods
• Proof methods divide into (roughly) two kinds:
• Model checking
• truth table enumeration (always exponential in n)
• improved backtracking, e.g., Davis--Putnam-Logemann-
Loveland (DPLL)
• heuristic search in model space (sound but incomplete)
e.g., min-conflicts-like hill-climbing algorithms
Application of inference rules
Conversion to CNF
1. Eliminate ⇔, replacing α ⇔ β with (α ⇒ β)∧(β ⇒ α).

2. Eliminate ⇒, replacing α ⇒ β with ¬α∨ β.

3. Move ¬ inwards using de Morgan's rules and double-negation:


¬(avb)
¬a∧¬b
4. Apply distributivity law (∧ over ∨) and flatten
Resolution example
The Resolution rule state that if P∨Q and ¬ PvR is true, then Q∨R will also be true.
Reasoning with Horn Clauses

• Forward Chaining
• For each new piece of data, generate all new facts, until the
desired fact is generated
• Data-directed reasoning
• Backward Chaining
• To prove the goal, find a clause that contains the goal as its head,
and prove the body recursively
• Goal-directed reasoning
Forward Chaining
● It is a strategy of an expert system to answer the question,
“What can happen next?”
● Data Driven
Here, the Inference Engine follows the chain of conditions and derivations
and finally deduces the outcome.
It considers all the facts and rules, and sorts them before concluding to a solution.
● This strategy is followed for working on conclusion,result,or effect.
● For example, prediction of share market status as an effect of changes in
interest rates.
Forward Chaining
Forward Chaining
Forward Chaining
Forward Chaining
A practical example will go as follows;
Tom is running (A)
If a person is running, he will sweat (A->B)
Therefore, Tom is sweating. (B)
Backward Chaining
● With this strategy, an expert system finds out the answer to the question,
“Why this happened?”
● Goal Driven
● On the basis of what has already happened, the Inference Engine tries
to find out which conditions could have happened in the past for this
result.
● This strategy is followed for finding out cause or reason. For example,
diagnosis of blood cancer in humans.
Backward Chaining
Backward Chaining
Backward Chaining
A suitable sequence can be as follows:
● The patient has a bacterial infection.
● The patient is vomiting.
● He/she is also experiencing diarrhea and severe stomach upset.
● Therefore, the patient has typhoid (salmonella bacterial infection).

The MYCIN expert system uses the information collected from the patient to
recommend suitable treatment.

The recommended treatment corresponds to the identified bacterial infection. In


the case above, the system may recommend the use of ciprofloxacin.
Model Checking in Propositional Logic
Model Checking in Propositional Logic
Propositional Logic
Agents based on Propositional Logic
• To enable the agent to deduce, to the extent possible, the state
of the world given its percept history. This requires writing down
a complete logical model of the effects of actions.
• How the agent can keep track of the world efficiently without
going back into the percept history for each inference.
• How the agent can use logical inference to construct plans that
are guaranteed to achieve its goals
The current state of the world
Atomic proposition variable for Wumpus world:

• Let Pi,j be true if there is a Pit in the room [i, j].


• Let Bi,j be true if agent perceives breeze in [i, j], (dead or
alive).
• Let Wi,j be true if there is wumpus in the square[i, j].
• Let Si,j be true if agent perceives stench in the square [i, j].
• Let Vi,j be true if that square[i, j] is visited.
• Let Gi,j be true if there is gold (and glitter) in the square [i, j].
• Let OKi,j be true if the room is safe.
The current state of the world
Some Propositional Rules for the wumpus world:
Making plans by propositional inference
Prove that Wumpus is in the room (1, 3)
We can prove that wumpus is in the room (1, 3) using propositional rules which we have derived for the wumpus
world and using inference rule.

Apply Modus Ponens with ¬S11 and R1:


Apply And-Elimination Rule:

After applying And-elimination rule to ¬ W11


∧ ¬ W12 ∧ ¬ W21, we will get three
statements:
¬ W11, ¬ W12, and ¬W21.
Prove that Wumpus is in the room (1, 3)

● Apply MP to S12 and R4:

• Apply Modus Ponens to ¬S21, and R2:

● Apply Unit resolution on W13 ∨ W12 ∨ W22

● Apply And -Elimination rule: ∨W11 and ¬ W11 :

Now again apply And-elimination rule to ¬ W21 ∧ ¬ W22 ∧¬


W31, We will get three statements:
¬ W21, ¬ W22, and ¬ W31.
Prove that Wumpus is in the room (1, 3)

• Apply Unit resolution on W13 ∨ W12 ∨ W22 and ¬ W22 :

● Apply Unit Resolution on W13 ∨


W12 and ¬ W12 :
First order Logic
In propositional logic, we can only represent the facts, which are either true or false.
PL is not sufficient to represent the complex sentences or natural language
statements. The propositional logic has very limited expressive power. Consider the
following sentence, which we cannot represent using PL logic.

"Some humans are intelligent", or

"Sachin likes cricket."

To represent the above statements, PL logic is not sufficient, so we required some


more powerful logic, such as first-order logic.
Example

• Express “Socrates is a man” in


• Propositional logic
– MANSOCRATES - single proposition representing entire idea
• First-Order Predicate Calculus
– Man(SOCRATES) - predicate representing property of constant SOCRATES
First Order Logic
• First-order logic is another way of knowledge representation in artificial intelligence. It is an
extension to propositional logic.
• FOL is sufficiently expressive to represent the natural language statements in a concise way.
• First-order logic is also known as Predicate logic or First-order predicate logic. First-order
logic is a powerful language that develops information about the objects in a more easy way
and can also express the relationship between those objects.
• First-order logic (like natural language) does not only assume that the world contains facts like
propositional logic but also assumes the following things in the world:
• Objects: A, B, people, numbers, colors, wars, theories, squares, pits, wumpus, ......
• Relations: It can be unary relation such as: red, round, is adjacent, or n-any relation
such as: the sister of, brother of, has color, comes between
• Function: Father of, best friend, third inning of, end of, ......
Syntax for First-Order Logic
Sentence → AtomicSentence
| Sentence Connective Sentence
| Quantifier Variable Sentence
| ¬Sentence
| (Sentence)
AtomicSentence → Predicate(Term, Term, ...)
| Term=Term
Term → Function(Term,Term,...)
| Constant
| Variable
Connective → ∨ | ∧ | ⇒ | ⇔
Quantifiers → ∃ | ∀
Constant → A | John | Car1
Variable → x | y | z |...
Predicate → Brother | Owns | ...
Function → father-of | plus | ...
First-Order Logic
• Term
Anything that identifies an object
Function(args)
Constant - function with 0 args
• Atomic sentence
Predicate with term arguments
Enemies(WilyCoyote, RoadRunner)
Married(FatherOf(Alex), MotherOf(Alex))
• Literals
atomic sentences and negated atomic sentences
• Connectives
(&), (v), (->), (<=>), (~)
Quantifiers
Universal Quantifier
Existential Quantifier
First-Order Logic

● Constant symbols (which refer to the "individuals" in the world) E.g.,


Mary, 3
● Function symbols (mapping individuals to individuals) E.g., father-
of(Mary) = John, color-of(Sky) = Blue
● Predicate symbols (mapping from individuals to truth values) E.g.,
greater(5,3), green(Grass), color(Grass, Green)
● Everyone likes someone: (Ax)(Ey)likes(x,y)
● Someone is liked by everyone: (Ey)(Ax)likes(x,y)
Quantifiers in First-order logic:

• A quantifier is a language element which generates quantification, and


quantification specifies the quantity of specimen in the universe of discourse.
• These are the symbols that permit to determine or identify the range and scope of
the variable in the logical expression. There are two types of quantifier:
a. Universal Quantifier, (for all, everyone, everything)
b. Existential quantifier, (for some, at least one).

Properties of Quantifiers:

• In universal quantifier, ∀x∀y is similar to ∀y∀x.


• In Existential quantifier, ∃x∃y is similar to ∃y∃x.
• ∃x∀y is not similar to ∀y∃x.
First Order Logic
1. All birds fly.
∀x bird(x) →fly(x).
1. Every man respects his parent.
∀x man(x) → respects (x, parent).
1. Some boys play cricket.
∃x boys(x) → play(x, cricket).
1. Not all students like both Mathematics and Science.
¬∀ (x) [ student(x) → like(x, Mathematics) ∧ like(x, Science)].
1. ∀x) student(x) → smart(x) “All students are smart”
2. (∃x) student(x) ∧ smart(x) “There is a student who is smart”
3. Everyone likes someone: (∀x)(∃y) likes(x,y)
4. Every gardener likes the sun. ∀x gardener(x) → likes(x,Sun)
5. You can fool some of the people all of the time.∃x ∀t person(x) ∧time(t) → can-fool(x,t)
6. All purple mushrooms are poisonous. ∀x (mushroom(x) ∧ purple(x)) → poisonous(x)
Use of Quantifiers
● Universal quantification naturally uses implication:
∀x Whale(x) ∧ Mammal(x)
Says that everything in the universe is both a whale and a
mammal.
● Existential quantification naturally uses conjunction:
∃x Owns(Mary,x) ⇒ Cat(x)
Says either there is something in the universe that Mary
does not own or there exists a cat in the universe.
● ∀x Owns(Mary,x) ⇒ Cat(x)
Says all Mary owns is cats (i.e. everything Mary owns is a
cat). Also true if Mary owns nothing.
● ∀x Cat(x) ⇒ Owns(Mary,x)
Says that Mary owns all the cats in the universe.
Also true if there are no cats in the universe.
Nesting Quantifiers
• The order of quantifiers of the same type doesn’t matter
∀x∀y(Parent(x,y) ∧ Male(y) ⇒ Son(y,x))
∃x∃y(Loves(x,y) ∧ Loves(y,x))
• The order of mixed quantifiers does matter:
1. ∀x∃y(Loves(x,y)) : Says everybody loves somebody, i.e. everyone has
someone whom they love.
2. ∃y∀x(Loves(x,y)): Says there is someone who is loved by everyone in the
universe.
3. ∀y∃x(Loves(x,y)): Says everyone has someone who loves them.
4. ∃x∀y(Loves(x,y)): Says there is someone who loves everyone in the
universe.
Variable Scope
● The scope of a variable is the sentence to which the quantifier
syntactically applies.
● As in a block structured programming language, a variable in a logical
expression refers to the closest quantifier within whose scope it appears.
∃x (Cat(x) ∧ ∀x(Black (x)))
The x in Black(x) is universally quantified Says cats exist and everything is
black
● In a well-formed formula (wff) all variables should be properly
introduced:
● ∃xP(y) not well-formed
● A ground expression contains no variables.
Relation Between Quantifiers

• Universal and existential quantification are logically related


• to each other:
• ∀x ¬Love(x,Saddam) ⇔ ¬∃x Loves(x,Saddam)
• ∀x Love(x,Princess-Di) ⇔ ¬∃x ¬Loves(x,Princess-Di)
• General Identities
• ∀x ¬P ⇔ ¬∃x P
• ¬∀x P ⇔ ∃x ¬P
• ∀x P ⇔ ¬∃x ¬P
• ∃x P ⇔ ¬∀x ¬P
• ∀x P(x)∧Q(x) ⇔ ∀xP(x) ∧ ∀xQ(x)
• ∃x P(x)∨Q(x) ⇔ ∃xP(x) ∨ ∃xQ(x)
Equality
• Can include equality as a primitive predicate in the logic, or require it to be introduced and
axiomatized as the identity relation.
• Useful in representing certain types of knowledge:

1) ∃x∃y(Owns(Mary, x) ∧ Cat(x) ∧ Owns(Mary,y) ∧ Cat(y) ∧ ¬(x=y))


• Mary owns two cats. Inequality needed to insure x and y
are distinct.

2) ∀x ∃y married(x, y) ∧ ∀z(married(x,z) ⇒ y=z)

Everyone is married to exactly one person. Second conjunct is needed to guarantee there is only one unique
spouse.
Higher-Order Logic

• FOPC is called first-order because it allows quantifiers to range over objects


(terms) but not properties, relations, or functions applied to those objects.
• Second-order logic allows quantifiers to range over predicates and functions as
well:
∀ x ∀ y [ (x=y) ⇔ (∀ p p(x) ⇔ p(y)) ]: Says that two objects are equal if and only if
they have exactly the same properties.

∀ f ∀ g [ (f=g) ⇔ (∀ x f(x) = g(x)) ]: Says that two functions are equal if and only if
they have the same value for all possible arguments.

Third-order would allow quantifying over predicates of predicates, etc.


For example, a second-order predicate would be Symmetric(p) stating that a binary
predicate p represents a symmetric relation.
Propositional vs. Predicate Logic
• In propositional logic, each possible atomic fact requires a separate
unique propositional symbol.
• If there are n people and m locations: representing the fact that
some person moved from one location to another requires nm2
separate symbols.
• Predicate logic includes a richer ontology.
• Ontology: A rigorous and exhaustive organization of some
knowledge domain that is usually hierarchical and contains all the
relevant entities and their relations.
Predicate logic / Ontology

• Predicate logic requires.


• Objects (terms)
• Properties (unary predicates on terms)
• Relations (n-ary predicates on terms)
• Functions (mappings from terms to other terms)
• Allows more flexible and compact representation of
knowledge.
• Move(x, y, z) for person x moved from location y to z.
First-Order Logic: Terms and Predicates
• Objects are represented by terms:
• Constants: Block1, John
• Function symbols: father-of, successor, plus
• An n-ary function maps a tuple of n terms to another
• term: father-of(John), succesor(0), plus(plus(1,1),2)
• Terms are simply names for objects.
• Logical functions are not procedural as in programming
languages.
• They do not need to be defined, and do not really return a value.
• Allows for the representation of an infinite number of terms.
First-Order Logic: Terms and Predicates

• Propositions are represented by a predicate applied to


a tuple of terms.
• A predicate represents a property of or relation between
terms that can be true or false:
• Brother(John, Fred), Left-of(Square1, Square2)
• GreaterThan (plus(1,1), plus(0,1))
First order Logic
In propositional logic, we can only represent the facts, which are either true or false.

PL is not sufficient to represent the complex sentences or natural language


statements.

The propositional logic has very limited expressive power. Consider the following
sentence, which we cannot represent using PL logic.

"Some humans are intelligent", or

"Sachin likes cricket."

To represent the above statements, PL logic is not sufficient, so we required some


more powerful logic, such as first-order logic.
Example

• Express “Socrates is a man” in


• Propositional logic
– MANSOCRATES - single proposition representing entire idea
• First-Order Predicate Calculus
– Man(SOCRATES) - predicate representing property of constant SOCRATES
First Order Logic
• First-order logic is another way of knowledge representation in artificial intelligence. It is an
extension to propositional logic.
• FOL is sufficiently expressive to represent the natural language statements in a concise way.
• First-order logic is also known as Predicate logic or First-order predicate logic. First-order
logic is a powerful language that develops information about the objects in a more easy way
and can also express the relationship between those objects.
• First-order logic (like natural language) does not only assume that the world contains facts
like propositional logic but also assumes the following things in the world:
• Objects: A, B, people, numbers, colors, wars, theories, squares, pits, wumpus
• Relations: It can be unary relation such as: red, round, is adjacent, or n-any relation
such as: the sister of, brother of, has color, comes between
• Function: Father of, best friend, third inning of, end of
Syntax for First-Order Logic
First-Order Logic
• Term
Anything that identifies an object
Function(args)
Constant - function with 0 args
• Atomic sentence
Predicate with term arguments
Enemies(WilyCoyote, RoadRunner)
Married(FatherOf(Alex), MotherOf(Alex))
• Literals
atomic sentences and negated atomic sentences

• Connectives
(&), (v), (->), (<=>), (~)

• Quantifiers
Universal Quantifier
Existential Quantifier
Quantifiers in First-order logic:

• A quantifier is a language element which generates quantification, and


quantification specifies the quantity of specimen in the universe of discourse.
• These are the symbols that permit to determine or identify the range and scope of
the variable in the logical expression. There are two types of quantifier:
a. Universal Quantifier, (for all, everyone, everything)
b. Existential quantifier, (for some, at least one).

Properties of Quantifiers:

• In universal quantifier, ∀x∀y is similar to ∀y∀x.


• In Existential quantifier, ∃x∃y is similar to ∃y∃x.
• ∃x∀y is not similar to ∀y∃x.
First Order Logic
1. All birds fly.
∀x bird(x) →fly(x).
1. Every man respects his parent.
∀x man(x) → respects (x, parent).
1. Some boys play cricket.
∃x boys(x) → play(x, cricket).
1. Not all students like both Mathematics and Science.
¬∀ (x) [ student(x) → like(x, Mathematics) ∧ like(x, Science)].
1. ∀x) student(x) → smart(x) “All students are smart”
2. (∃x) student(x) ∧ smart(x) “There is a student who is smart”
3. Everyone likes someone: (∀x)(∃y) likes(x,y)
4. Every gardener likes the sun. ∀x gardener(x) → likes(x,Sun)
5. You can fool some of the people all of the time.∃x ∀t person(x) ∧time(t) → can-fool(x,t)
6. All purple mushrooms are poisonous. ∀x (mushroom(x) ∧ purple(x)) → poisonous(x)
Use of Quantifiers
● Universal quantification naturally uses implication:
∀x Whale(x) ∧ Mammal(x)
Says that everything in the universe is both a whale and a mammal.
● Existential quantification naturally uses conjunction:
∃x Owns(Mary,x) ⇒ Cat(x)
Says either there is something in the universe that Mary does not own or there
exists a cat in the universe.
● ∀x Owns(Mary,x) ⇒ Cat(x)
Says all Mary owns is cats (i.e. everything Mary owns is a cat). Also true if
Mary owns nothing.
● ∀x Cat(x) ⇒ Owns(Mary,x)
Says that Mary owns all the cats in the universe.Also true if there are no cats in
the universe.
Nesting Quantifiers
• The order of quantifiers of the same type doesn’t matter
∀x∀y(Parent(x,y) ∧ Male(y) ⇒ Son(y,x))
∃x∃y(Loves(x,y) ∧ Loves(y,x))
• The order of mixed quantifiers does matter:
1. ∀x∃y(Loves(x,y)) : Says everybody loves somebody, i.e. everyone has
someone whom they love.
2. ∃y∀x(Loves(x,y)): Says there is someone who is loved by everyone in the
universe.
3. ∀y∃x(Loves(x,y)): Says everyone has someone who loves them.
4. ∃x∀y(Loves(x,y)): Says there is someone who loves everyone in the
universe.
Relation Between Quantifiers

• Universal and existential quantification are logically related


• to each other:
• ∀x ¬Love(x,Saddam) ⇔ ¬∃x Loves(x,Saddam)
• ∀x Love(x,Princess-Di) ⇔ ¬∃x ¬Loves(x,Princess-Di)
• General Identities
• ∀x ¬P ⇔ ¬∃x P
• ¬∀x P ⇔ ∃x ¬P
• ∀x P ⇔ ¬∃x ¬P
• ∃x P ⇔ ¬∀x ¬P
• ∀x P(x)∧Q(x) ⇔ ∀xP(x) ∧ ∀xQ(x)
• ∃x P(x)∨Q(x) ⇔ ∃xP(x) ∨ ∃xQ(x)
Inference in First order logic
In First-Order Logic, inference is used to derive new facts or sentences from existing ones.

Substitution:
Substitution is a basic procedure that is applied to terms and formulations. It can be found in all first-order logic
inference systems. When there are quantifiers in FOL, the substitution becomes more complicated. When we write
F[a/x], we are referring to the substitution of a constant "a" for the variable "x."

Equality:
In First-Order Logic, atomic sentences are formed not only via the use of predicate and words, but also through the
application of equality. We can do this by using equality symbols, which indicate that the two terms relate to the
same thing.

Example: Brother (John) = Smith.

In the above example, the object referred by the Brother (John) is close to the object referred by Smith. The equality
symbol can be used with negation to portray that two terms are not the same objects.

Example: ¬(x=y) which is equivalent to x ≠y.


Inference in First order logic
FOL inference rules for quantifier:
First-order logic has inference rules similar to propositional logic, therefore here are some
basic inference rules in FOL:

● Universal Generalization
● Universal Instantiation
● Existential Instantiation
● Existential introduction
Inference in First order logic
Inference in First order logic
Universal Generalization
● Universal generalization is a valid inference rule that states that if premise P(c) is
true for any arbitrary element c in the universe of discourse, we can arrive at the
conclusion x P. (x).
● It can be represented as

● If we want to prove that every element has a similar property, we can apply this rule.
● x must not be used as a free variable in this rule.
Let's represent, P(c): "A byte contains 8 bits", so "All bytes contain 8 bits."for ∀ x P(x) , it
will also be true.
Inference in First order logic
Universal Instantiation:

A valid inference rule is universal instantiation, often known as universal elimination or UI.
IF "Every person like ice-cream"=> ∀x P(x) so we can infer that
"John likes ice-cream" => P(c)

Let's take a example,


"All kings who are greedy are Evil." So let our knowledge base contains this detail as in the
form of FOL: ∀x king(x) ∧ greedy (x) → Evil (x),
We can infer any of the following statements using Universal Instantiation from this
information:
● King(John) ∧ Greedy (John) → Evil (John),
● King(Richard) ∧ Greedy (Richard) → Evil (Richard),
● We can infer any phrase by replacing a ground word for the variable, according to UI
● King(Father(John)) ∧ Greedy (Father(John)) → Evil (Father(John)),
Inference in First order logic
Existential Instantiation:
● Existential instantiation is also known as Existential Elimination, and it is a
legitimate first-order logic inference rule.
● It can only be used to replace the existential sentence once.
From the given sentence: ∃x Crown(x) ∧ OnHead(x, John),

So we can infer: Crown(K) ∧ OnHead( K, John), as long as K does not appear in the
knowledge base.

● The above used K is a constant symbol, which is known as Skolem constant.


● The Existential instantiation is a special case of Skolemization process.
Inference in First order logic
Existential introduction
● An existential generalization is a valid inference rule in first-order
logic that is also known as an existential introduction.
● This rule argues that if some element c in the universe of
discourse has the property P, we can infer that something in the
universe has the attribute P.
● Example: Let's say that,
"Priyanka got good marks in English."
"Therefore, someone got good marks in English."
Inference in First order logic
FOL inference rules for quantifier:
Universal generalization is a valid inference rule that states that if premise P(c) is true for any
arbitrary element c in the universe of discourse, we can arrive at the conclusion x P. (x).

It can be represented as:

● If we want to prove that every element has a similar property, we can apply this rule.
● x must not be used as a free variable in this rule.

Example: Let's represent,


P(c): "A byte contains 8 bits", so "All bytes contain 8 bits."for ∀ x P(x) , it will also be true.
Knowledge Engineering in First-order logic
The process of constructing a knowledge-base in first-order logic is called as
knowledge- engineering.
1. Identify the task:

● Does the circuit add properly?


● What will be the output of gate A2, if all the inputs are
high?
● Which gate is connected to the first input terminal?
● Does the circuit have feedback loops?
Knowledge Engineering in First-order logic
2. Assemble the relevant knowledge:

In the second step, we will assemble the relevant knowledge which is required for digital
circuits. So for digital circuits, we have the following required knowledge:

• Logic circuits are made up of wires and gates.


• Signal flows through wires to the input terminal of the gate, and each gate produces
the corresponding output which flows further.
• In this logic circuit, there are four types of gates used: AND, OR, XOR, and NOT.
• All these gates have one output terminal and two input terminals (except NOT gate, it
has one input terminal).
Knowledge Engineering in First-order logic
3. Decide on vocabulary:
• The next step of the process is to select functions, predicate, and constants to
represent the circuits, terminals, signals, and gates.
• The functionality of each gate is determined by its type, which is taken as constants
such as AND, OR, XOR, or NOT.
• Circuits will be identified by a predicate: Circuit (C1).
• For the terminal, we will use predicate: Terminal(x).
• For gate input, we will use the function In(1, X1) for denoting the first input terminal of
the gate, and for output terminal we will use Out (1, X1).
• The function Arity(c, i, j) is used to denote that circuit c has i input, j output.
• The connectivity between gates can be represented by predicate Connect(Out(1, X1),
In(1, X1)).
Knowledge Engineering in First-order logic

4. Encode general knowledge about the domain:


To encode the general knowledge about the logic circuit, we need some following
rules:

○ If two terminals are connected then they have the same input signal, it can be
represented as:

∀ t1, t2 Terminal (t1) ∧ Terminal (t2) ∧ Connect (t1, t2) → Signal (t1) = Signal
(2).

○ Signal at every terminal will have either value 0 or 1, it will be represented as:

∀ t Terminal (t) →Signal (t) = 1 ∨Signal (t) = 0.


Knowledge Engineering in First-order logic

5. Encode a description of the problem instance


The given circuit C1, we can encode the problem instance in atomic sentences as
below:

Since in the circuit there are two XOR, two AND, and one OR gate so atomic
sentences for these gates will be

1. For XOR gate: Type(x1)= XOR, Type(X2) = XOR


2. For AND gate: Type(A1) = AND, Type(A2)= AND
3. For OR gate: Type (O1) = OR.
Knowledge Engineering in First-order logic

6. Pose queries to the inference procedure and get answers


What should be the combination of input which would generate the first output of
circuit C1, as 0 and a second output to be 1?

1. ∃ i1, i2, i3 Signal (In(1, C1))=i1 ∧ Signal (In(2, C1))=i2 ∧ Signal (In(3, C1))= i3 ∧
Signal (Out(1, C1)) =0 ∧ Signal (Out(2, C1))=1

7. Debug the knowledge base:


Now we will debug the knowledge base, and this is the last step of the complete
process. In this step, we will try to debug the issues of knowledge base.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy