Docsity

Computational Logic for Artificial Intelligence, Appunti di Tecniche Di Intelligenza Artificiale

Anteprima parziale del testo

Scarica Computational Logic for Artificial Intelligence e più Appunti in PDF di Tecniche Di Intelligenza Artificiale solo su Docsity!

Computational Logic for

Artificial Intelligence

Z

SMTLIB2 standard: is a conventional language used for all solver

and or xor not ¬ ⇒ → = ⇔

💻 Sintax:

(declare-const p Bool) (declare-const q Bool)

; SIUUUUM =

comment

(assert (⇒ (not p) q)) = ¬p → q

(push)

(assert p) → what it is after the “pushˮ is asserted, but then delated by the “popˮ (it works only with assertion)

(pop)

(check-sat) (get-model) → pay attention: it give you one of the possible model, not all of them

pay attention to the spaces while writing the assert sentences

In z3 are logically equivalent iff → → =

⇔ is a tautology, that is iff ¬ ⇔ is not satisfiable

A , B ( A B ) ∧ ( B A ) A B ( A B )

💻 (define-fun Inbetween ((x Real) (y Real) (z Real)) Bool (and (> x y) (> y z)))

to define a function. In this example we define a function to declare a ternary predicate that holds between x, y and z when x > y > z

💻 (declare-datatypes ()^ S A B C D E

to declare a enumerated type and call it S. the system will use the equality S  A, B, C, D, E assuming that the constants A, B, C, D, E are all distinct. The simple statement would be:

(declare-sort S (assert (distinct A B C D E

ex: Formalisetion of Sokrates problem (declare-sort D (declare-const s D (declare-fun H D Bool) (declare-fun M D Bool)

(assert (forall ((x D)) (⇒ (H x) (M x)) )) (assert (H s)) (assert (not (M s)))

(check-sat)

📌 Bounded model checking technique

General situation: I have variables: x, y I have initial situation: INITIAL (x, y) I have desired final situation: FINAL (x, y) I have evolution constraint: TRANS (x, y, xʼ, yʼ)

Plan: INITIAL (x , y ) TRANS (x , y , x , y ) ‘… TRANS (xʼ, yʼ, x , y ) FINAL (x , y )

Propositional Logic

A set is composed by atomic sentences , is a sentence ( formula ) If A, B are formulas, so are A B, A B, … Connectivesʼ precedences: ¬ >>>

→ We still use brakets to make it unambigous Valuation : function from to truth values

0 0 ∧^0 0 1 1 ∧^ ∧^ n n ∧^ n

n

L p

∀ p ∈ L p

L

📖 A^ ^ B^ =^ ¬A^ B ¬A  B = A ¬B ¬¬A = A ¬A B = ¬A ¬B ¬A B = ¬A ¬B A B C = A B A C B C A = B A C A

with the replacement lemma you can transform a not NNF into an NNF; when no rules apply you have a NNF

How our solvers program resolve our problems? Resolution procedure DPLL procedure

Resolution Procedure

itʼ a saturation mechanism

📖 resolution rule:^ you can^ remove one literal at a time

¬p C p D ———————————— C D If I get the empty clause ⇒ UNSAT If I donʼt get the empty clause (and resolution rule cannot produce anything new)  SAT

Let us call a set of clauses saturated iff is closed under resolution rule

Theorem:

If

is saturated, then is satisfiable iff it doesnʼt contain the

empty clause

So there is an assignment making all clauses from

true

Heuristics

📖 Subsumption:

we can remove C (we can do it because we are considering clauses “ ˮ)

example: set of clauses:

C

C C □

C

D ⊆ C

 ¬b p  ¬b ¬r  ¬c q  ¬c ¬r we fix the order a > b > c > r > q > p resolution among 13 and 14 produces  r ¬p

 r ¬q

here we cannot remove by subsumption now resolution among 25 and 26 produces

 c p

 c ¬r

Now c occurs positively in 2, 11, 12, but we donʼt consider the clause 2 because it doesnʼt have c maximal resolution among 117 118 127 12 8

 p q

 p ¬r

 ¬r q

 ¬r

Now we can subsumed from 16. and therefore remove 6, 8, 12, 14, 15 Then resolution among 169 and 1610 produces

 ¬q

 ¬p

⟶ remove 3, 4 In the end resolution among 1317 produces

 p

But 18 and 19 produces the empty clause  UNSAT example: check whether ((p → q) → q) → (p q) is a tautology We first negate the formula, then bring to CNF and then apply resolution: ¬(((p → q) → q) → (p q)) ((p → q) → q) ¬(p q) (¬(p → q) q) ¬p ¬q ((p ¬q) q) ¬p ¬q (p q) (q ¬q) ¬p ¬q In the end we have the clauses:  p q  ¬p  ¬q We get UNSAT  the original formula is a tautology

Horn Clause : clause with at most one positive literal Facts: Rules: Golas (queries):

DPLL = CDCL

Status of the Algorithm

p

¬ q 1 ∨... ∨ ¬ qn ∨ p

¬ q 1 ∨... ∨ ¬ qn

< V ∣ F ∣ α >

Suppose that V ¬C For instance C is (p q) V p  0 , q  0  V ¬(p q) The literal have been assignment in the wrong way , something wrong happened. So I go to conflict state V | F, C | C

Decide If there is nothing else to do, if the previous rules do not apply, then we apply this rule. Still there are unassigned variables So (at your choice) decide to assign a non-assigned variable p to 1 or to 0 p is marked decided

Conflict rules

Failure rule C If C is the empty clause, exit with UNSAT

Explain rule V | F, D | C If is a literal is the opposite literal) Suppose that literals in D were assigned before D C —————————

< V ∣ F ∣ >

< ∨ l ˉ^ ∨ l >

l l ˉ

l

∨ l ˉ^ ∨ l

D C

This one is the new conflict clause Typically has been propageted and D caused the propagation

Backjumping rule

V, (d), Vʼ | F | C ( is decided: last assingned literal in C is decided) V ¬C V, (p) | F, C | C should be false

As far as the last assigned literal in the conflict clause is propagated, apply Explain. When this is not the case, apply Backjumping

ex:

F  ¬p ¬q  p q  ¬p q  p ¬q Initially we have: empty assingment, clauses from 1 to 4, search state: | 14 | We donʼt have unit literals, so we decide: p(d) | 14 | now we propagate If p is true, cause we decided, looking at ¬p q, then q must be true p(d), q(3) | 14 | Conflict

l ˉ^ ∨ l ˉ

< l ∨ l ˉ>

l ˉ^ ∨ l ˉ

< l ˉ^ ∨ l ˉ ∗ >

a(d), ¬p(3), ¬q(4), ¬b(5), ¬c(7) | 18 | Conflict a(d), ¬p(3), ¬q(4), ¬b(5), ¬c(7) | 18 | b c Explain

The last assinged literal is “cˮ, this means that if I have assinged ¬c, I can make resolution beetwen:

b c ¬c q

but it produces another conflict:

a(d), ¬p(3), ¬q(4), ¬b(5), ¬c(7) | 18 | b q Explain (again)

the last assinged literal now is ¬b, so resolution:

b q ¬b p

produces:

a(d), ¬p(3), ¬q(4), ¬b(5), ¬c(7) | 18 | p q Explain (again)

p q ¬a ¬q

a(d), ¬p(3), ¬q(4), ¬b(5), ¬c(7) | 18 | ¬a p Explain (again) a(d), ¬p(3), ¬q(4), ¬b(5), ¬c(7) | 18 | ¬a Backjumping

Now ¬a is decided and we learn the conflict clause

 ¬a

we go back to search state

¬a(9) | 19 | Propagate ¬a(9), r(1) | 19 | Propagate (twice) ¬a(9), r(1), ¬b(6), ¬c(8) | 19 | Conflict ¬a(9), r(1), ¬b(6), ¬c(8) | 19 | b c Explain

Now we are in conflict and there is no decided literal, so we are gonna get UNSAT in any case, so we can stop.

If we are in conflict and there is no decided literal, we are gonna get UNSAT in any case, so we can stop

First Order Logic FOL

We need to formalise Sokratesʼ Syllogism (we cannot with propositional logic) Individual constants : names for single objects Predicates : property of objects Pradicate with 0 arguments, so 0-ary can be seen as propositional letters (constants symbol) Operetions :

  • has 2 argouments
  • has 2 argouments
  • has 2 argouments log has 1 argouments sin has 1 argouments If … then … else … has 3 argouments

Signature (first oder language / elementary language)

A language is composed by:

: set of operations symbols

: set of predicate symbols

: assigment of arity (number of arguments to elements of

ex:

(human)  1

L F P α

L

F

P

α F P

a

a

Ex: P )  P ): we have two occurences, but the first is bounded by , while the second one is free Sentence : formula s.t. no variables has a free occurrence in it Open formula : a formula without quantifiers Existential formula : a formula of the kind Universal formula : a formula of the kind

📖 Substitution : A : means that at most have a free occurrence in A A : means the result of the simultaneous substitution of all the free occurrences of by respectively when doing substitution, rename bound variables so that the terms you want to substitute do not contain the renamed variables example: If we want to replace x by y in y R(x, y) then rename y by yʼ yʼ R(x, yʼ) in the end replace x by y: yʼ R(y, yʼ)

Formal Notion of Truth

Revision of set theory

∃ x x x ∃ x

∃ x ...

∀ x ...

( x 1 , ..., x n ) x 1 , ..., xn

( t 1 / x 1 , ..., t n / x n )

x 1 , ..., xn t 1 , ..., tn

📌 Function ^ X^ ^ ^ Y is a correspondence that associetes with every x X a unique element of Y called (x)

Injective : if x is different then x , so are (x) and (x ) x x (x x → (x) (x )) x x ( (x) = (x ) → x = x )

Surjective : for every y Y there is an x X s. t. y = (x) y x ( (x) = y)

Bijective : injective + surjective X   Y If is bijective there is a s. t. :

y ( (y) = y)

x ( (x) = x) X   Y

When I have a Set and a subset : I can define a function, the characteristic function of the subset, which give me a Bool:

— ⟶ 0, 1

 1 iff Viceversa, given:

f

∈ f

1 f^ f^ 1

∀ ∀ 1 = 1 f = f 1

∀ ∀ 1 f f 1 1

∈ ∈ f

∀ ∃ f

f

f g

∀ gf

∀ fg

g

X S S ⊆ X

X vs

vs ( x ) x ∈ S