Datalog S. Costantini.

Slides:



Advertisements
Presentazioni simili
Trieste, 26 novembre © 2005 – Renato Lukač Using OSS in Slovenian High Schools doc. dr. Renato Lukač LinuxDay Trieste.
Advertisements

Sfogliandomi… Viaggio tra me e me alla scoperta dellaltro… A travel between me and myself discovering the other…
Preposizioni semplici e articolate
I numeri, l’ora, I giorni della settimana
Giovanni Falcone & Paolo Borsellino.
Cache Memory Prof. G. Nicosia University of Catania
Prof. Stefano Bistarelli
Teoria e Tecniche del Riconoscimento
1 Teaching Cloud Computing and Windows Azure in Academia Domenico Talia UNIVERSITA DELLA CALABRIA & ICAR-CNR Italy Faculty Days 2010.
Obiettivo: To be confident when describing yourself and others
DG Ricerca Ambientale e Sviluppo FIRMS' FUNDING SCHEMES AND ENVIRONMENTAL PURPOSES IN THE EU STRUCTURAL FUNDS (Monitoring of environmental firms funding.
Sequential Statements. – Il VHDL simula lo svolgersi in parallelo di varie operazioni – Loggetto fondamentale e il PROCESS – Un PROCESS contiene una serie.
Prof. Mario Pavone - crentro di ricerca IPPARI
Grammar Tips. Meanings of verbs in the present May describe things that are continuing over a period of time.
Each student will be able to ask an adult or stranger: What do you like to do? and What dont you like to …?
Interrogativi Asking and answering questions in italiano.
piacere The verb to like does not have a direct equivalent in Italian.
Cancer Pain Management Guidelines
A. Nuzzo U.O. di Oncologia Medica ospedale Renzetti di Lanciano (CH)
Sta andando meglio? oppure ti senti uguale? Is it getting better? Or do you feel the same?
Che ore è? Che ore Sono?.
© and ® 2011 Vista Higher Learning, Inc.4B.2-1 Punto di partenza The verbs conoscere and sapere both mean to know. The choice of verb depends on its context.
Punto di partenza Reciprocal verbs are reflexives that express a shared or reciprocal action between two or more people or things. In English we often.
Il presente del congiuntivo (the present subjunctive)
Il presente del congiuntivo (the present subjunctive)
Raffaele Cirullo Head of New Media Seconda Giornata italiana della statistica Aziende e bigdata.
J0 1 Marco Ronchetti - Corso di Formazione Sodalia – Febbraio 2001 – Modulo Web Programming Tomcat configuration.
C Consiglio Nazionale delle Ricerche - Pisa Iit Istituto per lInformatica e la Telematica Reasoning about Secure Interoperation using Soft Constraints.
1. Conoscere luso delle collezioni in Java Comprendere le principali caratteristiche nelle varie classi di Collection disponibili Saper individuare quali.
Metodi di simulazione numerica in Chimica Fisica Dario Bressanini Universita degli Studi dellInsubria III anno della Laurea triennale in Scienze Chimiche.
2000 Prentice Hall, Inc. All rights reserved. 1 Capitolo 3 - Functions Outline 3.1Introduction 3.2Program Components in C++ 3.3Math Library Functions 3.4Functions.
SQL Esercitazione per il corso “Basi di Dati” Gabriel Kuper
Magnetochimica AA Marco Ruzzi Marina Brustolon
Chistmas is the most loved holiday of the years. Adults and children look forward to Chistmas and its magical atmosphere. It is traditional to decorate.
Le regole Giocatori: da 2 a 10, anche a coppie o a squadre Scopo del gioco: scartare tutte le carte per primi Si gioca con 108 carte: 18 carte.
SOURCE TERM ON NPP SAFETY ANALYSES Marino Mazzini Professore Ordinario nel s.s.d. Impianti Nucleari Università di Pisa Facoltà di Ingegneria Dipartimento.
Concord A tool for the analysis and concordances of the terminological constituents P. Plini, N. Mastidoro* * - Èulogos, Rome Institute for Atmospheric.
Che cosa ti metti per…? Obiettivo: To be able to say what you wear for different occasions using the verb mettersi correctly venerdì il 20 settembre.
Alcuni, qualche, un po’ di
Guardate le seguenti due frasi:
Motor Sizing.
My Italian Experience By Ryan Davidson. My daily routine in Urbino If there was no field trip in the morning, my daily routine in Urbino was very basic.
La Gioconda was painted by which Italian renaissance artist? a) Raphael b) Leonardo da Vinci c) Caravaggio d) Michelangelo.
Tutor: Elisa Turrini Mail:
Enzo Anselmo Ferrari By Giovanni Amicucci. Di Enzo Questo è Enzo Anselmo Ferrari. Enzo compleanno è diciotto febbraio Enzo muore è quattordici agosto.
FOR EVERY CALLOUT THAT YOU WILL SEE IN ENGLISH PROVIDE (IN WRITING) THE CORRECT ITALIAN SENTENCE OR EXPRESSION. REMEMBER TO LOOK AT THE VERBS AND PAY.
Present Perfect.
UG40 Energy Saving & Twin Cool units Functioning and Adjustment
The Unìversal Declaratìon of Human Rìghts MìKèLa GaBrìèLLì … 3°G …ù.ù.
Collection & Generics in Java
EMPOWERMENT OF VULNERABLE PEOPLE An integrated project.
LA WEB RADIO: UN NUOVO MODO DI ESSERE IN ONDA.
You’ve got a friend in me!
A PEACEFUL BRIDGE BETWEEN THE CULTURES TROUGH OLYMPICS OLYMPIC CREED: the most significant thing in the olympic games is not to win but to take part OLYMPIC.
IL GIUDIZIO FINALE THE LAST JUDGMENT Quando il Figlio dell’uomo verrà nella sua Gloria con tutti i suoi angeli, si siederà sul trono della sua gloria.
Passato Prossimo. What is it?  Passato Prossimo is a past tense and it is equivalent to our:  “ed” as in she studied  Or “has” + “ed” as in she has.
Saluti ed espressioni Greetings in Italian.
Italian 1 -- Capitolo 2 -- Strutture
Ratifica dei trattati internazionali - Italia Art. 87 Costituzione “Il Presidente della Repubblica…ratifica i trattati internazionali, previa, quando occorra,
Buon giorno Io sono Professoressa Kachmar. Buon giorno Io sono Professoressa Kachmar.
DatalogDatalog S. Costantini. S. Costantini / Logical Query Languages 2 Logic As a Query Language If-then logical rules have been used in many systems.
Accoppiamento scalare
SUMMARY Time domain and frequency domain RIEPILOGO Dominio del tempo e della frequenza RIEPILOGO Dominio del tempo e della frequenza.
MSc in Communication Sciences Program in Technologies for Human Communication Davide Eynard Facoltà di scienze della comunicazione Università della.
WRITING – EXERCISE TYPES
AusTel by taha.a.
Il condizionale.
La Grammatica Italiana Avanti! p
The Behavioral Insight Team
Transcript della presentazione:

Datalog S. Costantini

Datalog base: notazione, esempi, semantica S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP A language for Deductive Databases Extensional part: tables Intensional part: rules S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP Logic: Intuition S. Costantini / Datalog e ASP

Datalog Terminology: Atoms An atom is a predicate, or relation name with variables or constants as arguments. E.g., in(alan,r123) part_of(r123,cs_building) p(X,a) S. Costantini / Datalog e ASP

Datalog Terminology: Atoms Conventions: Databases: Predicates begin with a capital, variables begin with lower-case. Example: P(x,’a’) where ‘a’ is a constant, i.e., a data item. Logic Programming: Variables begin with a capital, predicates and constants begin with lower-case. Example: p(X,a). S. Costantini / Datalog e ASP

Datalog Terminology: Rules The head of a rule is an atom; the body of a rule is the AND of one or more atoms. E.g., in(X,Y):- part_of(Z,Y), in(X,Z). where “:-” stands for “” S. Costantini / Datalog e ASP

Datalog Terminology: Rules Rules without body: E.g., in(alan,r123). S. Costantini / Datalog e ASP

Datalog and Transitivity Rule in(X,Y):- part_of(X,Z),in(Z,Y) defines in as the transitive closure of part_of S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP Arithmetic Subgoals In addition to relations as predicates, a predicate of the body can be an arithmetic comparison. We write such atoms in the usual way, e.g.: x < y. S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP Example: Arithmetic A beer is “cheap” if there are at least two bars that sell it for under $2. cheap(Beer) :- sells(Bar1,Beer,P1), sells(Bar2,Beer,P2), P1 < 2.00, P2 < 2.00, Bar1 <> Bar2. S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP Terminology: p  q, not r. or p :- q, not r. is a rule, where p is the head, or conclusion, or consequent, and q, not r is the body, or the conditions, or the antecedent. p, q and r are atoms. A rule without body, indicated as p . or p. Is called a unit rule, or a fact. This kind of rules ale also called Horn Clauses. S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP Terminology: p  q, not r Atoms in the body can be called subgoals. Atoms which occur positively in the body are positive literals, and the negations are negative literals. S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP Terminology: p  q, not r We say that p depends on q and not r. The same atom can occur in a rule both as a positive literal, and inside a negative literal (e.g. rule p  not p). S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP Datalog Programs A Datalog theory, or “program”, is a collection of rules. In a program, predicates can be either EDB = Extensional Database = facts. IDB = Intensional Database = relation defined by rules. S. Costantini / Datalog e ASP

Expressive Power of Datalog Without recursion, Datalog can express all and only the queries of core relational algebra. But with recursion, Datalog can express more than these languages. Yet still not Turing-complete. S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP Example p(X) r(X),q(X). r(Z)  s(Z). s(a). s(b). q(b). In every rule, each variable stands for the same value. Thus, variables can be considered as “placeholders” for values. Possible values are those that occur as constants in some rule/fact of the program itself. S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP Its grounding can be obtained by: considering the constants, here a,b. substituting variables with constants in any possible (coherent) way) E. g., the atom r(Z) is transformed by grounding over constants a, b into the two ground atoms r(a), r(b). S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP Grounding E. g., the atom r(Z) is transformed by grounding over constants a, b into the two ground atoms r(a), r(b). Rule r(Z)  s(Z). is transformed into the two rules r(a)  s(a). r(b)  s(b). S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP Grounding of the program p(a)  r(a),q(a). p(b)  r(b),q(b). r(a)  s(a). r(b)  s(b). s(a). s(b). q(b). Semantics: Least Herbrand Model M = {s(a),s(b),q(b),r(a),r(b),p(b)} S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP A shortcut of the grounded program p1  r1,q1. p2  r2,q2. r1  s1. r2  s2. s1. s2. q2. M = {s1,s2,q2,r1,r2,p2} S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP Datalog semantics Without negation (no negative literal in the body of rules): Least Herbrand Model The head of a rule is in the Least Herbrand Model only if the body is in the Least Herbrand Model. S. Costantini / Datalog e ASP

Least Herbrand Model: Intuition S. Costantini / Datalog e ASP

Least Herbrand Model: Intuition In the example: Least Herbrand Model M0 = {in(alan,r123), part_of(r123,cs_building)} M1= {in(alan,r123), part_of(r123,cs_building), in(alan,cs_building)} S. Costantini / Datalog e ASP

Least Herbrand Model: How to find it p g,h. g  r,s. m  p,q. r  f. s. f. h. Step 1: facts M0 = {s,f,h} Step 2: M1 = M0 plus what I can derive from facts M1 = {s,f,h,r} Step 3: M2 = M1 plus what I can derive from M1 M2 = {s,f,h,r,g} Step 4: M3 = M2 plus what I can derive from M2 M3 = {s,f,h,r,g,p} If you try to go on, no more added conclusions: fixpoint S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP Datalog con Negazione S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP Negated Subgoals We may put NOT in front of an atom, to negate its meaning. Example: at_home(alan):- not at_work(alan). S. Costantini / Datalog e ASP

Negated Subgoals: Intuition Given atom A, not A holds if A cannot be proved Negation as finite failure S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP Minimal Models When there is no negation, a Datalog program has a unique minimal model (one that does not contain any other model). But with negation, there can be several minimal models. S. Costantini / Datalog e ASP

Cos’è un modello minimo: è un insieme di atomi Data una regola A:- B1,...,Bn,not C1,...,not Cm Un modello è un insieme di atomi che se NON contiene C1,...,Cm e contiene B1,...,Bn allora deve contenere A Un modello minimo non è sovrainsieme di un altro modello S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP Datalog semantics With negation: several proposals, in deductive databases Answer Set Semantics. Based on Answer Set Semantics: Answer Set Programming, new logic programming paradigm S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP Safe Rules A rule is safe if: Each variable in the head Each variable in an arithmetic subgoal, Each variable in a negated subgoal, also appears in a nonnegated, subgoal in the body. We allow only safe rules. S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP Example: Unsafe Rules Each of the following is unsafe and not allowed: s(X) :- r(Y). s(X) :- r(Y), not r(X). s(X) :- r(Y), X < Y. In each case, an infinity of X ’s can satisfy the rule, even if R is a finite relation. S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP Non-Monotonicità Aggiungere nuove conoscenze può portare a ritrarre precedenti conclusioni. Vi possono essere conclusioni alternative tramite cicli sulla negazione. S. Costantini / Datalog e ASP

Non-Monotonicità = Problema? No, se gestita con opportuni strumenti semantici Non-Monotonic Reasoning (NMR) = campo di ricerca in Intelligenza Artificiale Database deduttivi si propone di sfruttare la non-monotonicità S. Costantini / Datalog e ASP

DATALOG senza Negazione Semantica del Least Herbrand Model Paradigma procedurale della ricerca per tentativi ripetuti Linguaggio Prolog (numerosi interpreti fra i quali SICSTUS-Prolog, SWI-Prolog) S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP DATALOG + Negazione Semantica degli Answer Sets Paradigma dell’Answer Set Programming (ASP) Negazione, insiemi-risposta alternativi Numerosi solver S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP Esempio NMR persona(anna). persona(carlo). persona(giorgio). malato(giorgio). a_casa(X):- persona(X), not in_ufficio(X). in_ufficio(X):- persona(X), not a_casa(X). :- in_ufficio(X),malato(X). % constraint S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP Risultato atteso Anna e Carlo sono o a casa oppure in ufficio. Giorgio non può essere in ufficio perchè è malato e quindi sarà a casa. S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP NMR in pratica Vi sono vari linguaggi logici che consentono non-monotonicità. Sono dotati di motori inferenziali (inference engines, o solvers) in grado di gestirla. Possibili soluzioni inesistenti o altrernative. Uno di essi: smodels S. Costantini / Datalog e ASP

Risultato di smodels (inference engine per NMR) Answer: 1 malato(giorgio) a_casa(giorgio) a_casa(carlo) in_ufficio(anna) Answer: 2 malato(giorgio) a_casa(giorgio) in_ufficio(carlo) in_ufficio(anna) S. Costantini / Datalog e ASP

Risultato di smodels (inference engine per NMR) Answer: 3 malato(giorgio) a_casa(giorgio) in_ufficio(carlo) a_casa(anna) Answer: 4 malato(giorgio) a_casa(giorgio) a_casa(carlo) a_casa(anna) S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP Datalog con negazione: nuovo Paradigma di Programmazione Logica Answer Set Programming (ASP) basato su Answer Set Semantics S. Costantini / Datalog e ASP

Uno sguardo sull’Answer Set Programming (ASP) S. Costantini / Datalog e ASP

Example: 3-coloring in ASP Assigning colors red/blue/green to vertices of a graph, so as no adjacent vertices have the same color. node(0..3). col(red). col(blue). col(green). edge(0,1). edge(1,2). edge(2,0). edge(1,3). edge(2,3). S. Costantini / Datalog e ASP

3-coloring in Answer Set Programming color(X,red) | color(X,blue) | color(X,green) :- node(X). :- edge(X,Y), col(C), color(X,C), color(Y,C). % I constraint (regole con conclusione vuota) % specificano cosa *non può* essere vero S. Costantini / Datalog e ASP

Come “eseguire” il programma? Si usa un “Motore Inferenziale”, ad esempio SMODELS (ma ce ne sono diversi) Esso fornisce le soluzioni al problema dato come “insiemi risposta, appunto “Answer Set” … S. Costantini / Datalog e ASP

Come “eseguire” il programma? Sintassi: lparse < 3col.txt | smodels 0 lparse effettua il parsing del programma dato e ne produce il grounding smodels calcola le risposte (smodels 0 le chiede tutte) … S. Costantini / Datalog e ASP

Cosa si ottiene nell’esempio? Answer1 color(0,red), color(1,blue), color(green), color(3,red) Answer2 color(0,red), color(1,green), color(blue), color(3,red) … % e tutte le altre colorazioni, ognuna come % “Answer Set” S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP Answer Set Semantics: su cosa si basano gli Answer Set e come si ottengono S. Costantini / Datalog e ASP

Cos’è un modello minimo: è un insieme di atomi Data una regola A:- B1,...,Bn,not C1,...,not Cm Un modello è un insieme di atomi che se NON contiene C1,...,Cm e contiene B1,...,Bn allora deve contenere A Un modello minimo non è sovrainsieme di un altro modello S. Costantini / Datalog e ASP

Modelli minimi Datalog I fatti fanno parte di tutti i modelli minimi Tutto ciò che si deriva in modo aciclico dai fatti fa parte di tutti i modelli minimi not A vale solo se non vale A S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP Esempio a:- not b. b:- e, not c. c. e. M = {c, e, a} S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP Esempio a:- not b. b:- not a. d:- c. c M1 = {c, d, a} M2 = {c, d, b} Cicli: vari modelli (diversi Answer Sets) S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP Cos’è un Answer Set E’ un modello minimo dove però dati due qualunque atomi che ne fanno parte, nessuno di essi può dipendere (direttamente o indirettamente) dalla negazione dell’altro (negazione coerente) S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP Esempio a:- not b. b:- not a. p:- not p, not a. {b,p} modello minimo, NO answer set {a} modello minimo, answer set S. Costantini / Datalog e ASP

Come si trovano gli Answer Set Cicli pari (dipendenze cicliche che coinvolgono un numero pari di atomi) a:- not b. b:- not a. M1 = {a} M2 = {b} S. Costantini / Datalog e ASP

Come si trovano gli Answer Set Cicli pari a:- not b. b:- not c. c:- not d. d:- not a. M1 = {a,c} M2 = {b,d} S. Costantini / Datalog e ASP

Come si trovano gli Answer Set Ogni ciclo pari ha due Answer Set, uno costituito dagli atomi “pari” del ciclo, l’altro da quelli “dispari”. Se vi sono diversi cicli pari, gli answer set si combinano S. Costantini / Datalog e ASP

Come si trovano gli Answer Set a:- not b. e:- not f. b:- not c. f:- not e. c:- not d. d:- not a. M11 = {a,c,e} M12 = {a,c,f} M21 = {b,d,e} M22 = {b,d,f} S. Costantini / Datalog e ASP

Come si trovano gli Answer Set Cicli dispari (dipendenze cicliche che coinvolgono un numero dispari di atomi) p:- not p. No Answer Set: contraddizione sulla negazione {p} S. Costantini / Datalog e ASP

Come si trovano gli Answer Set Cicli dispari (dipendenze cicliche che coinvolgono un numero dispari di atomi) a:- not b. b:- not c. c:- not a. No Answer Set: contraddizione sulla negazione Es. {a,c} {a,b} {b,c} S. Costantini / Datalog e ASP

Come si trovano gli Answer Set Programmi con cicli dispari: possono avere Answer Set solo se: vi sono anche cicli pari vi sono connessioni fra cicli pari e dispari che “rimuovono” le contraddizioni Chiamiamo queste speciali connessioni “Handle” S. Costantini / Datalog e ASP

Come si trovano gli Answer Set: OR Handle OR Handle: legata a regola alternativa per uno degli atomi del ciclo dispari a:- not b. p:- not p. b:- not a. p:- a. OR handle M = {a,p} S. Costantini / Datalog e ASP

Come si trovano gli Answer Set OR Handle: legata a regola alternativa per uno degli atomi del ciclo dispari a:- not b. p:- not q. b:- not a. q:- not r. r:- not p. q:- not b. OR handle M = {a,q,r} S. Costantini / Datalog e ASP

Come si trovano gli Answer Set OR handle: regola alternativa per un qualche atomo che fa parte del ciclo dispari. Il corpo deve essere VERO per “supportare” l’atomo S. Costantini / Datalog e ASP

Come si trovano gli Answer Set AND Handle: letterale aggiuntivo in una delle regole del ciclo dispari: a:- not b. p:- not p, not a. AND b:- not a. handle M = {a} S. Costantini / Datalog e ASP

Come si trovano gli Answer Set Cicli dispari: Answer set se Handle da cicli pari a:- not b. p:- not p, a. AND b:- not a. handle M = {b} S. Costantini / Datalog e ASP

Come si trovano gli Answer Set Cicli dispari: Answer set se Handle da cicli pari AND handle: letterale L (A oppure not A) nel corpo di una regola del ciclo dispari, dove A fa parte di un ciclo pari. L deve essere FALSO per “aprire” il ciclo dispari rendendo falso uno dei suoi atomi S. Costantini / Datalog e ASP

Come si trovano gli Answer Set Si cercano gli Answer Set della parte aciclica “di base” del programma Si cercano gli Answer Set dei cicli pari Si combinano le due componenti Si estendono alla parte aciclica “intermedia” (se c’è) Fra gli Answer Set risultanti si selezionano quelli (se vi sono) che forniscono handle ai cicli dispari Si riconsidera la parte aciclica “top” rimanente (se c’è) S. Costantini / Datalog e ASP

Come si trovano gli Answer Set c. p:- not p. d:- c. p:- e. a:- not b. g:- p. b:- not a. e:- b. h:- b,p. S. Costantini / Datalog e ASP

Come si trovano gli Answer Set: parte aciclica di base d:- c. M1 = {c,d} S. Costantini / Datalog e ASP

Come si trovano gli Answer Set: ciclo pari e parte aciclica intermedia a:- not b. b:- not a. e:- b. M1 = {c,d} M11 = {a,c,d} M12 = {b,c,d,e} S. Costantini / Datalog e ASP

Come si trovano gli Answer Set: ciclo dispari e parte aciclica”top” p:- not p. p:- e. g:- p. Si seleziona M12 per dare la OR handle all’atomo p. M = {b,c,d,e,p,g} S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP Caso problematico p:- not p, not a. q:- not q, not b. a:- not b. b:- not a. Per ciclo pari M1 = {a} M2 = {b} ma non abbiamo le due AND handle per i cicli dispari (richiesta contraddittoria): no Answer Set S. Costantini / Datalog e ASP

Caso problematico Risolto p:- not p, not a. p:- e. q:- not q, not b. a:- not b. e:- not f. b:- not a. f:- not e. Per cicli pari M11 = {a,e} M12 = {a,f} M21 = {b,e} M12 = {b,f} Con M21 otteniamo M1 = {b,p,e} S. Costantini / Datalog e ASP

S. Costantini / Datalog e ASP ASP più in dettaglio S. Costantini / Datalog e ASP

Answer Set Programming Constraints :- v,w,z. rephrased as p :- not p, v,w,z. S. Costantini / Datalog e ASP

Answer Set Programming Disjunction v | w |z. rephrased as v :- not w, not z. w :- not v, not z. z :- not v, not w. S. Costantini / Datalog e ASP

Answer Set Programming Choice (XOR) v+w+z. rephrased as v | w | z. :- w, z. :- v, z. :- v, w. S. Costantini / Datalog e ASP

Answer Set Programming Classical Negation ¬p - p :- q,r. rephrased as p' :- q,r. :- p,p‘ S. Costantini / Datalog e ASP

Answer Set Programming A party: guests that hate each other cannot seat together, guests that love each other should sit together table(1..3). guest(1..5). hates(1,3). hates(2,4). hates(1,4). hates(2,3). hates(4,5). hates(1,5). likes(2,5). S. Costantini / Datalog e ASP

Answer Set Programming % Choice rules 1{at_table(P,T) : table(T)}1 :- guest(P). 0{at_table(P,T) : guest(P)}3 :- table(T). S. Costantini / Datalog e ASP

Answer Set Programming % Choice rules n { p(X,Y) : d1(X) } m :- d2(Y). Meaning: forall Y which is a d2 we admit only answer sets with at least n atoms and at most m atoms of the form p(X,Y), where X is a d1 S. Costantini / Datalog e ASP

Answer Set Programming % hard constraint :- hates(P1,P2),at_table(P1,T),at_table(P2,T), guest(P1),guest(P2),table(T). S. Costantini / Datalog e ASP

Answer Set Programming % should be a soft constraint! :- likes(P1,P2), at_table(P1,T1), at_table(P2,T2), T1 != T2, guest(P1), guest(P2),table(T1),table(T2). S. Costantini / Datalog e ASP