2. What is Logic ?
• KBS needs to express general rules and represent specific cases.
• The logic is appropriate for knowledge representation and reasoning.
• واالستدالل المعرفة لتمثيل مناسب المنطق
.
• The logic is the study of entailment relations, languages, truth
conditions, and rules of inference.
• االستدالل وقواعد الحقيقة وشروط واللغات االستداللية العالقات دراسة هو المنطق
.
3. First-Order Logic (FOL)
• Objects represent a set of relevant facts in a specific domain.
• First-Order Logic (FOL) is a knowledge representation language used
in mathematics, philosophy, linguistics, computer science, and
artificial intelligence for reasoning and knowledge representation in
order to express logical concepts.
• First-order logic is also known as Predicate logic or First-order
predicate logic.
• Basically, FOL is used for representing information about the objects
(entities) and the relationships between these objects.
4. • We also use it for representing the rules induced from this set of
objects and the relationships between them.
• FOL deals with declarative propositions and uses quantifiers and
relations for expressing knowledge.
• FOL uses quantified variables over non-logical objects, and allows the
use of sentences that contain variables, so that rather than
propositions such as "Socrates is a man“, one can have expressions in
the form "there exists x such that x is Socrates and x is a man", where
"there exists" is a quantifier المحدد , while x is a variable متغير .
5. Objects, relations, and functions
• Objects: A, B, people, numbers, colors, houses, theories,
games, ......
• Relations: It can be unary relation احادية عالقة such as: red,
round, prime, or any relation such as: the sister of, brother
of, has color, comes between, part of, owns
• Function: Father of, best friend, Mother of, end of, beginning
of ......
6. FOL
• The first-order logic language has two main parts:
1. Syntax شكل
صيغة
الرموز بنية
2. Semantics الجملة سياق من المفهوم الرموز معنى
7. 1. Syntax of FOL
• The syntax of FOL is a set of logical symbols, arranged in a
properly formed way.
• وصحيح جيد بشكل المرتبة المنطقية الرموز من مجموعة هو
• The syntax of FOL determines which collection of symbols is a
well-formed and a logical expression in first-order logic.
• جيد بشكل مضاع منطقي تعبير تمثل الرموز من مجموعه اي يحدد
• So, we write statements in short-hand notation رموز in FOL
using a set of logical symbols.
• We know that the sentences of the language are what express
propositions. والفرضيات االقتراحات عن تعبر التي هي اللغة جمل
8. Example of sentence syntax in general
• In English language, for example:
the noun phrase “the food that my mother loves” is a well-formed
noun phrase.
صحيح بشكل ومصاغة مشكلة اسمية جملة شبة هي
• but the noun phrase “that the my loves mother food” is a not well-
formed noun phrase.
اسمية جملة شبة هي
غير
صحيح بشكل ومصاغة مشكلة
9. 2. Semantic of FOL
• Semantic of FOL represents what is the well-formed expressions are
supposed to mean.
صحيحة بصيغة المشكلة للجمل المعنى
• Some well-formed expressions like “the hardnosed decimal holiday” might
not mean anything.
• For sentences, we need to be clear about what idea that is being
expressed. We must express the sentence in a meaningful way.
• In English, for example, “There is someone right behind you” could be used
as a warning to be careful in some contexts الجمله سياق and a request to
move in others.
• الجملة سياق من يفهم المعنى
11. Constants 1, 2, A, John, Mumbai, cat,....
Variables x, y, z, a, b,....
Predicates Brother, Father, Mother, >,....
Functions sqrt, LeftLegOf, ....
Connectives ∧, ∨, ¬, ⇒, ⇔
Equality ==
Quantifiers ∀ لكل, ∃ يوجد
Basic Elements of First-order logic syntax:
The following are the basic elements of FOL syntax:
Punctuations “(”, “)”, and “.”.
12. Logical symbols
• Please see the pdf file for the rest of the logical symbols and their
meanings.
13. Logical symbols
• The logical symbol ∀ is a universal quantifier that denotes “for all” لكل
• The logical symbol ∈, for example x ∈ A indicates that an element x is a
member in a set A لمجموعه ينتمي العنصر
• xA means that the element x is not a member in the set A
• The logical symbol ∪ denotes a union تكرار بدون المجموعتين عناصر لجميع اتحاد
• The logical symbol ⊨ means an implication (entailment). او يشمل او يتضمن
على ينطوي او يعني
• The logical symbol ⊭ indicates a negated implication. اليتضمن
• C ⊆G, C is a subset of G, where ⊆ indicates a subset. جزئية مجموعه
14. Logical symbols
• The logical symbol ∃ means there exists
• The logical symbol ∄ means there does not exists
• The logical symbol ¬ means NOT
• The logical symbol ^ means AND (conjunction)
• The logical symbol means OR (disjunction)
• The logical symbol means if … then ; implies
• The logical symbol means if … then ; implies
15. Logical symbols
• The logical symbol means if and only if (equivalent)
• The logical symbol means if and only if (equivalent)
• The logical symbol = is logical equality
• The logical symbol means is defined as (x y means x is defined to
be another name for y)
• The logical symbol ⊨ means entails تتضمن (x ⊨ y means x semantically
entails y, A B ⊨ ¬ B ¬ A)
• The logical symbols !, ¬, ~, x‘ means not – negation نفي
16. Logical symbols
• A B means that A is a subset of B (every element in
the A set is contained in the B set).
• A B means that A is NOT a subset of B (NOT every
element in the A set is contained in the B set).
• ∀ and ∃ are called quantifiers.
17. • Variables: an infinite supply of symbols, which we will denote here
using x, y, and z.
• The non-logical symbols are those that have an application-
dependent meaning or use التطبيق على يعتمد اواستخدام معنى لها التي الرموز هي.
• In FOL, there are two sorts of non-logical symbols:
1. Function symbols
2. Predicate symbols
18. The non-logical symbols
1. Function symbols: an infinite supply of symbols, which we will
write in uncapitalized mixed case, e.g., bestFriend, and which we will
denote more generally using a, b, c, f , g, and h, with subscripts and
superscripts. والمرتفعه المنخفضة الحروف مع
2. Predicate symbols: an infinite supply of symbols, which we will write
in capitalized mixed case, e.g., OlderThan, and which we will denote
more generally using P, Q, and R, with subscripts and superscripts.
19. Two types of sentences
1. Atomic sentences
2. Complex Sentences
20. 1. Atomic sentences
• An atomic sentence is a clause الجملة.
• A clause is a disjunction of literals منفصله وكلمات حروف
• Atomic sentences are the 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).
• A term is a variable متغير or constant ثابث or function (Any expression f(t1,...,tn)) .
21. Examples of Atomic sentences
1. Ravi and Ajay are brothers
Brother(ravi, ajay).
2. Chinky is a cat
cat (chinky).
3. Sally and Sara are sisters
Sister(sally, sara)
SALLY is a sister of Sara
Predicates
22. What is a predicate?
• A predicate: is a relation between objects. For example:
color(snow, white)
The above example consists of the predicate “color” and the two
(terms/arguments) “snow” and “white”.
• A predicate takes an entity or entities in the domain of discourse ( مجال
)الحوار as input while outputs are either True or False.
• A domain of discourse specifies the range of the quantifiers.
23. • Relationships between predicates can be stated using logical
connectives (∧, ∨, ¬, ⇒, ⇔).
• Quantifiers (∀, ∃) can be applied to variables in a formula.
More examples of predicates:
• color(snow, white)
• color(sky, blue)
• color(banana, yellow)
• color(grass, green)
24. 2. 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
joins two atoms together in a statement.
25. • Consider the statement:
"x is an integer“.
The above statement consists of two parts: In the first part x
is the subject of the statement, and in the second part "is an
integer," is the predicate.
The above statement is represented in FOL as:
Integer(x)
27. Quantifiers in First-order logic (FOL):
• A quantifier المحدد is a language element which generates quantifications تحديد
الكميات
• Quantification specifies the quantity of specimenexamples او مثال او عينة
نموذج in the universe of discourseالحوار عالم او مجال
• The universe (domain) of discourse is the complete range الكامل النطاق of
objects, facts, events, attributes, relations, ideas, that are expressed,
assumed, or implied in a discussionمعين حوار او معين نقاش في .
• These are the symbols that permit to determine the range and scope of the
variable in the logical expression.
There are two types of quantifier:
1. Universal Quantifier, (for all, everyone, everything)
2. Existential quantifier, (for some, there is at least one, there exists).
28. 1. 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 ∀ لكل
• Note: In universal quantifier we use implication "→".
• If X is a variable, then ∀X is read as:
• For all X
• For each X
• For every X
29. 1. Universal Quantifier
• An example of universal quantifier:
1. All men drink coffee
∀ x man(X) → drink(X, coffee)
Suppose that x is a variable which
refers to a man.
x1, x2, x3, x4 ∈ X
∀x man(X) → drink (X, coffee).
30. 2. Existential Quantifier ∃ :
• Existential quantifier is a 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 ∃
• When it is used with a predicate variable then it is called as an existential
quantifier.
• Note: In Existential quantifier, we always use AND or Conjunction symbol (∧).
• If x is a variable, then the 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'
31. 2. Existential Quantifier:
• An example of Existential quantifier:
• some boys are intelligent.
∃X boy(X) ∧ intelligent(X)
Suppose that x is a variable which
represent a boy.
x1, x2, x3, x4 ∈ X
• ∃X: boys(X) ∧ intelligent(X)
32. Points to remember:
• The main connective for universal quantifier ∀ is implication →.
• The main connective for existential quantifier ∃ is and ∧.
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.
33. Some examples of mapping sentences into
FOL using quantifiers:
• 1. All birds fly.
∀X bird(X) → fly (X)
In this question, the predicate is "fly(bird).“
Using FOL quantifier, the above sentence is represented
as follows:
∀X bird(X) → fly(X).
34. Some examples of mapping sentences into
FOL using quantifiers:
• All men are mortal ()بشر
∀X man(X) → mortal(X)
The above sentence is represented using FOL as follows:
∀X man(X) → mortal (X).
35. • Every man respects his parent.
∀X man(X) → respect (X, parent)
In this question, the predicate is "respect(X, Y)," where X=man, and Y= parent.
Since there is every man so will use ∀, and it will be represented as follows:
∀X man(X) → respects (X, parent).
36. • 3. All boys play cricket.
∀X boy(X) → play(X , cricket)
In this question, the predicate is "play(X, Y)," where x=
boys, and y= cricket game.
• The above sentence will be represented as:
∀X boys(X) → play(X, cricket).
37. • 4. Some boys play cricket.
• ∃X boy (X) ∧ play (X, cricket)
In this question, the predicate is "play(X, Y)," where X=
boys, and Y= cricket game.
• Since there are some boys so we will use ∃, and it will
be represented as:
∃X boys(X) ∧ play(X, cricket).
38. • 5. Not all students like both Mathematics and Science.
In this question, the predicate is "like(X, Y)," where X=
student, and Y= subject which is Mathematics and
Science.
Since there are not all students, so we will use ∀ with negation,
so following representation for this:
¬∀ X [ student(X) → like(X, mathematics) ∧ like(X, science)].
39. • All IT students are smart.
The above sentence is represented as follows:
∀X IT_student(X) → smart (X)
• Ahmad owns a car.
owns(ahmad, car)
The above sentence is represented as follows:
owns (ahmad, car)
or in general: ∀XY Owns (X, Y)
Constants
Variables
40. • Every dog is an animal.
The above sentence is represented as follows:
∀X dog(X) → animal (X)
• All cats are cute.
The above sentence is represented as follows:
∀X cat(X) → cute (X)
41. • Every fruit is rich in vitamins.
The above sentence is represented as follows:
∀X fruit(X) → is_rich (X, vitamins).
• Every orange is a fruit.
The above sentence is represented as follows:
∀X orange(X) → fruit(X)
Then,
every orange is rich in vitamins.
∀X orange(X) → is_rich (X, vitamins).
42. • All frogs are green.
X frog(X) green (X)
• Some frogs are green.
X frog(X) ∧ green(X)
Not all frogs are green.
¬ ∀ X frog(X) green(X)
• Some frogs are not green.
X ( frog(X) ∧ ¬ green(X))
43. • Everybody loves somebody.
• Suppose that Everybody refers to X
• Suppose that somebody refers to Y
The above sentence is represented as follows:
∀X ∃Y loves(X, Y).
• Cat of Sami is cute.
isCute(catOf(sami))
The above sentence is represented as follows:
isCute (catOf(Sami))
44. • Some dogs are pets. (اليفة )حيوانات
X dog(X) ∧ pets(X)
The above sentence is represented as follows:
∃X dog(X) ∧ pet (X)
45. • Brothers are siblings (اشقاء هم )االخوة.
• X Y brother (X, Y) sibling( X, Y)
• Mother is one female parent.
• X Y mother(X, Y) female(X) ∧ parent (X, Y)
• Father is one male parent.
• X Y father(X, Y) male (X) ∧ parent (X, Y)
46. • A cousin is a child of a parent’s sibling.
الوالدين احد شقيق ابن هو العم ابن
The above sentence is represented as follows:
∀X ∀Y cousin (X, Y) → ∃ Z, F parent (Z, X) ∧ sibling (Z, F) ∧ parent (F, Y)
• For every computer virus, there is an anti-virus program that kills it.
• Suppose computer virus refers to X
• Suppose antivirus refers to Y
X Y kills( Y, X)
47. • All students studying AI are genius.
X student (X) ∧ studyingAI(X) → genius(X)
The above sentence is represented as follows:
• Some students studying AI are genius and homeworking.
X student(X) ∧ studyingAI(X) ∧ genius(X) ∧ homeworking(X)
The above sentence is represented as follows:
∃x student(X) ∧ studyingAI (X) ∧ genius(X) ∧ homeworking(X)
48. • No one likes Sami.
The above sentence is represented as follows:
∀x person(X) → ¬ likes(X, sami)
• Everybody has a mother.
The above sentence is represented as follows:
∀X∃Y mother(Y, X)
• Everybody has a mother and a father.
The above sentence is represented as follows:
∀X ∃Y ∃Z mother(Y, X) ∧ father (Z, X)
49. • If x is a parent of y, then x is older than y.
∀X ∃Y parent(X, Y) → older (X, Y)
• If x is a mother of y, then x is parent of y.
∀X ∃Y mother (X, Y) → parent (X, Y)
Smar is the mother of Sally.
mother (smar, sally)
Then, Smar is older than Sally.
older(smar, sally)
50. Some more sentences
a) John likes all kind of food.
X food(X) likes (John, X)
a) Apple and vegetable are food.
food(apple) ∧ food(vegetable)
a) Anything anyone eats and not killed is a food.
X Y eats(Y, X) ∧ ¬killed(X) food(X)
a) Anil eats peanuts and still alive.
eats(anil, peanuts) ∧ alive(anil)
a) Harry eats everything that Anil eats.
x eats (anil, X) eats (harry, X)
a) John likes peanuts.
b) likes (john, peanuts)
51.
52. What is the answer of mapping the following
sentences into FOL using quantifiers?
• All men are mortal; Socrates is a man, therefore Socrates is mortal
53. Limitations of FOL
• Although first-order logic is sufficient for formalizing much of
mathematics, and is commonly used in computer science and other fields,
it has certain limitations. These include limitations on its expressiveness
and limitations of the fragments of natural languages that it can describe.