280 likes | 438 Views
The CHR-based Implementation of the SCIFF Abductive System. Marco Gavanelli – Università di Ferrara, Italy Marco Alberti – Universidade nova de Lisboa, Portugal Evelina Lamma – Università di Ferrara, Italy. Abductive Logic Programming. ALP = < KB, A, IC > KB = logic program (set of clauses)
E N D
The CHR-based Implementation of the SCIFFAbductive System Marco Gavanelli – Università di Ferrara, Italy Marco Alberti – Universidade nova de Lisboa, Portugal Evelina Lamma – Università di Ferrara, Italy
Abductive Logic Programming • ALP = < KB, A, IC > • KB = logic program (set of clauses) • A = atoms without definitions, can be assumed • IC = Integrity constraints (usually, implications) KB ╞═ G KB ╞═ IC • Reasoning from effects to causes
Diagnosis headache:- flu. headache:- period. headache:- hangover. flu, vaccine -> false. hangover -> drank. period, sex(male) -> false. ?- headache. Yes, flu More? ; Yes, period
Event Calculus holdsat(Fluent,Time):- initially(Fluent), not(clipped(0,Fluent,Time)). holdsat(Fluent,Time):- initiates(Action,Fluent), happens(Action,T1), not(clipped(T1,Fluent,Time)). clipped(T1,Fluent,T2):- terminates(Action), happens(Action,T), T1<T<T2. initially(f1). initially(f2). happens(c,7) happens(a,2) happens(b,4)
Abductive Event Calculus holdsat(Fluent,Time):- initially(Fluent), not(clipped(0,Fluent,Time)). holdsat(Fluent,Time):- initiates(Action,Fluent), happens(Action,T1), not(clipped(T1,Fluent,Time)). clipped(T1,Fluent,T2):- terminates(Action), happens(Action,T), T1<T<T2. initially(f1). initially(f2). happens(c,7) ={ happens(a,2) happens(b,4) }
Sound negation p(1). p(f(X)):- q(X). q(2). • ?- not(p(Y)). yes, Y\=1, Y\=f(2)
Abduction = constraint solving[Kowalski, Toni, Wetzel 98] • headache :- flu. • headache :- hangover. • flu, vaccine -> false Constraint Store ?- , headache. vaccine Constraint Solver flu fail
Abduction = constraint solving[Kowalski, Toni, Wetzel 98] • headache :- flu. • headache :- hangover. • headache :- period. • flu, vaccine -> false. • hangover -> drank. • period, sex(male) -> false. Constraint Store Constraint Solver ?- , headache. vaccine fail flu
Constraint Handling Rules (CHR) • Declarative language for defining constraint solvers • Simplification rules: c1, c2, ..., cn <=> guard | body • activated if some constraints in the store match with c1, c2, ..., cn and guard is true • removes c1, c2, ..., cn from the store and executes body • Propagation rules: c1, c2, ..., cn ==> guard | body • activated if some constraints in the store match with c1, c2, ..., cn and guard is true • executes body
Example: leq (less or equal) reflexivity@leq(X,X) <=> true. antisymmetry@leq(X,Y), leq(Y,X) <=> X=Y. transitivity@leq(X,Y), leq(Y,Z) ==> leq(X,Z). leq(A,B), leq(B,C), leq(C,A) leq(A,B), leq(B,C), leq(C,A), leq(A,C) leq(A,B), leq(B,A), A=C A=B, A=C
Abduction in CHR [Abdennadher, Christiansen, Dahl] • Abducibles mapped to CHR constraints • headache :- flu. • headache :- hangover. • flu, vaccine -> false
Abduction in CHR • headache :- flu. • headache :- ... • flu, vaccine ==> false Constraint Store ?- , headache. vaccine fail flu
Abduction in CHR • headache :- hangover. • headache :- ... • drank. • hangover ==> drank Constraint Store ?- headache. hangover drank success
Abduction in CHR • headache :- period. • headache :- ... • sex(male). Constraint Store • period, sex(male) ==> false ! CHR: invalid syntax "sex(male)" ! Undeclared constraint sex/1 in head of rule
Operational semantics • Propagation • a(X) a(Y), b -> c (X=Y, b) -> c • Case analysis • (X=Y, b) -> c X=Y, (b -> c) \/ X\=Y • Equality rewriting • p(A,B,C)=p(D,E,F) A=D, B=E, C=F • Unfolding • p(X) -> Goal p(X):- a. p(X):-b. • a -> Goal. b -> Goal • ... • Constraint solving
Abduction in CHR (SCIFF) Constraint Store • headache :- flu. • headache :- ... ic( flu -> false) ic( ) vaccine, flu -> false ?- , headache. vaccine fail flu
Transitions • Propagation transition (+ case analysis): abd(X), ic([abd(Y)|Rest]-> Head) ==> copy(ic([abd(Y) |Rest ]-> Head) , ic([abd(Y’)|Rest’]-> Head’)), reif_unify(X,Y’,Boolean), ( Boolean=1, ic(Rest’->Head’) ; Boolean=0).
Transitions • Propagation transition (+ case analysis): abd(X), ic([abd(Y)|Rest]-> Head) ==> copy(ic([abd(Y) |Rest ]-> Head) , ic([abd(Y’)|Rest’]-> Head’)), reif_unify(X,Y’,Boolean), ( Boolean=1, ic(Rest’->Head’) ; Boolean=0). ic([abd(vaccine),abd(flu)]-> false) ic([abd(period),sex(male)]-> false) ic([abd(hangover)]-> drank) abd(hangover)
No hashing • Does not use CHR’s hashing • Solution: abducibles are represented with redundant information: abd(Functor, Arity, Atom) • So to abduce atom X: abd(X):- functor(F, A, X), abd(F, A, X). • E.g., if I abduce atom mother(X,john), the constraint store contains abd(mother, 2, mother(X,john))
Hashing • Propagation transition (+ case analysis): abd(F,A,X), ic([abd(F,A,Y)|Rest]-> Head) ==> copy(ic([abd(Y) |Rest ]-> Head) , ic([abd(Y’)|Rest’]-> Head’)), reif_unify(X,Y’,Boolean), ( Boolean=1, ic(Rest’->Head’) ; Boolean=0). Requires the first two arguments identical
Hashing • Propagation transition (+ case analysis): abd(F,A,X), ic([abd(F,A,Y)|Rest]-> Head) ==> copy(ic([abd(Y) |Rest ]-> Head) , ic([abd(Y’)|Rest’]-> Head’)), reif_unify(X,Y’,Boolean), ( Boolean=1, ic(Rest’->Head’) ; Boolean=0). ic([abd(vaccine,1,vaccine),abd(flu,1,flu)]-> false) ic([abd(period,1,period),sex(male)]-> false) ic([abd(hangover,1,hangover)]-> drank) abd(hangover,1,hangover)
Postpone choices • new CHR constraint nondeterministic(Goal) says that Goal can open a choice point, so should be called as late as possible. • Two phases, declared by a CHR constraint phase/1: • phase(deterministic): only deterministic goals are executed • phase(nondeterministic): exactly ONE nondeterministic goal can be executed switch2det @ phase(nondeterministic), nondeterministic(G) <=> call(G), phase(deterministic). switch2nondet @ phase(deterministic) <=> phase(nondeterministic)
Postponing nondet. • Propagation transition (+ case analysis): abd(F,A,X), ic([abd(F,A,Y)|Rest]-> Head) ==> copy(ic([abd(Y) |Rest ]-> Head) , ic([abd(Y’)|Rest’]-> Head’)), reif_unify(X,Y’,B), ( B=1, ic(Rest’->Head’) ; B=0).
Postponing nondet. • Propagation transition (+ case analysis): abd(F,A,X), ic([abd(F,A,Y)|Rest]-> Head) ==> copy(ic([abd(Y) |Rest ]-> Head) , ic([abd(Y’)|Rest’]-> Head’)), reif_unify(X,Y’,B), (B == 1 -> ic(Rest’, Head’) ; B == 0 -> true ; nondeterministic((B#=1,ic(Rest’,Head’)) ; B#=0)) ).
Conclusions • CHR implementation of an abductive proof-procedure • Sound, complete, sound treatment of negation • Well integrated with constraint solving, CLP(FD), CLP(R), universally quantified variables, quantifier restrictions, etc. • Easy to extend for other features (see other talk after coffee break)
Thank you for your attention! Questions?