This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
explain(A,E0,E):-explain(A,E0,E):-prove_e(A,E0,E).prove_e(A,E0,E). % explain by % explain by rules rules onlyonly
explain(A,E0,[explain(A,E0,[default((A:-B))default((A:-B))|E]):-|E]):-default((A:-B))default((A:-B)),, % explain by % explain by defaultdefaultexplain(B,E0,E),explain(B,E0,E),not contradiction(A,E)not contradiction(A,E).. % A % A consistent consistent with Ewith E
explain(A,E0,E):-explain(A,E0,E):- prove_e(A,E0,E)prove_e(A,E0,E).. % explain by % explain by rules rules onlyonly
explain(A,E0,[explain(A,E0,[default(default(NameName))|E]):-|E]):- default(default(NameName,(A:-B)),(A:-B)),, % explain by % explain by default ruledefault rule explain(B,E0,E), explain(B,E0,E), not contradiction(Name,E)not contradiction(Name,E),, % default should be % default should be applicableapplicable not contradiction(A,E)not contradiction(A,E).. % A should be % A should be consistent consistent with Ewith E
For each For each default namedefault name, introduce a , introduce a predicate introducing the predicate introducing the oppositeopposite (‘abnormality predicate’) (‘abnormality predicate’)
Incompleteness arises when assumptions regarding a Incompleteness arises when assumptions regarding a domain are not explicitly represented in a logic program domain are not explicitly represented in a logic program PP. .
There are several ways to make these assumptions There are several ways to make these assumptions explicit: explicit:
by selecting one of the models of by selecting one of the models of PP as the as the intended modelintended model
by transforming by transforming PP into the into the intended programintended program
• Closed World AssumptionClosed World Assumption
• Predicate CompletionPredicate Completion
New information can invalidate previous conclusions if New information can invalidate previous conclusions if they were based on assumptionsthey were based on assumptions
Step 1: rewrite clauses such that the head contains only Step 1: rewrite clauses such that the head contains only distinct variables, by adding literals distinct variables, by adding literals Var=TermVar=Term to the to the bodybody
Step 2: for each head predicate, Step 2: for each head predicate, combine its clausescombine its clauses into a single universally quantified implication with into a single universally quantified implication with disjunctive bodydisjunctive body
take care of existential variablestake care of existential variables
Step 3: turn all implications into Step 3: turn all implications into equivalencesequivalencesundefined predicates undefined predicates pp are rewritten to are rewritten to X:X:p(X)p(X)
(Step 4: rewrite as (Step 4: rewrite as general clausesgeneral clauses))
abduce(abduce(AA,E,[,E,[AA|E]):-|E]):- % % A A can be added to Ecan be added to Enot element(not element(AA,E),,E), % if it's not already there,% if it's not already there,abducible(abducible(AA).). % and if it's abducible% and if it's abducible
abduce(abduce(AA,E,[,E,[AA|E]):-|E]):- % % A A can be added to Ecan be added to Enot element(not element(AA,E),,E), % if it's not already there,% if it's not already there,abducible(abducible(AA),), % if it's abducible,% if it's abducible,not abduce_not(not abduce_not(AA,E,E).,E,E). % and E doesn't explain % and E doesn't explain not(A)not(A)
abduce(abduce(not(A)not(A),E0,E):-,E0,E):- % find explanation for % find explanation for not(A)not(A)not element(not element(AA,E0),,E0), % should be consistent% should be consistentabduce_not(abduce_not(AA,E0,E).,E0,E).
abduce_not(abduce_not(AA,E,[,E,[not(A)not(A)|E]):-|E]):- % % not(A) not(A) can be added to Ecan be added to Enot element(not element(not(A)not(A),E),,E), % if it's not already there,% if it's not already there,abducible(abducible(AA),), % if % if A A is abducibleis abduciblenot abduce(not abduce(AA,E,E).,E,E). % and E doesn't explain % and E doesn't explain AA
abduce_not(abduce_not(not(A)not(A),E0,E):-,E0,E):- % find explanation for % find explanation for AAnot element(not element(not(A)not(A),E0),,E0), % should be consistent% should be consistentabduce(abduce(AA,E0,E).,E0,E).
adder(N,X,Y,Z,Sum,Carry):- xorg(N-xor1,X,Y,S), % N-xor1 is the name of this gate xorg(N-xor2,Z,S,Sum), andg(N-and1,X,Y,C1), andg(N-and2,Z,S,C2), org(N-or1,C1,C2,Carry).
% fault model (similar for andg, org)xorg(N,X,Y,Z):-xor(X,Y,Z). % normal operationxorg(N,1,1,1):-fault(N=s1). % stuck at 1xorg(N,0,0,1):-fault(N=s1). % stuck at 1xorg(N,1,0,0):-fault(N=s0). % stuck at 0xorg(N,0,1,0):-fault(N=s0). % stuck at 0
% gates (similar for and, or)xor(1,0,1).xor(0,1,1).xor(1,1,0).xor(0,0,0).