2005-12-24 18:07:41 +00:00
|
|
|
|
2006-11-07 17:11:47 +00:00
|
|
|
:- category(solver).
|
2005-12-24 18:07:41 +00:00
|
|
|
|
|
|
|
:- info([
|
|
|
|
version is 1.0,
|
|
|
|
date is 2004/5/2,
|
|
|
|
author is 'Paulo Moura',
|
|
|
|
comment is 'Simple meta-interpreter for pure Prolog with only conjunctions as clause bodies.']).
|
|
|
|
|
|
|
|
:- public(solve/1).
|
|
|
|
:- mode(solve(+goal), zero_or_more).
|
|
|
|
:- info(solve/1, [
|
|
|
|
comment is 'Proves goal.',
|
|
|
|
argnames is ['Goal']]).
|
|
|
|
|
|
|
|
solve(true) :-
|
|
|
|
!.
|
|
|
|
solve((A, B)) :-
|
2006-11-07 17:11:47 +00:00
|
|
|
!,
|
|
|
|
solve(A),
|
|
|
|
solve(B).
|
2005-12-24 18:07:41 +00:00
|
|
|
solve(A) :-
|
2006-11-07 17:11:47 +00:00
|
|
|
::clause(A, B),
|
|
|
|
solve(B).
|
2005-12-24 18:07:41 +00:00
|
|
|
|
2006-11-07 17:11:47 +00:00
|
|
|
:- end_category.
|
2005-12-24 18:07:41 +00:00
|
|
|
|
|
|
|
|
2006-11-07 17:11:47 +00:00
|
|
|
:- category(proof_tree).
|
2005-12-24 18:07:41 +00:00
|
|
|
|
|
|
|
:- info([
|
|
|
|
version is 1.0,
|
|
|
|
date is 2004/5/2,
|
|
|
|
author is 'Paulo Moura',
|
|
|
|
comment is 'Meta-interpreter for pure Prolog with only conjunctions as clause bodies.']).
|
|
|
|
|
2006-11-07 17:11:47 +00:00
|
|
|
:- public(proof_tree/2).
|
|
|
|
:- mode(proof_tree(+goal, -tree), zero_or_more).
|
|
|
|
:- info(proof_tree/2, [
|
2005-12-24 18:07:41 +00:00
|
|
|
comment is 'Constructs a proof tree for a goal.',
|
|
|
|
argnames is ['Goal', 'Tree']]).
|
|
|
|
|
2006-11-07 17:11:47 +00:00
|
|
|
proof_tree(true, true) :-
|
|
|
|
!.
|
|
|
|
proof_tree((A, B), (PA, PB)) :-
|
|
|
|
!,
|
|
|
|
proof_tree(A, PA),
|
|
|
|
proof_tree(B, PB).
|
|
|
|
proof_tree(A, (A :- PB)) :-
|
|
|
|
::clause(A, B),
|
|
|
|
proof_tree(B, PB).
|
2005-12-24 18:07:41 +00:00
|
|
|
|
2006-11-07 17:11:47 +00:00
|
|
|
:- end_category.
|
2005-12-24 18:07:41 +00:00
|
|
|
|
|
|
|
|
2006-11-07 17:11:47 +00:00
|
|
|
:- category(tracer).
|
2005-12-24 18:07:41 +00:00
|
|
|
|
|
|
|
:- info([
|
|
|
|
version is 1.0,
|
|
|
|
date is 2004/5/5,
|
|
|
|
author is 'Paulo Moura',
|
|
|
|
comment is 'A simple tracer meta-interpreter for pure Prolog with only conjunctions as clause bodies.']).
|
|
|
|
|
|
|
|
:- public(trace/1).
|
|
|
|
:- mode(trace(+goal), zero_or_more).
|
|
|
|
:- info(trace/1, [
|
|
|
|
comment is 'Traces goal proof.',
|
|
|
|
argnames is ['Goal']]).
|
|
|
|
|
|
|
|
trace(Goal) :-
|
|
|
|
trace(Goal, 1).
|
|
|
|
|
|
|
|
trace(true, _) :-
|
|
|
|
!.
|
|
|
|
trace((A, B), Depth) :-
|
2006-11-07 17:11:47 +00:00
|
|
|
!,
|
|
|
|
trace(A, Depth),
|
|
|
|
trace(B, Depth).
|
2005-12-24 18:07:41 +00:00
|
|
|
trace(A, Depth) :-
|
|
|
|
write_trace(call, A, Depth),
|
|
|
|
clause(A, B),
|
|
|
|
Depth2 is Depth + 1,
|
|
|
|
trace(B, Depth2),
|
|
|
|
( write_trace(exit, A, Depth)
|
|
|
|
;
|
|
|
|
write_trace(redo, A, Depth),
|
|
|
|
fail).
|
|
|
|
trace(A, Depth) :-
|
|
|
|
write_trace(fail, A, Depth),
|
|
|
|
fail.
|
|
|
|
|
|
|
|
write_trace(Port, Goal, Depth) :-
|
|
|
|
write(Depth), write(' '), write(Port), write(': '), writeq(Goal), nl.
|
|
|
|
|
2006-11-07 17:11:47 +00:00
|
|
|
:- end_category.
|