:- style_check(-singleton). % added djd
%%:- module('Integers', []).  % converted djd
:- module(integers).  % converted djd

:- op(500, yfx, and).
:- op(400, yfx, or).

/* 
File:		Integers.sup
Subject:	Implemention of the whole system module Integers
Author: 	Jiwei Wang
Date:		17 September 1991

================================================================================
*/

%% '$$module'('@(#)Integers.sup 1.17 last updated 93/12/08 16:19:08 by jiwei').
module(integerssup). % converted djd

'Integers.=<.P2'(X, Y) :-
   ( integer(X), integer(Y)
     -> X =< Y
     ;  user:goedel_freeze(ground([X,Y]), X =< Y)
   ).

'~Integers.=<.P2'(X, Y) :-
   ( integer(X), integer(Y)
     -> X =< Y
     ;  user:goedel_freeze(ground([X,Y]), X =< Y)
   ).
%- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


'Integers.>=.P2'(X, Y) :-
   ( integer(X), integer(Y)
     -> X >= Y
     ;  user:goedel_freeze(ground([X,Y]), X >= Y)
   ).

'~Integers.>=.P2'(X, Y) :-
   ( integer(X), integer(Y)
     -> X >= Y
     ;  user:goedel_freeze(ground([X,Y]), X >= Y)
   ).
%- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


'Integers.>.P2'(X, Y) :-
   ( integer(X), integer(Y)
     -> X > Y
     ;  user:goedel_freeze(ground([X,Y]), X > Y)
   ).

'~Integers.>.P2'(X, Y) :-
   ( integer(X), integer(Y)
     -> X > Y
     ;  user:goedel_freeze(ground([X,Y]), X > Y)
   ).

%- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


'Integers.<.P2'(X, Y) :-
   ( integer(X), integer(Y)
     -> X < Y
     ;  user:goedel_freeze(ground([X,Y]), X < Y)
   ).

'~Integers.<.P2'(X, Y) :-
   ( integer(X), integer(Y)
     -> X < Y
     ;  user:goedel_freeze(ground([X,Y]), X < Y)
   ).

%- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


'Integers.Interval.P3'(L, N, H) :-
   nonvar(L), nonvar(H), !,
   ( var(N)
     -> L =< H,
        between(L, N, H)
     ;  integer(N),
        L =< N, N =< H
   ).

'Integers.Interval.P3'(L, N, H) :-
   user:goedel_freeze(ground([L,H]),
   		'Integers':'Integers.Interval.P3'(L, N, H) ).

'~Integers.Interval.P3'(L, N, H) :-
   'Integers':'Integers.Interval.P3'(L, N, H).


between(L, L, _).

between(L, N, H) :-
   L < H,
   L1 is L + 1,
   between(L1, N, H).

/*==============================================================================
 * Following are functions that support the constraint solving with integers.
 */


plus(X, Y, Z) :-
   integer(X), integer(Y), !, Z is X + Y.

plus(X, Y, Z) :-
   integer(X), integer(Z), !, Y is Z - X.

plus(X, Y, Z) :-
   integer(Y), integer(Z), !, X is Z - Y.

plus(X, Y, Z) :-
   user:goedel_freeze(ground([X,Z]) or ground([Y,Z]) or ground([X,Y]),
                        'Integers':plus(X, Y, Z)).

/*------------------------------------------------------------------------------
 */


negative(X, Y) :-
   integer(X), !, Y is -X.

negative(X, Y) :-
   integer(Y), !, X is -Y.

negative(X, Y) :-
   user:goedel_freeze(ground([Y]) or ground([X]), 'Integers':negative(X, Y) ).

/*------------------------------------------------------------------------------
 */


minus(X, Y, Z) :-
   integer(X), integer(Y), !, Z is X - Y.

minus(X, Y, Z) :-
   integer(X), integer(Z), !, Y is X - Z.

minus(X, Y, Z) :-
   integer(Y), integer(Z), !, X is Z + Y.

minus(X, Y, Z) :-
   user:goedel_freeze(ground([X,Z]) or ground([Y,Z]) or ground([X,Y]),
			'Integers':minus(X, Y, Z)).

/*------------------------------------------------------------------------------
 */
 



times(X, Y, Z) :-
   integer(X), integer(Y), !,
   Z is X * Y.

times(X, Y, Z) :-
   integer(X), integer(Z), !,
   ( X == 0, Z == 0
     -> true		% X is left uninstantiated
     ;  X =\= 0, 	% make sure X is not zero. If X is zero, it fails.
        Y is Z // X, Z =:= X * Y
   ).

times(X, Y, Z) :-
   integer(Y), integer(Z), !,
   ( Y == 0, Z == 0
     -> true		% X is left uninstantiated
     ;  Y =\= 0, 	% make sure Y is not zero. If X is zero, it fails.
        X is Z // Y, Z =:= X * Y
   ).

times(X, Y, Z) :-
   user:goedel_freeze(ground([X,Z]) or ground([Y,Z]) or ground([X,Y]),
			'Integers':times(X, Y, Z)).

/*------------------------------------------------------------------------------
 * divides does not allow 8 Div x = 2, yet, but x Div 3 = 2 is ok (which
 * returns multiple answers).
 */
 
divides(X, Y, Z) :-
   integer(X), integer(Y), !,
   ( Y = 0
     -> % Z = 0, but this value is never used
	format(user_error, "Arithmetic exception: division by 0.~n", []),
	raise_exception(catch_in_query)
     ;  Z is X // Y
   ).

divides(X, Y, Z) :-
   integer(Z), integer(Y), !,
   ( Y = 0
     -> % Z = 0, but this value is never used
        format(user_error, "Arithmetic exception: division by 0.~n", []),
	raise_exception(catch_in_query)
     ;  A is Y*Z,
	( A > 0
	  -> B is A + abs(Z) -1,
	     between(A, X, B)
	  ;  B is A - abs(Z) + 1,
	     between(B, X, A)
	)
   ).

divides(X, Y, Z) :-
   user:goedel_freeze(ground([Y,Z]) or ground([X,Y]),
		'Integers':divides(X, Y, Z)).

/*------------------------------------------------------------------------------
 */

power(X, Y, Z) :-
   integer(X), integer(Y), !,
   ( Y < 0
     -> % Z = 0, but this value is never used
	format(user_error, "Arithmetic exception: negative exponent.~n", []),
	raise_exception(catch_in_query)
     ;  ( Y = 0
	  -> Z = 1
	  ;  power2(Y, X, 1, Z)
	)
   ).

power(X, Y, Z) :-
   integer(X), integer(Z), !,
   X * Z >= 0,		% checking X and Z are of the same sign
   ( X = 0, Z = 0
     -> 'Integers.>.P2'(Y, 0)	% return constraint Y > 0
     ;  ( X = 0, Z = 1
	  -> Y = 0
	  ;  ( ( X = 0, Z =\= 0; X =\= 0, Z = 0 )
	       -> fail	% this is the incompatible case
               ;  ( X = 1
	            -> Z = 1	% if Z \= 1 this fails,
				% otherwise X is left uninstantiated
	            ;  Y is integer(round(log(abs(Z))/log(abs(X)))),
	  	       power2(Y, X, 1, Z)
		  )
	     )
	)
   ).

power(X, Y, Z) :-
   integer(Y), integer(Z), !,
   ( Y < 0
     -> format(user_error, "Arithmetic exception: negative exponent.~n", []),
	raise_exception(catch_in_query)
     ;  ( Y = 0
	  -> Z = 1		% X is left as a variable
	  ;  ( 0 =:= Y mod 2
	       -> ( Z =< 0
	            -> fail		% should fail
	            ;  ( X is integer(round(exp(log(Z)/Y)));
	                 X is - integer(round(exp(log(Z)/Y)))
		       ),
	  	       power2(Y, X, 1, Z)	% the test
	          )
	       ;  ( Z > 0
	            -> X is integer(round(exp(log(abs(Z))/Y)))
	            ;  ( Z < 0
		         -> X is - integer(round(exp(log(abs(Z))/Y)))
		         ;  fail	% when Z=0
		       )
	          ),
	  	  power2(Y, X, 1, Z)	% the test
	     )
	)
   ).

power(X, Y, Z) :-
   user:goedel_freeze(ground([X,Z]) or ground([Y,Z]) or ground([X,Y]),
		'Integers':power(X, Y, Z)).


power2(1, X, P, NewP) :-
   NewP is X*P, !.
power2(N, X, P, NewP) :-
   N > 1,
   P2 is X*P, 
   N2 is N - 1,
   power2(N2, X, P2, NewP).

/*------------------------------------------------------------------------------
 * mod is more restrictive than divides.
 */

mod(X, Y, Z) :-
   integer(X), integer(Y), !,
   ( Y = 0
     -> % Z = 0, but this value is never used
	format(user_error, "Arithmetic exception: mod by 0.~n", []),
	raise_exception(catch_in_query)
     ;  Z is X mod Y
   ).

mod(X, Y, Z) :-
   user:goedel_freeze(ground([X,Y]), 'Integers':mod(X, Y, Z)).

/*------------------------------------------------------------------------------
 * rem is more restrictive than divides.
 */

rem(X, Y, Z) :-
   integer(X), integer(Y), !,
   ( Y = 0
     -> % Z = 0, but this value is never used
	format(user_error, "Arithmetic exception: rem by 0.~n", []),
	raise_exception(catch_in_query)
     ;  A is X // Y,
        ( A > 0
	  -> A2 = A
	  ;  A2 is A - 1
	),
	Z is X - A2 * Y
   ).

rem(X, Y, Z) :-
   user:goedel_freeze(ground([X,Y]), 'Integers':rem(X, Y, Z)).

/*------------------------------------------------------------------------------
 */

absolute(X, Y) :-
   integer(X), !,
   ( X >= 0
     -> Y is X
     ;  Y is -X
   ).

absolute(X, Y) :-
   integer(Y), !, Y >= 0, 
   ( X is Y
   ;
     X is -Y
   ).

absolute(X, Y) :-
   user:goedel_freeze(ground([Y]) or ground([X]), 'Integers':absolute(X, Y) ).

/*------------------------------------------------------------------------------
 * maximum and minimum assum that X and Y are integers.
 */

sign(X, Y) :-
   integer(X), !,
   ( X = 0
     -> Y = 0
     ;  ( X > 0
          -> Y = 1
	  ;  Y = -1
	)
   ).

sign(X, Y) :-
   user:goedel_freeze(ground([X]), 'Integers':sign(X, Y) ).


/*------------------------------------------------------------------------------
 * maximum and minimum assum that X and Y are integers.
 */
 
maximum(X, Y, Z) :-
   integer(X), integer(Y), !,
   ( X < Y
     -> Z = Y
     ;  Z = X
   ).

maximum(X, Y, Z) :-
   user:goedel_freeze(ground([X,Y]), 'Integers':maximum(X, Y, Z) ).

/*------------------------------------------------------------------------------
 */

minimum(X, Y, Z) :-
   integer(X), integer(Y), !,
   ( X < Y
     -> Z = X
     ;  Z = Y
   ).

minimum(X, Y, Z) :-
   user:goedel_freeze(ground([X,Y]), 'Integers':minimum(X, Y, Z) ).
 
:- style_check(-singleton). % added djd
%% :- module('Rationals', []). converted djd
:- module(rationals). % converted djd

:- op(500, yfx, and).
:- op(400, yfx, or).

/* 
File:		Rationals.sup
Subject:	Implementation of the system module Rationals.
Author: 	Jiwei Wang
Date:		29 April 1992

================================================================================
*/


%% '$$module'('@(#)Rationals.sup 1.8 last updated 93/12/08 16:19:16 by jiwei').
module(rationalssup). %% converted djd

%------------------------------------------------------------------------------
% not completely certain about the optimized implementation.
%------------------------------------------------------------------------------


'Rationals.=<.P2'(X, Y) :-
   nonvar(X), nonvar(Y), !,
   eval(X, XX), eval(Y, YY), XX =< YY.

'Rationals.=<.P2'(X, Y) :-
   user:goedel_freeze(ground([X,Y]),
   	('Rationals':eval(X, XX), 'Rationals':eval(Y, YY), XX =< YY)).

'~Rationals.=<.P2'(X, Y) :-
   nonvar(X), nonvar(Y), !,
   eval(X, XX), eval(Y, YY), XX =< YY.

'~Rationals.=<.P2'(X, Y) :-
   user:goedel_freeze(ground([X,Y]),
	('Rationals':eval(X, XX), 'Rationals':eval(Y, YY), XX =< YY)).

%- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

'Rationals.>=.P2'(X, Y) :-
   nonvar(X), nonvar(Y), !,
   eval(X, XX), eval(Y, YY), XX >= YY.

'Rationals.>=.P2'(X, Y) :-
   user:goedel_freeze(ground([X,Y]),
   	('Rationals':eval(X, XX), 'Rationals':eval(Y, YY), XX >= YY)).

'~Rationals.>=.P2'(X, Y) :-
   nonvar(X), nonvar(Y), !,
   eval(X, XX), eval(Y, YY), XX >= YY.

'~Rationals.>=.P2'(X, Y) :-
   user:goedel_freeze(ground([X,Y]),
   	('Rationals':eval(X, XX), 'Rationals':eval(Y, YY), XX >= YY)).

%- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

'Rationals.>.P2'(X, Y) :-
   nonvar(X), nonvar(Y), !,
   eval(X, XX), eval(Y, YY), XX > YY.

'Rationals.>.P2'(X, Y) :-
   user:goedel_freeze(ground([X,Y]),
   	('Rationals':eval(X, XX), 'Rationals':eval(Y, YY), XX > YY)).

'~Rationals.>.P2'(X, Y) :-
   nonvar(X), nonvar(Y), !,
   eval(X, XX), eval(Y, YY), XX > YY.

'~Rationals.>.P2'(X, Y) :-
   user:goedel_freeze(ground([X,Y]),
   	('Rationals':eval(X, XX), 'Rationals':eval(Y, YY), XX > YY)).

%- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

'Rationals.<.P2'(X, Y) :-
   nonvar(X), nonvar(Y), !,
   eval(X, XX), eval(Y, YY), XX < YY.

'Rationals.<.P2'(X, Y) :-
   user:goedel_freeze(ground([X,Y]),
   	('Rationals':eval(X, XX), 'Rationals':eval(Y, YY), XX < YY)).

'~Rationals.<.P2'(X, Y) :-
   nonvar(X), nonvar(Y), !,
   eval(X, XX), eval(Y, YY), XX < YY.

'~Rationals.<.P2'(X, Y) :-
   user:goedel_freeze(ground([X,Y]),
   	('Rationals':eval(X, XX), 'Rationals':eval(Y, YY), XX < YY)).

%- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

'Rationals.StandardRational.P3'(X, Y, Z) :-
   user:goedel_freeze(ground([X]), X = Y//Z).

/*==============================================================================
 * Following are functions that support the constraint solving with integers.
 */

% for //
% Note: x//y= 3//5 has infinite solutions.

rational(X//Y, Z) :-
   integer(X), integer(Y), !,
   simplify(X//Y, Z).

rational(X//Y, Z) :-
   nonvar(Z), integer(X), !,
   assign(X//Y, Z).

rational(X//Y, Z) :-
   nonvar(Z), integer(Y), !,
   assign(X//Y, Z).

rational(X//Y, Z) :-
   user:goedel_freeze(ground([X,Z]) or ground([Y,Z]) or ground([X,Y]),
			'Rationals':rational(X//Y, Z) ).

%------------------------------------------------------------------------------

plus(A//B, C//D, X) :-
   integer(A), integer(B),
   integer(C), integer(D), !,
   simplify( (A*D + B*C) // (B*D), Z),
   assign(X, Z).

plus(A//B, X, C//D) :-
   integer(A), integer(B),
   integer(C), integer(D), !,
   simplify( (-A*D + B*C) // (B*D), Z),
   assign(X, Z).

plus(X, A//B, C//D) :-
   integer(A), integer(B),
   integer(C), integer(D), !,
   simplify( (-A*D + B*C) // (B*D), Z),
   assign(X, Z).

plus(X, Y, Z) :-
   user:goedel_freeze(ground([X,Z]) or ground([Y,Z]) or ground([X,Y]),
			'Rationals':plus(X, Y, Z)).

%------------------------------------------------------------------------------


negative(A//B, X) :-
   nonvar(A), !,
   simplify((-A)//B, Z),
   assign(X, Z).

negative(-(A//B), X) :-
   nonvar(A), !,
   simplify(A//B, Z),
   assign(X, Z).

negative(X, A//B) :-
   nonvar(A), !,
   simplify((-A)//B, Z),
   assign(X, Z).

negative(X, -(A//B)) :-
   nonvar(A), !,
   simplify(A//B, Z),
   assign(X, Z).

negative(X, Y) :-
   user:goedel_freeze(ground([Y]) or ground([X]), 'Rationals':negative(X, Y)).

%------------------------------------------------------------------------------

minus(A//B, C//D, X) :-
   integer(A), integer(B),
   integer(C), integer(D), !,
   simplify( (A*D - B*C) // (B*D), Z),
   assign(X, Z).

minus(A//B, X, C//D) :-
   integer(A), integer(B),
   integer(C), integer(D), !,
   simplify( (A*D - B*C) // (B*D), Z),
   assign(X, Z).

minus(X, A//B, C//D) :-
   integer(A), integer(B),
   integer(C), integer(D), !,
   simplify( (A*D + B*C) // (B*D), Z),
   assign(X, Z).

minus(X, Y, Z) :-
   user:goedel_freeze(ground([X,Z]) or ground([Y,Z]) or ground([X,Y]),
			'Rationals':minus(X, Y, Z)).

%------------------------------------------------------------------------------
 
times(A//B, C//D, X) :-
   integer(A), integer(B),
   integer(C), integer(D), !,
   simplify( (A*C) // (B*D), Z),
   assign(X, Z).

times(A//B, X, C//D) :-
   integer(A), integer(B),
   integer(C), integer(D), !,
   ( A =:= 0, C =:= 0
     -> true		% X is left uninstantiated
     ;  A =\= 0,	% make sure A//B is not zero. If A//B is zero, it fails.
        simplify( (B*C) // (A*D), Z),
        assign(X, Z)
   ).

times(X, A//B, C//D) :-
   integer(A), integer(B),
   integer(C), integer(D), !,
   ( A =:= 0, C =:= 0
     -> true		% X is left uninstantiated
     ;  A =\= 0,	% make sure A//B is not zero. If A//B is zero, it fails.
        simplify( (B*C) // (A*D), Z),
        assign(X, Z)
   ).

times(X, Y, Z) :-
   user:goedel_freeze(ground([X,Z]) or ground([Y,Z]) or ground([X,Y]),
			'Rationals':times(X, Y, Z)).

%------------------------------------------------------------------------------
 
divides(A//B, C//D, X) :-
   integer(A), integer(B),
   integer(C), integer(D), !,
   ( C = 0
     -> % X = 0, but this value is never used
        format(user_error, "Arithmetic exception: division by 0.~n", []),
	raise_exception(catch_in_query)
     ;  simplify( (A*D) // (B*C), Z),
        assign(X, Z)
   ).

divides(X, A//B, C//D) :-
   integer(A), integer(B),
   integer(C), integer(D), !,
   ( A = 0
     -> % X = 0, but this value is never used
        format(user_error, "Arithmetic exception: division by 0.~n", []),
	raise_exception(catch_in_query)
     ;  simplify( (A*C) // (B*D), Z),
        assign(X, Z)
   ).

divides(A//B, X, C//D) :-
   integer(A), integer(B),
   integer(C), integer(D), !,
   simplify( (A*C) // (B*D), Z),
   assign(X, Z).

divides(X, Y, Z) :-
   user:goedel_freeze(ground([Y,Z]) or ground([X,Z]) or ground([X,Y]),
		'Rationals':divides(X, Y, Z)).

%------------------------------------------------------------------------------

power(A//B, Y, Z) :-
   integer(A), integer(B),
   integer(Y), !,
   ( Y = 0
     -> Z = 1//1
     ;  Y2 is abs(Y),
        power2(Y2, A, 1, A2),
        power2(Y2, B, 1, B2),
        ( Y > 0
          -> simplify(A2 // B2, C)
          ;  simplify(B2 // A2, C)
        ),
   	assign(Z, C)
   ).

power(A//B, X, C//D) :-
   integer(A), integer(B),
   integer(C), integer(D), !,
   A*B*C*D >= 0,		% checking X and Z are of the same sign
   ( A = 0, C = 0
     -> 'Rationals.>.P2'(X, 0)	% add constraint X > 0 
     ;  ( A = 0, C = 1, D = 1
	  -> X = 0//1
	  ;  ( (A = 0, C =\= 0; A =\= 0, C = 0)
	       -> fail
	       ;  ( A = 1
		    -> C = 1	% if C \= 1 this fails, X is left uninstantiated
		    ;  X is integer(round(log(abs(C/D))/log(abs(A/B)))),
     		       X2 is abs(X),
        	       power2(X2, A, 1, A2),
        	       power2(X2, B, 1, B2),
        	       ( X > 0
          		 -> simplify(A2 // B2, Z)
          		 ;  simplify(B2 // A2, Z)
        	       ),
		       simplify(C//D, Z)	% testing integers
		  )
	     )
	)
   ).

power(X, Y, C//D) :-
   integer(Y), integer(C), integer(D), !,
   ( Y = 0
     -> C = 1              % X is left as a variable
     ;  A = integer(round(exp(log(abs(C))/Y))),
	B = integer(round(exp(log(abs(D))/Y))),
        Y2 is abs(Y),
        power2(Y2, A, 1, A2),
        power2(Y2, B, 1, B2),
        ( Y > 0
          -> simplify(A2 // B2, S)
          ;  simplify(B2 // A2, S)
        ),
        simplify(abs(C)//abs(D), S),	% testing integers
	( 0 =:= Y mod 2
	  -> ( C < 0
	       -> fail			% should fail
	       ;  ( Y > 0
	            -> ( simplify(A//B, Z), assign(X, Z);
		         simplify((-A)//B, Z), assign(X, Z)
		       )
	            ;  ( simplify(B//A, Z), assign(X, Z);
		         simplify((-B)//A, Z), assign(X, Z)
		       )
		  )
	     )
	  ;  ( Y > 0
	       -> simplify(A//B, Z), assign(X, Z)
	       ;  simplify(B//A, Z), assign(X, Z)
	     )
	)
   ).

power(X, Y, Z) :-
   user:goedel_freeze(ground([X,Z]) or ground([Y,Z]) or ground([X,Y]),
		'Rationals':power(X, Y, Z)).


power2(1, X, P, NewP) :-
   NewP is X*P, !.
power2(N, X, P, NewP) :-
   N > 1,
   P2 is X*P, 
   N2 is N - 1,
   power2(N2, X, P2, NewP).

%------------------------------------------------------------------------------

absolute(A // B, Y) :-
   integer(A), !,
   ( A >= 0
     -> Y = A // B
     ;  simplify((-A) // B, Y)
   ).

absolute(X, A//B) :-
   integer(A), !,
   ( X = A//B
   ;
     simplify((-A) // B, X)
   ).

absolute(X, Y) :-
   user:goedel_freeze(ground([Y]) or ground([X]), 'Rationals':absolute(X, Y) ).

%------------------------------------------------------------------------------
% The first case prevents a zero rational slips through.

sign(X, 0) :-
   nonvar(X), X = 0, !.

sign(A // _, Y) :-
   integer(A), !,
   ( A = 0
     -> Y = 0
     ;  ( A > 0
          -> Y = 1
	  ;  Y = -1
	)
   ).

sign(X, Y) :-
   user:goedel_freeze(ground([X]), 'Rationals':sign(X, Y) ).

/*------------------------------------------------------------------------------
 * maximum and minimum assum that X and Y are integers.
 */
 
maximum(X, Y, Z) :-
   user:goedel_freeze(ground([X,Y]), 'Rationals':maximum_aux(X, Y, Z) ).

maximum_aux(X, Y, Z) :-
   eval(X, A),
   eval(Y, B),
   ( B > A
     -> Z = Y
     ;  Z = X
   ).

/*------------------------------------------------------------------------------
 */

minimum(X, Y, Z) :-
   user:goedel_freeze(ground([X,Y]), 'Rationals':minimum_aux(X, Y, Z) ).
 
minimum_aux(X, Y, Z) :-
   eval(X, A),
   eval(Y, B),
   ( B < A
     -> Z = Y
     ;  Z = X
   ).

%------------------------------------------------------------------------------

% // is defined as a function in SICStus
simplify(Expr1 // Expr2, Result) :- !,
   X is Expr1,
   Y is Expr2,
   ( Y = 0
     -> Result = 0,
	format(user_error, "Arithmetic exception: illegal rational number.~n",
		[]),
	raise_exception(catch_in_query)
     ;  ( Xabs is abs(X),
	  Yabs is abs(Y),
	  gcd(Xabs, Yabs, GCD),
	  M is Xabs // GCD,
	  N is Yabs // GCD,
	  ( X = 0
	    -> Result = 0 // 1
	    ; ( ( X > 0, Y > 0; X < 0, Y < 0 ) 
	        -> Result = M // N
	        ;  NegM is -M,
		   Result = NegM // N
	      )
	  )
	)
   ).

simplify(Expr, Result) :- 
   Result is Expr.


% Euclid's algorithm
gcd(X, Y, Z) :-
   A is X mod Y,
   ( A = 0
     -> Z = Y
     ;  gcd(Y, A, Z)
   ).

%------------------------------------------------------------------------------

eval(X // Y, Z) :- !,
   Z is X / Y.

eval(X, X).

%------------------------------------------------------------------------------
% assign(X//Y, A//B) assigns the value of A//B to X//Y in which X or Y or both
% can be variables.

assign(X//Y, A//B) :-
   var(X), var(Y), !,
   X = A,
   Y = B.

assign(X//Y, A//B) :-
   var(X), !,
   (Y*A) mod B =:= 0,
   X is (Y*A) // B.

assign(X//Y, A//B) :-
   var(Y), !,
   (X*B) mod A =:= 0,
   Y is (X*B) // A.

:- style_check(-singleton). % added djd
%% :- module('Floats', []).
:- module(floats).  %% converted djd

:- op(500, yfx, and).
:- op(400, yfx, or).

:- style_check(-singleton). % added djd
%% :- module('Numbers', []).
:- module(numbers).  % converted djd


:- op(500, yfx, and).
:- op(400, yfx, or).

/* 
File:		Numbers.sup
Subject:	Implemention of the system module Numbers
Author: 	Jiwei Wang
Date:		28 October 1992

================================================================================
*/




%% '$$module'('@(#)Numbers.sup 1.3 last updated 93/06/22 16:08:16 by jiwei').
module(numberssup).  %% converted djd


'Numbers.IntegerString.P2'(X, Y) :-
   integer(X), !,
   name(X, Ints),
   'Strings':'Strings.StringInts.P2'(Y, Ints).

'Numbers.IntegerString.P2'(X, Y) :-
   nonvar(Y), !,
   'Strings':'Strings.StringInts.P2'(Y, Ints),
   Ints \== [],
   remove_sign(Ints, Ints2),
   sort(Ints2, Ints3),
   user:subset(Ints3, [0'0, 0'1, 0'2, 0'3, 0'4, 0'5, 0'6, 0'7, 0'8, 0'9]),
   name(X, Ints).

'Numbers.IntegerString.P2'(X, Y) :-
   user:goedel_freeze(ground([X]) or ground([Y]),
		'Numbers':'Numbers.IntegerString.P2'(X, Y) ).

remove_sign([0'-|Ints], Ints) :- !.
remove_sign(Ints, Ints).

'~Numbers.IntegerString.P2'(X, Y) :-
   'Numbers.IntegerString.P2'(X, Y).
:- style_check(-singleton). % added djd
%% :- module('Lists', []).
:- module(lists).  % converted djd

:- discontiguous 'lists.Member.P2.0'/2. %% added djd
:- discontiguous '~lists.Member.P2.0'/2. %% added djd
:- discontiguous 'lists.Delete.P3.0'/3. %% added djd
:- discontiguous '~lists.Delete.P3.0'/3. %% added djd
:- discontiguous 'lists.Append.P3.0'/3. %% added djd
:- discontiguous '~lists.Append.P3.0'/3. %% added djd
:- discontiguous 'lists.DeleteFirst.P3.0'/3. %% added djd
:- discontiguous '~lists.DeleteFirst.P3.0'/3. %% added djd
:- discontiguous 'lists.Length.P2.0'/2. %% added djd
:- discontiguous '~lists.Length.P2.0'/2. %% added djd
:- discontiguous 'lists.Permutation.P2.0'/2. %% added djd
:- discontiguous '~lists.Permutation.P2.0'/2. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous 'lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous 'lists.MemberCheck.P2.0'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.0'/2. %% added djd
:- discontiguous 'lists.Partition.P4'/4. %% added djd
:- discontiguous '~lists.Partition.P4'/4. %% added djd
:- discontiguous 'lists.Partition.P4'/4. %% added djd
:- discontiguous '~lists.Partition.P4'/4. %% added djd
:- discontiguous 'lists.Sorted.P1.1'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.1'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.1'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.1'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.0'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.0'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.0'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.0'/1. %% added djd
:- discontiguous 'lists.Sort.P2.0'/2. %% added djd
:- discontiguous '~lists.Sort.P2.0'/2. %% added djd
:- discontiguous 'lists.Reverse3.P3'/3. %% added djd
:- discontiguous '~lists.Reverse3.P3'/3. %% added djd
:- discontiguous 'lists.Split.P4'/4. %% added djd
:- discontiguous '~lists.Split.P4'/4. %% added djd
:- discontiguous 'lists.Member.P2.0'/2. %% added djd
:- discontiguous '~lists.Member.P2.0'/2. %% added djd
:- discontiguous 'lists.Delete.P3.0'/3. %% added djd
:- discontiguous '~lists.Delete.P3.0'/3. %% added djd
:- discontiguous 'lists.Append.P3.0'/3. %% added djd
:- discontiguous '~lists.Append.P3.0'/3. %% added djd
:- discontiguous 'lists.DeleteFirst.P3.0'/3. %% added djd
:- discontiguous '~lists.DeleteFirst.P3.0'/3. %% added djd
:- discontiguous 'lists.Length.P2.0'/2. %% added djd
:- discontiguous '~lists.Length.P2.0'/2. %% added djd
:- discontiguous 'lists.Permutation.P2.0'/2. %% added djd
:- discontiguous '~lists.Permutation.P2.0'/2. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous 'lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous 'lists.MemberCheck.P2.0'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.0'/2. %% added djd
:- discontiguous 'lists.Partition.P4'/4. %% added djd
:- discontiguous '~lists.Partition.P4'/4. %% added djd
:- discontiguous 'lists.Partition.P4'/4. %% added djd
:- discontiguous '~lists.Partition.P4'/4. %% added djd
:- discontiguous 'lists.Sorted.P1.1'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.1'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.1'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.1'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.0'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.0'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.0'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.0'/1. %% added djd
:- discontiguous 'lists.Sort.P2.0'/2. %% added djd
:- discontiguous '~lists.Sort.P2.0'/2. %% added djd
:- discontiguous 'lists.Reverse3.P3'/3. %% added djd
:- discontiguous '~lists.Reverse3.P3'/3. %% added djd
:- discontiguous 'lists.Split.P4'/4. %% added djd
:- discontiguous '~lists.Split.P4'/4. %% added djd
:- discontiguous 'lists.Member.P2.0'/2. %% added djd
:- discontiguous '~lists.Member.P2.0'/2. %% added djd
:- discontiguous 'lists.Delete.P3.0'/3. %% added djd
:- discontiguous '~lists.Delete.P3.0'/3. %% added djd
:- discontiguous 'lists.Append.P3.0'/3. %% added djd
:- discontiguous '~lists.Append.P3.0'/3. %% added djd
:- discontiguous 'lists.DeleteFirst.P3.0'/3. %% added djd
:- discontiguous '~lists.DeleteFirst.P3.0'/3. %% added djd
:- discontiguous 'lists.Length.P2.0'/2. %% added djd
:- discontiguous '~lists.Length.P2.0'/2. %% added djd
:- discontiguous 'lists.Permutation.P2.0'/2. %% added djd
:- discontiguous '~lists.Permutation.P2.0'/2. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous 'lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous 'lists.MemberCheck.P2.0'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.0'/2. %% added djd
:- discontiguous 'lists.Partition.P4'/4. %% added djd
:- discontiguous '~lists.Partition.P4'/4. %% added djd
:- discontiguous 'lists.Partition.P4'/4. %% added djd
:- discontiguous '~lists.Partition.P4'/4. %% added djd
:- discontiguous 'lists.Sorted.P1.1'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.1'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.1'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.1'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.0'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.0'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.0'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.0'/1. %% added djd
:- discontiguous 'lists.Sort.P2.0'/2. %% added djd
:- discontiguous '~lists.Sort.P2.0'/2. %% added djd
:- discontiguous 'lists.Reverse3.P3'/3. %% added djd
:- discontiguous '~lists.Reverse3.P3'/3. %% added djd
:- discontiguous 'lists.Split.P4'/4. %% added djd
:- discontiguous '~lists.Split.P4'/4. %% added djd
:- discontiguous 'lists.Member.P2.0'/2. %% added djd
:- discontiguous '~lists.Member.P2.0'/2. %% added djd
:- discontiguous 'lists.Delete.P3.0'/3. %% added djd
:- discontiguous '~lists.Delete.P3.0'/3. %% added djd
:- discontiguous 'lists.Append.P3.0'/3. %% added djd
:- discontiguous '~lists.Append.P3.0'/3. %% added djd
:- discontiguous 'lists.DeleteFirst.P3.0'/3. %% added djd
:- discontiguous '~lists.DeleteFirst.P3.0'/3. %% added djd
:- discontiguous 'lists.Length.P2.0'/2. %% added djd
:- discontiguous '~lists.Length.P2.0'/2. %% added djd
:- discontiguous 'lists.Permutation.P2.0'/2. %% added djd
:- discontiguous '~lists.Permutation.P2.0'/2. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous 'lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous 'lists.MemberCheck.P2.0'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.0'/2. %% added djd
:- discontiguous 'lists.Partition.P4'/4. %% added djd
:- discontiguous '~lists.Partition.P4'/4. %% added djd
:- discontiguous 'lists.Partition.P4'/4. %% added djd
:- discontiguous '~lists.Partition.P4'/4. %% added djd
:- discontiguous 'lists.Sorted.P1.1'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.1'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.1'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.1'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.0'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.0'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.0'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.0'/1. %% added djd
:- discontiguous 'lists.Sort.P2.0'/2. %% added djd
:- discontiguous '~lists.Sort.P2.0'/2. %% added djd
:- discontiguous 'lists.Reverse3.P3'/3. %% added djd
:- discontiguous '~lists.Reverse3.P3'/3. %% added djd
:- discontiguous 'lists.Split.P4'/4. %% added djd
:- discontiguous '~lists.Split.P4'/4. %% added djd
:- discontiguous 'lists.Member.P2.0'/2. %% added djd
:- discontiguous '~lists.Member.P2.0'/2. %% added djd
:- discontiguous 'lists.Delete.P3.0'/3. %% added djd
:- discontiguous '~lists.Delete.P3.0'/3. %% added djd
:- discontiguous 'lists.Append.P3.0'/3. %% added djd
:- discontiguous '~lists.Append.P3.0'/3. %% added djd
:- discontiguous 'lists.DeleteFirst.P3.0'/3. %% added djd
:- discontiguous '~lists.DeleteFirst.P3.0'/3. %% added djd
:- discontiguous 'lists.Length.P2.0'/2. %% added djd
:- discontiguous '~lists.Length.P2.0'/2. %% added djd
:- discontiguous 'lists.Permutation.P2.0'/2. %% added djd
:- discontiguous '~lists.Permutation.P2.0'/2. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous 'lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous 'lists.MemberCheck.P2.0'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.0'/2. %% added djd
:- discontiguous 'lists.Partition.P4'/4. %% added djd
:- discontiguous '~lists.Partition.P4'/4. %% added djd
:- discontiguous 'lists.Partition.P4'/4. %% added djd
:- discontiguous '~lists.Partition.P4'/4. %% added djd
:- discontiguous 'lists.Sorted.P1.1'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.1'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.1'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.1'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.0'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.0'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.0'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.0'/1. %% added djd
:- discontiguous 'lists.Sort.P2.0'/2. %% added djd
:- discontiguous '~lists.Sort.P2.0'/2. %% added djd
:- discontiguous 'lists.Reverse3.P3'/3. %% added djd
:- discontiguous '~lists.Reverse3.P3'/3. %% added djd
:- discontiguous 'lists.Split.P4'/4. %% added djd
:- discontiguous '~lists.Split.P4'/4. %% added djd
:- discontiguous 'lists.Member.P2.0'/2. %% added djd
:- discontiguous '~lists.Member.P2.0'/2. %% added djd
:- discontiguous 'lists.Delete.P3.0'/3. %% added djd
:- discontiguous '~lists.Delete.P3.0'/3. %% added djd
:- discontiguous 'lists.Append.P3.0'/3. %% added djd
:- discontiguous '~lists.Append.P3.0'/3. %% added djd
:- discontiguous 'lists.DeleteFirst.P3.0'/3. %% added djd
:- discontiguous '~lists.DeleteFirst.P3.0'/3. %% added djd
:- discontiguous 'lists.Length.P2.0'/2. %% added djd
:- discontiguous '~lists.Length.P2.0'/2. %% added djd
:- discontiguous 'lists.Permutation.P2.0'/2. %% added djd
:- discontiguous '~lists.Permutation.P2.0'/2. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous 'lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous 'lists.MemberCheck.P2.0'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.0'/2. %% added djd
:- discontiguous 'lists.Partition.P4'/4. %% added djd
:- discontiguous '~lists.Partition.P4'/4. %% added djd
:- discontiguous 'lists.Partition.P4'/4. %% added djd
:- discontiguous '~lists.Partition.P4'/4. %% added djd
:- discontiguous 'lists.Sorted.P1.1'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.1'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.1'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.1'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.0'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.0'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.0'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.0'/1. %% added djd
:- discontiguous 'lists.Sort.P2.0'/2. %% added djd
:- discontiguous '~lists.Sort.P2.0'/2. %% added djd
:- discontiguous 'lists.Reverse3.P3'/3. %% added djd
:- discontiguous '~lists.Reverse3.P3'/3. %% added djd
:- discontiguous 'lists.Split.P4'/4. %% added djd
:- discontiguous '~lists.Split.P4'/4. %% added djd
:- discontiguous 'lists.Member.P2.0'/2. %% added djd
:- discontiguous '~lists.Member.P2.0'/2. %% added djd
:- discontiguous 'lists.Delete.P3.0'/3. %% added djd
:- discontiguous '~lists.Delete.P3.0'/3. %% added djd
:- discontiguous 'lists.Append.P3.0'/3. %% added djd
:- discontiguous '~lists.Append.P3.0'/3. %% added djd
:- discontiguous 'lists.DeleteFirst.P3.0'/3. %% added djd
:- discontiguous '~lists.DeleteFirst.P3.0'/3. %% added djd
:- discontiguous 'lists.Length.P2.0'/2. %% added djd
:- discontiguous '~lists.Length.P2.0'/2. %% added djd
:- discontiguous 'lists.Permutation.P2.0'/2. %% added djd
:- discontiguous '~lists.Permutation.P2.0'/2. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous 'lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous 'lists.MemberCheck.P2.0'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.0'/2. %% added djd
:- discontiguous 'lists.Partition.P4'/4. %% added djd
:- discontiguous '~lists.Partition.P4'/4. %% added djd
:- discontiguous 'lists.Partition.P4'/4. %% added djd
:- discontiguous '~lists.Partition.P4'/4. %% added djd
:- discontiguous 'lists.Sorted.P1.1'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.1'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.1'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.1'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.0'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.0'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.0'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.0'/1. %% added djd
:- discontiguous 'lists.Sort.P2.0'/2. %% added djd
:- discontiguous '~lists.Sort.P2.0'/2. %% added djd
:- discontiguous 'lists.Reverse3.P3'/3. %% added djd
:- discontiguous '~lists.Reverse3.P3'/3. %% added djd
:- discontiguous 'lists.Split.P4'/4. %% added djd
:- discontiguous '~lists.Split.P4'/4. %% added djd
:- discontiguous 'lists.Member.P2.0'/2. %% added djd
:- discontiguous '~lists.Member.P2.0'/2. %% added djd
:- discontiguous 'lists.Delete.P3.0'/3. %% added djd
:- discontiguous '~lists.Delete.P3.0'/3. %% added djd
:- discontiguous 'lists.Append.P3.0'/3. %% added djd
:- discontiguous '~lists.Append.P3.0'/3. %% added djd
:- discontiguous 'lists.DeleteFirst.P3.0'/3. %% added djd
:- discontiguous '~lists.DeleteFirst.P3.0'/3. %% added djd
:- discontiguous 'lists.Length.P2.0'/2. %% added djd
:- discontiguous '~lists.Length.P2.0'/2. %% added djd
:- discontiguous 'lists.Permutation.P2.0'/2. %% added djd
:- discontiguous '~lists.Permutation.P2.0'/2. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous 'lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous 'lists.MemberCheck.P2.0'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.0'/2. %% added djd
:- discontiguous 'lists.Partition.P4'/4. %% added djd
:- discontiguous '~lists.Partition.P4'/4. %% added djd
:- discontiguous 'lists.Partition.P4'/4. %% added djd
:- discontiguous '~lists.Partition.P4'/4. %% added djd
:- discontiguous 'lists.Sorted.P1.1'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.1'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.1'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.1'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.0'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.0'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.0'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.0'/1. %% added djd
:- discontiguous 'lists.Sort.P2.0'/2. %% added djd
:- discontiguous '~lists.Sort.P2.0'/2. %% added djd
:- discontiguous 'lists.Reverse3.P3'/3. %% added djd
:- discontiguous '~lists.Reverse3.P3'/3. %% added djd
:- discontiguous 'lists.Split.P4'/4. %% added djd
:- discontiguous '~lists.Split.P4'/4. %% added djd
:- discontiguous 'lists.Member.P2.0'/2. %% added djd
:- discontiguous '~lists.Member.P2.0'/2. %% added djd
:- discontiguous 'lists.Delete.P3.0'/3. %% added djd
:- discontiguous '~lists.Delete.P3.0'/3. %% added djd
:- discontiguous 'lists.Append.P3.0'/3. %% added djd
:- discontiguous '~lists.Append.P3.0'/3. %% added djd
:- discontiguous 'lists.DeleteFirst.P3.0'/3. %% added djd
:- discontiguous '~lists.DeleteFirst.P3.0'/3. %% added djd
:- discontiguous 'lists.Length.P2.0'/2. %% added djd
:- discontiguous '~lists.Length.P2.0'/2. %% added djd
:- discontiguous 'lists.Permutation.P2.0'/2. %% added djd
:- discontiguous '~lists.Permutation.P2.0'/2. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous 'lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous 'lists.MemberCheck.P2.0'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.0'/2. %% added djd
:- discontiguous 'lists.Partition.P4'/4. %% added djd
:- discontiguous '~lists.Partition.P4'/4. %% added djd
:- discontiguous 'lists.Partition.P4'/4. %% added djd
:- discontiguous '~lists.Partition.P4'/4. %% added djd
:- discontiguous 'lists.Sorted.P1.1'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.1'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.1'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.1'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.0'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.0'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.0'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.0'/1. %% added djd
:- discontiguous 'lists.Sort.P2.0'/2. %% added djd
:- discontiguous '~lists.Sort.P2.0'/2. %% added djd
:- discontiguous 'lists.Reverse3.P3'/3. %% added djd
:- discontiguous '~lists.Reverse3.P3'/3. %% added djd
:- discontiguous 'lists.Split.P4'/4. %% added djd
:- discontiguous '~lists.Split.P4'/4. %% added djd
:- discontiguous 'lists.Member.P2.0'/2. %% added djd
:- discontiguous '~lists.Member.P2.0'/2. %% added djd
:- discontiguous 'lists.Delete.P3.0'/3. %% added djd
:- discontiguous '~lists.Delete.P3.0'/3. %% added djd
:- discontiguous 'lists.Append.P3.0'/3. %% added djd
:- discontiguous '~lists.Append.P3.0'/3. %% added djd
:- discontiguous 'lists.DeleteFirst.P3.0'/3. %% added djd
:- discontiguous '~lists.DeleteFirst.P3.0'/3. %% added djd
:- discontiguous 'lists.Length.P2.0'/2. %% added djd
:- discontiguous '~lists.Length.P2.0'/2. %% added djd
:- discontiguous 'lists.Permutation.P2.0'/2. %% added djd
:- discontiguous '~lists.Permutation.P2.0'/2. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous 'lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous 'lists.MemberCheck.P2.0'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.0'/2. %% added djd
:- discontiguous 'lists.Partition.P4'/4. %% added djd
:- discontiguous '~lists.Partition.P4'/4. %% added djd
:- discontiguous 'lists.Partition.P4'/4. %% added djd
:- discontiguous '~lists.Partition.P4'/4. %% added djd
:- discontiguous 'lists.Sorted.P1.1'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.1'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.1'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.1'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.0'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.0'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.0'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.0'/1. %% added djd
:- discontiguous 'lists.Sort.P2.0'/2. %% added djd
:- discontiguous '~lists.Sort.P2.0'/2. %% added djd
:- discontiguous 'lists.Reverse3.P3'/3. %% added djd
:- discontiguous '~lists.Reverse3.P3'/3. %% added djd
:- discontiguous 'lists.Split.P4'/4. %% added djd
:- discontiguous '~lists.Split.P4'/4. %% added djd
:- discontiguous 'lists.Member.P2.0'/2. %% added djd
:- discontiguous '~lists.Member.P2.0'/2. %% added djd
:- discontiguous 'lists.Delete.P3.0'/3. %% added djd
:- discontiguous '~lists.Delete.P3.0'/3. %% added djd
:- discontiguous 'lists.Append.P3.0'/3. %% added djd
:- discontiguous '~lists.Append.P3.0'/3. %% added djd
:- discontiguous 'lists.DeleteFirst.P3.0'/3. %% added djd
:- discontiguous '~lists.DeleteFirst.P3.0'/3. %% added djd
:- discontiguous 'lists.Length.P2.0'/2. %% added djd
:- discontiguous '~lists.Length.P2.0'/2. %% added djd
:- discontiguous 'lists.Permutation.P2.0'/2. %% added djd
:- discontiguous '~lists.Permutation.P2.0'/2. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous 'lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous 'lists.MemberCheck.P2.0'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.0'/2. %% added djd
:- discontiguous 'lists.Partition.P4'/4. %% added djd
:- discontiguous '~lists.Partition.P4'/4. %% added djd
:- discontiguous 'lists.Partition.P4'/4. %% added djd
:- discontiguous '~lists.Partition.P4'/4. %% added djd
:- discontiguous 'lists.Sorted.P1.1'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.1'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.1'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.1'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.0'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.0'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.0'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.0'/1. %% added djd
:- discontiguous 'lists.Sort.P2.0'/2. %% added djd
:- discontiguous '~lists.Sort.P2.0'/2. %% added djd
:- discontiguous 'lists.Reverse3.P3'/3. %% added djd
:- discontiguous '~lists.Reverse3.P3'/3. %% added djd
:- discontiguous 'lists.Split.P4'/4. %% added djd
:- discontiguous '~lists.Split.P4'/4. %% added djd
:- discontiguous 'lists.Member.P2.0'/2. %% added djd
:- discontiguous '~lists.Member.P2.0'/2. %% added djd
:- discontiguous 'lists.Delete.P3.0'/3. %% added djd
:- discontiguous '~lists.Delete.P3.0'/3. %% added djd
:- discontiguous 'lists.Append.P3.0'/3. %% added djd
:- discontiguous '~lists.Append.P3.0'/3. %% added djd
:- discontiguous 'lists.DeleteFirst.P3.0'/3. %% added djd
:- discontiguous '~lists.DeleteFirst.P3.0'/3. %% added djd
:- discontiguous 'lists.Length.P2.0'/2. %% added djd
:- discontiguous '~lists.Length.P2.0'/2. %% added djd
:- discontiguous 'lists.Permutation.P2.0'/2. %% added djd
:- discontiguous '~lists.Permutation.P2.0'/2. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous 'lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous 'lists.MemberCheck.P2.0'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.0'/2. %% added djd
:- discontiguous 'lists.Partition.P4'/4. %% added djd
:- discontiguous '~lists.Partition.P4'/4. %% added djd
:- discontiguous 'lists.Partition.P4'/4. %% added djd
:- discontiguous '~lists.Partition.P4'/4. %% added djd
:- discontiguous 'lists.Sorted.P1.1'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.1'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.1'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.1'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.0'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.0'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.0'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.0'/1. %% added djd
:- discontiguous 'lists.Sort.P2.0'/2. %% added djd
:- discontiguous '~lists.Sort.P2.0'/2. %% added djd
:- discontiguous 'lists.Reverse3.P3'/3. %% added djd
:- discontiguous '~lists.Reverse3.P3'/3. %% added djd
:- discontiguous 'lists.Split.P4'/4. %% added djd
:- discontiguous '~lists.Split.P4'/4. %% added djd
:- discontiguous 'lists.Member.P2.0'/2. %% added djd
:- discontiguous '~lists.Member.P2.0'/2. %% added djd
:- discontiguous 'lists.Delete.P3.0'/3. %% added djd
:- discontiguous '~lists.Delete.P3.0'/3. %% added djd
:- discontiguous 'lists.Append.P3.0'/3. %% added djd
:- discontiguous '~lists.Append.P3.0'/3. %% added djd
:- discontiguous 'lists.DeleteFirst.P3.0'/3. %% added djd
:- discontiguous '~lists.DeleteFirst.P3.0'/3. %% added djd
:- discontiguous 'lists.Length.P2.0'/2. %% added djd
:- discontiguous '~lists.Length.P2.0'/2. %% added djd
:- discontiguous 'lists.Permutation.P2.0'/2. %% added djd
:- discontiguous '~lists.Permutation.P2.0'/2. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.Merge.P3.0'/3. %% added djd
:- discontiguous '~lists.Merge.P3.0'/3. %% added djd
:- discontiguous 'lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous 'lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.1'/2. %% added djd
:- discontiguous 'lists.MemberCheck.P2.0'/2. %% added djd
:- discontiguous '~lists.MemberCheck.P2.0'/2. %% added djd
:- discontiguous 'lists.Partition.P4'/4. %% added djd
:- discontiguous '~lists.Partition.P4'/4. %% added djd
:- discontiguous 'lists.Partition.P4'/4. %% added djd
:- discontiguous '~lists.Partition.P4'/4. %% added djd
:- discontiguous 'lists.Sorted.P1.1'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.1'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.1'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.1'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.0'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.0'/1. %% added djd
:- discontiguous 'lists.Sorted.P1.0'/1. %% added djd
:- discontiguous '~lists.Sorted.P1.0'/1. %% added djd
:- discontiguous 'lists.Sort.P2.0'/2. %% added djd
:- discontiguous '~lists.Sort.P2.0'/2. %% added djd
:- discontiguous 'lists.Reverse3.P3'/3. %% added djd
:- discontiguous '~lists.Reverse3.P3'/3. %% added djd
:- discontiguous 'lists.Split.P4'/4. %% added djd
:- discontiguous '~lists.Split.P4'/4. %% added djd
:- discontiguous 'lists.Reverse3.P3'/3. %% added djd




:- op(500, yfx, and).
:- op(400, yfx, or).

'lists.Member.P2'(A, B) :-
        user:goedel_freeze(nonvar(B), 'Lists':'lists.Member.P2.0'(A,B)).
'~lists.Member.P2'(A, B) :-
        user:goedel_freeze(nonvar(B), 'Lists':'~lists.Member.P2.0'(A,B)).
'lists.Member.P2.0'(A, [A|_]).
'~lists.Member.P2.0'(A, [A|_]).
'lists.Member.P2.0'(A, [_|B]) :-
        'lists.Member.P2'(A, B).
'~lists.Member.P2.0'(A, [_|B]) :-
        '~lists.Member.P2'(A, B).
'lists.Delete.P3'(A, B, C) :-
        user:goedel_freeze(nonvar(B)or nonvar(C), 'Lists':'lists.Delete.P3.0'(A,B,C)).
'~lists.Delete.P3'(A, B, C) :-
        user:goedel_freeze(nonvar(B)or nonvar(C), 'Lists':'~lists.Delete.P3.0'(A,B,C)).
'lists.Delete.P3.0'(A, [A|B], B).
'~lists.Delete.P3.0'(A, [A|B], B).
'lists.Delete.P3.0'(A, [B|C], [B|D]) :-
        'lists.Delete.P3'(A, C, D).
'~lists.Delete.P3.0'(A, [B|C], [B|D]) :-
        '~lists.Delete.P3'(A, C, D).
'lists.Append.P3'(A, B, C) :-
        user:goedel_freeze(nonvar(A)or nonvar(C), 'Lists':'lists.Append.P3.0'(A,B,C)).
'~lists.Append.P3'(A, B, C) :-
        user:goedel_freeze(nonvar(A)or nonvar(C), 'Lists':'~lists.Append.P3.0'(A,B,C)).
'lists.Append.P3.0'([], A, A).
'~lists.Append.P3.0'([], A, A).
'lists.Append.P3.0'([A|B], C, [A|D]) :-
        'lists.Append.P3'(B, C, D).
'~lists.Append.P3.0'([A|B], C, [A|D]) :-
        '~lists.Append.P3'(B, C, D).
'lists.DeleteFirst.P3'(A, B, C) :-
        user:goedel_freeze(nonvar(A)and nonvar(B)or nonvar(C), 'Lists':'lists.DeleteFirst.P3.0'(A,B,C)).
'~lists.DeleteFirst.P3'(A, B, C) :-
        user:goedel_freeze(nonvar(A)and nonvar(B)or nonvar(C), 'Lists':'~lists.DeleteFirst.P3.0'(A,B,C)).
'lists.DeleteFirst.P3.0'(A, [A|B], B) :- !.
'~lists.DeleteFirst.P3.0'(A, [A|B], B).
'lists.DeleteFirst.P3.0'(A, [B|C], [B|D]) :-
        call_residue(user:not_equal([],[A,B],A,B), E),
        (   E=[] ->
            !
        ;   user:release_suspended(E)
        ),
        'lists.DeleteFirst.P3'(A, C, D).
'~lists.DeleteFirst.P3.0'(A, [B|C], [B|D]) :-
        user:not_equal([], [A,B], A, B),
        '~lists.DeleteFirst.P3'(A, C, D).
'lists.Length.P2'(A, B) :-
        user:goedel_freeze(nonvar(A)or nonvar(B), 'Lists':'lists.Length.P2.0'(A,B)).
'~lists.Length.P2'(A, B) :-
        user:goedel_freeze(nonvar(A)or nonvar(B), 'Lists':'~lists.Length.P2.0'(A,B)).
'lists.Length.P2.0'([], 0).
'~lists.Length.P2.0'([], 0).
'lists.Length.P2.0'([_|A], B) :-
        'Integers':plus(C, 1, B),
        'Integers':'Integers.>=.P2'(C, 0),
        'lists.Length.P2'(A, C).
'~lists.Length.P2.0'([_|A], B) :-
        'Integers':plus(C, 1, B),
        'Integers':'~Integers.>=.P2'(C, 0),
        '~lists.Length.P2'(A, C).
'lists.Reverse.P2'(A, B) :-
        user:goedel_freeze(nonvar(A)or nonvar(B), 'Lists':'lists.Reverse.P2.0'(A,B)).
'~lists.Reverse.P2'(A, B) :-
        user:goedel_freeze(nonvar(A)or nonvar(B), 'Lists':'~lists.Reverse.P2.0'(A,B)).
'lists.Reverse.P2.0'(A, B) :-
        'lists.Reverse3.P3'(A, [], B).
'~lists.Reverse.P2.0'(A, B) :-
        '~lists.Reverse3.P3'(A, [], B).
'lists.Permutation.P2'(A, B) :-
        user:goedel_freeze(nonvar(A)or nonvar(B), 'Lists':'lists.Permutation.P2.0'(A,B)).
'~lists.Permutation.P2'(A, B) :-
        user:goedel_freeze(nonvar(A)or nonvar(B), 'Lists':'~lists.Permutation.P2.0'(A,B)).
'lists.Permutation.P2.0'([], []).
'~lists.Permutation.P2.0'([], []).
'lists.Permutation.P2.0'([A|B], [C|D]) :-
        'lists.Delete.P3'(C, [A|B], E),
        'lists.Permutation.P2'(E, D).
'~lists.Permutation.P2.0'([A|B], [C|D]) :-
        '~lists.Delete.P3'(C, [A|B], E),
        '~lists.Permutation.P2'(E, D).
'lists.Merge.P3'(A, B, C) :-
        user:goedel_freeze((nonvar(A)and nonvar(B))or nonvar(C), 'Lists':'lists.Merge.P3.0'(A,B,C)).
'~lists.Merge.P3'(A, B, C) :-
        user:goedel_freeze((nonvar(A)and nonvar(B))or nonvar(C), 'Lists':'~lists.Merge.P3.0'(A,B,C)).
'lists.Merge.P3.0'([], A, A).
'~lists.Merge.P3.0'([], A, A).
'lists.Merge.P3.0'(A, [], A).
'~lists.Merge.P3.0'(A, [], A).
'lists.Merge.P3.0'([A|B], [C|D], [A|E]) :-
        'Integers':'Integers.<.P2'(A, C),
        'lists.Merge.P3'(B, [C|D], E).
'~lists.Merge.P3.0'([A|B], [C|D], [A|E]) :-
        'Integers':'~Integers.<.P2'(A, C),
        '~lists.Merge.P3'(B, [C|D], E).
'lists.Merge.P3.0'([A|B], [C|D], [C|E]) :-
        'Integers':'Integers.>=.P2'(A, C),
        'lists.Merge.P3'([A|B], D, E).
'~lists.Merge.P3.0'([A|B], [C|D], [C|E]) :-
        'Integers':'~Integers.>=.P2'(A, C),
        '~lists.Merge.P3'([A|B], D, E).
'lists.MemberCheck.P2'(A, B) :-
        user:goedel_freeze(nonvar(B), 'Lists':'lists.MemberCheck.P2.1'(A,B)).
'~lists.MemberCheck.P2'(A, B) :-
        user:goedel_freeze(nonvar(B), 'Lists':'~lists.MemberCheck.P2.1'(A,B)).
'lists.MemberCheck.P2.1'(A, [B|C]) :- !,
        user:goedel_freeze(nonvar(A)and nonvar(B), 'Lists':'lists.MemberCheck.P2.0'(A,[B|C])).
'~lists.MemberCheck.P2.1'(A, [B|C]) :- !,
        user:goedel_freeze(nonvar(A)and nonvar(B), 'Lists':'~lists.MemberCheck.P2.0'(A,[B|C])).
'lists.MemberCheck.P2.1'(A, []) :- !,
        'lists.MemberCheck.P2.0'(A, []).
'~lists.MemberCheck.P2.1'(A, []) :- !,
        '~lists.MemberCheck.P2.0'(A, []).
'lists.MemberCheck.P2.1'(A, B) :-
        'lists.MemberCheck.P2.0'(A, B).
'~lists.MemberCheck.P2.1'(A, B) :-
        '~lists.MemberCheck.P2.0'(A, B).
'lists.MemberCheck.P2.0'(A, [A|_]) :- !.
'~lists.MemberCheck.P2.0'(A, [A|_]).
'lists.MemberCheck.P2.0'(A, [B|C]) :-
        call_residue(user:not_equal([],[A,B],A,B), D),
        (   D=[] ->
            !
        ;   user:release_suspended(D)
        ),
        'lists.MemberCheck.P2'(A, C).
'~lists.MemberCheck.P2.0'(A, [B|C]) :-
        user:not_equal([], [A,B], A, B),
        '~lists.MemberCheck.P2'(A, C).
'lists.Partition.P4'([], _, [], []).
'~lists.Partition.P4'([], _, [], []).
'lists.Partition.P4'([A|B], C, [A|D], E) :-
        'Integers':'Integers.=<.P2'(A, C),
        'lists.Partition.P4'(B, C, D, E).
'~lists.Partition.P4'([A|B], C, [A|D], E) :-
        'Integers':'~Integers.=<.P2'(A, C),
        '~lists.Partition.P4'(B, C, D, E).
'lists.Partition.P4'([A|B], C, D, [A|E]) :-
        'Integers':'Integers.>.P2'(A, C),
        'lists.Partition.P4'(B, C, D, E).
'~lists.Partition.P4'([A|B], C, D, [A|E]) :-
        'Integers':'~Integers.>.P2'(A, C),
        '~lists.Partition.P4'(B, C, D, E).
'lists.Prefix.P3'(A, B, C) :-
        user:goedel_freeze(nonvar(A)and nonvar(B)or nonvar(C), 'Lists':'lists.Prefix.P3.0'(A,B,C)).
'~lists.Prefix.P3'(A, B, C) :-
        user:goedel_freeze(nonvar(A)and nonvar(B)or nonvar(C), 'Lists':'~lists.Prefix.P3.0'(A,B,C)).
'lists.Prefix.P3.0'(A, B, C) :-
        'Integers':'Integers.>=.P2'(B, 0),
        'lists.Length.P2'(A, D),
        'Integers':'Integers.=<.P2'(B, D),
        'lists.Split.P4'(B, A, C, _).
'~lists.Prefix.P3.0'(A, B, C) :-
        'Integers':'~Integers.>=.P2'(B, 0),
        '~lists.Length.P2'(A, D),
        'Integers':'~Integers.=<.P2'(B, D),
        '~lists.Split.P4'(B, A, C, _).
'lists.Sorted.P1'(A) :-
        user:goedel_freeze(nonvar(A), 'Lists':'lists.Sorted.P1.1'(A)).
'~lists.Sorted.P1'(A) :-
        user:goedel_freeze(nonvar(A), 'Lists':'~lists.Sorted.P1.1'(A)).
'lists.Sorted.P1.1'([A|B]) :- !,
        user:goedel_freeze(nonvar(B), 'Lists':'lists.Sorted.P1.0'([A|B])).
'~lists.Sorted.P1.1'([A|B]) :- !,
        user:goedel_freeze(nonvar(B), 'Lists':'~lists.Sorted.P1.0'([A|B])).
'lists.Sorted.P1.1'([]) :- !,
        'lists.Sorted.P1.0'([]).
'~lists.Sorted.P1.1'([]) :- !,
        '~lists.Sorted.P1.0'([]).
'lists.Sorted.P1.1'(A) :-
        'lists.Sorted.P1.0'(A).
'~lists.Sorted.P1.1'(A) :-
        '~lists.Sorted.P1.0'(A).
'lists.Sorted.P1.0'([]).
'~lists.Sorted.P1.0'([]).
'lists.Sorted.P1.0'([_]).
'~lists.Sorted.P1.0'([_]).
'lists.Sorted.P1.0'([A,B|C]) :-
        'Integers':'Integers.=<.P2'(A, B),
        'lists.Sorted.P1'([B|C]).
'~lists.Sorted.P1.0'([A,B|C]) :-
        'Integers':'~Integers.=<.P2'(A, B),
        '~lists.Sorted.P1'([B|C]).
'lists.Sort.P2'(A, B) :-
        user:goedel_freeze(nonvar(A), 'Lists':'lists.Sort.P2.0'(A,B)).
'~lists.Sort.P2'(A, B) :-
        user:goedel_freeze(nonvar(A), 'Lists':'~lists.Sort.P2.0'(A,B)).
'lists.Sort.P2.0'([], []).
'~lists.Sort.P2.0'([], []).
'lists.Sort.P2.0'([A|B], C) :-
        'lists.Partition.P4'(B, A, D, E),
        'lists.Sort.P2'(D, F),
        'lists.Sort.P2'(E, G),
        'lists.Append.P3'(F, [A|G], C).
'~lists.Sort.P2.0'([A|B], C) :-
        '~lists.Partition.P4'(B, A, D, E),
        '~lists.Sort.P2'(D, F),
        '~lists.Sort.P2'(E, G),
        '~lists.Append.P3'(F, [A|G], C).
'lists.Reverse3.P3'([], A, A).
'~lists.Reverse3.P3'([], A, A).
'lists.Reverse3.P3'([A|B], C, D) :-
        'lists.Reverse3.P3'(B, [A|C], D).
'~lists.Reverse3.P3'([A|B], C, D) :-
        '~lists.Reverse3.P3'(B, [A|C], D).
'lists.Suffix.P3'(A, B, C) :-
        user:goedel_freeze(nonvar(A)and nonvar(B)or nonvar(C), 'Lists':'lists.Suffix.P3.0'(A,B,C)).
'~lists.Suffix.P3'(A, B, C) :-
        user:goedel_freeze(nonvar(A)and nonvar(B)or nonvar(C), 'Lists':'~lists.Suffix.P3.0'(A,B,C)).
'lists.Suffix.P3.0'(A, B, C) :-
        'Integers':'Integers.>=.P2'(B, 0),
        'lists.Length.P2'(A, D),
        'Integers':'Integers.=<.P2'(B, D),
        'Integers':minus(D, B, F),
        E=F,
        'lists.Split.P4'(E, A, _, C).
'~lists.Suffix.P3.0'(A, B, C) :-
        'Integers':'~Integers.>=.P2'(B, 0),
        '~lists.Length.P2'(A, D),
        'Integers':'~Integers.=<.P2'(B, D),
        'Integers':minus(D, B, F),
        E=F,
        '~lists.Split.P4'(E, A, _, C).
'lists.Split.P4'(0, A, [], A).
'~lists.Split.P4'(0, A, [], A).
'lists.Split.P4'(A, [B|C], [B|D], E) :-
        'Integers':'Integers.>.P2'(A, 0),
        'Integers':minus(A, 1, F),
        'lists.Split.P4'(F, C, D, E).
'~lists.Split.P4'(A, [B|C], [B|D], E) :-
        'Integers':'~Integers.>.P2'(A, 0),
        'Integers':minus(A, 1, F),
        '~lists.Split.P4'(F, C, D, E).
:- style_check(-singleton). % added djd
%% :- module('Sets', []).
:- module(sets).  %% converted djd

:- op(500, yfx, and).
:- op(400, yfx, or).

/* 
File:		Sets.sup
Subject:	Implemention of the system module Sets
Author: 	Jiwei Wang
Date:		17 July 1992

================================================================================
*/


'$$module'('@(#)Sets.sup 1.5 last updated 93/12/09 12:28:00 by jiwei
').

/*==============================================================================
 * Following are functions support the constraint solving with sets.
 */

normalise(Vlist, List, set(NormalisedSet)) :-
   user:goedel_freeze(ground(Vlist), sort(List, NormalisedSet)).


plus(set(X), set(Y), set(Z)) :-
   user:goedel_freeze(ground([X,Y]), user:union(X, Y, Z)).


diff(set(X), set(Y), set(Z)) :-
   user:goedel_freeze(ground([X,Y]), user:difference(X, Y, Z)).

 
times(set(X), set(Y), set(Z)) :-
   user:goedel_freeze(ground([X,Y]), user:intersection(X, Y, Z)).

set_of(T, W, X, FreeVars) :-
   user:goedel_freeze(ground(FreeVars), 'Sets':set_of_aux(T, W, X)).

%- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

set_of_aux(T, W, set(X)) :-
   ( setof(pair(T, Suspended), W^call_residue(W, Suspended), Y)
     -> ( 'Sets':clear_set(Y, X)
	  -> true
	  ;  format(user_error, 'Floundered in an intensional set.~n', []),
	     raise_exception(catch_in_query)
	)
     ;  X = []
   ),
   user:remove_ground_rep(X, XX),	% remove OProgram term
   prolog:term_variables(XX, Vars),
   ( Vars = []
     -> true
     ;  format(user_error, 'Floundered in an intensional set.~n', []),
        raise_exception(catch_in_query)
   ).

% this fails if there is one pair whose Suspended is not empty
clear_set([], []).
clear_set([pair(T, [])|A], [T|B]) :-
   clear_set(A, B).


%------------------------------------------------------------------------------

'Sets.In.P2'(A, X):-
   user:goedel_freeze(ground([X]), 'Sets':'Sets.In.P2.0'(A, X)).

'Sets.In.P2.0'(A, set(X)):-
   user:member(A, X).

'~Sets.In.P2'(A, X):-
   user:goedel_freeze(ground([X]), 'Sets':'Sets.In.P2.0'(A, X)).

'Sets.Size.P2'(X, Y):-
   user:goedel_freeze(ground([X]), 'Sets':'Sets.Size.P2.0'(X, Y)).

'Sets.Size.P2.0'(set(X), Y):-
   sort(X, Z),
   length(Z, Y).

'~Sets.Size.P2'(X, Y):-
   user:goedel_freeze(ground([X]), 'Sets':'Sets.Size.P2.0'(X, Y)).


'Sets.Subset.P2'(X, Y):-
   user:goedel_freeze(ground([Y]), 'Sets':'Sets.Subset.P2.0'(X, Y)).

'Sets.Subset.P2.0'(set(X), set(Y)):-
   'Sets.Subset.P2.1'(X, Y).

'Sets.Subset.P2.1'([], _).
'Sets.Subset.P2.1'([X|Xs], [X|Ys]) :-
   'Sets.Subset.P2.1'(Xs, Ys).
'Sets.Subset.P2.1'([X|Xs], [_|Ys]) :-
   'Sets.Subset.P2.1'([X|Xs], Ys).
   

'~Sets.Subset.P2'(X, Y):-
   user:goedel_freeze(ground([Y]), 'Sets':'Sets.Subset.P2.0'(X, Y)).


'Sets.StrictSubset.P2'(X, Y):-
   user:goedel_freeze(ground([Y]), 'Sets':'Sets.StrictSubset.P2.0'(X, Y)).

'Sets.StrictSubset.P2.0'(X, Y):-
   'Sets.Subset.P2'(X, Y),
   'Sets.Size.P2'(X, A),
   'Sets.Size.P2'(Y, B),
   A < B.

'~Sets.StrictSubset.P2'(X, Y):-
   user:goedel_freeze(ground([Y]), 'Sets':'Sets.StrictSubset.P2.0'(X, Y)).

:- style_check(-singleton). % added djd
%% :- module('Strings', []).
:- module(strings).  % converted djd
:- discontiguous 'Strings':'Strings.Split.P4'/4. %% added djd
:- discontiguous 'Strings':'~Strings.Split.P4'/4. %% added djd
:- discontiguous 'Strings.Split.P4'/4. %% added djd
:- discontiguous '~Strings.Split.P4'/4. %% added djd



:- op(500, yfx, and).
:- op(400, yfx, or).

'Strings.LastSubstring.P3'(A, B, C) :-
        user:goedel_freeze(ground([A])and ground([B])or ground([C]), 'Strings':'Strings.LastSubstring.P3.0'(A,B,C)).
'~Strings.LastSubstring.P3'(A, B, C) :-
        user:goedel_freeze(ground([A])and ground([B])or ground([C]), 'Strings':'~Strings.LastSubstring.P3.0'(A,B,C)).
'Strings.LastSubstring.P3.0'(A, B, C) :-
        'Integers':'Integers.>=.P2'(B, 0),
        'Strings.StringInts.P2'(A, D),
        'Lists':'Lists.Length.P2'(D, E),
        'Integers':minus(E, B, F),
        'Strings.Split.P4'(F, D, _, G),
        'Strings.StringInts.P2'(C, G).
'~Strings.LastSubstring.P3.0'(A, B, C) :-
        'Integers':'~Integers.>=.P2'(B, 0),
        '~Strings.StringInts.P2'(A, D),
        'Lists':'~Lists.Length.P2'(D, E),
        'Integers':minus(E, B, F),
        '~Strings.Split.P4'(F, D, _, G),
        '~Strings.StringInts.P2'(C, G).
'Strings.FirstSubstring.P3'(A, B, C) :-
        user:goedel_freeze(ground([A])and ground([B])or ground([C]), 'Strings':'Strings.FirstSubstring.P3.0'(A,B,C)).
'~Strings.FirstSubstring.P3'(A, B, C) :-
        user:goedel_freeze(ground([A])and ground([B])or ground([C]), 'Strings':'~Strings.FirstSubstring.P3.0'(A,B,C)).
'Strings.FirstSubstring.P3.0'(A, B, C) :-
        'Integers':'Integers.>=.P2'(B, 0),
        'Strings.StringInts.P2'(A, D),
        'Strings.Split.P4'(B, D, E, _),
        'Strings.StringInts.P2'(C, E).
'~Strings.FirstSubstring.P3.0'(A, B, C) :-
        'Integers':'~Integers.>=.P2'(B, 0),
        '~Strings.StringInts.P2'(A, D),
        '~Strings.Split.P4'(B, D, E, _),
        '~Strings.StringInts.P2'(C, E).
'Strings.Split.P4'(0, A, [], A).
'~Strings.Split.P4'(0, A, [], A).
'Strings.Split.P4'(A, [B|C], [B|D], E) :-
        'Integers':'Integers.>.P2'(A, 0),
        'Integers':minus(A, 1, F),
        'Strings.Split.P4'(F, C, D, E).
'~Strings.Split.P4'(A, [B|C], [B|D], E) :-
        'Integers':'~Integers.>.P2'(A, 0),
        'Integers':minus(A, 1, F),
        '~Strings.Split.P4'(F, C, D, E).
'Strings.Width.P2'(A, B) :-
        user:goedel_freeze(ground([A]), 'Strings':'Strings.Width.P2.0'(A,B)).
'~Strings.Width.P2'(A, B) :-
        user:goedel_freeze(ground([A]), 'Strings':'~Strings.Width.P2.0'(A,B)).
'Strings.Width.P2.0'(A, B) :-
        'Strings.StringInts.P2'(A, C),
        'Lists':'Lists.Length.P2'(C, B).
'~Strings.Width.P2.0'(A, B) :-
        '~Strings.StringInts.P2'(A, C),
        'Lists':'~Lists.Length.P2'(C, B).
/* 
File:		strings.sup
Subject:	the system module Strings.
Author:		Jiwei Wang
Date:		17 September 1991

================================================================================
*/

'$$module'('@(#)Strings.sup 1.10 last updated 93/12/08 17:56:01 by jiwei
').


'Strings.StringInts.P2'(String, IntList) :-
   nonvar(String), !,
   name(String, [0'"|IntList]).

'Strings.StringInts.P2'(String, IntList) :-
   ground(IntList), !,
   name(String, [0'"|IntList]).

'Strings.StringInts.P2'(String, IntList) :-
   user:goedel_freeze(ground([IntList]) or ground([String]),
		'Strings':'Strings.StringInts.P2'(String, IntList)).

'~Strings.StringInts.P2'(String, IntList) :-
   'Strings.StringInts.P2'(String, IntList).

%------------------------------------------------------------------------------

'Strings.<.P2'(X, Y) :-
   atom(X), atom(Y), !,
   X @< Y.

'Strings.<.P2'(X, Y) :-
   user:goedel_freeze(ground([X,Y]),  X @< Y).


'~Strings.<.P2'(X, Y) :-
   atom(X), atom(Y), !,
   X @< Y.

'~Strings.<.P2'(X, Y) :-
   user:goedel_freeze(ground([X,Y]),  X @< Y).

%------------------------------------------------------------------------------

'Strings.>.P2'(X, Y) :-
   atom(X), atom(Y), !,
   X @> Y.

'Strings.>.P2'(X, Y) :-
   user:goedel_freeze(ground([X,Y]),  X @> Y).


'~Strings.>.P2'(X, Y) :-
   atom(X), atom(Y), !,
   X @> Y.

'~Strings.>.P2'(X, Y) :-
   user:goedel_freeze(ground([X,Y]),  X @> Y).

%------------------------------------------------------------------------------

'Strings.=<.P2'(X, Y) :-
   atom(X), atom(Y), !,
   X @=< Y.

'Strings.=<.P2'(X, Y) :-
   user:goedel_freeze(ground([X,Y]),  X @=< Y).

'~Strings.=<.P2'(X, Y) :-
   atom(X), atom(Y), !,
   X @=< Y.

'~Strings.=<.P2'(X, Y) :-
   user:goedel_freeze(ground([X,Y]),  X @=< Y).

%------------------------------------------------------------------------------

'Strings.>=.P2'(X, Y) :-
   atom(X), atom(Y), !,
   X @>= Y.

'Strings.>=.P2'(X, Y) :-
   user:goedel_freeze(ground([X,Y]),  X @>= Y).

'~Strings.>=.P2'(X, Y) :-
   atom(X), atom(Y), !,
   X @>= Y.

'~Strings.>=.P2'(X, Y) :-
   user:goedel_freeze(ground([X,Y]),  X @>= Y).

%------------------------------------------------------------------------------
% for ++

concat(X, Y, Z) :-
   nonvar(X), nonvar(Y), !,
   name(X, Xs),
   name(Y, [0'"|Ys]),
   user:append(Xs, Ys, L),
   name(Z, L).

concat(X, Y, Z) :-
   nonvar(Z), !,
   name(Z, [0'"|Zs]),
   ( nonvar(X)
     -> name(X, [0'"|Xs]),
	user:append(Xs, Ys, Zs),
	name(Y, [0'"|Ys])
     ;  ( nonvar(Y)
          -> name(Y, [0'"|Ys]),
	     user:append(Xs, Ys, Zs), !,
	     name(X, [0'"|Xs])
	  ;  user:append(Xs, Ys, Zs),
	     name(Y, [0'"|Ys]),
	     name(X, [0'"|Xs])
	)
   ).

concat(X, Y, Z) :-
   user:goedel_freeze(ground([Z]) or ground([X,Y]), 'Strings':concat(X,Y,Z)).

:- style_check(-singleton). % added djd
%% :- module('Tables', []).
:- module(tables).  % converted djd
:- discontiguous 'Tables':'Tables.FirstNode.P3.0'/3. %% added djd
:- discontiguous 'Tables':'~Tables.FirstNode.P3.0'/3. %% added djd
:- discontiguous 'Tables':'Tables.Combine.P5'/5. %% added djd
:- discontiguous 'Tables':'~Tables.Combine.P5'/5. %% added djd
:- discontiguous 'Tables':'Tables.Adjustment.P4'/4. %% added djd
:- discontiguous 'Tables':'~Tables.Adjustment.P4'/4. %% added djd
:- discontiguous 'Tables':'Tables.Adjust.P6'/6. %% added djd
:- discontiguous 'Tables':'~Tables.Adjust.P6'/6. %% added djd
:- discontiguous 'Tables':'Tables.Amend.P7'/7. %% added djd
:- discontiguous 'Tables':'~Tables.Amend.P7'/7. %% added djd
:- discontiguous 'Tables':'Tables.BalanceTable1.P3'/3. %% added djd
:- discontiguous 'Tables':'~Tables.BalanceTable1.P3'/3. %% added djd
:- discontiguous 'Tables':'Tables.BalanceTable2.P3'/3. %% added djd
:- discontiguous 'Tables':'~Tables.BalanceTable2.P3'/3. %% added djd
:- discontiguous 'Tables':'Tables.DeleteKey.P5'/5. %% added djd
:- discontiguous 'Tables':'~Tables.DeleteKey.P5'/5. %% added djd
:- discontiguous 'Tables':'Tables.HeightIncreased.P3'/3. %% added djd
:- discontiguous 'Tables':'~Tables.HeightIncreased.P3'/3. %% added djd
:- discontiguous 'Tables':'Tables.HeightDecreased.P3'/3. %% added djd
:- discontiguous 'Tables':'~Tables.HeightDecreased.P3'/3. %% added djd
:- discontiguous 'Tables':'Tables.Insert.P5'/5.  %% added djd
:- discontiguous 'Tables':'~Tables.Insert.P5'/5. %% added djd
:- discontiguous 'Tables':'Tables.JoinAux.P3'/3. %% added djd
:- discontiguous 'Tables':'~Tables.JoinAux.P3'/3. %% added djd
:- discontiguous 'Tables':'Tables.LastNode.P3.0'/3. %% added djd
:- discontiguous 'Tables':'~Tables.LastNode.P3.0'/3. %% added djd
:- discontiguous 'Tables':'Tables.Restructure.P3'/3. %% added djd
:- discontiguous 'Tables':'~Tables.Restructure.P3'/3. %% added djd
:- discontiguous 'Tables':'Tables.PreviousNode.P4.0'/4. %% added djd
:- discontiguous 'Tables':'~Tables.PreviousNode.P4.0'/4. %% added djd
:- discontiguous 'Tables':'Tables.NextNode.P4.0'/4. %% added djd
:- discontiguous 'Tables':'~Tables.NextNode.P4.0'/4. %% added djd
:- discontiguous 'Tables':'Tables.ListsToTable.P3'/3. %% added djd
:- discontiguous 'Tables':'~Tables.ListsToTable.P3'/3. %% added djd
:- discontiguous 'Tables':'Tables.ListsToTable1.P5'/5. %% added djd
:- discontiguous 'Tables':'~Tables.ListsToTable1.P5'/5. %% added djd
:- discontiguous 'Tables':'Tables.RemoveRightmost.P5'/5. %% added djd
:- discontiguous 'Tables':'~Tables.RemoveRightmost.P5'/5. %% added djd
:- discontiguous 'Tables':'Tables.Rebalance.P4'/4. %% added djd
:- discontiguous 'Tables':'~Tables.Rebalance.P4'/4. %% added djd
:- discontiguous 'Tables':'Tables.TableSearch.P3'/3. %% added djd
:- discontiguous 'Tables':'~Tables.TableSearch.P3'/3. %% added djd
:- discontiguous 'Tables':'Tables.TableMember.P3'/3. %% added djd
:- discontiguous 'Tables':'~Tables.TableMember.P3'/3. %% added djd
:- discontiguous 'Tables':'Tables.UpdateTable.P5.0'/5. %% added djd
:- discontiguous 'Tables':'~Tables.UpdateTable.P5.0'/5. %% added djd
:- discontiguous 'Tables':'Tables.TableToLists.P5'/5. %% added djd
:- discontiguous 'Tables':'~Tables.TableToLists.P5'/5. %% added djd
:- discontiguous 'Tables.FirstNode.P3.0'/3. %% added djd
:- discontiguous '~Tables.FirstNode.P3.0'/3. %% added djd
:- discontiguous 'Tables.Combine.P5'/5. %% added djd
:- discontiguous '~Tables.Combine.P5'/5. %% added djd
:- discontiguous 'Tables.Combine.P5'/5. %% added djd
:- discontiguous '~Tables.Combine.P5'/5. %% added djd
:- discontiguous 'Tables.Adjustment.P4'/4. %% added djd
:- discontiguous '~Tables.Adjustment.P4'/4. %% added djd
:- discontiguous 'Tables.Adjustment.P4'/4. %% added djd
:- discontiguous '~Tables.Adjustment.P4'/4. %% added djd
:- discontiguous 'Tables.Adjustment.P4'/4. %% added djd
:- discontiguous '~Tables.Adjustment.P4'/4. %% added djd
:- discontiguous 'Tables.Adjustment.P4'/4. %% added djd
:- discontiguous '~Tables.Adjustment.P4'/4. %% added djd
:- discontiguous 'Tables.Adjustment.P4'/4. %% added djd
:- discontiguous '~Tables.Adjustment.P4'/4. %% added djd
:- discontiguous 'Tables.Adjust.P6'/6. %% added djd
:- discontiguous '~Tables.Adjust.P6'/6. %% added djd
:- discontiguous 'Tables.Amend.P7'/7. %% added djd
:- discontiguous '~Tables.Amend.P7'/7. %% added djd
:- discontiguous 'Tables.Amend.P7'/7. %% added djd
:- discontiguous '~Tables.Amend.P7'/7. %% added djd
:- discontiguous 'Tables.Amend.P7'/7. %% added djd
:- discontiguous '~Tables.Amend.P7'/7. %% added djd
:- discontiguous 'Tables.BalanceTable1.P3'/3. %% added djd
:- discontiguous '~Tables.BalanceTable1.P3'/3. %% added djd
:- discontiguous 'Tables.BalanceTable1.P3'/3. %% added djd
:- discontiguous '~Tables.BalanceTable1.P3'/3. %% added djd
:- discontiguous 'Tables.BalanceTable2.P3'/3. %% added djd
:- discontiguous '~Tables.BalanceTable2.P3'/3. %% added djd
:- discontiguous 'Tables.BalanceTable2.P3'/3. %% added djd
:- discontiguous '~Tables.BalanceTable2.P3'/3. %% added djd
:- discontiguous 'Tables.DeleteKey.P5'/5. %% added djd
:- discontiguous '~Tables.DeleteKey.P5'/5. %% added djd
:- discontiguous 'Tables.DeleteKey.P5'/5. %% added djd
:- discontiguous '~Tables.DeleteKey.P5'/5. %% added djd
:- discontiguous 'Tables.HeightIncreased.P3'/3. %% added djd
:- discontiguous '~Tables.HeightIncreased.P3'/3. %% added djd
:- discontiguous 'Tables.HeightIncreased.P3'/3. %% added djd
:- discontiguous '~Tables.HeightIncreased.P3'/3. %% added djd
:- discontiguous 'Tables.HeightIncreased.P3'/3. %% added djd
:- discontiguous '~Tables.HeightIncreased.P3'/3. %% added djd
:- discontiguous 'Tables.HeightIncreased.P3'/3. %% added djd
:- discontiguous '~Tables.HeightIncreased.P3'/3. %% added djd
:- discontiguous 'Tables.HeightDecreased.P3'/3. %% added djd
:- discontiguous '~Tables.HeightDecreased.P3'/3. %% added djd
:- discontiguous 'Tables.HeightDecreased.P3'/3. %% added djd
:- discontiguous '~Tables.HeightDecreased.P3'/3. %% added djd
:- discontiguous 'Tables.HeightDecreased.P3'/3. %% added djd
:- discontiguous '~Tables.HeightDecreased.P3'/3. %% added djd
:- discontiguous 'Tables.HeightDecreased.P3'/3. %% added djd
:- discontiguous '~Tables.HeightDecreased.P3'/3. %% added djd
:- discontiguous 'Tables.HeightDecreased.P3'/3. %% added djd
:- discontiguous '~Tables.HeightDecreased.P3'/3. %% added djd
:- discontiguous 'Tables.Insert.P5'/5. %% added djd
:- discontiguous '~Tables.Insert.P5'/5. %% added djd
:- discontiguous 'Tables.Insert.P5'/5. %% added djd
:- discontiguous '~Tables.Insert.P5'/5. %% added djd
:- discontiguous 'Tables.Insert.P5'/5. %% added djd
:- discontiguous '~Tables.Insert.P5'/5. %% added djd
:- discontiguous 'Tables.JoinAux.P3'/3. %% added djd
:- discontiguous '~Tables.JoinAux.P3'/3. %% added djd
:- discontiguous 'Tables.LastNode.P3.0'/3. %% added djd
:- discontiguous '~Tables.LastNode.P3.0'/3. %% added djd
:- discontiguous 'Tables.Restructure.P3'/3. %% added djd
:- discontiguous '~Tables.Restructure.P3'/3. %% added djd
:- discontiguous 'Tables.Restructure.P3'/3. %% added djd
:- discontiguous '~Tables.Restructure.P3'/3. %% added djd
:- discontiguous 'Tables.Restructure.P3'/3. %% added djd
:- discontiguous '~Tables.Restructure.P3'/3. %% added djd
:- discontiguous 'Tables.PreviousNode.P4.0'/4. %% added djd
:- discontiguous '~Tables.PreviousNode.P4.0'/4. %% added djd
:- discontiguous 'Tables.PreviousNode.P4.0'/4. %% added djd
:- discontiguous '~Tables.PreviousNode.P4.0'/4. %% added djd
:- discontiguous 'Tables.NextNode.P4.0'/4. %% added djd
:- discontiguous '~Tables.NextNode.P4.0'/4. %% added djd
:- discontiguous 'Tables.NextNode.P4.0'/4. %% added djd
:- discontiguous '~Tables.NextNode.P4.0'/4. %% added djd
:- discontiguous 'Tables.ListsToTable.P3'/3. %% added djd
:- discontiguous '~Tables.ListsToTable.P3'/3. %% added djd
:- discontiguous 'Tables.ListsToTable1.P5'/5. %% added djd
:- discontiguous '~Tables.ListsToTable1.P5'/5. %% added djd
:- discontiguous 'Tables.RemoveRightmost.P5'/5. %% added djd
:- discontiguous '~Tables.RemoveRightmost.P5'/5. %% added djd
:- discontiguous 'Tables.Rebalance.P4'/4. %% added djd
:- discontiguous '~Tables.Rebalance.P4'/4. %% added djd
:- discontiguous 'Tables.TableSearch.P3'/3. %% added djd
:- discontiguous '~Tables.TableSearch.P3'/3. %% added djd
:- discontiguous 'Tables.TableSearch.P3'/3. %% added djd
:- discontiguous '~Tables.TableSearch.P3'/3. %% added djd
:- discontiguous 'Tables.TableMember.P3'/3. %% added djd
:- discontiguous '~Tables.TableMember.P3'/3. %% added djd
:- discontiguous 'Tables.TableMember.P3'/3. %% added djd
:- discontiguous '~Tables.TableMember.P3'/3. %% added djd
:- discontiguous 'Tables.UpdateTable.P5.0'/5. %% added djd
:- discontiguous '~Tables.UpdateTable.P5.0'/5. %% added djd
:- discontiguous 'Tables.UpdateTable.P5.0'/5. %% added djd
:- discontiguous '~Tables.UpdateTable.P5.0'/5. %% added djd
:- discontiguous 'Tables.TableToLists.P5'/5. %% added djd
:- discontiguous '~Tables.TableToLists.P5'/5. %% added djd


:- op(500, yfx, and).
:- op(400, yfx, or).

'Tables.ListTable.P3'(A, B, C) :-
        user:goedel_freeze(nonvar(A)or(nonvar(B)and nonvar(C)), 'Tables':'Tables.ListTable.P3.0'(A,B,C)).
'~Tables.ListTable.P3'(A, B, C) :-
        user:goedel_freeze(nonvar(A)or(nonvar(B)and nonvar(C)), 'Tables':'~Tables.ListTable.P3.0'(A,B,C)).
'Tables.ListTable.P3.0'(A, B, C) :-
        'Tables.ListTableAux.P3'(A, B, C).
'~Tables.ListTable.P3.0'(A, B, C) :-
        '~Tables.ListTableAux.P3'(A, B, C).
'Tables.FirstNode.P3'(A, B, C) :-
        user:goedel_freeze(nonvar(A), 'Tables':'Tables.FirstNode.P3.0'(A,B,C)).
'~Tables.FirstNode.P3'(A, B, C) :-
        user:goedel_freeze(nonvar(A), 'Tables':'~Tables.FirstNode.P3.0'(A,B,C)).
'Tables.FirstNode.P3.0'('Tables.Node.F5'('Tables.Null.C0',A,B,_,_), A, B) :- !.
'~Tables.FirstNode.P3.0'('Tables.Node.F5'('Tables.Null.C0',A,B,_,_), A, B).
'Tables.FirstNode.P3.0'('Tables.Node.F5'(A,_,_,_,_), B, C) :-
        call_residue(user:not_equal([],[A],A,'Tables.Null.C0'), D),
        (   D=[] ->
            !
        ;   user:release_suspended(D)
        ),
        'Tables.FirstNode.P3'(A, B, C).
'~Tables.FirstNode.P3.0'('Tables.Node.F5'(A,_,_,_,_), B, C) :-
        user:not_equal([], [A], A, 'Tables.Null.C0'),
        '~Tables.FirstNode.P3'(A, B, C).
'Tables.Combine.P5'('Tables.Null.C0', _, A, A, 'Tables.Yes.C0') :- !.
'~Tables.Combine.P5'('Tables.Null.C0', _, A, A, 'Tables.Yes.C0').
'Tables.Combine.P5'(A, _, 'Tables.Null.C0', A, 'Tables.Yes.C0') :- !.
'~Tables.Combine.P5'(A, _, 'Tables.Null.C0', A, 'Tables.Yes.C0').
'Tables.Combine.P5'(A, B, C, D, E) :-
        call_residue((user:not_equal([],[A],A,'Tables.Null.C0'),user:not_equal([],[C],C,'Tables.Null.C0')), F),
        (   F=[] ->
            !
        ;   user:release_suspended(F)
        ),
        'Tables.RemoveRightmost.P5'(A, G, H, I, J),
        'Tables.Adjust.P6'(J, 'Tables.Node.F5'(I,G,H,B,C), B, 'Tables.Right.C0', K, D),
        'Tables.HeightDecreased.P3'(B, K, E).
'~Tables.Combine.P5'(A, B, C, D, E) :-
        user:not_equal([], [A], A, 'Tables.Null.C0'),
        user:not_equal([], [C], C, 'Tables.Null.C0'),
        '~Tables.RemoveRightmost.P5'(A, F, G, H, I),
        '~Tables.Adjust.P6'(I, 'Tables.Node.F5'(H,F,G,B,C), B, 'Tables.Right.C0', J, D),
        '~Tables.HeightDecreased.P3'(B, J, E).
'Tables.AmendTable.P6'(A, B, C, D, E, F) :-
        user:goedel_freeze(nonvar(A)and ground([B]), 'Tables':'Tables.AmendTable.P6.0'(A,B,C,D,E,F)).
'~Tables.AmendTable.P6'(A, B, C, D, E, F) :-
        user:goedel_freeze(nonvar(A)and ground([B]), 'Tables':'~Tables.AmendTable.P6.0'(A,B,C,D,E,F)).
'Tables.AmendTable.P6.0'(A, B, C, D, E, F) :-
        'Tables.Amend.P7'(A, B, C, D, E, F, _).
'~Tables.AmendTable.P6.0'(A, B, C, D, E, F) :-
        '~Tables.Amend.P7'(A, B, C, D, E, F, _).
'Tables.Adjustment.P4'('Tables.EQ.C0', 'Tables.Left.C0', 'Tables.LH.C0', 'Tables.No.C0') :- !.
'~Tables.Adjustment.P4'('Tables.EQ.C0', 'Tables.Left.C0', 'Tables.LH.C0', 'Tables.No.C0').
'Tables.Adjustment.P4'('Tables.EQ.C0', 'Tables.Right.C0', 'Tables.RH.C0', 'Tables.No.C0') :- !.
'~Tables.Adjustment.P4'('Tables.EQ.C0', 'Tables.Right.C0', 'Tables.RH.C0', 'Tables.No.C0').
'Tables.Adjustment.P4'('Tables.LH.C0', 'Tables.Left.C0', _, 'Tables.Yes.C0') :- !.
'~Tables.Adjustment.P4'('Tables.LH.C0', 'Tables.Left.C0', _, 'Tables.Yes.C0').
'Tables.Adjustment.P4'('Tables.LH.C0', 'Tables.Right.C0', 'Tables.EQ.C0', 'Tables.No.C0') :- !.
'~Tables.Adjustment.P4'('Tables.LH.C0', 'Tables.Right.C0', 'Tables.EQ.C0', 'Tables.No.C0').
'Tables.Adjustment.P4'('Tables.RH.C0', 'Tables.Left.C0', 'Tables.EQ.C0', 'Tables.No.C0') :- !.
'~Tables.Adjustment.P4'('Tables.RH.C0', 'Tables.Left.C0', 'Tables.EQ.C0', 'Tables.No.C0').
'Tables.Adjustment.P4'('Tables.RH.C0', 'Tables.Right.C0', _, 'Tables.Yes.C0') :- !.
'~Tables.Adjustment.P4'('Tables.RH.C0', 'Tables.Right.C0', _, 'Tables.Yes.C0').
'Tables.Adjust.P6'('Tables.No.C0', A, B, _, B, A).
'~Tables.Adjust.P6'('Tables.No.C0', A, B, _, B, A).
'Tables.Adjust.P6'('Tables.Yes.C0', A, B, C, D, E) :-
        'Tables.Adjustment.P4'(B, C, D, F),
        'Tables.Rebalance.P4'(F, A, D, E).
'~Tables.Adjust.P6'('Tables.Yes.C0', A, B, C, D, E) :-
        '~Tables.Adjustment.P4'(B, C, D, F),
        '~Tables.Rebalance.P4'(F, A, D, E).
'Tables.Amend.P7'('Tables.Null.C0', A, B, C, 'Tables.Node.F5'('Tables.Null.C0',A,B,'Tables.EQ.C0','Tables.Null.C0'), C, 'Tables.Yes.C0').
'~Tables.Amend.P7'('Tables.Null.C0', A, B, C, 'Tables.Node.F5'('Tables.Null.C0',A,B,'Tables.EQ.C0','Tables.Null.C0'), C, 'Tables.Yes.C0').
'Tables.Amend.P7'('Tables.Node.F5'(A,B,C,D,E), F, G, H, I, J, K) :-
        call_residue('Strings':'Strings.<.P2'(F,B), L),
        (   L=[] ->
            !
        ;   user:release_suspended(L)
        ),
        'Tables.Amend.P7'(A, F, G, H, M, J, N),
        'Tables.Adjust.P6'(N, 'Tables.Node.F5'(M,B,C,D,E), D, 'Tables.Left.C0', O, I),
        'Tables.HeightIncreased.P3'(D, O, K).
'~Tables.Amend.P7'('Tables.Node.F5'(A,B,C,D,E), F, G, H, I, J, K) :-
        'Strings':'~Strings.<.P2'(F, B),
        '~Tables.Amend.P7'(A, F, G, H, L, J, M),
        '~Tables.Adjust.P6'(M, 'Tables.Node.F5'(L,B,C,D,E), D, 'Tables.Left.C0', N, I),
        '~Tables.HeightIncreased.P3'(D, N, K).
'Tables.Amend.P7'('Tables.Node.F5'(A,B,C,D,E), F, G, H, I, J, K) :-
        call_residue('Strings':'Strings.>.P2'(F,B), L),
        (   L=[] ->
            !
        ;   user:release_suspended(L)
        ),
        'Tables.Amend.P7'(E, F, G, H, M, J, N),
        'Tables.Adjust.P6'(N, 'Tables.Node.F5'(A,B,C,D,M), D, 'Tables.Right.C0', O, I),
        'Tables.HeightIncreased.P3'(D, O, K).
'~Tables.Amend.P7'('Tables.Node.F5'(A,B,C,D,E), F, G, H, I, J, K) :-
        'Strings':'~Strings.>.P2'(F, B),
        '~Tables.Amend.P7'(E, F, G, H, L, J, M),
        '~Tables.Adjust.P6'(M, 'Tables.Node.F5'(A,B,C,D,L), D, 'Tables.Right.C0', N, I),
        '~Tables.HeightIncreased.P3'(D, N, K).
'Tables.Amend.P7'('Tables.Node.F5'(A,B,C,D,E), F, G, _, H, I, J) :-
        call_residue(F=B, K),
        (   K=[] ->
            !
        ;   user:release_suspended(K)
        ),
        H='Tables.Node.F5'(A,F,G,D,E),
        I=C,
        J='Tables.No.C0'.
'~Tables.Amend.P7'('Tables.Node.F5'(A,B,C,D,E), F, G, _, H, I, J) :-
        F=B,
        H='Tables.Node.F5'(A,F,G,D,E),
        I=C,
        J='Tables.No.C0'.
'Tables.BalanceTable1.P3'('Tables.EQ.C0', 'Tables.RH.C0', 'Tables.LH.C0').
'~Tables.BalanceTable1.P3'('Tables.EQ.C0', 'Tables.RH.C0', 'Tables.LH.C0').
'Tables.BalanceTable1.P3'('Tables.LH.C0', 'Tables.EQ.C0', 'Tables.EQ.C0').
'~Tables.BalanceTable1.P3'('Tables.LH.C0', 'Tables.EQ.C0', 'Tables.EQ.C0').
'Tables.BalanceTable1.P3'('Tables.RH.C0', 'Tables.EQ.C0', 'Tables.EQ.C0').
'~Tables.BalanceTable1.P3'('Tables.RH.C0', 'Tables.EQ.C0', 'Tables.EQ.C0').
'Tables.BalanceTable2.P3'('Tables.LH.C0', 'Tables.EQ.C0', 'Tables.RH.C0').
'~Tables.BalanceTable2.P3'('Tables.LH.C0', 'Tables.EQ.C0', 'Tables.RH.C0').
'Tables.BalanceTable2.P3'('Tables.RH.C0', 'Tables.LH.C0', 'Tables.EQ.C0').
'~Tables.BalanceTable2.P3'('Tables.RH.C0', 'Tables.LH.C0', 'Tables.EQ.C0').
'Tables.BalanceTable2.P3'('Tables.EQ.C0', 'Tables.EQ.C0', 'Tables.EQ.C0').
'~Tables.BalanceTable2.P3'('Tables.EQ.C0', 'Tables.EQ.C0', 'Tables.EQ.C0').
'Tables.DeleteNode.P4'(A, B, C, D) :-
        user:goedel_freeze(nonvar(A), 'Tables':'Tables.DeleteNode.P4.0'(A,B,C,D)).
'~Tables.DeleteNode.P4'(A, B, C, D) :-
        user:goedel_freeze(nonvar(A), 'Tables':'~Tables.DeleteNode.P4.0'(A,B,C,D)).
'Tables.DeleteNode.P4.0'(A, B, C, D) :-
        'Tables.DeleteKey.P5'(A, B, C, D, _).
'~Tables.DeleteNode.P4.0'(A, B, C, D) :-
        '~Tables.DeleteKey.P5'(A, B, C, D, _).
'Tables.DeleteKey.P5'('Tables.Node.F5'(A,B,C,D,E), F, G, H, I) :-
        call_residue('Strings':'Strings.<.P2'(F,B), J),
        (   J=[] ->
            !
        ;   user:release_suspended(J)
        ),
        'Tables.DeleteKey.P5'(A, F, G, K, L),
        'Tables.Adjust.P6'(L, 'Tables.Node.F5'(K,B,C,D,E), D, 'Tables.Right.C0', M, H),
        'Tables.HeightDecreased.P3'(D, M, I).
'~Tables.DeleteKey.P5'('Tables.Node.F5'(A,B,C,D,E), F, G, H, I) :-
        'Strings':'~Strings.<.P2'(F, B),
        '~Tables.DeleteKey.P5'(A, F, G, J, K),
        '~Tables.Adjust.P6'(K, 'Tables.Node.F5'(J,B,C,D,E), D, 'Tables.Right.C0', L, H),
        '~Tables.HeightDecreased.P3'(D, L, I).
'Tables.DeleteKey.P5'('Tables.Node.F5'(A,B,C,D,E), F, G, H, I) :-
        call_residue('Strings':'Strings.>.P2'(F,B), J),
        (   J=[] ->
            !
        ;   user:release_suspended(J)
        ),
        'Tables.DeleteKey.P5'(E, F, G, K, L),
        'Tables.Adjust.P6'(L, 'Tables.Node.F5'(A,B,C,D,K), D, 'Tables.Left.C0', M, H),
        'Tables.HeightDecreased.P3'(D, M, I).
'~Tables.DeleteKey.P5'('Tables.Node.F5'(A,B,C,D,E), F, G, H, I) :-
        'Strings':'~Strings.>.P2'(F, B),
        '~Tables.DeleteKey.P5'(E, F, G, J, K),
        '~Tables.Adjust.P6'(K, 'Tables.Node.F5'(A,B,C,D,J), D, 'Tables.Left.C0', L, H),
        '~Tables.HeightDecreased.P3'(D, L, I).
'Tables.DeleteKey.P5'('Tables.Node.F5'(A,B,C,D,E), F, G, H, I) :-
        call_residue(F=B, J),
        (   J=[] ->
            !
        ;   user:release_suspended(J)
        ),
        G=C,
        'Tables.Combine.P5'(A, D, E, H, I).
'~Tables.DeleteKey.P5'('Tables.Node.F5'(A,B,C,D,E), F, G, H, I) :-
        F=B,
        G=C,
        '~Tables.Combine.P5'(A, D, E, H, I).
'Tables.EmptyTable.P1'('Tables.Null.C0').
'~Tables.EmptyTable.P1'('Tables.Null.C0').
'Tables.InsertNode.P4'(A, B, C, D) :-
        user:goedel_freeze(nonvar(A)and ground([B]), 'Tables':'Tables.InsertNode.P4.0'(A,B,C,D)).
'~Tables.InsertNode.P4'(A, B, C, D) :-
        user:goedel_freeze(nonvar(A)and ground([B]), 'Tables':'~Tables.InsertNode.P4.0'(A,B,C,D)).
'Tables.InsertNode.P4.0'(A, B, C, D) :-
        'Tables.Insert.P5'(A, B, C, D, _).
'~Tables.InsertNode.P4.0'(A, B, C, D) :-
        '~Tables.Insert.P5'(A, B, C, D, _).
'Tables.HeightIncreased.P3'('Tables.RH.C0', 'Tables.EQ.C0', 'Tables.No.C0') :- !.
'~Tables.HeightIncreased.P3'('Tables.RH.C0', 'Tables.EQ.C0', 'Tables.No.C0').
'Tables.HeightIncreased.P3'('Tables.LH.C0', 'Tables.EQ.C0', 'Tables.No.C0') :- !.
'~Tables.HeightIncreased.P3'('Tables.LH.C0', 'Tables.EQ.C0', 'Tables.No.C0').
'Tables.HeightIncreased.P3'('Tables.EQ.C0', 'Tables.LH.C0', 'Tables.Yes.C0') :- !.
'~Tables.HeightIncreased.P3'('Tables.EQ.C0', 'Tables.LH.C0', 'Tables.Yes.C0').
'Tables.HeightIncreased.P3'('Tables.EQ.C0', 'Tables.RH.C0', 'Tables.Yes.C0') :- !.
'~Tables.HeightIncreased.P3'('Tables.EQ.C0', 'Tables.RH.C0', 'Tables.Yes.C0').
'Tables.HeightIncreased.P3'(A, A, 'Tables.No.C0') :- !.
'~Tables.HeightIncreased.P3'(A, A, 'Tables.No.C0').
'Tables.HeightDecreased.P3'('Tables.LH.C0', 'Tables.RH.C0', 'Tables.No.C0') :- !.
'~Tables.HeightDecreased.P3'('Tables.LH.C0', 'Tables.RH.C0', 'Tables.No.C0').
'Tables.HeightDecreased.P3'('Tables.RH.C0', 'Tables.LH.C0', 'Tables.No.C0') :- !.
'~Tables.HeightDecreased.P3'('Tables.RH.C0', 'Tables.LH.C0', 'Tables.No.C0').
'Tables.HeightDecreased.P3'('Tables.LH.C0', 'Tables.EQ.C0', 'Tables.Yes.C0') :- !.
'~Tables.HeightDecreased.P3'('Tables.LH.C0', 'Tables.EQ.C0', 'Tables.Yes.C0').
'Tables.HeightDecreased.P3'('Tables.RH.C0', 'Tables.EQ.C0', 'Tables.Yes.C0') :- !.
'~Tables.HeightDecreased.P3'('Tables.RH.C0', 'Tables.EQ.C0', 'Tables.Yes.C0').
'Tables.HeightDecreased.P3'('Tables.EQ.C0', _, 'Tables.No.C0') :- !.
'~Tables.HeightDecreased.P3'('Tables.EQ.C0', _, 'Tables.No.C0').
'Tables.HeightDecreased.P3'(A, A, 'Tables.No.C0') :- !.
'~Tables.HeightDecreased.P3'(A, A, 'Tables.No.C0').
'Tables.Insert.P5'('Tables.Null.C0', A, B, 'Tables.Node.F5'('Tables.Null.C0',A,B,'Tables.EQ.C0','Tables.Null.C0'), 'Tables.Yes.C0').
'~Tables.Insert.P5'('Tables.Null.C0', A, B, 'Tables.Node.F5'('Tables.Null.C0',A,B,'Tables.EQ.C0','Tables.Null.C0'), 'Tables.Yes.C0').
'Tables.Insert.P5'('Tables.Node.F5'(A,B,C,D,E), F, G, H, I) :-
        call_residue('Strings':'Strings.<.P2'(F,B), J),
        (   J=[] ->
            !
        ;   user:release_suspended(J)
        ),
        'Tables.Insert.P5'(A, F, G, K, L),
        'Tables.Adjust.P6'(L, 'Tables.Node.F5'(K,B,C,D,E), D, 'Tables.Left.C0', M, H),
        'Tables.HeightIncreased.P3'(D, M, I).
'~Tables.Insert.P5'('Tables.Node.F5'(A,B,C,D,E), F, G, H, I) :-
        'Strings':'~Strings.<.P2'(F, B),
        '~Tables.Insert.P5'(A, F, G, J, K),
        '~Tables.Adjust.P6'(K, 'Tables.Node.F5'(J,B,C,D,E), D, 'Tables.Left.C0', L, H),
        '~Tables.HeightIncreased.P3'(D, L, I).
'Tables.Insert.P5'('Tables.Node.F5'(A,B,C,D,E), F, G, H, I) :-
        call_residue('Strings':'Strings.>.P2'(F,B), J),
        (   J=[] ->
            !
        ;   user:release_suspended(J)
        ),
        'Tables.Insert.P5'(E, F, G, K, L),
        'Tables.Adjust.P6'(L, 'Tables.Node.F5'(A,B,C,D,K), D, 'Tables.Right.C0', M, H),
        'Tables.HeightIncreased.P3'(D, M, I).
'~Tables.Insert.P5'('Tables.Node.F5'(A,B,C,D,E), F, G, H, I) :-
        'Strings':'~Strings.>.P2'(F, B),
        '~Tables.Insert.P5'(E, F, G, J, K),
        '~Tables.Adjust.P6'(K, 'Tables.Node.F5'(A,B,C,D,J), D, 'Tables.Right.C0', L, H),
        '~Tables.HeightIncreased.P3'(D, L, I).
'Tables.Insert.P5'('Tables.Node.F5'(A,B,C,D,E), F, G, H, I) :-
        call_residue(F=B, J),
        (   J=[] ->
            !
        ;   user:release_suspended(J)
        ),
        G=C,
        H='Tables.Node.F5'(A,B,C,D,E),
        I='Tables.No.C0'.
'~Tables.Insert.P5'('Tables.Node.F5'(A,B,C,D,E), F, G, H, I) :-
        F=B,
        G=C,
        H='Tables.Node.F5'(A,B,C,D,E),
        I='Tables.No.C0'.
'Tables.JoinTables.P3'(A, B, C) :-
        user:goedel_freeze(nonvar(A)and nonvar(B), 'Tables':'Tables.JoinTables.P3.0'(A,B,C)).
'~Tables.JoinTables.P3'(A, B, C) :-
        user:goedel_freeze(nonvar(A)and nonvar(B), 'Tables':'~Tables.JoinTables.P3.0'(A,B,C)).
'Tables.JoinTables.P3.0'(A, B, C) :-
        'Tables.JoinAux.P3'(B, A, C).
'~Tables.JoinTables.P3.0'(A, B, C) :-
        '~Tables.JoinAux.P3'(B, A, C).
'Tables.JoinAux.P3'('Tables.Null.C0', A, A).
'~Tables.JoinAux.P3'('Tables.Null.C0', A, A).
'Tables.JoinAux.P3'('Tables.Node.F5'(A,B,C,_,D), E, F) :-
        'Tables.Amend.P7'(E, B, C, _, G, _, _),
        'Tables.JoinAux.P3'(A, G, H),
        'Tables.JoinAux.P3'(D, H, F).
'~Tables.JoinAux.P3'('Tables.Node.F5'(A,B,C,_,D), E, F) :-
        '~Tables.Amend.P7'(E, B, C, _, G, _, _),
        '~Tables.JoinAux.P3'(A, G, H),
        '~Tables.JoinAux.P3'(D, H, F).
'Tables.LastNode.P3'(A, B, C) :-
        user:goedel_freeze(nonvar(A), 'Tables':'Tables.LastNode.P3.0'(A,B,C)).
'~Tables.LastNode.P3'(A, B, C) :-
        user:goedel_freeze(nonvar(A), 'Tables':'~Tables.LastNode.P3.0'(A,B,C)).
'Tables.LastNode.P3.0'('Tables.Node.F5'(_,A,B,_,'Tables.Null.C0'), A, B) :- !.
'~Tables.LastNode.P3.0'('Tables.Node.F5'(_,A,B,_,'Tables.Null.C0'), A, B).
'Tables.LastNode.P3.0'('Tables.Node.F5'(_,_,_,_,A), B, C) :-
        call_residue(user:not_equal([],[A],A,'Tables.Null.C0'), D),
        (   D=[] ->
            !
        ;   user:release_suspended(D)
        ),
        'Tables.LastNode.P3'(A, B, C).
'~Tables.LastNode.P3.0'('Tables.Node.F5'(_,_,_,_,A), B, C) :-
        user:not_equal([], [A], A, 'Tables.Null.C0'),
        '~Tables.LastNode.P3'(A, B, C).
'Tables.Restructure.P3'('Tables.Node.F5'(A,B,C,'Tables.RH.C0','Tables.Node.F5'(D,E,F,G,H)), I, J) :-
        call_residue(user:not_equal([],[G],G,'Tables.LH.C0'), K),
        (   K=[] ->
            !
        ;   user:release_suspended(K)
        ),
        J='Tables.Node.F5'('Tables.Node.F5'(A,B,C,L,D),E,F,I,H),
        'Tables.BalanceTable1.P3'(G, L, I).
'~Tables.Restructure.P3'('Tables.Node.F5'(A,B,C,'Tables.RH.C0','Tables.Node.F5'(D,E,F,G,H)), I, J) :-
        user:not_equal([], [G], G, 'Tables.LH.C0'),
        J='Tables.Node.F5'('Tables.Node.F5'(A,B,C,K,D),E,F,I,H),
        '~Tables.BalanceTable1.P3'(G, K, I).
'Tables.Restructure.P3'('Tables.Node.F5'('Tables.Node.F5'(A,B,C,D,E),F,G,'Tables.LH.C0',H), I, J) :-
        call_residue(user:not_equal([],[D],D,'Tables.RH.C0'), K),
        (   K=[] ->
            !
        ;   user:release_suspended(K)
        ),
        J='Tables.Node.F5'(A,B,C,I,'Tables.Node.F5'(E,F,G,L,H)),
        'Tables.BalanceTable1.P3'(D, I, L).
'~Tables.Restructure.P3'('Tables.Node.F5'('Tables.Node.F5'(A,B,C,D,E),F,G,'Tables.LH.C0',H), I, J) :-
        user:not_equal([], [D], D, 'Tables.RH.C0'),
        J='Tables.Node.F5'(A,B,C,I,'Tables.Node.F5'(E,F,G,K,H)),
        '~Tables.BalanceTable1.P3'(D, I, K).
'Tables.Restructure.P3'('Tables.Node.F5'(A,B,C,'Tables.RH.C0','Tables.Node.F5'('Tables.Node.F5'(D,E,F,G,H),I,J,'Tables.LH.C0',K)), 'Tables.EQ.C0', 'Tables.Node.F5'('Tables.Node.F5'(A,B,C,L,D),E,F,'Tables.EQ.C0','Tables.Node.F5'(H,I,J,M,K))) :- !,
        'Tables.BalanceTable2.P3'(G, L, M).
'~Tables.Restructure.P3'('Tables.Node.F5'(A,B,C,'Tables.RH.C0','Tables.Node.F5'('Tables.Node.F5'(D,E,F,G,H),I,J,'Tables.LH.C0',K)), 'Tables.EQ.C0', 'Tables.Node.F5'('Tables.Node.F5'(A,B,C,L,D),E,F,'Tables.EQ.C0','Tables.Node.F5'(H,I,J,M,K))) :-
        true,
        '~Tables.BalanceTable2.P3'(G, L, M).
'Tables.Restructure.P3'('Tables.Node.F5'('Tables.Node.F5'(A,B,C,'Tables.RH.C0','Tables.Node.F5'(D,E,F,G,H)),I,J,'Tables.LH.C0',K), 'Tables.EQ.C0', 'Tables.Node.F5'('Tables.Node.F5'(A,B,C,L,D),E,F,'Tables.EQ.C0','Tables.Node.F5'(H,I,J,M,K))) :- !,
        'Tables.BalanceTable2.P3'(G, L, M).
'~Tables.Restructure.P3'('Tables.Node.F5'('Tables.Node.F5'(A,B,C,'Tables.RH.C0','Tables.Node.F5'(D,E,F,G,H)),I,J,'Tables.LH.C0',K), 'Tables.EQ.C0', 'Tables.Node.F5'('Tables.Node.F5'(A,B,C,L,D),E,F,'Tables.EQ.C0','Tables.Node.F5'(H,I,J,M,K))) :-
        true,
        '~Tables.BalanceTable2.P3'(G, L, M).
'Tables.PreviousNode.P4'(A, B, C, D) :-
        user:goedel_freeze(nonvar(A)and nonvar(B), 'Tables':'Tables.PreviousNode.P4.0'(A,B,C,D)).
'~Tables.PreviousNode.P4'(A, B, C, D) :-
        user:goedel_freeze(nonvar(A)and nonvar(B), 'Tables':'~Tables.PreviousNode.P4.0'(A,B,C,D)).
'Tables.PreviousNode.P4.0'('Tables.Node.F5'(A,B,_,_,_), C, D, E) :-
        call_residue(C=B, F),
        (   F=[] ->
            !
        ;   user:release_suspended(F)
        ),
        'Tables.LastNode.P3'(A, D, E).
'~Tables.PreviousNode.P4.0'('Tables.Node.F5'(A,B,_,_,_), C, D, E) :-
        C=B,
        '~Tables.LastNode.P3'(A, D, E).
'Tables.PreviousNode.P4.0'('Tables.Node.F5'(A,B,_,_,_), C, D, E) :-
        call_residue('Strings':'Strings.<.P2'(C,B), F),
        (   F=[] ->
            !
        ;   user:release_suspended(F)
        ),
        'Tables.PreviousNode.P4'(A, C, D, E).
'~Tables.PreviousNode.P4.0'('Tables.Node.F5'(A,B,_,_,_), C, D, E) :-
        'Strings':'~Strings.<.P2'(C, B),
        '~Tables.PreviousNode.P4'(A, C, D, E).
'Tables.PreviousNode.P4.0'('Tables.Node.F5'(_,A,B,_,C), D, E, F) :-
        call_residue('Strings':'Strings.>.P2'(D,A), G),
        (   G=[] ->
            !
        ;   user:release_suspended(G)
        ),
        user:goedel_freeze(ground([C,D]), if(('Tables':'~Tables.PreviousNode.P4'(C,D,H,I),true),(E=H,F=I),('Tables':'Tables.FirstNode.P3'(C,D,_),E=A,F=B))).
'~Tables.PreviousNode.P4.0'('Tables.Node.F5'(_,A,B,_,C), D, E, F) :-
        'Strings':'~Strings.>.P2'(D, A),
        user:goedel_freeze(ground([C,D]), if(('Tables':'~Tables.PreviousNode.P4'(C,D,G,H),true),(E=G,F=H),('Tables':'~Tables.FirstNode.P3'(C,D,_),E=A,F=B))).
'Tables.NextNode.P4'(A, B, C, D) :-
        user:goedel_freeze(nonvar(A)and nonvar(B), 'Tables':'Tables.NextNode.P4.0'(A,B,C,D)).
'~Tables.NextNode.P4'(A, B, C, D) :-
        user:goedel_freeze(nonvar(A)and nonvar(B), 'Tables':'~Tables.NextNode.P4.0'(A,B,C,D)).
'Tables.NextNode.P4.0'('Tables.Node.F5'(_,A,_,_,B), C, D, E) :-
        call_residue(C=A, F),
        (   F=[] ->
            !
        ;   user:release_suspended(F)
        ),
        'Tables.FirstNode.P3'(B, D, E).
'~Tables.NextNode.P4.0'('Tables.Node.F5'(_,A,_,_,B), C, D, E) :-
        C=A,
        '~Tables.FirstNode.P3'(B, D, E).
'Tables.NextNode.P4.0'('Tables.Node.F5'(A,B,C,_,_), D, E, F) :-
        call_residue('Strings':'Strings.<.P2'(D,B), G),
        (   G=[] ->
            !
        ;   user:release_suspended(G)
        ),
        user:goedel_freeze(ground([A,D]), if(('Tables':'~Tables.NextNode.P4'(A,D,H,I),true),(E=H,F=I),('Tables':'Tables.LastNode.P3'(A,D,_),E=B,F=C))).
'~Tables.NextNode.P4.0'('Tables.Node.F5'(A,B,C,_,_), D, E, F) :-
        'Strings':'~Strings.<.P2'(D, B),
        user:goedel_freeze(ground([A,D]), if(('Tables':'~Tables.NextNode.P4'(A,D,G,H),true),(E=G,F=H),('Tables':'~Tables.LastNode.P3'(A,D,_),E=B,F=C))).
'Tables.NextNode.P4.0'('Tables.Node.F5'(_,A,_,_,B), C, D, E) :-
        call_residue('Strings':'Strings.>.P2'(C,A), F),
        (   F=[] ->
            !
        ;   user:release_suspended(F)
        ),
        'Tables.NextNode.P4'(B, C, D, E).
'~Tables.NextNode.P4.0'('Tables.Node.F5'(_,A,_,_,B), C, D, E) :-
        'Strings':'~Strings.>.P2'(C, A),
        '~Tables.NextNode.P4'(B, C, D, E).
'Tables.ListsToTable.P3'([], [], 'Tables.Null.C0').
'~Tables.ListsToTable.P3'([], [], 'Tables.Null.C0').
'Tables.ListsToTable.P3'([A|B], C, D) :-
        'Tables.ListsToTable1.P5'(B, A, C, 'Tables.Null.C0', D).
'~Tables.ListsToTable.P3'([A|B], C, D) :-
        '~Tables.ListsToTable1.P5'(B, A, C, 'Tables.Null.C0', D).
'Tables.ListsToTable1.P5'([], A, [B], C, D) :-
        'Tables.InsertNode.P4'(C, A, B, D).
'~Tables.ListsToTable1.P5'([], A, [B], C, D) :-
        '~Tables.InsertNode.P4'(C, A, B, D).
'Tables.ListsToTable1.P5'([A|B], C, [D|E], F, G) :-
        'Strings':'Strings.<.P2'(C, A),
        'Tables.InsertNode.P4'(F, C, D, H),
        'Tables.ListsToTable1.P5'(B, A, E, H, G).
'~Tables.ListsToTable1.P5'([A|B], C, [D|E], F, G) :-
        'Strings':'~Strings.<.P2'(C, A),
        '~Tables.InsertNode.P4'(F, C, D, H),
        '~Tables.ListsToTable1.P5'(B, A, E, H, G).
'Tables.NodeInTable.P3'(A, B, C) :-
        user:goedel_freeze(nonvar(A), 'Tables':'Tables.NodeInTable.P3.0'(A,B,C)).
'~Tables.NodeInTable.P3'(A, B, C) :-
        user:goedel_freeze(nonvar(A), 'Tables':'~Tables.NodeInTable.P3.0'(A,B,C)).
'Tables.NodeInTable.P3.0'(A, B, C) :-
        'Tables.NodeInTableAux.P3'(A, B, C).
'~Tables.NodeInTable.P3.0'(A, B, C) :-
        '~Tables.NodeInTableAux.P3'(A, B, C).
'Tables.RemoveRightmost.P5'('Tables.Node.F5'(A,B,C,D,E), F, G, H, I) :-
        call_residue(user:not_equal([],[E],E,'Tables.Null.C0'), J),
        (   J=[] ->
            !
        ;   user:release_suspended(J)
        ),
        'Tables.RemoveRightmost.P5'(E, F, G, K, L),
        'Tables.Adjust.P6'(L, 'Tables.Node.F5'(A,B,C,D,K), D, 'Tables.Left.C0', M, H),
        'Tables.HeightDecreased.P3'(D, M, I).
'~Tables.RemoveRightmost.P5'('Tables.Node.F5'(A,B,C,D,E), F, G, H, I) :-
        user:not_equal([], [E], E, 'Tables.Null.C0'),
        '~Tables.RemoveRightmost.P5'(E, F, G, J, K),
        '~Tables.Adjust.P6'(K, 'Tables.Node.F5'(A,B,C,D,J), D, 'Tables.Left.C0', L, H),
        '~Tables.HeightDecreased.P3'(D, L, I).
'Tables.RemoveRightmost.P5'('Tables.Node.F5'(A,B,C,_,'Tables.Null.C0'), B, C, A, 'Tables.Yes.C0') :- !.
'~Tables.RemoveRightmost.P5'('Tables.Node.F5'(A,B,C,_,'Tables.Null.C0'), B, C, A, 'Tables.Yes.C0').
'Tables.Rebalance.P4'('Tables.No.C0', 'Tables.Node.F5'(A,B,C,_,D), E, 'Tables.Node.F5'(A,B,C,E,D)).
'~Tables.Rebalance.P4'('Tables.No.C0', 'Tables.Node.F5'(A,B,C,_,D), E, 'Tables.Node.F5'(A,B,C,E,D)).
'Tables.Rebalance.P4'('Tables.Yes.C0', A, B, C) :-
        'Tables.Restructure.P3'(A, B, C).
'~Tables.Rebalance.P4'('Tables.Yes.C0', A, B, C) :-
        '~Tables.Restructure.P3'(A, B, C).
'Tables.TableSearch.P3'('Tables.Node.F5'(_,A,B,_,_), C, D) :-
        call_residue(C=A, E),
        (   E=[] ->
            !
        ;   user:release_suspended(E)
        ),
        D=B.
'~Tables.TableSearch.P3'('Tables.Node.F5'(_,A,B,_,_), C, D) :-
        C=A,
        D=B.
'Tables.TableSearch.P3'('Tables.Node.F5'(A,B,_,_,_), C, D) :-
        call_residue('Strings':'Strings.<.P2'(C,B), E),
        (   E=[] ->
            !
        ;   user:release_suspended(E)
        ),
        'Tables.TableSearch.P3'(A, C, D).
'~Tables.TableSearch.P3'('Tables.Node.F5'(A,B,_,_,_), C, D) :-
        'Strings':'~Strings.<.P2'(C, B),
        '~Tables.TableSearch.P3'(A, C, D).
'Tables.TableSearch.P3'('Tables.Node.F5'(_,A,_,_,B), C, D) :-
        call_residue('Strings':'Strings.>.P2'(C,A), E),
        (   E=[] ->
            !
        ;   user:release_suspended(E)
        ),
        'Tables.TableSearch.P3'(B, C, D).
'~Tables.TableSearch.P3'('Tables.Node.F5'(_,A,_,_,B), C, D) :-
        'Strings':'~Strings.>.P2'(C, A),
        '~Tables.TableSearch.P3'(B, C, D).
'Tables.TableMember.P3'('Tables.Node.F5'(_,A,B,_,_), A, B).
'~Tables.TableMember.P3'('Tables.Node.F5'(_,A,B,_,_), A, B).
'Tables.TableMember.P3'('Tables.Node.F5'(A,_,_,_,_), B, C) :-
        'Tables.TableMember.P3'(A, B, C).
'~Tables.TableMember.P3'('Tables.Node.F5'(A,_,_,_,_), B, C) :-
        '~Tables.TableMember.P3'(A, B, C).
'Tables.TableMember.P3'('Tables.Node.F5'(_,_,_,_,A), B, C) :-
        'Tables.TableMember.P3'(A, B, C).
'~Tables.TableMember.P3'('Tables.Node.F5'(_,_,_,_,A), B, C) :-
        '~Tables.TableMember.P3'(A, B, C).
'Tables.UpdateTable.P5'(A, B, C, D, E) :-
        user:goedel_freeze(nonvar(A)and ground([B]), 'Tables':'Tables.UpdateTable.P5.0'(A,B,C,D,E)).
'~Tables.UpdateTable.P5'(A, B, C, D, E) :-
        user:goedel_freeze(nonvar(A)and ground([B]), 'Tables':'~Tables.UpdateTable.P5.0'(A,B,C,D,E)).
'Tables.UpdateTable.P5.0'('Tables.Node.F5'(A,B,C,D,E), F, G, H, I) :-
        call_residue(F=B, J),
        (   J=[] ->
            !
        ;   user:release_suspended(J)
        ),
        H='Tables.Node.F5'(A,B,G,D,E),
        I=C.
'~Tables.UpdateTable.P5.0'('Tables.Node.F5'(A,B,C,D,E), F, G, H, I) :-
        F=B,
        H='Tables.Node.F5'(A,B,G,D,E),
        I=C.
'Tables.UpdateTable.P5.0'('Tables.Node.F5'(A,B,C,D,E), F, G, H, I) :-
        call_residue('Strings':'Strings.<.P2'(F,B), J),
        (   J=[] ->
            !
        ;   user:release_suspended(J)
        ),
        'Tables.UpdateTable.P5'(A, F, G, K, I),
        H='Tables.Node.F5'(K,B,C,D,E).
'~Tables.UpdateTable.P5.0'('Tables.Node.F5'(A,B,C,D,E), F, G, H, I) :-
        'Strings':'~Strings.<.P2'(F, B),
        '~Tables.UpdateTable.P5'(A, F, G, J, I),
        H='Tables.Node.F5'(J,B,C,D,E).
'Tables.UpdateTable.P5.0'('Tables.Node.F5'(A,B,C,D,E), F, G, H, I) :-
        call_residue('Strings':'Strings.>.P2'(F,B), J),
        (   J=[] ->
            !
        ;   user:release_suspended(J)
        ),
        'Tables.UpdateTable.P5'(E, F, G, K, I),
        H='Tables.Node.F5'(A,B,C,D,K).
'~Tables.UpdateTable.P5.0'('Tables.Node.F5'(A,B,C,D,E), F, G, H, I) :-
        'Strings':'~Strings.>.P2'(F, B),
        '~Tables.UpdateTable.P5'(E, F, G, J, I),
        H='Tables.Node.F5'(A,B,C,D,J).
'Tables.TableToLists.P5'('Tables.Null.C0', A, A, B, B).
'~Tables.TableToLists.P5'('Tables.Null.C0', A, A, B, B).
'Tables.TableToLists.P5'('Tables.Node.F5'(A,B,C,_,D), E, F, G, H) :-
        'Tables.TableToLists.P5'(A, E, [B|I], G, [C|J]),
        'Tables.TableToLists.P5'(D, I, F, J, H).
'~Tables.TableToLists.P5'('Tables.Node.F5'(A,B,C,_,D), E, F, G, H) :-
        '~Tables.TableToLists.P5'(A, E, [B|I], G, [C|J]),
        '~Tables.TableToLists.P5'(D, I, F, J, H).
%------------------------------------------------------------------------------
% Supplementary routines for Tables.
%------------------------------------------------------------------------------

% %Z%%M% %I% last updated %E% %U% by %Q%
 
'Tables.NodeInTableAux.P3'(Tree, Key, Item) :-
   ( var(Key) ->
     'Tables.TableMember.P3'(Tree, Key, Item)
   ; 'Tables.TableSearch.P3'(Tree, Key, Item)
   ).

'~Tables.NodeInTableAux.P3'(Tree, Key, Item) :-
   'Tables.NodeInTableAux.P3'(Tree, Key, Item).


'Tables.ListTableAux.P3'(Tree, Keys, Items) :-
   ( var(Tree) ->
     'Tables.ListsToTable.P3'(Keys, Items, Tree)
   ; 'Tables.TableToLists.P5'(Tree, Keys, [], Items, [])
   ).

'~Tables.ListTableAux.P3'(Tree, Keys, Items) :-
   'Tables.ListTableAux.P3'(Tree, Keys, Items).
:- style_check(-singleton). % added djd
%% :- module('Units', []).
:- module(units).  % converted djd

:- discontiguous 'Units':token_id/4. %% added djd
:- discontiguous token_id/4. %% added djd

:- op(500, yfx, and).
:- op(400, yfx, or).


/*
Subject:	A tokenizer for Identifiers.
Author:		Jiwei Wang
Date:		30 Nov. 1992

-----------------------------------------------------------------------------*/


'$$module'('@(#)Units.sup 1.5 last updated 93/10/14 14:25:15 by jiwei
').

%------------------------------------------------------------------------------

'Units.StringToUnit.P2'(GString, Unit) :-
   nonvar(GString), !,
   name(GString, [0'"|Chars]),
   unit(Chars, Remains, Unit),
   Remains = [],
   Unit \== null.

'Units.StringToUnit.P2'(GString, Unit) :-
   user:goedel_freeze(ground([GString]),
	'Units':'Units.StringToUnit.P2.0'(GString, Unit) ).

'~Units.StringToUnit.P2'(GString, Unit) :-
   user:goedel_freeze(ground([GString]),
	'Units':'Units.StringToUnit.P2.0'(GString, Unit) ).

%------------------------------------------------------------------------------

'Units.UnitToString.P2'(Unit, GString) :-
   nonvar(Unit), !,
   unit2chars(Unit, Chars),
   name(GString, [0'"|Chars]).

'Units.UnitToString.P2'(Unit, GString) :-
   user:goedel_freeze(ground([Unit]),
	'Units':'Units.UnitToString.P2.0'(Unit, GString) ).

'~Units.UnitToString.P2'(Unit, GString) :-
   user:goedel_freeze(ground([Unit]),
	'Units':'Units.UnitToString.P2.0'(Unit, GString) ).

%- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

unit2chars('Units.Unit.F2'(Head, Tail), Chars) :-
   ( Tail = []
     -> name(Head, [_|Chars])
     ;  unit2chars_aux(Tail, Chars2),
        name(Head, [_|HeadChars]),
        user:append(Chars2, [0')], Chars3),
        user:append(HeadChars, [0'(|Chars3], Chars)
   ).

unit2chars_aux([], []).
unit2chars_aux([H|T], St) :-
   unit2chars(H, Sh),
   unit2chars_aux(T, St2),
   ( St2 = []
     -> user:append(Sh, St2, St)
     ;  user:append(Sh, [0',, 32|St2], St)
   ).

%------------------------------------------------------------------------------

'Units.UnitParts.P3'('Units.Unit.F2'(String, Units), String, Units).

'~Units.UnitParts.P3'('Units.Unit.F2'(String, Units), String, Units).

%------------------------------------------------------------------------------

'Units.UnitArgument.P3'(Unit, N, Unit2) :-
   user:goedel_freeze(ground([Unit]),
		'Units':'Units.UnitArgument.P3.0'(Unit, N, Unit2) ).

'~Units.UnitArgument.P3'(Unit, N, Unit2) :-
   user:goedel_freeze(ground([Unit]),
		'Units':'Units.UnitArgument.P3.0'(Unit, N, Unit2) ).

'Units.UnitArgument.P3.0'(Unit, N, Unit2) :-
   nonvar(Unit), !,
   Unit = 'Units.Unit.F2'(_, List),
   nth_element(List, N, Unit2).

'Units.UnitArgument.P3.0'('Units.Unit.F2'(_, List), N, Unit2) :-
   nonvar(N),
   functor(F, term, N),
   arg(N, F, Unit2),
   F =.. [_|List].


nth_element(List, N, Elem) :-
   ( nonvar(N)
     -> nth_element_aux(List, N, Elem)
     ;  user:member(Elem, List)
   ).

nth_element_aux([Elem|_], 1, Elem) :- !.
nth_element_aux([_|List], N, Elem) :-
   N > 1,
   N2 is N - 1,
   nth_element_aux(List, N2, Elem).

%------------------------------------------------------------------------------
%------------------------------------------------------------------------------
% the entry point of the unit parser
% Goedel units are represented as
%	'Units.Unit.F2'(Functor, List(Unit)).

unit(Chars, Remains, Unit) :-
   token_identifiers(Chars, Tokens, []),
   parse_unit(Tokens, Remains, Unit).

% parse_unit returns "null" when there is no token.

parse_unit([], [], null).
parse_unit([Token|Tokens], Remains, Unit) :-
   ( non_identifier(Token)
     -> fail			% syntax error
     ;  user:string2Gstring(Token, GToken),
	( Tokens = [Token2|Tokens2]
	  -> ( Token2 = '('
	       -> unit_seq(Tokens2, Remains, UnitSeq),
		  ( UnitSeq = empty
		    -> Unit = 'Units.Unit.F2'(GToken, [])
		    ;  Unit = 'Units.Unit.F2'(GToken, UnitSeq)
		  )
	       ;  Remains = Tokens,
		  user:string2Gstring(Token, GToken),
		  Unit = 'Units.Unit.F2'(GToken, [])
	     )
	  ;  Remains = Tokens,
	     Unit = 'Units.Unit.F2'(GToken, [])
        ) 
   ).

%- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% unit_seq may fail, it consumes the ')'

unit_seq(Tokens, Remains, UnitSeq) :-
   ( Tokens = [')'|Remains]
     -> UnitSeq = empty		% empty signals the empty unit_seq 
     ;  unit_seq_aux(Tokens, Remains, UnitSeq)
   ).

unit_seq_aux(Tokens, Remains, UnitSeq) :-
   parse_unit(Tokens, Remains2, Unit),
   ( Unit = null
     -> fail		% was Remains = [], UnitSeq = null
     ;  ( Remains2 = [')'|Remains]
	  -> UnitSeq = [Unit]
	  ;  ( Remains2 = [','|Remains3]
	       -> unit_seq_aux(Remains3, Remains, UnitSeq2),
		  UnitSeq = [Unit|UnitSeq2]
	       ;  fail 	% syntax error
	     )
	)
   ).

non_identifier(',').
non_identifier('(').
non_identifier(')').
non_identifier('''').
non_identifier('"').

%------------------------------------------------------------------------------
%------------------------------------------------------------------------------
% the entry point of the identifier tokenizer

token_identifiers([], Tokens, Tokens).
token_identifiers([Char|Chars], Tokens, Tokens2):-
   token_id(Char, Chars, Remains, Token),
   ( Token = end_of_token(null)
     -> Tokens = Tokens2
     ;  Tokens = [Token|Tokens3],
	token_identifiers(Remains, Tokens3, Tokens2)
   ).

token_id([], [], end_of_token(null)).
token_id([Char|Chars], Remains, Token) :-
   token_id(Char, Chars, Remains, Token).

%------------------------------------------------------------------------------

% Layout-char
token_id(32, Chars, Remains, Token) :- !,
   token_id(Chars, Remains, Token).
token_id(9, Chars, Remains, Token) :- !,
   token_id(Chars, Remains, Token).
token_id(10, Chars, Remains, Token) :- !,
   token_id(Chars, Remains, Token).

%------------------------------------------------------------------------------
% QuotedId 

token_id(0'', Chars, Remains, String) :- !,
   single_quoted_id(Chars, Remains, SChars),
   name(String, [0''|SChars]).

%- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% One ' terminates string, two ' escapes this, anything else just adds
% characters to the string

single_quoted_id([], [], []) :-
   format(user_error, '~nError: incomplete single quoted string.~n', []).
		% does error recovery
single_quoted_id([C|Chars], Remains, SChars) :-
   ( C == 0''
     -> ( Chars = [0''|Chars2]
	  -> SChars = [C, C|SChars2],
	     single_quoted_id(Chars2, Remains, SChars2)
	  ;  SChars = [0''],
	     Remains = Chars
	)
     ;  SChars = [C|SChars2],
        single_quoted_id(Chars, Remains, SChars2)
   ).

%------------------------------------------------------------------------------
% DbleQuotedId 

token_id(0'", Chars, Remains, String) :- !,
   double_quoted_id(Chars, Remains, SChars),
   name(String, [0'"|SChars]).

%- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% One " terminates string, two " escapes this, anything else just adds
% characters to the string

double_quoted_id([], [], []) :-
   format(user_error, '~nError: incomplete string.~n', []).
		% does error recovery
double_quoted_id([C|Chars], Remains, SChars) :-
   ( C == 0'"
     -> ( Chars = [0'"|Chars2]
	  -> SChars = [C, C|SChars2],
	     double_quoted_id(Chars2, Remains, SChars2)
	  ;  SChars = [0'"],
	     Remains = Chars
	)
     ;  SChars = [C|SChars2],
        double_quoted_id(Chars, Remains, SChars2)
   ).

%------------------------------------------------------------------------------

% left round
token_id(0'(, Chars, Chars, '(') :- !.

% right round
token_id(0'), Chars, Chars, ')') :- !.

% Comma
token_id(0',, Chars, Chars, ',') :- !.

% Full stop
token_id(0'., Chars, Chars, '.') :- !.

%------------------------------------------------------------------------------
% This is an ordinary id

token_id(C, Chars, Remains, Token) :-
   33 =< C, C =< 126, !,	% this covers all the visible chars
   identifier(Chars, Remains, IdChars),
   name(Token, [C|IdChars]).

identifier([], [], []).
identifier([C|Chars], Remains, IdChars) :-
   ( 33 =< C, C =< 126		% this covers all the visible chars
     -> ( non_id_char(C)
	  -> Remains = [C|Chars],
	     IdChars = []
	  ;  ( C = 0'.
	       -> ( Chars = [C2|_]
	            -> ( start_of_new_id(C2)
		         -> Remains = [C|Chars],
			    IdChars = []
			 ;  IdChars = [C|IdChars2],
			    identifier(Chars, Remains, IdChars2)
		       )
		    ;  Remains = [C|Chars],
		       IdChars = [] 
	          )
	       ;  IdChars = [C|IdChars2],
	          identifier(Chars, Remains, IdChars2)
	     )
	) 
     ;  Remains = [C|Chars],
	IdChars = []
   ).

%- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

non_id_char(0',).
non_id_char(0'().
non_id_char(0')).
non_id_char(0'').
non_id_char(0'").

% This specifies those chars that a full stop should be taken as a terminator
start_of_new_id(32).
start_of_new_id(10).
start_of_new_id(9).
start_of_new_id(0'').
start_of_new_id(0'").

%------------------------------------------------------------------------------

% Cope with illegal characters
token_id(C, Chars, Remains, Token) :- 
   format(user_error, '~nError: illegal character with ASCII code "~q".~n',
		[C]),
   token_id(Chars, Remains, Token).

:- style_check(-singleton). % added djd
%% :- module('Flocks', []).
:- module(flocks). %% converted djd

:- discontiguous 'Flocks.DelNthElement.P4'/4. %% added djd
:- discontiguous '~Flocks.DelNthElement.P4'/4. %% added djd
:- discontiguous 'Flocks.InsNthElement.P4'/4. %% added djd
:- discontiguous '~Flocks.InsNthElement.P4'/4. %% added djd
:- discontiguous 'Flocks.NthElement.P3'/3. %% added djd
:- discontiguous '~Flocks.NthElement.P3'/3. %% added djd


:- op(500, yfx, and).
:- op(400, yfx, or).

'Flocks.Extent.P2'(A, B) :-
        user:goedel_freeze(ground([A]), 'Flocks':'Flocks.Extent.P2.0'(A,B)).
'~Flocks.Extent.P2'(A, B) :-
        user:goedel_freeze(ground([A]), 'Flocks':'~Flocks.Extent.P2.0'(A,B)).
'Flocks.Extent.P2.0'('Flocks.Flock.F1'(A), B) :-
        'Lists':'Lists.Length.P2'(A, B).
'~Flocks.Extent.P2.0'('Flocks.Flock.F1'(A), B) :-
        'Lists':'~Lists.Length.P2'(A, B).
'Flocks.DeleteUnit.P4'(A, B, C, D) :-
        user:goedel_freeze(ground([A]), 'Flocks':'Flocks.DeleteUnit.P4.0'(A,B,C,D)).
'~Flocks.DeleteUnit.P4'(A, B, C, D) :-
        user:goedel_freeze(ground([A]), 'Flocks':'~Flocks.DeleteUnit.P4.0'(A,B,C,D)).
'Flocks.DeleteUnit.P4.0'('Flocks.Flock.F1'(A), B, C, 'Flocks.Flock.F1'(D)) :-
        'Flocks.DelNthElement.P4'(A, C, B, D).
'~Flocks.DeleteUnit.P4.0'('Flocks.Flock.F1'(A), B, C, 'Flocks.Flock.F1'(D)) :-
        '~Flocks.DelNthElement.P4'(A, C, B, D).
'Flocks.DelNthElement.P4'([A|B], 1, A, B).
'~Flocks.DelNthElement.P4'([A|B], 1, A, B).
'Flocks.DelNthElement.P4'([A|B], C, D, [A|E]) :-
        'Integers':'Integers.>.P2'(C, 1),
        'Integers':minus(C, 1, F),
        'Flocks.DelNthElement.P4'(B, F, D, E).
'~Flocks.DelNthElement.P4'([A|B], C, D, [A|E]) :-
        'Integers':'~Integers.>.P2'(C, 1),
        'Integers':minus(C, 1, F),
        '~Flocks.DelNthElement.P4'(B, F, D, E).
'Flocks.EmptyFlock.P1'('Flocks.Flock.F1'([])).
'~Flocks.EmptyFlock.P1'('Flocks.Flock.F1'([])).
'Flocks.UnitInFlock.P3'(A, B, C) :-
        user:goedel_freeze(ground([A]), 'Flocks':'Flocks.UnitInFlock.P3.0'(A,B,C)).
'~Flocks.UnitInFlock.P3'(A, B, C) :-
        user:goedel_freeze(ground([A]), 'Flocks':'~Flocks.UnitInFlock.P3.0'(A,B,C)).
'Flocks.UnitInFlock.P3.0'('Flocks.Flock.F1'(A), B, C) :-
        'Flocks.NthElement.P3'(A, C, B).
'~Flocks.UnitInFlock.P3.0'('Flocks.Flock.F1'(A), B, C) :-
        '~Flocks.NthElement.P3'(A, C, B).
'Flocks.InsertUnit.P4'(A, B, C, D) :-
        user:goedel_freeze(ground([A,B,C]), 'Flocks':'Flocks.InsertUnit.P4.0'(A,B,C,D)).
'~Flocks.InsertUnit.P4'(A, B, C, D) :-
        user:goedel_freeze(ground([A,B,C]), 'Flocks':'~Flocks.InsertUnit.P4.0'(A,B,C,D)).
'Flocks.InsertUnit.P4.0'('Flocks.Flock.F1'(A), B, C, 'Flocks.Flock.F1'(D)) :-
        'Flocks.InsNthElement.P4'(A, C, B, D).
'~Flocks.InsertUnit.P4.0'('Flocks.Flock.F1'(A), B, C, 'Flocks.Flock.F1'(D)) :-
        '~Flocks.InsNthElement.P4'(A, C, B, D).
'Flocks.InsNthElement.P4'(A, 1, B, [B|A]) :- !.
'~Flocks.InsNthElement.P4'(A, 1, B, [B|A]).
'Flocks.InsNthElement.P4'([A|B], C, D, [A|E]) :-
        call_residue('Integers':'Integers.>.P2'(C,1), F),
        (   F=[] ->
            !
        ;   user:release_suspended(F)
        ),
        'Integers':minus(C, 1, G),
        'Flocks.InsNthElement.P4'(B, G, D, E).
'~Flocks.InsNthElement.P4'([A|B], C, D, [A|E]) :-
        'Integers':'~Integers.>.P2'(C, 1),
        'Integers':minus(C, 1, F),
        '~Flocks.InsNthElement.P4'(B, F, D, E).
'Flocks.NthElement.P3'([A|_], 1, A).
'~Flocks.NthElement.P3'([A|_], 1, A).
'Flocks.NthElement.P3'([_|A], B, C) :-
        'Integers':'Integers.>.P2'(B, 1),
        'Integers':minus(B, 1, D),
        'Flocks.NthElement.P3'(A, D, C).
'~Flocks.NthElement.P3'([_|A], B, C) :-
        'Integers':'~Integers.>.P2'(B, 1),
        'Integers':minus(B, 1, D),
        '~Flocks.NthElement.P3'(A, D, C).
'Flocks.UnitWithIdentifier.P4'(A, B, C, D) :-
        user:goedel_freeze(ground([A]), 'Flocks':'Flocks.UnitWithIdentifier.P4.0'(A,B,C,D)).
'~Flocks.UnitWithIdentifier.P4'(A, B, C, D) :-
        user:goedel_freeze(ground([A]), 'Flocks':'~Flocks.UnitWithIdentifier.P4.0'(A,B,C,D)).
'Flocks.UnitWithIdentifier.P4.0'('Flocks.Flock.F1'(A), B, C, D) :-
        'Flocks.NthElement.P3'(A, D, C),
        'Units':'Units.UnitParts.P3'(C, B, _).
'~Flocks.UnitWithIdentifier.P4.0'('Flocks.Flock.F1'(A), B, C, D) :-
        '~Flocks.NthElement.P3'(A, D, C),
        'Units':'~Units.UnitParts.P3'(C, B, _).
:- style_check(-singleton). % added djd
%% :- module('FlocksIO', []).
:- module(flocksIO).  %% converted djd

:- op(500, yfx, and).
:- op(400, yfx, or).

'FlocksIO.GetFlock.P2'(A, B) :-
        user:goedel_freeze(ground([A]), 'FlocksIO':'FlocksIO.GetFlock.P2.0'(A,B)).
'~FlocksIO.GetFlock.P2'(A, B) :-
        user:goedel_freeze(ground([A]), 'FlocksIO':'~FlocksIO.GetFlock.P2.0'(A,B)).
'FlocksIO.GetFlock.P2.0'(A, B) :-
        'FlocksIO.ReadFlock.P2'(A, B).
'~FlocksIO.GetFlock.P2.0'(A, B) :-
        '~FlocksIO.ReadFlock.P2'(A, B).
'FlocksIO.PutFlock.P2'(A, B) :-
        user:goedel_freeze(ground([A,B]), 'FlocksIO':'FlocksIO.PutFlock.P2.0'(A,B)).
'~FlocksIO.PutFlock.P2'(A, B) :-
        user:goedel_freeze(ground([A,B]), 'FlocksIO':'~FlocksIO.PutFlock.P2.0'(A,B)).
'FlocksIO.PutFlock.P2.0'(A, B) :-
        'FlocksIO.WriteFlock.P2'(A, B).
'~FlocksIO.PutFlock.P2.0'(A, B) :-
        '~FlocksIO.WriteFlock.P2'(A, B).
/*
Subject:	Supporting routines for FlocksIO module
Author:		Jiwei Wang
Date:		2 Dec. 1992

-----------------------------------------------------------------------------*/


'$$module'('@(#)FlocksIO.sup 1.3 last updated 93/09/02 16:47:07 by jiwei
').

%------------------------------------------------------------------------------

'FlocksIO.WriteFlock.P2'(Stream, Flock) :-
   'IO':translate_stream(Stream, PrologStream),
   writeq(PrologStream, Flock),
   write(PrologStream, '.'),
   nl(PrologStream).

'~FlocksIO.WriteFlock.P2'(Stream, Flock) :-
   'FlocksIO.WriteFlock.P2'(Stream, Flock).


'FlocksIO.ReadFlock.P2'(Stream, Flock) :-
   'IO':translate_stream(Stream, PrologStream),
   read(PrologStream, Flock).

'~FlocksIO.ReadFlock.P2'(Stream, Flock) :-
   'FlocksIO.ReadFlock.P2'(Stream, Flock).

%------------------------------------------------------------------------------
 
'FlocksIO.FlockCompile.P2'(GString, 'Flocks.Flock.F1'(FlockList)) :-
   nonvar(GString), !,
   user:gstring2string(GString, String),
   ( open(String, read, Stream)
     -> user:read_file(Stream, Chars),
        'Units':token_identifiers(Chars, Tokens, []),
        user:flock_compile_cmd_aux(Tokens, FlockList), !,
        close(Stream)
     ;  format(user_error, '~nError: cannot open file "~a".~n', [String])
   ).

'FlocksIO.FlockCompile.P2'(GString, Flock) :-
   user:goedel_freeze(ground([GString]),
        'FlocksIO':'FlocksIO.FlockCompile.P2'(GString, Flock) ).


'~FlocksIO.FlockCompile.P2'(GString, Flock) :-
   'FlocksIO.FlockCompile.P2'(GString, Flock).

%------------------------------------------------------------------------------

'FlocksIO.FlockDecompile.P2'(Flock, GString) :-
   nonvar(Flock), !,
   nonvar(GString), !,
   user:gstring2string(GString, String),
   Flock = 'Flocks.Flock.F1'(List),
   ( open(String, write, Stream)
     -> user:flock_decompile_cmd_aux(List, Stream), !,
        close(Stream)
     ;  format(user_error, '~nError: cannot open file "~a".~n', [String])
   ).


'FlocksIO.FlockDecompile.P2'(Flock, GString) :-
   user:goedel_freeze(ground([GString, Flock]),
        'FlocksIO':'FlocksIO.FlockDecompile.P2'(Flock, GString) ).


'~FlocksIO.FlockDecompile.P2'(Flock, GString) :-
   'FlocksIO.FlockDecompile.P2'(Flock, GString).

:- style_check(-singleton). % added djd
%% :- module('IO', []).
:- module('iO').  %% converted djd

:- discontiguous 'iO.WriteCharList.P2'/2. %% added djd
:- discontiguous '~iO.WriteCharList.P2'/2. %% added djd


:- op(500, yfx, and).
:- op(400, yfx, or).

'iO.NewLine.P1'(A) :-
        user:goedel_freeze(ground([A]), 'IO':'iO.NewLine.P1.0'(A)).
'~iO.NewLine.P1'(A) :-
        user:goedel_freeze(ground([A]), 'IO':'~iO.NewLine.P1.0'(A)).
'iO.NewLine.P1.0'(A) :-
        'iO.Put.P2'(A, 10).
'~iO.NewLine.P1.0'(A) :-
        '~iO.Put.P2'(A, 10).
'iO.WriteCharList.P2'([], _).
'~iO.WriteCharList.P2'([], _).
'iO.WriteCharList.P2'([A|B], C) :-
        'iO.Put.P2'(C, A),
        'iO.WriteCharList.P2'(B, C).
'~iO.WriteCharList.P2'([A|B], C) :-
        '~iO.Put.P2'(C, A),
        '~iO.WriteCharList.P2'(B, C).
'iO.WriteString.P2'(A, B) :-
        user:goedel_freeze(ground([A,B]), 'IO':'iO.WriteString.P2.0'(A,B)).
'~iO.WriteString.P2'(A, B) :-
        user:goedel_freeze(ground([A,B]), 'IO':'~iO.WriteString.P2.0'(A,B)).
'iO.WriteString.P2.0'(A, B) :-
        'Strings':'Strings.StringInts.P2'(B, C),
        'iO.WriteCharList.P2'(C, A).
'~iO.WriteString.P2.0'(A, B) :-
        'Strings':'~Strings.StringInts.P2'(B, C),
        '~iO.WriteCharList.P2'(C, A).
/* 
File:      iO.sup
Subject:   the system module iO.
Author:	   Jiwei Wang
Date:      17 September 1991

================================================================================
*/

'$$module'('@(#)iO.sup 1.13 last updated 94/02/11 17:07:48 by jiwei
').


?- dynamic '$end_of_stream'/1.


'iO.Get.P2'(X, Y) :-
   nonvar(X), !,
   'iO.Get.P2.1'(X,Y).

'iO.Get.P2'(X, Y) :-
   user:goedel_freeze(ground([X]), 'IO':'iO.Get.P2.1'(X,Y)).


'iO.Get.P2.1'('iO.StdIn.c0', Char) :-
   !,
   prompt(Old, ''),
   get0(user_input, Char),
   prompt(_, Old).

'iO.Get.P2.1'(ResultOfFind, Char) :-
   '$end_of_stream'(ResultOfFind), !,
   Char = -1.

'iO.Get.P2.1'(ResultOfFind, Char) :-
   translate_stream(ResultOfFind, Stream),
   get0(Stream, Char),
   check_for_end_of_stream(ResultOfFind, Char).

'~iO.Get.P2'(ResultOfFind, Char) :-
   'iO.Get.P2'(ResultOfFind, Char).

%------------------------------------------------------------------------------

'iO.ReadChar.P2'(X, Y) :-
   nonvar(X), !,
   'iO.ReadChar.P2.1'(X,Y).

'iO.ReadChar.P2'(X, Y) :-
   user:goedel_freeze(ground([X]), 'IO':'iO.ReadChar.P2.1'(X,Y)).


'iO.ReadChar.P2.1'('iO.StdIn.C0', String) :-
   !,
   prompt(Old, ''),
   get0(user_input, Char),
   name(String, [0'", Char]),
   prompt(_, Old).

'iO.ReadChar.P2.1'(ResultOfFind, String) :-
   '$end_of_stream'(ResultOfFind), !,
   name(String, [0'"]).   % return empty string

'iO.ReadChar.P2.1'(ResultOfFind, String) :-
   translate_stream(ResultOfFind, Stream),
   get0(Stream, Char),
   ( Char == -1
     -> assert('$end_of_stream'(ResultOfFind)),
        name(String, [0'"])   % return empty string
     ;  name(String, [0'", Char])
   ).

'~iO.ReadChar.P2'(ResultOfFind, String) :-
   'iO.ReadChar.P2'(ResultOfFind, String).

%------------------------------------------------------------------------------

'iO.Put.P2'(X, Y) :-
   nonvar(X), integer(Y), !,
   'iO.Put.P2.1'(X,Y).

'iO.Put.P2'(X, Y) :-
   user:goedel_freeze(ground([X,Y]), 'IO':'iO.Put.P2.1'(X,Y)).


'iO.Put.P2.1'(ResultOfFind, Char) :-
   Char >= 0, Char =< 127,
   translate_stream(ResultOfFind, Stream),
   put(Stream, Char).

'~iO.Put.P2'(ResultOfFind, Char) :-
   'iO.Put.P2'(ResultOfFind, Char).

%------------------------------------------------------------------------------

check_for_end_of_stream(ResultOfFind, C) :-
   ( C == -1
     -> assert('$end_of_stream'(ResultOfFind))
     ;  true
   ).

%------------------------------------------------------------------------------

'iO.FindInput.P2'(X, Y) :-
   user:goedel_freeze(ground([X]), 'IO':'iO.FindInput.P2.1'(X,Y)).

'iO.FindInput.P2.1'(FileString, ResultOfFind) :-
   user:gstring2string(FileString, FileName),
   ( open(FileName, read, Stream)
     -> translate_stream('iO.InputStreamDescriptor.F1'(List), Stream),
	ResultOfFind = 'iO.In.F1'('iO.InputStreamDescriptor.F1'(List))
     ;  ResultOfFind = 'iO.NotFound.C0'
   ).

'~iO.FindInput.P2'(FileString, ResultOfFind) :-
   'iO.FindInput.P2'(FileString, ResultOfFind).

%------------------------------------------------------------------------------
 
'iO.FindOutput.P2'(X, Y) :-
   user:goedel_freeze(ground([X]), 'IO':'iO.FindOutput.P2.1'(X,Y)).

'iO.FindOutput.P2.1'(FileString, ResultOfFind) :-
   user:gstring2string(FileString, FileName),
   ( open(FileName, write, Stream)
     -> translate_stream('iO.OutputStreamDescriptor.F1'(List), Stream),
	ResultOfFind = 'iO.Out.F1'('iO.OutputStreamDescriptor.F1'(List))
     ;  ResultOfFind = 'iO.NotFound.C0'
   ).

'~iO.FindOutput.P2'(FileString, ResultOfFind) :-
   'iO.FindOutput.P2'(FileString, ResultOfFind).

%------------------------------------------------------------------------------

'iO.FindUpdate.P2'(X, Y) :-
   user:goedel_freeze(ground([X]), 'IO':'iO.FindUpdate.P2.1'(X,Y)).

'iO.FindUpdate.P2.1'(FileString, ResultOfFind) :-
   user:gstring2string(FileString, FileName),
   ( open(FileName, append, Stream)
     -> translate_stream('iO.OutputStreamDescriptor.F1'(List), Stream),
	ResultOfFind = 'iO.Out.F1'('iO.OutputStreamDescriptor.F1'(List))
     ;  ResultOfFind = 'iO.NotFound.C0'
   ).

'~iO.FindUpdate.P2'(FileString, ResultOfFind) :-
   'iO.FindUpdate.P2'(FileString, ResultOfFind).

%------------------------------------------------------------------------------

'iO.EndInput.P1'(X) :-
   user:goedel_freeze(ground([X]), 'IO':'iO.EndInput.P1.1'(X)).

'iO.EndInput.P1.1'(GoedelStream) :-
   retractall('$end_of_stream'(GoedelStream)),
   translate_stream(GoedelStream, Stream),
   close(Stream).

'~iO.EndInput.P1'(GoedelStream) :-
   'iO.EndInput.P1'(GoedelStream).

%------------------------------------------------------------------------------

'iO.EndOutput.P1'(X) :-
   user:goedel_freeze(ground([X]), 'IO':'iO.EndOutput.P1.1'(X)).

'iO.EndOutput.P1'(GoedelStream) :-
   translate_stream(GoedelStream, Stream),
   close(Stream).

'~iO.EndOutput.P1'(GoedelStream) :-
   'iO.EndOutput.P1'(GoedelStream).

%------------------------------------------------------------------------------

'iO.Flush.P1'(X) :-
   nonvar(X), !,
   'iO.Flush.P1.1'(X).

'iO.Flush.P1'(X) :-
   user:goedel_freeze(ground([X]), 'IO':'iO.Flush.P1.1'(X)).

'iO.Flush.P1.1'(GoedelStream) :-
   translate_stream(GoedelStream, Stream),
   flush_output(Stream).

'~iO.Flush.P1'(GoedelStream) :-
   'iO.Flush.P1'(GoedelStream).

%------------------------------------------------------------------------------
 
translate_stream('iO.InputStreamDescriptor.F1'(List), Stream) :-
   Stream =.. ['$stream'|List].
translate_stream('iO.OutputStreamDescriptor.F1'(List), Stream) :-
   Stream =.. ['$stream'|List].
translate_stream('iO.StdIn.C0', user_input).
translate_stream('iO.StdOut.C0', user_output).
translate_stream('iO.StdErr.C0', user_error).
:- style_check(-singleton). % added djd
%% :- module('NumbersIO', []).
:- module(numbersIO). %% converted djd

:- op(500, yfx, and).
:- op(400, yfx, or).

