Μεταφραστές Περιορισμένης Αναζήτησης
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), X1 is X-1,bounded_solve(B,X1). % bounded_solve (Goal,Depth,Proof). bounded_solve (true,X,true). bounded_solve (A,B),X, (ProofA, ProofB)):- bounded_solve (A,X,ProofA), bounded_solve (B,X,ProofB). 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), X1 is X-1, bounded_solve (B,X1,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) <-- solve2(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) <-- solve2(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). solve2(true,true) solve2((A,B), (ProofA, ProofB)): - solve2(A, Proof A), solve2 (B, ProofB). solve2((A, (A <-- true)):- clause(A,B), B==true, solve2(A, (A <-- Proof)):- clause(A,B), B=/=true, solve2(B,Proof).
Άσκηση 8 – Λύση [2] (συνέχεια) present((Proof1,Proof2)) <-- present(Proof1), present(Proof2). present(Proof) <-- fact(Proof,Fact), nl, writeln ([Fact, 'is a fact in the program.']). present(Proof) <-- rule(Proof,Head,Body,Rest), nl, writeln([Head, 'is proved using the rule']), display _rule(rule(Head,Body)), present(Rest). fact((Fact <-- true),Fact). rule((Goal <-- Proof),Goal,Body,Proof) <-- Proof ≠ true, extract_body(Proof,Body) extract_body ((Proof1, Proof2), (Body1, Body2)) <-- !, extract_body(Proof1,Body1), extract_ body(Proof2,Body2). extract_body((Goal <-- Proof),Goal)).