Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
20 views38 pages

Lecture02 Logic

The lecture on Knowledge Representation introduces the foundations of logic, discussing its formalization and implementation in machines. It covers elements of logic, including propositions, consequence, syntax, and semantics, as well as various deductive systems and types of logic such as propositional and first-order logic. Key concepts such as validity, satisfiability, and the structure of logical expressions are also explored, emphasizing the importance of logic in artificial intelligence and reasoning.
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)
20 views38 pages

Lecture02 Logic

The lecture on Knowledge Representation introduces the foundations of logic, discussing its formalization and implementation in machines. It covers elements of logic, including propositions, consequence, syntax, and semantics, as well as various deductive systems and types of logic such as propositional and first-order logic. Key concepts such as validity, satisfiability, and the structure of logical expressions are also explored, emphasizing the importance of logic in artificial intelligence and reasoning.
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/ 38

CITS3005 Knowledge Representation

Lecture 2: Foundations of Logic

Tim French

The University of Western Australia

2024
Overview
In this lecture we will look at logic in its broadest sense and consider how
a logic can be formalised and implemented in a machine.

Logic, as the methodology of reason has been studied for thousands of


year, but logic as a formal process was studied intensely in the early
twentieth century, as a response to Hilbert’s questions:

Consistency of Arithmetic
Show that the axioms of arithmetic are consistent.

Decision Problem
Show that there is an effective process for determining whether a
statement is provable in first order logic.

In this unit we will see several different logics, so here we aim to set up a
common framework for discussing logic.
Elements of Logic
In the most general sense, a logic requires:
▶ Propositions: symbols or statements that can be considered true or
false within some frame of reference, like “it rained today”, or “Kate
is tired”.
▶ Consequence: a set of rules that determine that one proposition
follows from one or more other propositions. From example, from “it
rained today” derive “the grass is wet”. There is no requirement for
the rule to be factually valid.
Logic can be expressed in general terms: A car with a flat battery will not
start. The car started so the battery is not flat.

Logic can be expressed in formal terms:

∀x ∈ R, x 2 ≥ 0 =⇒ π 2 ≥ 0.
Elements of Formal Logic
In formal logic propositions are given a grammatical structure, and
consequence is defined with respect to that structure.
This divides the logic into:
1. Syntax: how the propositions are defined from atoms and operators.
2. Semantics: the meaning of the propositions.
The define semantics the meaning must be grounded in some
interpretation. Formal logic uses mathematical structures as the basis for
the interpretation.

Note, there is an alternative proof-


theoretic semantics that charac-
terise the meaning of propositions
through rules of inference, rather
than through interpretations.
A famous example is non-Euclidean
geometry for which the existence of
an interpretation was a long standing
open question.
Example: Propositional Logic
The language of propositional logic consists of
▶ a set P of propositional atoms: rain today, Kate is tired, x, . . .
▶ the constants ⊤ (true) and ⊥ (false)
▶ the operators: ¬ (not), ∧ (and), → (implies), ↔ (if and only if).
The set of propositions is specified using Backus Naur form (BNF):

L = α ::= ⊤ | ⊥ | x | ¬α | α ∧ α | α ∨ α | α → α | α ↔ α

where x ∈ P.
Any terms defined as α can be substituted for α in the grammar, so this
will generate an infinite set of propositions:

x ∧ y , ¬z → (x ∧ y ), ¬(x ∨ z) → (x ∧ y ), . . .

Note that BNF imposes a tree structure on a formula, so brackets aren’t


required in the formal syntax, but we use them to write the formulas as
strings.
Example Continued: Propositional Logic
An interpretation of propositional logic is simply the set I ⊆ P or atomic
propositions that are true.
The semantics of propositional logic determine whether a proposition, α
is true, given an interpretation, I. We say I |= α, and define this relation
recursively:

I |= ⊤
I ̸|= ⊥
I |= ¬α ⇔ I ̸|= α
I |= α ∧ β ⇔ I |= α and I |= β
I |= α ∨ β ⇔ I |= α or I |= β
I |= α → β ⇔ I |= β or I ̸|= α
I |= α ↔ β ⇔ I |= α → β and I |= β → α

There is a degree of redundancy in these operators as α ∨ β is equivalent


to ¬(¬α ∧ ¬β), α → β is equivalent to ¬α ∨ β etc so ∧ and ¬ are
normally sufficient to describe the full semantics.
Validity and Satisfiability
We say a formula is valid if it is true in every
possible interpretation, and we say a formula
x y z ¬(x ∧ y ) → z
is satisfiable if it is true in some possible in-
⊤ ⊤ ⊤ ⊤
terpretation.
⊤ ⊤ ⊥ ⊤
⊤ ⊥ ⊤ ⊤
The fundamental definition of a logic is the
⊤ ⊥ ⊥ ⊥
set of all valid formulas.
⊥ ⊤ ⊤ ⊤
⊥ ⊤ ⊥ ⊥
However, determining whether a formula is
⊥ ⊥ ⊤ ⊤
valid or not is generally computationally in-
⊥ ⊥ ⊥ ⊥
tractable, so this is not necessarily the best
approach to reasoning.
Proof and Derivation
While the semantic interpretations allow us to understand a formulas in
terms of a mathematical description of an interpretation, it is often the
case that it is intractable to build a full interpretation.

A “proof” progresses from what we know to what we can infer: in that


sense we maintain a knowledge base and add new knowledge from either
observation or by applying deduction.

Deductive systems come in several forms:


▶ Hilbert-style axiom systems
▶ Sequent calculus
▶ Natural Deduction
▶ Tableaux
Deductive Systems
Deductive systems progress from what we know to what we can infer:
α, β α, α→β
(∧-intro) (modus ponens)
α∧β β
Hilbert style axiom systems give fundamental axioms (e.g. x ∨ ¬x) and
provide rules to add to the set of axioms (like substitution: from x ∨ ¬x
infer raining ∨ ¬raining ).

A proof is a sequence of deductive steps from a set of premises, Θ, (or


antecedents) to a conclusion, α (or consequent) and we write Θ ⊢ α to
say that α is derivable from Θ

α∧β Premise
⊢α∧β →α ∧-elimination
α∧β ⊢α modus ponens
⊢α→α∨β ∨-introduction
α∧β ⊢α∨β modus ponens
⊢ (α ∧ β) → (α ∨ β) → -introduction
Natural Deduction
Natural deduction attempts to codify intuitive rules that can present an
argument in a natural way way.

For computational reasoning it is often more efficient to use less


explainable rules with more efficient implementations, like resolution:
Θ, α ⊢ β Ψ, ¬α ⊢ β
Θ, Ψ ⊢ β
or conversion to conjunctive normal form.
An Axiomatization of Propositional Logic
In this unit we will use the following system for producing proofs in
propositional logic. Starting with a set of premises (above the line), the
rules below can be used to derive consequences (below the line).
α∧¬α
true ⊤ false ⊥

α→⊥ ¬¬α
¬-intro ¬α ¬-elim α

α β α∧β
∧-intro α∧β ∧-elim α β

α
...
β α α→β
→ -intro α→β → -elimination β

A consequence that can be derived from an empty set of premises is a


tautology.
Example Deduction
Suppose we wanted to apply the axiom system to show:

From ¬(α → β) we can infer ¬β


Consistency, Soundness and Completeness
Once we have a deductive system we can ask the following questions:
▶ Is it consistent? That is, are all the axioms true in every
interpretation?
▶ Is it sound? That is, do the rules produce conclusions that are true
in every interpretation?
▶ Is it complete? That is, can it prove every valid proposition?
Other logical questions are:
▶ Satisfiability checking: can we check whether a given formula has a
model, and if so, how complex is the process.
▶ Model checking: given an interpretation, check whether a
proposition holds in that interpretation.
▶ Expressivity: given two logics can one be translated to the other?
▶ Synthesis: given a proposition, can we construct an interpretation
where that proposition is true.
Types of Logic
There are many different types of logic, including;
▶ propositional logic
▶ first order logic (and second order logic,...)
▶ description logic
▶ modal logics (logics or time, space, knowledge, obligation,
necessity,...)
▶ computational logics (logics of program correctness
▶ logics of uncertainty (fuzzy logic, probabilistic logic, para-consistent
logic)
Logic programming is a fragment of first order logic with a computational
implementation.
First Order Logic Overview
We will now consider the formal aspects of first order logic, including the
syntax, the semantics, and reasoning techniques.

First order logic goes beyond propositional logic, where every proposition
can only include a finite number of Boolean concepts, to consider
unbounded sets of entities.

Functions describe correspondences between these entities and predicates


define relations over these entities. First order logic uses quantifiers to
define propositions that are dependent on the entire domain, rather than
propositions that are isolated facts.

First order logic is the logic of ontology and artificial intelligence. It is


just expressive enough to describe the state of the world, what is.
Elements of First Order Logic
The elements of first order logic consists of :
▶ Entities: elements of the domain, about which we have facts. For
example, tim, jane, cits3005, uwa. Some may have a fixed label (a
constant), like tim french, but we can also reason about sets of
entities without needing each one to be labelled (e.g. all the
students at UWA).
▶ Functions: these map tuples of entities to other entities. For
example grade(jane, cits3005 ) = credit is a function mapping
students and units to grades.
▶ Predicates: these provide the truth function for the logic, and assign
tuples of entities a truth assignment, with meaning. For example,
enrolled(jane, cits3005 ), is true if jane is enrolled in cits3005 and
false otherwise.
▶ Operators: these are just the operators from propositional logic, ∧,
∨, ¬, etc
▶ Quantifiers: ∃ (there exists) and ∀ (for all), that range over all
entities.
Language of First Order Logic
The language of a first order logic is given by:
▶ A set C of constant symbols, eg tim ∈ C ;
▶ A set F of function symbols, where each f ∈ F has arity #f , eg
grade ∈ F and #grade = 2;
▶ A set P of predicate symbols, where each p ∈ P has arity #p, eg
enrolled ∈ P and #enrolled = 2;
▶ A set var of variable symbols, where we write variables starting with
a capital, eg X ∈ var.

Different domains will use different languages. For example:


▶ Family Tree: C = {john, jane, cris...}, F = {mother , father },
P = {ancestor , male, related}.
▶ Arithmetic: C = {0, 1}, F = {successor , +}, P = {=, ≤}
Syntax of First Order Logic
The syntax of first order logic has two parts: the terms correspond to the
entities; and the propositions correspond to truth values.

The terms are given by the following BNF:

τ ::= c | X | f (τ1 , . . . , τ#f )

where c ∈ C , X ∈ var and f ∈ F .

The propositions are then given by the BNF:

α ::= ⊤ | ¬α | α ∧ α | p(τ1 , . . . , τ#p ) | ∀X α

where X ∈ var, p ∈ P, and τi is a term.

We use the abbreviations ⊥ = ¬⊤, α ∨ β = ¬(¬α ∧ ¬β),


α → β = ¬α ∨ β, and ∃X α = ¬∀X ¬α.

If a variable X in α does not appear in the scope of a quantifier, ∀X , then


it is a free variable, and a formula with no free variables is a sentence.
Exercise: Logics of Arithmetic
Express some simple arithmetic properties using arithmetic logic:
▶ Every even number is followed by an odd number.

▶ For every number there is always a prime larger than it

▶ Every number is the square of some different number.


Interpretations of First Order Logic
The semantics of first order logic over a language (C , F , P, var), are
given with respect to an interpretation, I, consisting of:
▶ a domain, D I , which is the set of entities in the system.
▶ for every constant symbol, c ∈ C , an element of the domain
cI ∈ DI.
▶ for every function symbol, f ∈ F , a function f I : (D I )#f −→ D I
▶ for every predicate symbol, p ∈ P. a function
p I : (D I )#p −→ {⊤, ⊥}

However, the interpretation doesn’t tell us anything about the free


variables, as they are not yet bound to the element of a domain.
We define an assignment to be a map from variables to domain elements:
θ : var −→ D I , and extend θ to act on all terms by: θ(c) = c I for all
c ∈ C and θ(f (t1 , . . . , t#f )) = f I (θ(t1 ), . . . , θ(t#f )).
Semantics of First Order Logic
We can now give the semantics for first order logic.
We say I satisfies α given the assignment θ (written I θ |= α), and define
this relation recursively:

I θ |= ⊤

I θ |= p(τ1 , . . . , τ#p ) ⇐⇒ p I (θ(τ1 ), . . . θ(τ#p )) = ⊤

I θ |= ¬α ⇐⇒ I θ ̸|= α

I θ |= α ∧ β ⇐⇒ I θ |= α and I θ |= β

I θ |= ∀X α
I
⇐⇒ ∀ψ : var → D s.t. θ(Y ) = ψ(Y ) if X ̸= Y , I ψ |= α.
Example: University
For example, in a University:
▶ the domain might be students, lecturers and units.
▶ the constants could be tim, jane, haolin, cits3005, cits2211.
▶ a function might be uc that maps a unit to the lecturer that
coordinates it.
▶ predicates might be studies, that relates students to the units that
study, or prereq that relates a unit to its prerequisite, or = for when
two domain elements are equal.
We can then considered sentences like:

∀Units (uc(Unit) = tim → ∃Student studies(Student, Unit))

For every unit that is coordinated by Tim, there is a student that studies
that unit.
Example: Natural Numbers
First order logic can also express properties of arithmetic:
▶ The domain is the natural numbers 0, 1, 2, 3, 4, . . .
▶ the only constant is 0 (zero).
▶ There is a function succ that maps a number to its successor, so
succ(1) = 2, and there are also functions +, −, /, ∗ etc.
▶ There are predicates =, <, , ≤.
We can define sentences like:

∀X ∀Y (X < Y → succ(X ) < succ(Y ))

or

∀X ∃Y (X < Y ∧ ∀Z (Z < Y → (∃W (W ∗ Z = Y )) → Z = succ(0))).


Validity and Satisfiability
We say a formula is valid if it is true in every possible interpretation, and
we say a formula is satisfiable if it is true in some possible interpretation.

In first order logic, determining whether a formula is valid or not is not


decidable. This means that there is no computational process that can
definitively answer the question.

Validity in first order logic is semi-decidable, which means there is a


process, such that, given long enough, will compute every possible
validity of first order logic.
However to know something is not valid, would require us to wait for the
generation process to end, and it is an infinite process.
One such process for generating all validities is to apply natural
deduction.
A Natural Deduction System for First Order Logic
α∧¬α
true ⊤ false ⊥

α→⊥ ¬¬α
¬-intro ¬α ¬-elim α

α β α∧β
∧-intro α∧β ∧-elim α β

α
...
β α α→β
→ -intro α→β → -elimination β

∃-intro ∗ α(t)
∃X α(X ) ∃-elim† β(t)→α
∃X β(X )→α

∀X α(X )
∀-intro † α→β(t)
α→∀X β(X ) ∀-elim∗ α(t)

: here t cannot occur within the scope of a quantifier over any sub-term
of t (t must be free in α).

: here, α cannot contain the term t or any of its sub-terms, and t
cannot be contained within an undischanged assumption.
Example Deduction
Suppose we wanted to apply natural deduction to show:

From ∀X (α(X ) → β(X ) we can infer ∃X α(X ) → ∃(X )β(X )


Automated Reasoning
Formal reasoning is difficult and error prone, so it is most useful to us if
it can be automated and verified. From an implementation point of view,
it is most convenient to work with a few rules and a restricted syntax, so
reasoning can be mechanically applied in a uniform fashion.

The reasoning problems we are most interested in are


▶ satisfiability - is there a satisfying interpretation for a set of formulas
▶ validity - does one formula always follow from a set of formulas.
These problems are duals of one another (i.e. α follows from Θ if and
only if Θ ∪ {¬α} is not satisfiable.).

Therefore we can transform formulas in without preserving their exact


meaning, so long as we preserve the existence of a satisfying model.

We will give such a transformation to clausal normal form.


Conjunctive Normal Form
A formula in conjunctive normal form is specified by the syntax:

τ ::= c | X | f (τ1 , . . . , τ#f )


lit ::= P(τ1 , . . . , τ#P ) | ¬P(τ1 , . . . , τ#P ) | ⊤ | ⊥
disj ::= lit | disj ∨ lit
conj ::= disj | conj ∧ disj

To convert a formula into conjunctive normal form we need to:


1. push all the negations (¬) down to the literals.
2. remove all of the existential quantifiers.
3. remove all of the universal quantifiers.
4. move all of the conjunctions to the outside of the formula.
5. remove all of the true/false constants.
Moving negations to literals.
To move the negations to literals, we can apply the following
transformations recursively:

¬(α ∧ β) ⇐⇒ ¬α ∨ ¬β
¬(α ∨ β) ⇐⇒ ¬α ∧ ¬β
¬∃X α ⇐⇒ ∀X ¬α
¬∀X α ⇐⇒ ∃X ¬α
¬¬α ⇐⇒ α
¬⊤ ⇐⇒ ⊥
¬⊥ ⇐⇒ ⊤

Since on the right side of each equality, the negated formula is less
complex than the negated formula on the right, we can apply these
transformations until negations are only applied to predicates.
Quantifier Elimination 1: Skolemisation
Suppose we are given a formula β(∃X α(t1 , ..., tn , X )). That is the
formula β contains a subformula ∃X α(. . .), and α contains the
unquantified terms t1 , ...tn as well as the variable X .

∃X α(t1, ..., tn , X ) is true if given t1 , ..., tn we can find an X that makes α


true. That is, X is dependent on t1 , ..., tn , so we can introduce a new
function to represent this dependency:

β(∃X α(t1 , ..., tn , X )) ∼


= β(α(t1 , ...tn , fX (t1 , ..., tn )))
This process is called Skolemisation and can be applied to every
existentially quantified sub-formula.
Note, it is not an axiom, since it assumes the function fX exists, but
given any interpretation, we can always add an extra such function.
Quantifier Elimination 2: Generalisation
Suppose we are given a formula β(∀X α(t1 , ..., tn , X )).
Since unquantified variable X has no constraints placed upon it, its
interpretation agrees with a universally quantified variable (see ∀-intro).
Therefore, we can just remove the universal quantifiers of a formula in
clausal normal form.

Example: suppose our domain is the natural numbers, and we have the
formula:
∃X ∀Y ∃Z (X − Z = Z − Y )
Letting eq be a predicate, and sub be a function we have:

∃X ∀Y ∃Z (eq(sub(X , Z ), sub(Z , Y ))
=⇒ ∃X ∀Y (eq(sub(X , f (X , Y )), sub(f (X , Y ), Y ))
=⇒ ∀Y (eq(sub(x, f (x, Y )), sub(f (x, Y ), Y ))
=⇒ (eq(sub(x, f (x, Y )), sub(f (x, Y ), Y ))
That is: x − f (x, Y ) = f (x, Y ) − Y . This predicate is not true for the
natural numbers, but taking f (x, y ) = x+y2 would make it true for the
rational numbers.
Conjunctive Normal Form
The above transformations will restrict formulas to the syntax:

τ ::= c | X | f (τ1 , . . . , τ#f )


lit ::= P(τ1 , . . . , τ#P | ¬P(τ1 , . . . , τ#P | ⊤ | ⊥
prop ::= lit | prop ∨ prop | prop ∧ prop

So we still need to transform the formula so that disjunctions only apply


to literals and other disjunctions. This can be done as:

α ∨ (β ∧ γ) ⇐⇒ (α ∨ β) ∧ (α ∨ γ)
⊤∨β ⇐⇒ ⊤
⊥∨β ⇐⇒ β
⊤∧β ⇐⇒ β
⊥∧β ⇐⇒ ⊥

Now we have a formula in clausal normal form, and this formula is


satisfiable if and only if the original formula is satisfiable.
Knowledge Bases
We can now reduce any set of first order formulas to one large formula in
clausal normal form.
(¬)p1 (t11 , . . . , t1#p1 ) ∨ . . . ∨ (¬)pn (tn1 , . . . , tn#pn )
^ (¬)q1 (u11 , . . . , u1#q1 ) ∨ . . . ∨ (¬)qn (un1 , . . . , un#qn )
..
.
(¬)r1 (v11 , . . . , v1#r1 ) ∨ . . . ∨ (¬)rn (vn1 , . . . , vn#rn )
Each clause
¬p(t11 , . . . , t1#p1 )∨¬p(tn1 , . . . , tn#pn )∨q(u11 , . . . , u1#q1 )∨q(un1 , . . . , un#qn )
can be rewritten as
(p(t11 , . . . , t1#p1 )∧p(tn1 , . . . , tn#pn )) → (q(u11 , . . . , u1#q1 )∨ q(un1 , . . . , un#qn ))
which is often written, (using ASCII syntax) as, for example:
q1(u1,u2), q2(f1(u3),u4) :- p1(t1,t2,f(t2)), p2(t1).
A knowledge base typically describes the set of facts and rules known
about a system, where facts are clauses with no negative literals:
blue(sky).
And rules are clauses with at least one negative literal:
day(time) :- blue(sky).
Resolution
Resolution is a reasoning process that uses a single rule, that is applied to
two clauses:

a, b ← c, d
c, e ← f , g
a, b, e ← f , g , d
In general, given two clauses:
p1 (t11 , . . .), pn (tn1 , . . .), . . . ← q1 (u11 , . . .), . . . , qm (um1 , . . .
and
q1 (u11 , . . .), r1 (v11 , . . .), . . . ← s1 (w11 , . . .), . . . , sn (wm′ 1 , . . .)
with a common element, we can combine them into a single clause:
p1 (t11 , . . .), pn (tn1 , . . .), . . . , r1 (v11 , . . .), . . .

q2 (u21 , . . .), . . . , qm (um1 , . . .), s1 (w11 , . . .), . . . , sn (wm′ 1 , . . .)
However, we have universal variables in our knowledge base, so it’s not
clear when we can apply resolution.
Unification
Suppose we are given two predicates, with the same predicate symbol,
but different terms. We would like to know under what substitutions the
two predicates will be equal.
A substitution θ : var → terms assigns a term to each variable.
Given a predicate p(t1 , . . . , t#p ) and a substitution θ, p(t1 , . . . , t#p )\θ is
the result of substituting every variable X that appears in any term in
p(t1 , . . . , t#p ), with θ(X ).

For example,

drive(father(X ), Y )\[X : sam, Y : morris]

becomes
drive(father(sam), morris)

To unify two predicate statements, p1 , p2 with the same predicate symbol


is to find two substitutions, θ1 , θ2 so that p1 \θ1 and p2 \θ2 are identical.
Example
For example, given drive(father(X ), Y ) and drive(X , car(X )) then:

drive(father(X ), Y )\[X : sam, Y : car(father(sam))]


drive(X , car(X ))\[X : father(sam)]
drive(father(sam), car(father(sam)))

are all equal.

The most general unifier is the pair of substitutions that makes the
predicates equal, with the least commitment.

Exercises
Ex 1. Show that if a unifier exists, a most general unifier exists.
Ex 2. Give an algorithm for finding the most general unifier.
Ex 3. Can you find a most general unifier for p(X , f (X )) and p(f (Y ), Y ).
Examples
Given the statements:
▶ Cris is a student in CITS3005.
▶ All students who study hard will pass if a unit is easy.
▶ CITS3005 is easy.
▶ Cris studies hard.
Formally show Cris passes CITS3005.
Logic Programming
A logic program is essentially just a set of of clauses, and an execution of
a logic program is a process of unification and resolution.

Logic programming languages add special predicates for reading and


writing input, and other functions, and provide extra syntax, like cuts, for
controlling execution.

Logic programs also typically restrict the clauses to have a single positive
literal, to constrain the possible executions of a program.

We will consider the finer details of logic programming in the next lecture.

You might also like