0% found this document useful (0 votes)
86 views51 pages

Knowledge Representation Using First-Order Logic

The document discusses knowledge representation using first-order logic. It begins by explaining the limitations of propositional logic in representing general knowledge, such as relationships between objects. It then introduces first-order predicate calculus as a more expressive logical system. Key components of first-order logic include objects, relations between objects represented by predicates, and functions. Models of first-order logic can be represented graphically or in tabular form similar to a relational database. The syntax and semantics of first-order logic are then overviewed, including terms, atomic sentences, quantifiers, and how to combine different logical components into more complex sentences.

Uploaded by

Anan Jaser
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)
86 views51 pages

Knowledge Representation Using First-Order Logic

The document discusses knowledge representation using first-order logic. It begins by explaining the limitations of propositional logic in representing general knowledge, such as relationships between objects. It then introduces first-order predicate calculus as a more expressive logical system. Key components of first-order logic include objects, relations between objects represented by predicates, and functions. Models of first-order logic can be represented graphically or in tabular form similar to a relational database. The syntax and semantics of first-order logic are then overviewed, including terms, atomic sentences, quantifiers, and how to combine different logical components into more complex sentences.

Uploaded by

Anan Jaser
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/ 51

Knowledge Representation using

First-Order Logic

Chapter 8
Outline

• What is First-Order Logic (FOL)?


• Syntax and semantics

• Using FOL

• Wumpus world in FOL

• Knowledge engineering in FOL


Limitations of propositional logic

 Propositional logic has limited expressive


power
•unlike natural language
•E.g., cannot say "pits cause breezes in
adjacent squares“
•except by writing one sentence for
each square
Wumpus World and propositional logic

• Find Pits in Wumpus world


• Bx,y  (Px,y+1  Px,y-1  Px+1,y  Px-1,y) (Breeze next to Pit) 16 rules

• Find Wumpus
• Sx,y  (Wx,y+1  Wx,y-1  Wx+1,y  Wx-1,y) (stench next to Wumpus) 16 rules

• At least one Wumpus in world


• W1,1  W1,2  …  W4,4 (at least 1 Wumpus) 1 rule

• At most one Wumpus


•  W1,1   W1,2 (155 RULES)
Limitations of Propositional Logic

• Propositional logic cannot express general-purpose knowledge


succinctly
• We need 32 sentences to describe the relationship between
wumpi and stenches
• We would need another 32 sentences for pits and breezes
• We would need at least 64 sentences to describe the effects of
actions
• How would we express the fact that there is only one wumpus?
• Difficult to identify specific individuals (Mary, among 3)
• Generalizations, patterns, regularities difficult to represent (all
triangles have 3 sides)
First-Order Predicate Calculus
• Propositional Logic uses only propositions (symbols representing
facts), only possible values are True and False
• First-Order Logic includes:
• Objects: peoples, numbers, places, ideas (atoms)
• Relations: relationships between objects (predicates, T/F value)
• Example: father(fred, mary)
• Properties: properties of atoms (predicates, T/F value)
Example: red(ball)
• Functions: father-of(mary), next(3), (any value in range)
• Constant: function with no parameters, MARY
FOPC Models
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

• Propositional logic assumes that the world contains


facts.

• First-order logic (like natural language) assumes the


world contains

• Objects: people, houses, numbers, colors, baseball games,


wars, …

• Relations: red, round, prime, brother of, bigger than, part of,
comes between, …

• Functions: father of, best friend, one more than, plus, …


Logics in General

• Ontological Commitment:
• What exists in the world — TRUTH
• PL : facts hold or do not hold.
• FOL : objects with relations between them that hold or do not hold

• Epistemological Commitment:
• What an agent believes about facts — BELIEF
Syntax of FOL: Basic elements

• Constant Symbols:
• Stand for objects
• e.g., KingJohn, 2, UCI,...

• Predicate Symbols
• Stand for relations
• E.g., Brother(Richard, John), greater_than(3,2)...

• Function Symbols
• Stand for functions
• E.g., Sqrt(3), LeftLegOf(John),...
Syntax of FOL: Basic elements

• Constants KingJohn, 2, UCI,...

• Predicates Brother, >,...

• Functions Sqrt, LeftLegOf,...

• Variables x, y, a, b,...

• Connectives , , , , 

• Equality =

• Quantifiers , 
Relations

• Some relations are properties: they state


some fact about a single object: Round(ball), Prime(7).

• n-ary relations state facts about two or more objects:


Married(John,Mary), LargerThan(3,2).

• Some relations are functions: their value is another object:


Plus(2,3), Father(Dan).
Models for FOL: Graphical Example
Tabular Representation

• A FOL model is basically equivalent to a relational database instance.


• Historically, the relational data model comes from FOL.

Student Course Professor


s-id Intelligence Ranking
c-id Rating Difficulty p-id Popularity Teaching-a
Jack 3 1
101 3 1 Oliver 3 1
Kim 2 1
Paul 1 2 102 2 2 Jim 2 1

Registration
RA
s-id c.id Grade Satisfaction
s-id p-id Salary Capability Jack 101 A 1
Jack Oliver High 3 Jack 102 B 2
Kim Oliver Low 1 Kim 102 A 1
Paul Jim Med 2 Paul 101 B 1

21
Terms
• Term = logical expression that refers to an object.

• There are 2 kinds of terms:


• constant symbols: Table, Computer
• function symbols: LeftLeg(Pete), Sqrt(3), Plus(2,3) etc
• Functions can be nested:
• Pat_Grandfather(x) = father(father(x))
• Terms can contain variables.
• No variables = ground term.
Atomic Sentences

• Atomic sentences state facts using terms and predicate symbols


• P(x,y) interpreted as “x is P of y”
• 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)

• Examples:
LargerThan(2,3) is false.
Brother_of(Mary,Pete) is false.
Married(Father(Richard), Mother(John)) could be true or false

• Note: Functions do not state facts and form no sentence:


• Brother(Pete) refers to John (his brother) and is neither true nor false.

• Brother_of(Pete,Brother(Pete)) is True.

Binary relation Function


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.

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.
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:
• Universal Quantifier, (for all, everyone, everything)
• Existential quantifier, (for some, at least one).
The Universal quantifier is represented by a symbol ∀, (all)
If x is a variable, then ∀x is read as:
For all x
For each x
For every x.
Example:
All man drink coffee.
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 ∃,

It will be read as: There are some x where x is a boy who is intelligent
Complex Sentences
• We make complex sentences with connectives (just like in
propositional logic).
property

Brother (LeftLeg (Richard ), John )  (Democrat (Bush ))

binary function
relation

objects

connectives
More Examples
• Brother(Richard, John)  Brother(John, Richard)

• King(Richard)  King(John)

• King(John) =>  King(Richard)

• LessThan(Plus(1,2) ,4)  GreaterThan(1,2)

(Semantics are the same as in propositional logic)


Variables

• Person(John) is true or false because we give it a single


argument ‘John’

• We can be much more flexible if we allow variables which can


take on values in a domain. e.g., all persons x, all integers i,
etc.
• E.g., can state rules like Person(x) => HasHead(x)
or Integer(i) => Integer(plus(i,1)
Universal Quantification 
•  means “for all”

• Allows us to make statements about all objects that have certain properties

• Can now state general rules:

 x King(x) => Person(x)

 x Person(x) => HasHead(x)

 i Integer(i) => Integer(plus(i,1))

Note that
 x King(x)  Person(x) is not correct!
This would imply that all objects x are Kings and are People

 x King(x) => Person(x) is the correct way to say


Existential Quantification 
•  x means “there exists an x such that….” (at least one object x)

• Allows us to make statements about some object without naming it

• Examples:

x King(x)

x Lives_in(John, Castle(x))

i Integer(i)  GreaterThan(i,0)

Note that  is the natural connective to use with 


(And => is the natural connective to use with  )
More examples
For all real x, x>2 implies x>3.

x [(x  2)  (x  3)] x  R (false )


x [(x 2  1)] x  R (false )

There exists some real x whose square is minus 1.

UBC AI space demo for rules


Combining Quantifiers
 x  y Loves(x,y)
• For everyone (“all x”) there is someone (“y”) that they love.

y  x Loves(x,y)
- there is someone (“y”) who is loved by everyone

Clearer with parentheses: y(x Loves(x,y) )


Duality: Connections between Quantifiers

• Asserting that all x have property P is the same as


asserting that
there does not exist any x that does’t have the property P

 x Likes(x, 430class)   x  Likes(x, 430class)

In effect:
-  is a conjunction over the universe of objects
-  is a disjunction over the universe of objects
Thus, DeMorgan’s rules can be applied
De Morgan’s Law for Quantifiers

De Morgan’s Rule Generalized De Morgan’s Rule


P  Q  (P  Q ) x P  x (P )
P  Q  (P  Q ) x P  x (P )
(P  Q )  P  Q x P  x (P )
(P  Q )  P  Q x P  x (P )

Rule is simple: if you bring a negation inside a disjunction or a conjunction,


always switch between them (or and, and  or).
Knowledge engineering in FOL
1. Identify the task

2. Assemble the relevant knowledge

3. Decide on a vocabulary of predicates, functions, and constants

4. Encode general knowledge about the domain

5. Encode a description of the specific problem instance

6. Pose queries to the inference procedure and get answers

7. Debug the knowledge base.


8. See text for full example: electric circuit knowledge base.
Knowledge Engineering in First-order logic

What is knowledge-engineering?

The process of constructing a knowledge-base in first-order logic is called as knowledge-


engineering. In knowledge-engineering, someone who investigates a particular domain, learns
important concept of that domain, and generates a formal representation of the objects, is known
as knowledge engineer.

In this topic, we will understand the Knowledge engineering process in an electronic circuit domain,
which is already familiar. This approach is mainly suitable for creating special-purpose knowledge
base.

The knowledge-engineering process:

Following are some main steps of the knowledge-engineering process. Using these steps, we will
develop a knowledge base which will allow us to reason about digital circuit (One-bit full adder)
which is given below
1. Identify the task:

The first step of the process is to identify the task, and for the digital circuit, there are various
reasoning tasks.

Skip Ad

At the first level or highest level, we will examine the functionality of the circuit:

o Does the circuit add properly?


o What will be the output of gate A2, if all the inputs are high?

At the second level, we will examine the circuit structure details such as:

o Which gate is connected to the first input terminal?


o Does the circuit have feedback loops?
o

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:

o Logic circuits are made up of wires and gates.


o Signal flows through wires to the input terminal of the gate, and each gate produces the
corresponding output which flows further.
o In this logic circuit, there are four types of gates used: AND, OR, XOR, and NOT.
o All these gates have one output terminal and two input terminals (except NOT gate, it has one
input terminal).
o

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. Firstly we will distinguish the gates from each other and from other
objects. Each gate is represented as an object which is named by a constant, such as, Gate(X1). 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)).

We use a unary predicate On (t), which is true if the signal at a terminal is on.
4. Encode general knowledge about the domain:

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

o If two terminals are connected then they have the same input signal, it can be represented as:
5. Encode a description of the problem instance:
Now we encode problem of circuit C1, firstly we categorize the circuit and its gate components. This step is easy if
ontology about the problem is already thought. This step involves the writing simple atomics sentences of instances
of concepts, which is known as ontology.
For 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:

You might also like