Академический Документы
Профессиональный Документы
Культура Документы
Michael Leuschel
Softwaretechnik und Programmiersprachen
Lecture 5
5/31/06
Recap: CNF & Resolution
Conjunctive Normal Form: set of clauses
clause = disjunction of literals
literal = p or ¬p
Example: { ¬p q , wet ¬rains ¬outside }
Resolution
From p and ¬p derive a new logical
consequence
Proof by refutation for S {L}:
Show that S {¬L} is inconsistent by obtaining
the contradiction by resolution
5/31/06
Resolution: Further Example
1.) i l ¬s i k
2.) e l ¬r o g
3.) r i k s
5 = 1+4.) i l i k e l o g i k
i like logik
5/31/06
T: D: ¬p
p ¬q
Linear Resolution q D’: ¬q
5/31/06
Linear Resolution and Prolog
umbrella rain outside
umbrella ¬ rain ¬
umbrella :- outside
rain, outside.
rain Linear =
rain.
One can forget the past
outside. outside
?- umbrella. ¬ umbrella
¬ rain ¬outside
yes
¬outside
5/31/06
Non Linear Resolution
One day Tokusan told his student Gantõ,
“I have two monks who have been here for many years.
Go and examine them.”
Gantõ picked up an ax, saying,
5/31/06
First-Order Logic
5/31/06
Why a more expressive logic?
Example:
John loves all girls
Janet is a girl
Therefore, John loves Janet
Propositional Logic:
{j_loves_janet}
{j_loves_all_girls, janet_is_girl}
But: argument above still valid
We have to be able to talk about
objects/individuals
5/31/06
Addition 1: Constants
Constants: a,b,c, john, janet
Start with lowercase letter
Do not stand for a truth-value (true/false)
Represent a particular object from the “real
world”
a
b
janet
(mathematically: interpretations will map each
constant to an element from a domain) john
5/31/06 c
Addition 2: Predicates
binary
Predicates: girl(_), loves(_,_), … relation
Start with lowercase letter
Represent relations between objects
Have an arity
loves(_,_): 2
loves(john,janet)
girl(_): 1
rains: 0
(propositions are just a special case)
5/31/06
Addition 3: Variables
Variables: X,Y,Z,…
Start with uppercase letter
Do not have a truth-value either
Can stand for “any” object from the “real
world”
5/31/06
Addition 4: Quantifiers
Universal quantifier (for all)
Example: X loves(X,X)
Intuitively: “Everybody loves himself”
5/31/06
Exercise: Dylan
Translate into logic:
You can fool some of the people all of the time.
You can fool all of the people some of the time.
But you cannot fool all of the people all of the
time.
Use predicate:
fool(X,T): you can fool X at time T
5/31/06
Exercise: Solution
Translate into logic:
You can fool some of the people all of the time.
You can fool all of the people some of the time.
But you cannot fool all of the people all of the
time.
A Solution:
X T fool(X, T)
X T fool(X, T) (also acceptable: T X fool(X, T))
¬ ( X T fool(X, T) )
5/31/06
Addition 5:
Function Symbols
unary
Function symbols: function
succ(_), cons(_,_), …
Start with lowercase letter
Represent total functions between objects
Have an arity
cons(_,_): 2
succ(_): 1
john: 0 (constants are just a special case)
5/31/06
Natural Numbers
0
Constant 0 1
Function symbol succ(_) succ 2
Describing natural numbers: 3
nat(0)
4
X ( nat(succ(X)) nat(X) )
5
6
Describing addition: 7
X plus(0, X, X)
8
X ( plus(succ(X),Y,succ(Z)) plus(X, Y, Z) ) 9
10
...
5/31/06 (but there are Prolog built-in’s)
Representing Lists
Constant nil: empty list
Function symbol .(_,_)
.(H,T): list with first element H and tail T
[a,b] denoted by
.(a,.(b,nil)) [a,b]
[a,a] [b,a]
[b,b]
.
[a] [b]
nil []
5/31/06 a b
Summary
1. First-Order Logic
- constants, functions, variables
(tom mother(tom) X)
- relations human(sokrates)
( human(.) married(. , .) ) X. human(X) mortal(X)
- quantifiers
( ) variables over objects
5/31/06