La presentazione è in caricamento. Aspetta per favore

La presentazione è in caricamento. Aspetta per favore

Programmazione Logica e ASP. Forma normale congiuntiva e clausole Un letterale è una formula atomica o la negazione di una formula atomica. Una clausola.

Presentazioni simili


Presentazione sul tema: "Programmazione Logica e ASP. Forma normale congiuntiva e clausole Un letterale è una formula atomica o la negazione di una formula atomica. Una clausola."— Transcript della presentazione:

1 Programmazione Logica e ASP

2

3 Forma normale congiuntiva e clausole Un letterale è una formula atomica o la negazione di una formula atomica. Una clausola è una disgiunzione di letterali: A 1... A n B 1... B m [con A i, B j atomi] equivalentemente, puo essere rappresentata in forma implicativa: B 1... B m A 1... A n Una formula in forma normale congiuntiva è una congiunzione di clausole. Qualsiasi formula proposizionale può essere convertita in una formula proposizionale in forma normale congiuntiva logicamente equivalente. Qualsiasi formula ben formata della logica dei predicati ø può essere convertita in una formula ben formata della logica dei predicati in forma normale congiuntiva ø. Si osservi che, 1. In generale ø non è logicamente equivalente a ø, ma 2. ø è insoddisfacibile sse ø è insoddisfacibile. Una Base della conoscenza (KB) è un insieme di clausole.

4 Risoluzione [I] Caso proposizionale con ( - { }) 1. { P, Q } 2. { P, R } 3. { Q, R }1,2 Il simbolo indica le clausole presenti inizialmente della ase della conoscenza. Esempio I simboli e indicano clausole, mentre è uno dei letterali che ne fanno parte (può naturalmente non essere lunico).

5 Procedura per Risoluzione Prooposizionale Premesse... KB φ sse KB φ sse KB {φ} insoddisfacibile sse KB {φ} incoerente KB φ Come dimostriamo KB φ ?

6 Esecuzione di un Programma [P] Una computazione corrisponde al tentativo di dimostrare, tramite la regola di risoluzione, che una formula (goal) segue logicamente da un insieme di formule (programma); cioè, che la formula e un teorema. Si deve determinare una sostituzione per le variabili del goal (detto anche query) per cui il goal segue logicamente dal programma. Dato un programma P e una query: :- S (t 1, t 2, …, t m ). se x 1, x 2, …, x n sono le variabili che compaiono in t 1, t 2, …, t m il significato logico della query e: x 1 x 2 … x n S (t 1, t 2, …, t m ) e lobiettivo e quello di trovare una sostituzione = [ x 1 / a 1, x 2 / a 2, …, x n / a n ] dove a i sono termini tale per cui P [S (t 1, t 2, …, t m )]

7 Risoluzione SLD Operativamente... La Risoluzione SLD seleziona un atomo A m dal goal G i secondo un determinato criterio, e lo unifica se possibile con la testa della clausola C i attraverso la sostituzione più generale: MOST GENERAL UNIFIER (MGU) Il nuovo risolvente e ottenuto da G i riscrivendo latomo selezionato con la parte destra della clausola C i ed applicando la sostituzione i. Più in dettaglio: :- A 1, …, A m-1, A m, A m+1, …,A k. Risolvente, A :- B 1, …, B k. clausola del programma P, e [A m ] i = [A] i allora la risoluzione SLD deriva il nuovo risolvente :- [A 1, …, A m-1, B 1, …, B q, A m+1, …, A k ] i.

8 Derivazione SLD Una derivazione SLD per un goal G 0 dallinsieme di clausole definite P e una sequenza di clausole goal G 0, …, G n, una sequenza di rinomine di clausole del programma C 1, …, C n, e una sequenza di sostituzioni MGU 1,…, n tali che G i+1 è derivato da G i e da C i+1 attraverso la sostituzione n. La sequenza può essere anche infinita. Esistono tre tipi di derivazioni: SUCCESSO, se per n finito G n è uguale alla clausola vuota G n = :-– FALLIMENTO FINITO, se per n finito non è più possibile derivare un nuovo risolvente da G n e G n non è uguale a :-– FALLIMENTO INFINITO, se è sempre possibile derivare nuovi risolventi tutti diversi dalla clausola vuota.

9 Non Determinismo Nella risoluzione SLD, così come è stata enunciata, si hanno due forme di non determinismo. La prima forma di non determinismo è legata alla selezione di un atomo A m del goal da unificare con la testa di una clausola, e viene gestita definendo una particolare regola di calcolo. La seconda forma di non determinismo è legata alla scelta di quale clausola del programma P utilizzare in un passo di risoluzione, e viene gestita definendo una strategia di ricerca.

10 Strategia di Ricerca Questa forma di non determinismo implica che possano esistere più soluzioni alternative per uno stesso goal, corrispondenti alle diverse scelte delle clausole con cui tentare lunificazione. La risoluzione SLD (completezza), deve essere in grado di generare tutte le possibili soluzioni e quindi deve considerare ad ogni passo di risoluzione tutte le possibili alternative. La strategia di ricerca deve garantire questa completezza Una forma grafica utile per rappresentare la risoluzione SLD e questa forma di non determinismo sono gli alberi SLD.

11 A 1... A m B 1 [ A 1,..., A m, B 1 ] [B 1 ] A 1... A m B 1 B 1 clausola di Horn una calusola con al più un letterale positivo Programmi logici: forma generale e terminologia

12 1.Mario è un architetto oppure è un geometra. Se Mario fosse architetto, allora Mario sarebbe laureato. Mario non è laureato. Quindi: Mario è un geometra. 2.Giovanni Paolo II è siciliano. Tutti i siciliani sono giardinieri. Quindi: Giovanni Paolo II è giardiniere. 3.Tutti i cigni osservati sinora in Europa sono bianchi. Tutti i cigni osservati sinora in Nord America sono bianchi. Tutti i cigni osservati sinora in Sud America sono bianchi […] Non sono mai stati osservati cigni che non fossero bianchi. Quindi: Tutti i cigni sono bianchi. 4.Lassassino ha sporcato di fango il tappeto. Chiunque fosse entrato dal giradino avrebbe sporcato di fango il tappeto. Quindi: Lassassino è entrato dal giardino. 5.Gli uccelli, salvo eccezioni/in genere, sono in grado di volare. Titti è un uccello. Quindi: Titti è in grado di volare. Alcune inferenze

13 Ragionamento non monotono Una nozione di inferenza e monotona se e solo se Г p implica Г A p mLa monotonia e la proprieta matematica di una funzione f tale per cui se x y, allora f(x) f(y).. mLa non monotonia e una proprieta definita per negazione (lassenza della monotonia). FOL è monotona... Al crescere della KB linsieme di inferenze può solo continuare crescere Prolog e ASP permettono di eseguire inferenze non monotone mIl ragionamento non monotono permette di trattare inferenze ragionando sullassenza di informazioni. mAl crescere di una KB, ci può essere lesigenza di ritrattare le inferenze fatte sulla base di ciò che non si conosce

14 Ragionamento non monotono E.g. rSupponiamo di codificare nella logica del primo ordine un orario ferroviario TrainFromTo(X,CittàPartenza,CittàArrivo,OrarioPart) rProviamo a chiederci... x TrainFromTo(X,Milano,Roma,14.50)...supponiamo non esista. In FOL dovremmo dimostrare: x TrainFromTo(X,Milano,Roma,14.50) mDovremmo dimostrare xTrainFromTo(X,Milano,Roma,14.50) Il fatto che non esista una dimostrazione di x TrainFromTo(X,Milano,Roma,14.50) non implica che ne esista una per x TrainFromTo(X,Milano,Roma,14.50)

15 Formal Knowledge Representation and Automated Reasoning for the Study of Archaeological Stratigraphy M. Cattani, G. Mantegari, A. Mosca, M. Palmonari Department of Archaeology, University of Bologna (Italy) Department of Informatics, Systems and Communication, University of Milan Bicocca (Italy)

16 Computerized stratigraphy has a long research history and brought to the creation of some succesfull softwares (e.g. ArchEd, Stratify) which can guarantee a quite satisfiable management of the stratigraphic sequences. Some problems concern: the difficulty to manage large/huge datasets the difficulty to integrate a digital matrix representation with other softwares (e.g. GIS) the difficulty to handle multilinear stratigraphic sequences the difficulty to manage uncertain or insufficient knowledge... At a more general level, which concerns the model itself, some other issues can be found. For example the Harris model has been criticized from different points of view (see the Harris-Carver debate) but it still represent the principal methology for modelling and representing the stratigraphic sequence. but...this is half of the problem...

17 A 1... A m B 1 clausola di Horn una calusola con al più un letterale positivo Programmi logici: forma generale e terminologia Atomi: A i = P(t), p, R(t1,t2) Letterali: L i = A i, A i Ground: P(a), p, R(a,b) … no variabili! Termini: X, marco, f(X), f(marco), f(f(X))

18 L 0 or... or L k :- L k+1... L m not L m+1... not L n rule : head body A 1... A m B 1 clausola di Horn una calusola con al più un letterale positivo Programmi logici: forma generale e terminologia A 0 :- A 1... A m not A m+1... not A n L 0 :- L 1... L m not L m+1... not L n L 0 :- A k :- A k+1... A m fact :- L 0... L m not L m+1... not L n constraint ( ) normal LPs extended LPs definite LPs disjunctive extended LPs ASP -not ASP A 0 or... or A k :- A k+1... A m not A m+1... not A n disjunctive LPs ASP or L 0 or... or L k :- L k+1... L m not L m+1... not L n ASP *= ASP,,or

19 L 0 or... or L k :- L k+1... L m not L m+1... not L n rule : head body A 1... A m B 1 clausola di Horn una calusola con al più un letterale positivo Programmi logici: forma generale e terminologia A 0 :- A 1... A m not A m+1... not A n L 0 :- L 1... L m not L m+1... not L n A k :- A k+1... A m normal LPs extended LPs definite LPs disjunctive extended LPs ASP -not ASP datalog = no simboli di funzione ASP A 0 or... or A k :- A k+1... A m not A m+1... not A n disjunctive LPs ASP or L 0 or... or L k :- L k+1... L m not L m+1... not L n ASP *= ASP,,or

20

21 The Answer set framework Answer set framework: -Axiom alphabet and language -Knowledge Base -Query alphabet and language -Entailment relation between a KB (a set of axioms) and a query

22 The project aims at proposing a new approach for the study of the archaeological stratigrafy by means of Computer Science techniques and tools Our main objective, in this phase, are to investigate: the possibility of modelling the stratigraphy by means of formal knowledge representation the possibility of performing automated reasoning with respect to: the spatial component the temporal component We are not interested, in this phase, to the visualization of the stratigraphic sequence. In our vision, the graphical representation is just the last step and, provided the logical model is adequate and the automatic reasoning works well, it is a minor problem. Of course we aim at realizing a software or a set of tools, but at the moment we focus mainly on the creation of a fomal model rather than on the specification of the software requirements.

23 Why do we care about KR? PROBLEM SOLUTION 1 1 STRATIGRAPHY: From the spatial relationship between the strata of an excavation find the temporal succession of such strata STRATIGRAPHY: A succession of the strata

24 ASP Alphabets & language ASP alphabet: variables X,Y,... (capital letter notation) connectives {,or,,not,,} (often :- instead of ) punctuation symbols{(,),.} the special symbol object constants function symbols predicate symbols (propositional symbols as 0-ary predicate!) Term definition: A variable is a termE.g. X Y A constant is a termE.g. marco If t1,...,tn are terms, f(t1,...,tn) is a term.E.g. f(marco,X) A term is ground if it does not contain any variable

25 A l p h a b e t Example Variables (Terms) X, Y, Z,... Constants (Terms) us1, us2, us3,... Unary Predicates (Atoms) cutUnit(X), trench(X), wall(X),... Binary Predicates (Atoms) cover(X,Y), fill(X,Y), cut(X,Y),... Positive & Negative Literals (Atoms or Classically Negated Atoms) wall(X), cut(X,Y),..., cover(X,Y), fill(X,Y),... Ground Literals cover(u6,u3), filledBy(u4,u8),... naf-Literals (Atoms or Atoms preceeded by not )..., not cover(X,Y), not fill(X,Y),... Rules dirPostTo(Z,Y) :- equalTo(X,Y),cover(Z,X). contemporary(X,Y) :- equalTo(X,Y). Constraints :- attachTo(X,X). Facts equal(X,X). cover(u6,u3).

26 L 0 or... or L k :- L k+1... L m not L m+1... not L n rule : head body A 0 :- A 1... A m not A m+1... not A n L 0 :- L 1... L m not L m+1... not L n L 0 :- A k :- A k+1... A m fact :- L 0... L m not L m+1... not L n constraint ( ) normal LPs extended LPs definite LPs disjunctive extended LPs ASP -not ASP A 0 or... or A k :- A k+1... A m not A m+1... not A n disjunctive LPs ASP or L 0 or... or L k :- L k+1... L m not L m+1... not L n ASP *= ASP,,or ASP Alphabets & language

27 ASP Semantics For ASP Datalog the Herbrand Base can be easily built (it is finite!)

28 AS ground programs: principles ASP rules: L 0 or... or L k :- L k+1... L m not L m+1... not L n A rule is said to be ground if all the literals of the rule are gorund The answer set language given by a alphabet consists of the set of all ground rules contructed from the symbols of the alphabet A answer set program Π: a set of rules A program Π identifies an alphabet used by Π (predicates, constants, function symbols) ground(Π): the set of goround rules obtained with the alphabet used in Π Intensional part of KB: axioms with body, constraints Extensional part of KB: the set of facts

29 Unary Predicates (Atoms) cutUnit(X), trench(X), wall(X),... Binary Predicates (Atoms) cover(X,Y), fill(X,Y), cut(X,Y),... Positive & Negative Literals (Atoms or Classically Negated Atoms) wall(X), cut(X,Y),..., cover(X,Y), fill(X,Y),... Ground Literals cover(u6,u3), filledBy(u4,u8),... Rules dirPostTo(Z,Y) :- equalTo(X,Y),cover(Z,X). contemporary(X,Y) :- equalTo(X,Y). contemporary(X,Y) v posteriorTo(X,Y) v posteriorTo(Y,X) :- us(X),us(Y), not posteriorTo(X,Y), not -posterior(X,Y). Constraints :- attachTo(X,X). Facts equal(X,X). cover(u6,u3). A l p h a b e t And Rules

30 Unary Predicates (Atoms) cutUnit(X), trench(X), wall(X),... Binary Predicates (Atoms) cover(X,Y), fill(X,Y), cut(X,Y),... Positive & Negative Literals (Atoms or Classically Negated Atoms) wall(X), cut(X,Y),..., cover(X,Y), fill(X,Y),... Ground Literals cover(u6,u3), filledBy(u4,u8),... Rules dirPostTo(Z,Y) :- equalTo(X,Y),cover(Z,X). contemporary(X,Y) :- equalTo(X,Y). contemporary(X,Y) v posteriorTo(X,Y) v posteriorTo(Y,X) :- us(X),us(Y), not posteriorTo(X,Y), not -posterior(X,Y). Constraints :- attachTo(X,X). Facts equal(X,X). cover(u6,u3). A l p h a b e t And Rules Ground rules: All the rules built by substituting the variables with the set of constants given in the alphabet (all the possible combination!) us1, us2, us3,...

31 Unary Predicates (Atoms) cutUnit(X), trench(X), wall(X),... Binary Predicates (Atoms) cover(X,Y), fill(X,Y), cut(X,Y),... Positive & Negative Literals (Atoms or Classically Negated Atoms) wall(X), cut(X,Y),..., cover(X,Y), fill(X,Y),... Ground Literals cover(u6,u3), filledBy(u4,u8),... Rules contemporary(X,Y) :- equalTo(X,Y). contemporary(us1,us2) :- equalTo(us1,us2). contemporary(us1,us3) :- equalTo(us1,us3). contemporary(us2,us3) :- equalTo(us2,us3). … Constraints :- attachTo(X,X). Facts equal(X,X). cover(u6,u3). A l p h a b e t And Rules Ground rules: All the rules built by substituting the variables with the set of constants given in the alphabet (all the possible combination!) us1, us2, us3,...

32 ASP Semantics: principles ASP semantics is based on answer sets (close to stable models) Strategy: semantics for mASP -not mASP ASP ASP *= ASP,,or

33 ASP Semantics: principles Informally, an answer set S of a ground program Π is a set of ground literals such that every rule is satisfied by S, i.e., for any rule in Π A B 1, …, B m, not C 1, …, not C n. if B j s are satisfied (B j s are in S ) and C j s are not satisfied (not C j is satisfied if C j is not in S ), then A is in S.

34 ASP Semantics: principles Which are the answer sets for a program Π? rInformally, given a program Π: mgenerate ground(Π) mgenerate all the possible models s 1,…, s n for Π, mfor all s i check if ground(Π) is satisfied by s i mfor all s i satisfying ground(Π), check which of them are minimal mthese are answer sets for Π rWhat is meant to be a model? mVia Herbrand base, literal set (for true negation) rProgram transformation for programs with not

35 How ASP differs from … Prolog: ordering matters in Prolog; can not handle cycles with not; has extra-logical features; does not have disjunction and classical negation; and is not declarative. Logic Programming: is a class of languages and many FOL: mClassical logic is monotonic. m in AnsProlog, which helps in expressing causality, is not reverse implication. mDisjunction symbol or in AnsProlog is non-classical. mThe negation as failure symbol not in AnsProlog is non- classical.

36 formally...

37 L 0 :- L 1... L m not L m+1... not L n

38

39 ASP: Gelfond-Lifshitz transformation In order to give the semantics to a ASP program (containing not) we have to apply the Gelfond-Lifshitz transformation to the program. Then proceed as usual….

40

41

42 Brave vs. Cautious Reasoning rBRAVE (credolous) reasoning mA query is bravely true for a substitution if it is satisfied in at least one model of the program. E.g. P(X)? if P(a)?,P(b)?... rCAUTIOUS (skeptical) reasoning mA query is cautiously true for a substitution if it is satisfied in all models of the program.

43 L 0 or... or L k :- L k+1... L m not L m+1... not L n rule : head body A 0 :- A 1... A m not A m+1... not A n L 0 :- L 1... L m not L m+1... not L n L 0 :- A k :- A k+1... A m fact :- L 0... L m not L m+1... not L n constraint ( ) normal LPs extended LPs definite LPs disjunctive extended LPs ASP -not ASP A 0 or... or A k :- A k+1... A m not A m+1... not A n disjunctive LPs ASP or L 0 or... or L k :- L k+1... L m not L m+1... not L n ASP *= ASP,,or ASP Alphabets & language

44 OR programs p | q :- s. c :- p. c :- q. s. p? (cautiously / bravely)

45 Tweety ASP fly(X) :- bird(X), not ab(X). ab(X) :- penguin(X). bird(X) :- penguin(X). bird(tweety). penguin(skippy). -fly(tweety)? fly(X)?

46 Tweety ASP fly(X) :- bird(X), not -fly(X). -fly(X) :- penguin(X). bird(tweety). bird(rocky). penguin(rocky).

47 Dottorandi... -haSoldi(X) :- dottorando(X), not ricco(X). maldive(X) :- ricco(X). -maldive(X) :- -ricco(X). dottorando(marco). Generalmente, i dottorandi non sono ricchi. Alle maldive ci va chi è ricco. Marco è un dottorando Queries: Marco va alle maldive? Chi va alle maldive? maldive(marco)? not maldive(marco)? -maldive(marco)? maldive(X)? -maldive(X)?

48 Dottorandi... -haSoldi(X) :- dottorando(X), not ricco(X). maldive(X) :- ricco(X). -maldive(X) :- -ricco(X). dottorando(marco). Generalmente, i dottorandi non sono ricchi. Alle maldive ci va chi è ricco. Marco è un dottorando Queries: Marco va alle maldive? Chi va alle maldive? maldive(marco)? not maldive(marco)? -maldive(marco)? maldive(X)? -maldive(X)?

49 -ruba(X) :- dottorando(X), not ruba(X). ricco(X) :- vinceTotip(X). ricco(X) :- ruba(X). ruba(X) :- ladro(X). ladro(X) :- stressato(X), not -ladro(X). stressato(marco). Si diventa ricchi ribando e/o vincendo il totip. I ladri rubano, ma generalmente, i dottorandi no; tuttavia le persone stressate possono diventare dei ladri. Marco è stressato Dottorandi...updating the KB

50 ricco(X) :- riceveRegalo(X). riceveRegalo(X) :- faRegalo(Y,X). faRegalo(X,Y) :- generoso(X), amico(X,Y), not -faRegalo(X,Y). generoso(maria). amico(maria,marco). -ruba(X) :- faRegalo(Y,X). Un altro modo per diventare ricchi è ricevere regali. Per ricevere un regalo occorre che qualcuno lo faccia il regalo. In genere (se non so il contrario?) se una persona è amico/a di unaltra persona ed è una persona generosa le fa un regalo. Maria è un amica di Marco molto generosa. Dottorandi...updating the KB II

51 Dottorandi... -haSoldi(X) :- dottorando(X), not ricco(X). maldive(X) :- ricco(X). -maldive(X) :- -ricco(X). dottorando(marco). Generalmente, i dottorandi non sono ricchi. Alle maldive ci va chi è ricco. Marco è un dottorando Queries: Marco va alle maldive? Chi va alle maldive? maldive(marco)? not maldive(marco)? -maldive(marco)? maldive(X)? -maldive(X)?

52 -ruba(X) :- dottorando(X), not ruba(X). ricco(X) :- vinceTotip(X). ricco(X) :- ruba(X). ruba(X) :- ladro(X). ladro(X) :- stressato(X), not -ladro(X). stressato(marco). Si diventa ricchi ribando e/o vincendo il totip. I ladri rubano, ma generalmente, i dottorandi no; tuttavia le persone stressate possono diventare dei ladri. Marco è stressato Dottorandi...updating the KB

53 ricco(X) :- riceveRegalo(X). riceveRegalo(X) :- faRegalo(Y,X). faRegalo(X,Y) :- generoso(X), amico(X,Y), not -faRegalo(X,Y). generoso(maria). amico(maria,marco). -ruba(X) :- faRegalo(Y,X). Un altro modo per diventare ricchi è ricevere regali. Per ricevere un regalo occorre che qualcuno lo faccia il regalo. In genere (se non so il contrario?) se una persona è amico/a di unaltra persona ed è una persona generosa le fa un regalo. Maria è un amica di Marco molto generosa. Dottorandi...updating the KB II

54


Scaricare ppt "Programmazione Logica e ASP. Forma normale congiuntiva e clausole Un letterale è una formula atomica o la negazione di una formula atomica. Una clausola."

Presentazioni simili


Annunci Google