% Copyright (C) 2003 Fred Mesnard <fred@univ-reunion.fr>
%
% This file is part of cTI.
%
% cTI is free software; you can redistribute it and/or modify it
% under the terms of the GNU General Public License as published by the
% Free Software Foundation; either version 2 of the License, or (at your
% option) any later version.
%
% cTI is distributed in the hope that it will be useful, but WITHOUT
% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
% FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
% for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
% USA.
%
% For the most up-to-date information see the cTI's web site:
% http://www.cs.unipr.it/cTI/

:- module(quantify,[ quantify/1 ]).

:- use_module(library(clpb)).

% quantify(+ListTermConds)
quantify([]):-!.
quantify(L2):-
	%trace,
	compte0s(L2,Per,_N,_Z),
	term_modes(L2,0,NTermModes),
	write('%  -------------------------------'),nl,
	%write('%  '),write(N),write(' predicates, of which '),%nl,
	%write('%  '),write(Z),write(' are possibly non-terminating'),nl,
	write('%  terminating predicates: '),format("~2d%",[Per]),nl,
	write('%  terminating modes: '),write(NTermModes),nl,
	write('%  -------------------------------'),nl.

compte0s(L,Q,N,Z):-
	length(L,N),
	c0s(L,0,Z),
	percent(N-Z,N,Q).

c0s([],N,N).
c0s([predicate_term_condition(_,CT)|L],N1,N2):-
	(CT==0 -> N3 is N1+1; N3 is N1),
	c0s(L,N3,N2).
	
percent(A,B,Q):- Q is (A*10000)//B.

term_modes([],N,N).
term_modes([predicate_term_condition(Atom,CT)|L],N0,N) :-
	Atom=..[_|Vars],
	findall(Vars,clpb:(sat(CT),labeling(Vars)),TermModes),
	length(TermModes,Ntm),
	N1 is N0+Ntm,
	term_modes(L,N1,N).


