% enhanced semantics with program points (naive engine)

:- module(induced_tp_pp_abs, [go/3]).

:- use_module(input_normalize_pp).
:- use_module(unification_operations, [unify/2]).
:- use_module(lub_operations, [lub/1]).
:- use_module(facts,[fact/1,flag/0]).
:- use_module(domain,[domain/1]).
:- use_module(utilities, [showfacts/0]).

:- use_module(library(lists),[append/3]).


%% interface
  go(File,Goal,Domain) :-              % Goal is atomic
      retractall(fact(_)),  
      retractall(domain(_)),    
      load_file(File),
      assert(domain(Domain)),
      assert(fact(call(_,_, Goal))),
      iterate,
      showfacts.

%% control

  iterate :- operator, fail.
  iterate :- retract(flag), iterate.
  iterate.

%% logic 

  operator :- 
      my_clause(Head,Body),  
      fact(call(_,_,Head)),
      prove(Body), 
      lub(ans(Head)).

  prove([pp(I,J,B)|_]) :-
        lub(call(I,J,B)), fail.
  prove([pp(_,_,B)|Bs]) :- 
        fact(ans(B)), prove(Bs).  
  prove([unify(A,B)|Bs]) :- 
        unify(A,B), prove(Bs).  
  prove([]).
