%%	(C)1993 Institute for New Generation Computer Technology
%%	$BG[I[$=$NB>$O(BCOPYRIGHT$B%U%!%$%k$r;2>H$7$F2<$5$$(B
%%	(Read COPYRIGHT for detailed information.)

IFS No.18 GDCC (Guarded Definite Clauses with Constraints)


				Abstract

   GDCC is the parallel constraint logic programming experimental system.
The purpose of the GDCC system is to provide a highly declarative, flexible
and efficient programming language by introducing parallelism into CLP
paradigms.
   GDCC has been developed on PIMOS and runs only on PIMOS. Therefore,
PIMOS needs to be installed on your machine before GDCC is installed.


0. Change Log
Aug 07, 1992: GDCC v2.5 release.
Aug 13, 1992: Addition of the operation manual.
Apr 30, 1993: GDCC v3.0 release.
               	Revision of Shell, Compiler and Algebraic constraint solvers.
		It is necessary that the PIMOS be v3.5 or above.

1. How to use GDCC

1.1 Environment
   GDCC runs only on PIMOS, that is, Multi-PSI, Pseudo Multi-PSI, PIM/m
and Pseudo PIM/m. It is necessary that the PIMOS be v3.5 or above.

1.2 Install
   Copy all the file listed in Chapter 3.

1.3 To start the GDCC system
(1) Login PIMOS. 
(2) Change to the directory where GDCC system is installed.
(3) Input the command "take("gdcc.init")" to the PIMOS shell window.
(4) The GDCC system will start and the GDCC shell window will appear on the
    display. Even if a warning message such as "!WARNING! already exists :
    gdcc" appears on the PIMOS shell window, ignore the message.

1.4 Input to the GDCC Shell Window
   We show some examples of input to the GDCC shell window. When you use the
GDCC system, you must declare the variable names which you wish to use before
inputting the constraints to be solved.
   For example, when you want to solve the following constraints,
	X**2 + Y**2 = 1,		(1)
	(X-1)**2 + (Y-1)**2 = 1,	(2)
you should input the following into the GDCC shell window.

	[1] alloc(0,X,Y),			%0 declare variable names
	    alg#X**2 + Y**2 = 1,		%1 constraint of (1) 
	    alg#(X-1)**2 + (Y-1)**2 = 1.	%2 constraint of (2)

	Y = -X + 1				%3 answer from the GDCC system
	X**2 = X				

Here, "alloc" means "allocation" and the first integer 0 is the "precedence"
of the variables. You can use any integer as a "precedence". "alg#" means that
this constraint is the algebraic constraint.
   The system remembers the input constraints until the command "#clear" is
input. Therefore, when you solve new constraints, you should input "#clear"
as follows.

	[2] #clear.

1.5 Programming GDCC
   We show some examples of GDCC programming.

1.5.1 Program for algebraic constraints
   This is a sample GDCC program for algebraic constraints.

	:- module heron.
	:- public tri1/4, tri2/4.

	tri1(A, B, C, S) :- true |
		alloc(100, CA, CB, H),
		alg#CA+CB=C,
		alg#2*S=C*H,
		alg#A**2=CA**2+H**2,
		alg#B**2=CB**2+H**2.

	tri2(A, B, C, S) :- true |
		kl1!shoen:raise(32768,get_std_out,[do(Out),nl,flush(_)]),
		call( tri1(A,B,C,S) ) using_solver alg initial nil giving Co,
		alg#print(Co,Out).

   This is an example of execution of this program from the GDCC shell window.

	[1] alloc(0,A,B,C), alloc(10,S),
	    heron:tri1(A,B,C,S).
	S**2 = -(1/16)*C**4 + (1/8)*B**2*C**2 - (1/16)*B**4 + (1/8)*A**2*C**2
	       + (1/8)*A**2*B**2 - (1/16)*A**4

	[2] #clear.

	[3] alloc(0,A,B,C), alloc(10,S),
	    heron:tri2(A,B,C,S).
	S**2 = -(1/16)*C**4 + (1/8)*B**2*C**2 - (1/16)*B**4 + (1/8)*A**2*C**2
	       + (1/8)*A**2*B**2 - (1/16)*A**4
	_B_0_0*C = (1/2)*C**2 - (1/2)*B**2 + (1/2)*A**2
	_B_0_2*C = 2*S
	_B_0_2*B**2 = _B_0_2*A**2-4*_B_0_0*S + 2*S*C
	_B_0_2*S = (1/4)*_B_0_0*B**2 - (1/4)*_B_0_0*A**2 - (1/8)*C**3
		   + (1/8)*B**2*C + (3/8)*A**2*C
	_B_0_2**2 = -_B_0_0**2 + A**2

In this program, variables A, B, C and S are the input variables. The results
of execution of the goal tri1(A,B,C,S) is automatically displayed in the GDCC
shell window.
   On the contrary, the goal tri2(A,B,C,S) is a little different from the goal
tri1(A,B,C,S). The goal tri2(A,B,C,S) uses the "block mechanism". This block
mechanism handles constraints explicitly.
   In this example of tri2(A,B,C,S), the goal calls a block and executes the
calculation of tri1(A,B,C,S) in the block. The result is given to the vari-
able Co. The predicate "alg#print(Co,Out)" receives the constraints Co and
gives Out, the output stream to the general output device.
   The command "using_solver alg" means that these constraints are algebraic
constraints and "initial nil" means that there is no initial constraint.
   You can find some examples of using the block mechanism in sample program,
"~/Sample/heron_root.gdcc".

1.5.2 Program for linear constraints
   This is a sample program of GDCC for linear constraints.

	:- module linear.
	:- public max/3.

	max(A, B, M) :- true |
		alloc(10,X,Y),
		call( area(X, Y) ) using_solver simplex initial nil giving Co,
		kl1!simplex::smplx_if:max(Co, A*X+B*Y, M, _).

	area(X, Y) :- true |
		simplex#X + Y =< 1,
		simplex#X + Y >= -1,
		simplex#X - Y =< 1,
		simplex#X - Y >= -1.

   This is an example of execution of this program from the GDCC shell window.

	[1] #use(simplex), #register(simplex,simplex).

	[2] linear:max(2,3,M).
	^M = 3.

In this program, the goal max(A,B,M) calls "block" and gives the constraints
determined by the goal area(X,Y) to the variable Co. The predicate
"kl1!simplex::...", one of the utilities of linear constraint solver (see 3.2),
receives Co and returns the maximum value of A*X+B*Y to the variable M.
   In this example, we used some "shell commands". By "#use(simplex)" and
"#register(simplex,simplex)", we declared that we would use a linear constraint
solver. You can find details of shell commands in Operation manual.

1.5.3 Program for boolean constraints
   This is a sample program of GDCC for boolean constraints
   which counts for 1 in V1 to V5 and returns as binary in V6 to V7.

:- module count.
:- public count/8.

count(V1,V2,V3,V4,V5,V6,V7,V8):- true |
    alloc(32768,V101,V102,V103,V104,V105,V106,V107,V108,V109,V110),
    alloc(32768,V111,V112,V113,V114,V115,V116,V117,V118,V119,V120),
    alloc(32768,V121,V122,V123,V124,V125,V126,V127),
    bool#(V101=V1/\V2),
    bool#(V102=V1\/V2),
    bool#(V103=V3/\V4),
    bool#(V104=V3\/V4),
    bool#((V105/\V101)=0),
    bool#((V105\/V101)=1),
    bool#((V106/\V102)= 0),
    bool#((V106\/V102)= 1),
    bool#((V107/\V103)= 0),
    bool#((V107\/V103)= 1),
    bool#((V108/\V104)= 0),
    bool#((V108\/V104)= 1),
    bool#(V109=V101\/V103),
    bool#(V110=V101/\V103),
    bool#(V111=V106\/V108),
    bool#(V112=V106/\V108),
    bool#((V113/\V5)= 0),
    bool#((V113\/V5)= 1),
    bool#(V114=V105/\V102),
    bool#(V115=V107/\V104),
    bool#((V116/\V114)= 0),
    bool#((V116\/V114)= 1),
    bool#((V117/\V115)= 0),
    bool#((V117\/V115)= 1),
    bool#(V118=V115\/V116),
    bool#(V119=V114\/V117),
    bool#(V120=V114\/V115),
    bool#(V121=V116\/V117),
    bool#(V122=V109/\V104/\V102/\V5),
    bool#(V123=V111/\V107/\V105/\V113),
    bool#(V124=V5/\V118/\V119),
    bool#(V125=V113/\V120/\V121),
    bool#(V126=V122\/V110),
    bool#(V127=V126\/V123\/V112),
    bool#(V6=V126),
    bool#((V7/\V127)= 0),
    bool#((V7\/V127)= 1),
    bool#(V8=V124\/V125).

   This is an example of execution of this program from the GDCC shell window.

    [1] #use(bool), #register(bool,bool).
    [2] compile("count.gdcc").
        .......... SOME MESSAGES for COMPILATION ..............
    [3] remember.
    [4] alloc(100,R1,R2,R3,R4,R5) .
    [5] count:count(R1,R2,R3,R4,R5,1,0,1).

    R5 = 1
    R4 = 1
    R3 = 1
    R2 = 1
    R1 = 1

    87905 reductions
    4216 msec

1.6 Compile
   You can compile your GDCC program in the same way as you would compile a KL1
program.

(1) Input the command "compile" into the PIMOS shell window to start the
    compiler. If the message "Parameter File : ..." does not appear, you must
    exit the compiler and copy the "compile.param" file for GDCC to your
    current directory and restart the compiler.
(2) Input the name of the file to be compiled.

This is an example of compilation.

	Shell>> compile
	** KL1 Compiler **
	Parameter File : "icpsi572::>sys>user>demo>GDCC>compile.param.1"

	COMPILE> linear.gdcc
	Compile File : "icpsi572::>sys>user>demo>GDCC>linear.gdcc.1"
	*** Translating module linear ***
	*** Analyzing ***
	*** Normalizing ***
	*** Transforming ***
	*** Optimize ***
	*** Output ***
	[linear.gdcc] Compile Module : linear
	Compile Succeeded : linear

	"gdcc:: linear" Loaded
	Compilation(s) Succeeded
	COMPILE>


2. Solver utilities

2.1 Find utility (Algebraic constraint solver)
   The find utility is used to find approximate real roots from the results
of solving algebraic constraints.

	kl1!alg::find:find(ConSet,Error,Nodes,^SubSet,^UniEqs,^CombSols)
	kl1!alg::find:sol(SubSet,CombSols,Error,Nodes,^NewConSets)

	ConSet, SubSet	::= constraint set
	Error		::= rational (calculation error)
	Nodes		::= list of node numbers
	UniEqs		::= list of univariate equations
	CombSols	::= list of all combinations of approximate real roots
			    of univariate equations
	NewConSets	::= list of constraint sets

2.2 Max-min utility (Linear constraint solver)
   The max-min utility is used to get the maximum or minimum value of a linear
polynomial under linear constraints.

	kl1!simplex::smplx_if:max(ConSet,Polynomial,^MaxValue,_)
	kl1!simplex::smplx_if:min(ConSet,Polynomial,^MinValue,_)

	ConSet		::= constraint set
	Polynomial	::= linear polynomial
	MaxValue	::= maximum value of polynomial
	MinValue	::= minimum value of polynomial


3. List of files

3.1 Shell files (~/Shell/*.*)
convert.kl1	exp_options.kl1	gdcc.kl1	pes.kl1		std_block.kl1
exp_cmds.kl1	exp_sub.kl1	gdcc.mac	query.kl1	trans_block.kl1
exp_cs.kl1	exp_util.kl1	ground.kl1	rule_pro.kl1	var.kl1
exp_main.kl1	expander.kl1	list.kl1	set.kl1		wconvert.kl1

3.2 Compiler files (~/Parser/*.*)
analyze.kl1	operator.kl1	reader.kl1	var_util.kl1
compiler.mac	output.kl1	transform.kl1	variable.kl1
normalize.kl1	parms.kl1	translator.kl1	wrapterm.kl1

3.3 Algebraic solver files (~/Alg/*.*)
alg_if.kl1		mole.kl1		rewrite.kl1
ask_daemon.kl1		otter.kl1		rule_db.kl1
criteria.kl1		pe_spec.kl1		rule_project.kl1
find.kl1		platypus.kl1		solver.kl1
for_debug.kl1		poly.kl1		std_con.kl1
maze.mac		poly_filter.kl1		wombat.kl1

3.4 Linear solver files (~/Simplex/*.*)
contents.kl1		rule_pro1.kl1		smplx_solver.kl1
ground.kl1		simplex3.kl1		std.kl1
list.kl1		smp_util3.kl1		std_con.kl1
poly.kl1		smplx3.kl1		var.kl1
poly_filter1.kl1	smplx_if3.kl1

3.5 Boolean solver files (~/Bool/*.*)
bool.kl1	bool_if.kl1	bool_solver.kl1

3.6 Sample files (~/Sample/*.*)
heron_root.gdcc		linear.gdcc          count.gdcc

3.7 Object and command files (~/*.*)
compile.param	(command file)	gdcc.init	(command file)
gdcc.com	(command file)	shell.sav	(object file)
parser.sav	(object file)	alg.sav		(object file)
simplex_if.sav	(object file)   bool.sav        (object file)

