Query the User solve true solve A B
Λύσεις με τη βοήθεια του Χρήστη (Query the User) solve (true). solve ((A, B)) : - solve (A), solve (B). solve (A) : - clause (A, B), solve (B). solve (A) : - askable(A), not known (A), ask (A, Answer), respond (Answer, A). ask (A, Answer) : - write (A), write ( «? » ), read (Answer). respond (yes, A) : - assert (A). respond (no, A) : - assert (untrue(A)), fail. known (A) : - A. known (A) : - untrue (A).
Παράδειγμα 1 (Query the User) entitled (X, Y) : - unemployed (X) age (X, Z), Z > 18, work_period (X, T), T > 6, Y is (200 * T) / 12. entitled (X, Y) : - student (X), identity_number (X, X 1), passed_semester (X 1), special_reading_applies (X, Z), calculate_sum (Z, Y). special_read_applies(X, economic) : - poor (X). special_read_applies(X, performance) : - grade (X) >> 8. 5 calculate (economic, Y) : - Y=150. calculate (performance, Y) : - Y=75. askable (age (X, Υ)). askable (identity_number (X. Y)). askable (X >> Y).
Παράδειγμα 2 should_take (Person, Drug) : complains_of (Person, Complaint), suppresses (Drug, Complaint), not unsuitable (Drug, Person). askable (complains_of (Χ, Y)). ? solve (should_take (peter, Drug)), . . . complains_of (Peter, Headache) ? YES / NO
Επεξήγηση Αποτυχίας %solve (Goal, Result, Proof) solve ((A, B), Result, (Proof. A, Proof. B)) : solve_one (A, Result. A, Proof. A), solve_and (Result. A, B, Result, Proof. B). solve_one (A, yes, (A is a fact)) : - clause (A, B), B==true. solve_one (A, Result, (A follows from Proof)) : clause (A, B), B/==true, solve (B, Result, Proof). solve_one (A, no, (no rule for A)) : - not clause (A, B)). solve_and (no, B, no, (B is unsearched)). solve_and (yes, B, Result, Proof. B) : - solve (B, Result, Proof. B).
Ερωτήσεις «γιατί» solve (G) : - solve (G, []). solve (true, Rules). solve ((A, B), Rules) : - solve (A, Rules), solve (B, Rules). solve (A, Rules) : - clause (A, B), solve (B, [rule (A, B) | Rules]) solve (A, Rules) : - askable (A), not known (A), ask (A, Answer), respond (Answer, A, Rules). ask (A, Answer) : - write (A), write (‘? ’), read (Answer). respond (yes, A, Rules) : - assert (A). respond (no, A, Rules) : - assert (untrue (A)), fail respond (why, A, [Rule|Rules]) : - display_rule (Rule), ask (A, Answer), respond (Answer, A, Rules). respond (why, A, []) : - writeln ([‘No more explanation possible’]), ask (A, Answer), respond (Answer, A, []).
Ερωτήσεις «γιατί» respond (yes, A, Rules) : - assert (A). respond (no, A, Rules) : - assert (untrue (A)), fail. respond (why, A, [Rule|Rules]) : display_rule (Rule), ask (A, Answer), respond (Answer, A, Rules). respond (why, A, []) : writeln ([‘No more explanation possible’]), ask (A, Answer), respond (Answer, A, []).
Ερωτήσεις «γιατί» display (rule (A, B)) : write (‘if’), write_conjuction (B), writeln ([‘Then’, A]). write_conjuction ((A, B)) : write (A), write (‘and’), write_conjunction (B). write_conjuction (A) : write (A), nl.
Bounded Solve % bounded_solve (Goal, Depth) – Ισχύει όταν ο στόχος Goal έχει απόδειξη βάθους μικρότερου ή ισου του Depth. bounded_solve (true, X) bounded_ solve ((A, B), X): - bounded_solve(A, X), bounded_solve(B, X). bounded_solve (A, X): - system (A), A. bounded_solve (A, X): - X ≥ 0, clause (A, B), X 1 is X-1, bounded_solve(B, X 1). % bounded_solve (Goal, Depth, Proof). bounded_solve (true, X, true). bounded_solve (A, B), X, (Proof. A, Proof. B)): - bounded_solve (A, X, Proof. A), bounded_solve (B, X, Proof. B). bounded_solve (A, X, (A is a system predicate)): - system(A), A. bounded_solve (A, X, (A follows from Proof)): - X ≥ 0, clause (A, B), X 1 is X-1, bounded_solve (B, X 1 , Proof).
Προσομοίωση με επεξήγηση shell <-- prompt, read(G), do(G). prompt <-- write ('Next command? '). do (exit) < -- ! do(G) <-- ground(G), !, answer_ground(G), shell. do(G) <-- answer(G), shell. answer_ground(G) <-- solve 2(G, Proof), !, write('Yes'), nl, write('Would you like an explanation? ’), nl, read (Answer), act(Answer, Proof). answer_ground(G) <-- write ('No'), nl.
Προσομοίωση με επεξήγηση (συν. ) answer(G) <-- solve 2(G, Proof), !, write(G), nl, write('Would you like an explanation? '), nl, read(Answer) , act(Answer, Proof), fail. answer(G) < -- write('No (more) solutions'), nl. act(yes, Proof) <-- present(Proof), nl. act(no, Proof). solve 2(true, true) solve 2((A, B), (Proof. A, Proof. B)): - solve 2(A, Proof A), solve 2 (B, Proof. B). solve 2((A, (A <-- true)): - clause(A, B), B==true, solve 2(A, (A <-- Proof)): - clause(A, B), B=/=true, solve 2(B, Proof).
- Slides: 11