cleanup: m4 conf and old CLPQR are not used any longer
This commit is contained in:
parent
1245c85ba1
commit
499f2c5368
@ -1,65 +0,0 @@
|
||||
|
||||
(c) Copyright 1992-2000
|
||||
Austrian Research Institute for Artificial Intelligence (OFAI)
|
||||
Schottengasse 3
|
||||
A-1010 Vienna, Austria
|
||||
|
||||
------------------------------------------------------------------------
|
||||
RESEARCH SOFTWARE DISCLAIMER -------------------------------------------
|
||||
------------------------------------------------------------------------
|
||||
|
||||
As unestablished, research software, this program is provided free of
|
||||
charge on an "as is" basis without warranty of any kind, either
|
||||
expressed or implied, including but not limited to implied warranties
|
||||
of merchantability and fitness for a particular purpose. OFAI does not
|
||||
warrant that the functions contained in this program will meet the user's
|
||||
requirements or that the operation of this program will be uninterrupted
|
||||
or error-free. Acceptance and use of this program constitutes the user's
|
||||
understanding that he will have no recourse to OFAI for any actual or
|
||||
consequential damages, including, but not limited to, lost profits or
|
||||
savings, arising out of the use or inability to use this program. Even
|
||||
if the user informs OFAI of the possibility of such damages, OFAI expects
|
||||
the user of this program to accept the risk of any harm arising out of
|
||||
the use of this program, or the user shall not attempt to use this
|
||||
program for any purpose.
|
||||
|
||||
------------------------------------------------------------------------
|
||||
USER AGREEMENT ---------------------------------------------------------
|
||||
------------------------------------------------------------------------
|
||||
|
||||
BY ACCEPTANCE AND USE OF THIS EXPERIMENTAL PROGRAM
|
||||
THE USER AGREES TO THE FOLLOWING:
|
||||
|
||||
a. This program is provided for the user's personal, non-commercial,
|
||||
experimental use and the user is granted permission to copy this
|
||||
program to the extent reasonably required for such use.
|
||||
|
||||
b. All title, ownership and rights to this program and any copies
|
||||
remain with OFAI, irrespective of the ownership of the media on
|
||||
which the program resides.
|
||||
|
||||
c. The user is permitted to create derivative works to this program.
|
||||
However, all copies of the program and its derivative works must
|
||||
contain the OFAI copyright notice, the RESEARCH SOFTWARE
|
||||
DISCLAIMER and this USER AGREEMENT.
|
||||
|
||||
d. By furnishing this program to the user, OFAI does NOT grant either
|
||||
directly or by implication, estoppel, or otherwise any license
|
||||
under any patents, patent applications, trademarks, copyrights or
|
||||
other rights belonging to OFAI or to any third party, except as
|
||||
expressly provided herein.
|
||||
|
||||
e. The user understands and agrees that this program and any derivative
|
||||
works are to be used solely for experimental uses and are not to be
|
||||
sold, or be commercially exploited in any manner.
|
||||
|
||||
f. OFAI requests that the user supply to OFAI a copy of any changes,
|
||||
enhancements, or derivative works which the user may create. The
|
||||
user grants OFAI and its subsidiaries an irrevocable, nonexclusive,
|
||||
worldwide and royalty-free license to use, execute, reproduce,
|
||||
display, perform, prepare derivative works based upon, and
|
||||
distribute, (INTERNALLY AND EXTERNALLY) copies of any and all such
|
||||
materials and derivative works thereof, and to sublicense others to
|
||||
do any, some, or all of the foregoing, (including supporting
|
||||
documentation).
|
||||
|
@ -1,153 +0,0 @@
|
||||
#
|
||||
# default base directory for YAP installation
|
||||
#
|
||||
ROOTDIR = @prefix@
|
||||
#
|
||||
# where the binary should be
|
||||
#
|
||||
BINDIR = $(ROOTDIR)/bin
|
||||
#
|
||||
# where YAP should look for libraries
|
||||
#
|
||||
LIBDIR=@libdir@/Yap
|
||||
#
|
||||
# where YAP should look for architecture-independent Prolog libraries
|
||||
#
|
||||
SHAREDIR=$(ROOTDIR)/share/Yap
|
||||
#
|
||||
#
|
||||
# You shouldn't need to change what follows.
|
||||
#
|
||||
INSTALL=@INSTALL@
|
||||
INSTALL_DATA=@INSTALL_DATA@
|
||||
INSTALL_PROGRAM=@INSTALL_PROGRAM@
|
||||
srcdir=@srcdir@
|
||||
|
||||
CLPQR_PROGRAMS= $(srcdir)/clpqr/arith.pl \
|
||||
$(srcdir)/clpqr/bb.yap \
|
||||
$(srcdir)/clpqr/bv.yap \
|
||||
$(srcdir)/clpqr/compenv.pl \
|
||||
$(srcdir)/clpqr/dump.pl \
|
||||
$(srcdir)/clpqr/fourmotz.pl \
|
||||
$(srcdir)/clpqr/ineq.yap \
|
||||
$(srcdir)/clpqr/itf3.pl \
|
||||
$(srcdir)/clpqr/ordering.yap \
|
||||
$(srcdir)/clpqr/project.pl \
|
||||
$(srcdir)/clpqr/redund.pl \
|
||||
$(srcdir)/clpqr/store.yap
|
||||
|
||||
CLPQR_LOCAL= \
|
||||
$(srcdir)/clpqr/expand.yap \
|
||||
$(srcdir)/clpqr/monash.pl \
|
||||
$(srcdir)/clpqr/printf.pl
|
||||
|
||||
CLPR_PROGRAMS= $(srcdir)/clpr/arith_r.yap \
|
||||
$(srcdir)/clpr/class.yap\
|
||||
$(srcdir)/clpr/geler.yap \
|
||||
$(srcdir)/clpr/nf.yap \
|
||||
$(srcdir)/clpr/nfr.yap
|
||||
|
||||
CLPQ_PROGRAMS= $(srcdir)/clpq/arith_q.yap \
|
||||
$(srcdir)/clpq/class.yap \
|
||||
$(srcdir)/clpq/geler.yap \
|
||||
$(srcdir)/clpr/nf.yap \
|
||||
$(srcdir)/clpq/nfq.yap
|
||||
|
||||
CLPR_TOP= $(srcdir)/clpr.yap
|
||||
|
||||
CLPQ_TOP= $(srcdir)/clpq.yap
|
||||
|
||||
CLPQR_LICENSE= $(srcdir)/CLPQR.LICENSE
|
||||
|
||||
CLPQR_EXAMPLES= $(srcdir)/clpqr/examples/README \
|
||||
$(srcdir)/clpqr/examples/caneghem.pl \
|
||||
$(srcdir)/clpqr/examples/eliminat.pl \
|
||||
$(srcdir)/clpqr/examples/matmul.pl \
|
||||
$(srcdir)/clpqr/examples/mg.pl \
|
||||
$(srcdir)/clpqr/examples/mip.pl \
|
||||
$(srcdir)/clpqr/examples/root.pl \
|
||||
$(srcdir)/clpqr/examples/simplex.pl \
|
||||
$(srcdir)/clpqr/examples/squares.pl
|
||||
|
||||
CLPQR_EXAMPLES_MONASH= $(srcdir)/clpqr/examples/monash/README \
|
||||
$(srcdir)/clpqr/examples/monash/air \
|
||||
$(srcdir)/clpqr/examples/monash/amplif \
|
||||
$(srcdir)/clpqr/examples/monash/complex \
|
||||
$(srcdir)/clpqr/examples/monash/critical \
|
||||
$(srcdir)/clpqr/examples/monash/dnf \
|
||||
$(srcdir)/clpqr/examples/monash/fib \
|
||||
$(srcdir)/clpqr/examples/monash/findroot \
|
||||
$(srcdir)/clpqr/examples/monash/invert \
|
||||
$(srcdir)/clpqr/examples/monash/laplace \
|
||||
$(srcdir)/clpqr/examples/monash/mortgage \
|
||||
$(srcdir)/clpqr/examples/monash/nrev \
|
||||
$(srcdir)/clpqr/examples/monash/option \
|
||||
$(srcdir)/clpqr/examples/monash/pictures \
|
||||
$(srcdir)/clpqr/examples/monash/rkf45 \
|
||||
$(srcdir)/clpqr/examples/monash/rlc \
|
||||
$(srcdir)/clpqr/examples/monash/smm \
|
||||
$(srcdir)/clpqr/examples/monash/toolpath \
|
||||
$(srcdir)/clpqr/examples/monash/zebra
|
||||
|
||||
CLPQR_EXAMPLES_SESSION= $(srcdir)/clpqr/examples/SESSION/010 \
|
||||
$(srcdir)/clpqr/examples/SESSION/011 \
|
||||
$(srcdir)/clpqr/examples/SESSION/012 \
|
||||
$(srcdir)/clpqr/examples/SESSION/013 \
|
||||
$(srcdir)/clpqr/examples/SESSION/014 \
|
||||
$(srcdir)/clpqr/examples/SESSION/015 \
|
||||
$(srcdir)/clpqr/examples/SESSION/016 \
|
||||
$(srcdir)/clpqr/examples/SESSION/017 \
|
||||
$(srcdir)/clpqr/examples/SESSION/018 \
|
||||
$(srcdir)/clpqr/examples/SESSION/019 \
|
||||
$(srcdir)/clpqr/examples/SESSION/020 \
|
||||
$(srcdir)/clpqr/examples/SESSION/021 \
|
||||
$(srcdir)/clpqr/examples/SESSION/022 \
|
||||
$(srcdir)/clpqr/examples/SESSION/023 \
|
||||
$(srcdir)/clpqr/examples/SESSION/024 \
|
||||
$(srcdir)/clpqr/examples/SESSION/030 \
|
||||
$(srcdir)/clpqr/examples/SESSION/031 \
|
||||
$(srcdir)/clpqr/examples/SESSION/032 \
|
||||
$(srcdir)/clpqr/examples/SESSION/033 \
|
||||
$(srcdir)/clpqr/examples/SESSION/034 \
|
||||
$(srcdir)/clpqr/examples/SESSION/035 \
|
||||
$(srcdir)/clpqr/examples/SESSION/110 \
|
||||
$(srcdir)/clpqr/examples/SESSION/111 \
|
||||
$(srcdir)/clpqr/examples/SESSION/112 \
|
||||
$(srcdir)/clpqr/examples/SESSION/113 \
|
||||
$(srcdir)/clpqr/examples/SESSION/114 \
|
||||
$(srcdir)/clpqr/examples/SESSION/115 \
|
||||
$(srcdir)/clpqr/examples/SESSION/116 \
|
||||
$(srcdir)/clpqr/examples/SESSION/117 \
|
||||
$(srcdir)/clpqr/examples/SESSION/118 \
|
||||
$(srcdir)/clpqr/examples/SESSION/119 \
|
||||
$(srcdir)/clpqr/examples/SESSION/120 \
|
||||
$(srcdir)/clpqr/examples/SESSION/122 \
|
||||
$(srcdir)/clpqr/examples/SESSION/123 \
|
||||
$(srcdir)/clpqr/examples/SESSION/124 \
|
||||
$(srcdir)/clpqr/examples/SESSION/130 \
|
||||
$(srcdir)/clpqr/examples/SESSION/131 \
|
||||
$(srcdir)/clpqr/examples/SESSION/132 \
|
||||
$(srcdir)/clpqr/examples/SESSION/133 \
|
||||
$(srcdir)/clpqr/examples/SESSION/134 \
|
||||
$(srcdir)/clpqr/examples/SESSION/135
|
||||
|
||||
install: $(CLPR_TOP) $(CLPQ_TOP) $(CLPQR_LICENSE) $(CLPQR_PROGRAMS) $(CLPQR_LOCAL)\
|
||||
$(CLPQR_EXAMPLES) $(CLPQR_EXAMPLES_MONASH) $(CLPQR_EXAMPLES_SESSION)
|
||||
mkdir -p $(DESTDIR)$(SHAREDIR)/clpq
|
||||
mkdir -p $(DESTDIR)$(SHAREDIR)/clpqr
|
||||
mkdir -p $(DESTDIR)$(SHAREDIR)/clpr
|
||||
mkdir -p $(DESTDIR)$(SHAREDIR)/clpqr/examples
|
||||
mkdir -p $(DESTDIR)$(SHAREDIR)/clpqr/examples/SESSION
|
||||
mkdir -p $(DESTDIR)$(SHAREDIR)/clpqr/examples/monash
|
||||
for h in $(CLPQ_TOP); do $(INSTALL_DATA) $$h $(DESTDIR)$(SHAREDIR); done
|
||||
for h in $(CLPR_TOP); do $(INSTALL_DATA) $$h $(DESTDIR)$(SHAREDIR); done
|
||||
for h in $(CLPQR_LICENSE); do $(INSTALL_DATA) $$h $(DESTDIR)$(SHAREDIR); done
|
||||
for h in $(CLPQR_PROGRAMS); do $(INSTALL_DATA) $$h $(DESTDIR)$(SHAREDIR)/clpqr; done
|
||||
for h in $(CLPQ_PROGRAMS); do $(INSTALL_DATA) $$h $(DESTDIR)$(SHAREDIR)/clpq; done
|
||||
for h in $(CLPR_PROGRAMS); do $(INSTALL_DATA) $$h $(DESTDIR)$(SHAREDIR)/clpr; done
|
||||
for h in $(CLPQR_LOCAL); do $(INSTALL_DATA) $$h $(DESTDIR)$(SHAREDIR)/clpqr; done
|
||||
for h in $(CLPQR_EXAMPLES); do $(INSTALL_DATA) $$h $(DESTDIR)$(SHAREDIR)/clpqr/examples; done
|
||||
for h in $(CLPQR_EXAMPLES_MONASH); do $(INSTALL_DATA) $$h $(DESTDIR)$(SHAREDIR)/clpqr/examples/monash; done
|
||||
for h in $(CLPQR_EXAMPLES_SESSION); do $(INSTALL_DATA) $$h $(DESTDIR)$(SHAREDIR)/clpqr/examples/SESSION; done
|
||||
|
||||
|
@ -1,78 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.3 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: clpq.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
:- module( clpq, [
|
||||
{}/1,
|
||||
maximize/1,
|
||||
minimize/1,
|
||||
inf/2, inf/4, sup/2, sup/4,
|
||||
bb_inf/3,
|
||||
bb_inf/5,
|
||||
ordering/1,
|
||||
entailed/1,
|
||||
dump/3
|
||||
]).
|
||||
|
||||
:- multifile
|
||||
user:portray/1,
|
||||
user:portray_message/2.
|
||||
|
||||
:- dynamic
|
||||
user:portray/1,
|
||||
user:portray_message/2.
|
||||
%
|
||||
user:portray( rat(A,B)) :-
|
||||
nonvar( A), % during debugging ...
|
||||
nonvar( B),
|
||||
portray_rat( A, B).
|
||||
|
||||
% Must write a space before negative numbers if called e.g. in the
|
||||
% context of writing F=rat(A,B).
|
||||
%
|
||||
portray_rat(A, B) :-
|
||||
( A<0, B==1 -> write(' '), write(A)
|
||||
; B==1 -> write(A)
|
||||
; A<0 -> write(' '), write(A/B)
|
||||
; write(A/B)
|
||||
).
|
||||
|
||||
%
|
||||
% Don't report export of private predicates from clpq
|
||||
%
|
||||
%
|
||||
user:portray_message( warning, import(_,_,clpq,private)).
|
||||
|
||||
this_linear_solver( clpq).
|
||||
|
||||
:- use_module( 'clpq/arith_q').
|
||||
|
||||
:- ensure_loaded(
|
||||
[
|
||||
'clpq/itf3',
|
||||
'clpq/store' % early because of macros
|
||||
% but after itf3
|
||||
]).
|
||||
|
||||
:- use_module( 'clpq/geler').
|
||||
:- use_module( 'clpq/nfq').
|
||||
:- use_module( 'clpq/class').
|
||||
|
||||
:- ensure_loaded(
|
||||
[
|
||||
'clpq/project',
|
||||
'clpq/bv',
|
||||
'clpq/ineq',
|
||||
'clpq/redund',
|
||||
'clpq/fourmotz',
|
||||
'clpq/bb',
|
||||
'clpq/dump'
|
||||
]).
|
@ -1,78 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.3 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: clpq.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
:- module( clpq, [
|
||||
{}/1,
|
||||
maximize/1,
|
||||
minimize/1,
|
||||
inf/2, inf/4, sup/2, sup/4,
|
||||
bb_inf/3,
|
||||
bb_inf/5,
|
||||
ordering/1,
|
||||
entailed/1,
|
||||
dump/3
|
||||
]).
|
||||
|
||||
:- multifile
|
||||
user:portray/1,
|
||||
user:portray_message/2.
|
||||
|
||||
:- dynamic
|
||||
user:portray/1,
|
||||
user:portray_message/2.
|
||||
%
|
||||
user:portray( rat(A,B)) :-
|
||||
nonvar( A), % during debugging ...
|
||||
nonvar( B),
|
||||
portray_rat( A, B).
|
||||
|
||||
% Must write a space before negative numbers if called e.g. in the
|
||||
% context of writing F=rat(A,B).
|
||||
%
|
||||
portray_rat(A, B) :-
|
||||
( A<0, B==1 -> write(' '), write(A)
|
||||
; B==1 -> write(A)
|
||||
; A<0 -> write(' '), write(A/B)
|
||||
; write(A/B)
|
||||
).
|
||||
|
||||
%
|
||||
% Don't report export of private predicates from clpq
|
||||
%
|
||||
%
|
||||
user:portray_message( warning, import(_,_,clpq,private)).
|
||||
|
||||
this_linear_solver( clpq).
|
||||
|
||||
:- use_module( 'clpq/arith_q').
|
||||
|
||||
:- ensure_loaded(
|
||||
[
|
||||
'clpqr/itf3',
|
||||
'clpqr/store' % early because of macros
|
||||
% but after itf3
|
||||
]).
|
||||
|
||||
:- use_module( 'clpq/geler').
|
||||
:- use_module( 'clpq/nfq').
|
||||
:- use_module( 'clpq/class').
|
||||
|
||||
:- ensure_loaded(
|
||||
[
|
||||
'clpqr/project',
|
||||
'clpqr/bv',
|
||||
'clpqr/ineq',
|
||||
'clpqr/redund',
|
||||
'clpqr/fourmotz',
|
||||
'clpqr/bb',
|
||||
'clpqr/dump'
|
||||
]).
|
@ -1,129 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.3 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: arith_q.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
:- module( arith_q,
|
||||
[
|
||||
arith_eps/1,
|
||||
arith_normalize/2,
|
||||
integerp/1,
|
||||
integerp/2,
|
||||
% Q specifics
|
||||
acosq/4,
|
||||
addq/6,
|
||||
asinq/4,
|
||||
atanq/4,
|
||||
ceilingq/4,
|
||||
comq/5,
|
||||
cosq/4,
|
||||
divq/6,
|
||||
divq_11/4,
|
||||
'divq_-11'/4,
|
||||
expq/4,
|
||||
expq/6,
|
||||
floorq/4,
|
||||
getq/3,
|
||||
logq/4,
|
||||
maxq/6,
|
||||
minq/6,
|
||||
mulq/6,
|
||||
putq/3,
|
||||
rat_float/3,
|
||||
roundq/4,
|
||||
signumq/4,
|
||||
sinq/4,
|
||||
subq/6,
|
||||
tanq/4,
|
||||
truncateq/4
|
||||
]).
|
||||
|
||||
%
|
||||
% Modules receiving Q expansion
|
||||
%
|
||||
arith_module( clpq).
|
||||
arith_module( nfq).
|
||||
|
||||
:- multifile
|
||||
user:goal_expansion/3.
|
||||
|
||||
:- dynamic
|
||||
user:goal_expansion/3.
|
||||
|
||||
:- discontiguous
|
||||
user:goal_expansion/3.
|
||||
|
||||
%
|
||||
user:goal_expansion( putq(D,N,Res), Module, (Res = rat(N,D))) :- arith_module( Module).
|
||||
|
||||
user:goal_expansion( arith_eval(Term,Res), Module, Expansion) :-
|
||||
arith_module( Module),
|
||||
compile_Qn( Term, Res, Code),
|
||||
l2conj( Code, Expansion).
|
||||
|
||||
user:goal_expansion(arith_eval(Rel), Module, Expansion) :-
|
||||
arith_module( Module),
|
||||
compile_Qn( Rel, boolean, Code),
|
||||
l2conj( Code, Expansion).
|
||||
|
||||
user:goal_expansion(case_signum(Term,Lt,Z,Gt), Module, Expansion) :-
|
||||
arith_module( Module),
|
||||
compile_case_signum_Qn( Term, Lt,Z,Gt, Code),
|
||||
l2conj( Code, Expansion).
|
||||
|
||||
:- use_module( arith).
|
||||
|
||||
arith_eps( 0). % for Monash #zero expansion
|
||||
|
||||
arith_normalize( Const, Norm) :-
|
||||
getq( Const, N, D),
|
||||
putq( D, N, Norm).
|
||||
|
||||
integerp( rat(_,1)).
|
||||
|
||||
integerp( rat(I,1), I).
|
||||
|
||||
%---------------------------------------------------------------------------
|
||||
|
||||
user:goal_expansion(comq(Na,Da,Nb,_,S), arith_q, 0<Nb) :-
|
||||
Na==0, Da==1, S==(<).
|
||||
|
||||
user:goal_expansion(comq(Na,_,Nb,Db,S), arith_q, Na<0) :-
|
||||
Nb==0, Db==1, S==(<).
|
||||
|
||||
user:goal_expansion(divq(Na,Da,Nb,Db,Nc,Dc), arith_q, Exp) :-
|
||||
( Na==1,Da==1
|
||||
-> Exp = divq_11(Nb,Db,Nc,Dc)
|
||||
; Na==(-1),Da==1
|
||||
-> Exp = 'divq_-11'(Nb,Db,Nc,Dc)
|
||||
).
|
||||
|
||||
/*
|
||||
1 addq(0, 1, 1, 1, _, _).
|
||||
10 comq(0, 1, _, _, <).
|
||||
1 comq(0, 1, _, _, _).
|
||||
16 comq(_, _, 0, 1, <).
|
||||
2 comq(_, _, 0, 1, _).
|
||||
1 comq(_, _, 1, 1000, <).
|
||||
6 comq(_, _, _, _, <).
|
||||
7 divq(-1, 1, _, _, _, _).
|
||||
1 divq(0, 1, 1, 1, _, _).
|
||||
1 divq(1, 1, 1000, 1, _, _).
|
||||
4 divq(1, 1, _, _, _, _).
|
||||
2 getq(_, -1, 1).
|
||||
13 getq(_, 0, 1).
|
||||
6 getq(_, 1, 1).
|
||||
1 mulq(0, 1, 1000, 1, _, _).
|
||||
1 putq(1, 0, _).
|
||||
1 putq(1, 1, _).
|
||||
1 putq(1000, 1, _).
|
||||
*/
|
||||
|
@ -1,129 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.3 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: arith_q.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
:- module( arith_q,
|
||||
[
|
||||
arith_eps/1,
|
||||
arith_normalize/2,
|
||||
integerp/1,
|
||||
integerp/2,
|
||||
% Q specifics
|
||||
acosq/4,
|
||||
addq/6,
|
||||
asinq/4,
|
||||
atanq/4,
|
||||
ceilingq/4,
|
||||
comq/5,
|
||||
cosq/4,
|
||||
divq/6,
|
||||
divq_11/4,
|
||||
'divq_-11'/4,
|
||||
expq/4,
|
||||
expq/6,
|
||||
floorq/4,
|
||||
getq/3,
|
||||
logq/4,
|
||||
maxq/6,
|
||||
minq/6,
|
||||
mulq/6,
|
||||
putq/3,
|
||||
rat_float/3,
|
||||
roundq/4,
|
||||
signumq/4,
|
||||
sinq/4,
|
||||
subq/6,
|
||||
tanq/4,
|
||||
truncateq/4
|
||||
]).
|
||||
|
||||
%
|
||||
% Modules receiving Q expansion
|
||||
%
|
||||
arith_module( clpq).
|
||||
arith_module( nfq).
|
||||
|
||||
:- multifile
|
||||
user:goal_expansion/3.
|
||||
|
||||
:- dynamic
|
||||
user:goal_expansion/3.
|
||||
|
||||
:- discontiguous
|
||||
user:goal_expansion/3.
|
||||
|
||||
%
|
||||
user:goal_expansion( putq(D,N,Res), Module, (Res = rat(N,D))) :- arith_module( Module).
|
||||
|
||||
user:goal_expansion( arith_eval(Term,Res), Module, Expansion) :-
|
||||
arith_module( Module),
|
||||
compile_Qn( Term, Res, Code),
|
||||
l2conj( Code, Expansion).
|
||||
|
||||
user:goal_expansion(arith_eval(Rel), Module, Expansion) :-
|
||||
arith_module( Module),
|
||||
compile_Qn( Rel, boolean, Code),
|
||||
l2conj( Code, Expansion).
|
||||
|
||||
user:goal_expansion(case_signum(Term,Lt,Z,Gt), Module, Expansion) :-
|
||||
arith_module( Module),
|
||||
compile_case_signum_Qn( Term, Lt,Z,Gt, Code),
|
||||
l2conj( Code, Expansion).
|
||||
|
||||
:- use_module( '../clpqr/arith').
|
||||
|
||||
arith_eps( 0). % for Monash #zero expansion
|
||||
|
||||
arith_normalize( Const, Norm) :-
|
||||
getq( Const, N, D),
|
||||
putq( D, N, Norm).
|
||||
|
||||
integerp( rat(_,1)).
|
||||
|
||||
integerp( rat(I,1), I).
|
||||
|
||||
%---------------------------------------------------------------------------
|
||||
|
||||
user:goal_expansion(comq(Na,Da,Nb,_,S), arith_q, 0<Nb) :-
|
||||
Na==0, Da==1, S==(<).
|
||||
|
||||
user:goal_expansion(comq(Na,_,Nb,Db,S), arith_q, Na<0) :-
|
||||
Nb==0, Db==1, S==(<).
|
||||
|
||||
user:goal_expansion(divq(Na,Da,Nb,Db,Nc,Dc), arith_q, Exp) :-
|
||||
( Na==1,Da==1
|
||||
-> Exp = divq_11(Nb,Db,Nc,Dc)
|
||||
; Na==(-1),Da==1
|
||||
-> Exp = 'divq_-11'(Nb,Db,Nc,Dc)
|
||||
).
|
||||
|
||||
/*
|
||||
1 addq(0, 1, 1, 1, _, _).
|
||||
10 comq(0, 1, _, _, <).
|
||||
1 comq(0, 1, _, _, _).
|
||||
16 comq(_, _, 0, 1, <).
|
||||
2 comq(_, _, 0, 1, _).
|
||||
1 comq(_, _, 1, 1000, <).
|
||||
6 comq(_, _, _, _, <).
|
||||
7 divq(-1, 1, _, _, _, _).
|
||||
1 divq(0, 1, 1, 1, _, _).
|
||||
1 divq(1, 1, 1000, 1, _, _).
|
||||
4 divq(1, 1, _, _, _, _).
|
||||
2 getq(_, -1, 1).
|
||||
13 getq(_, 0, 1).
|
||||
6 getq(_, 1, 1).
|
||||
1 mulq(0, 1, 1000, 1, _, _).
|
||||
1 putq(1, 0, _).
|
||||
1 putq(1, 1, _).
|
||||
1 putq(1000, 1, _).
|
||||
*/
|
||||
|
@ -1,112 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.2 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: class.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%
|
||||
% the class theory
|
||||
%
|
||||
|
||||
:- module( classq,
|
||||
[
|
||||
class_allvars/2,
|
||||
class_new/4,
|
||||
class_drop/2,
|
||||
class_basis/2,
|
||||
class_basis_add/3,
|
||||
class_basis_drop/2,
|
||||
class_basis_pivot/3,
|
||||
|
||||
ordering/1,
|
||||
arrangement/2
|
||||
]).
|
||||
|
||||
:- use_module( clpq, '../clpq', [get_or_add_class/2]).
|
||||
|
||||
:- ensure_loaded( ordering).
|
||||
|
||||
:- use_module( library(lists), [append/3]).
|
||||
|
||||
:- use_module( library(atts)).
|
||||
|
||||
:- attribute class_atts/4.
|
||||
|
||||
|
||||
verify_attributes( X, Y, []) :-
|
||||
get_atts( X, class_atts(La,Lat,ABasis,PrioA)),
|
||||
!,
|
||||
var( Y), % required
|
||||
get_atts( Y, class_atts(Lb,Lbt,BBasis,PrioB)),
|
||||
Lat = Lb, % append
|
||||
append( ABasis, BBasis, CBasis),
|
||||
combine( PrioA, PrioB, PrioC),
|
||||
put_atts( Y, class_atts(La,Lbt,CBasis,PrioC)).
|
||||
verify_attributes( _, _, []).
|
||||
|
||||
%
|
||||
% for the debugger
|
||||
%
|
||||
% attribute_goal( V, V:A) :- get_atts( V, A), A = [_|_].
|
||||
|
||||
|
||||
% ----------------------------------------------------------------------------------
|
||||
|
||||
class_new( Class, All,AllT, Basis) :-
|
||||
put_atts( Su, class_atts(All,AllT,Basis,[])),
|
||||
Su = Class.
|
||||
|
||||
class_get_prio( Class, Priority) :-
|
||||
get_atts( Class, class_atts(_,_,_,Priority)).
|
||||
|
||||
class_put_prio( Class, Priority) :-
|
||||
get_atts( Class, class_atts(All,AllT,Basis,_)),
|
||||
put_atts( Class, class_atts(All,AllT,Basis,Priority)).
|
||||
|
||||
class_drop( Class, X) :-
|
||||
get_atts( Class, class_atts(Allvars,Tail,Basis,Priority)),
|
||||
delete_first( Allvars, X, NewAllvars),
|
||||
delete_first( Basis, X, NewBasis),
|
||||
put_atts( Class, class_atts(NewAllvars,Tail,NewBasis,Priority)).
|
||||
|
||||
class_allvars( Class, All) :- get_atts( Class, class_atts(All,_,_,_)).
|
||||
|
||||
class_basis( Class, Basis) :- get_atts( Class, class_atts(_,_,Basis,_)).
|
||||
|
||||
class_basis_add( Class, X, NewBasis) :-
|
||||
NewBasis = [X|Basis],
|
||||
get_atts( Class, class_atts(All,AllT,Basis,Priority)),
|
||||
put_atts( Class, class_atts(All,AllT,NewBasis,Priority)).
|
||||
|
||||
class_basis_drop( Class, X) :-
|
||||
get_atts( Class, class_atts(All,AllT,Basis0,Priority)),
|
||||
delete_first( Basis0, X, Basis),
|
||||
Basis0 \== Basis, % anything deleted ?
|
||||
!,
|
||||
put_atts( Class, class_atts(All,AllT,Basis,Priority)).
|
||||
class_basis_drop( _, _).
|
||||
|
||||
class_basis_pivot( Class, Enter, Leave) :-
|
||||
get_atts( Class, class_atts(All,AllT,Basis0,Priority)),
|
||||
delete_first( Basis0, Leave, Basis1),
|
||||
put_atts( Class, class_atts(All,AllT,[Enter|Basis1],Priority)).
|
||||
|
||||
%
|
||||
% remove the first occurence
|
||||
%
|
||||
delete_first( L, _, Res) :- var(L), !, Res = L.
|
||||
delete_first( [], _, []).
|
||||
delete_first( [Y|Ys], X, Res) :-
|
||||
( X==Y ->
|
||||
Res = Ys
|
||||
;
|
||||
Res = [Y|Tail],
|
||||
delete_first( Ys, X, Tail)
|
||||
).
|
@ -1,112 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.2 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: class.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%
|
||||
% the class theory
|
||||
%
|
||||
|
||||
:- module( classq,
|
||||
[
|
||||
class_allvars/2,
|
||||
class_new/4,
|
||||
class_drop/2,
|
||||
class_basis/2,
|
||||
class_basis_add/3,
|
||||
class_basis_drop/2,
|
||||
class_basis_pivot/3,
|
||||
|
||||
ordering/1,
|
||||
arrangement/2
|
||||
]).
|
||||
|
||||
:- use_module( clpq, '../clpq', [get_or_add_class/2]).
|
||||
|
||||
:- ensure_loaded( '../clpqr/ordering').
|
||||
|
||||
:- use_module( library(lists), [append/3]).
|
||||
|
||||
:- use_module( library(atts)).
|
||||
|
||||
:- attribute class_atts/4.
|
||||
|
||||
|
||||
verify_attributes( X, Y, []) :-
|
||||
get_atts( X, class_atts(La,Lat,ABasis,PrioA)),
|
||||
!,
|
||||
var( Y), % required
|
||||
get_atts( Y, class_atts(Lb,Lbt,BBasis,PrioB)),
|
||||
Lat = Lb, % append
|
||||
append( ABasis, BBasis, CBasis),
|
||||
combine( PrioA, PrioB, PrioC),
|
||||
put_atts( Y, class_atts(La,Lbt,CBasis,PrioC)).
|
||||
verify_attributes( _, _, []).
|
||||
|
||||
%
|
||||
% for the debugger
|
||||
%
|
||||
% attribute_goal( V, V:A) :- get_atts( V, A), A = [_|_].
|
||||
|
||||
|
||||
% ----------------------------------------------------------------------------------
|
||||
|
||||
class_new( Class, All,AllT, Basis) :-
|
||||
put_atts( Su, class_atts(All,AllT,Basis,[])),
|
||||
Su = Class.
|
||||
|
||||
class_get_prio( Class, Priority) :-
|
||||
get_atts( Class, class_atts(_,_,_,Priority)).
|
||||
|
||||
class_put_prio( Class, Priority) :-
|
||||
get_atts( Class, class_atts(All,AllT,Basis,_)),
|
||||
put_atts( Class, class_atts(All,AllT,Basis,Priority)).
|
||||
|
||||
class_drop( Class, X) :-
|
||||
get_atts( Class, class_atts(Allvars,Tail,Basis,Priority)),
|
||||
delete_first( Allvars, X, NewAllvars),
|
||||
delete_first( Basis, X, NewBasis),
|
||||
put_atts( Class, class_atts(NewAllvars,Tail,NewBasis,Priority)).
|
||||
|
||||
class_allvars( Class, All) :- get_atts( Class, class_atts(All,_,_,_)).
|
||||
|
||||
class_basis( Class, Basis) :- get_atts( Class, class_atts(_,_,Basis,_)).
|
||||
|
||||
class_basis_add( Class, X, NewBasis) :-
|
||||
NewBasis = [X|Basis],
|
||||
get_atts( Class, class_atts(All,AllT,Basis,Priority)),
|
||||
put_atts( Class, class_atts(All,AllT,NewBasis,Priority)).
|
||||
|
||||
class_basis_drop( Class, X) :-
|
||||
get_atts( Class, class_atts(All,AllT,Basis0,Priority)),
|
||||
delete_first( Basis0, X, Basis),
|
||||
Basis0 \== Basis, % anything deleted ?
|
||||
!,
|
||||
put_atts( Class, class_atts(All,AllT,Basis,Priority)).
|
||||
class_basis_drop( _, _).
|
||||
|
||||
class_basis_pivot( Class, Enter, Leave) :-
|
||||
get_atts( Class, class_atts(All,AllT,Basis0,Priority)),
|
||||
delete_first( Basis0, Leave, Basis1),
|
||||
put_atts( Class, class_atts(All,AllT,[Enter|Basis1],Priority)).
|
||||
|
||||
%
|
||||
% remove the first occurence
|
||||
%
|
||||
delete_first( L, _, Res) :- var(L), !, Res = L.
|
||||
delete_first( [], _, []).
|
||||
delete_first( [Y|Ys], X, Res) :-
|
||||
( X==Y ->
|
||||
Res = Ys
|
||||
;
|
||||
Res = [Y|Tail],
|
||||
delete_first( Ys, X, Tail)
|
||||
).
|
@ -1,124 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.3 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: geler.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
:- module( geler_q,
|
||||
[
|
||||
geler/2,
|
||||
project_nonlin/3,
|
||||
collect_nonlin/3
|
||||
]).
|
||||
|
||||
:- use_module( library(atts)).
|
||||
|
||||
:- attribute goals/1, all_nonlin/1.
|
||||
|
||||
attribute_goal( X, Goals) :-
|
||||
get_atts( X, goals(Gs)),
|
||||
nonexhausted( Gs, Goals, []),
|
||||
Goals = [_|_].
|
||||
attribute_goal( X, Conj) :-
|
||||
get_atts( X, all_nonlin(Goals)),
|
||||
l2conj( Goals, Conj).
|
||||
|
||||
l2conj( [X|Xs], Conj) :-
|
||||
( Xs = [], Conj = X
|
||||
; Xs = [_|_], Conj = (X,Xc), l2conj( Xs, Xc)
|
||||
).
|
||||
|
||||
nonexhausted( run(Mutex,G)) -->
|
||||
( {
|
||||
var(Mutex)
|
||||
} ->
|
||||
[ G ]
|
||||
;
|
||||
[]
|
||||
).
|
||||
nonexhausted( (A,B)) -->
|
||||
nonexhausted( A),
|
||||
nonexhausted( B).
|
||||
|
||||
verify_attributes( X, Y, Later) :-
|
||||
get_atts( X, goals(Gx)),
|
||||
!,
|
||||
( var(Y),
|
||||
( get_atts( Y, goals(Gy)) ->
|
||||
Later = [Gx,Gy],
|
||||
put_atts( Y, -goals(_))
|
||||
;
|
||||
Later = [],
|
||||
put_atts( Y, goals(Gx))
|
||||
)
|
||||
; nonvar( Y),
|
||||
Later = [Gx]
|
||||
).
|
||||
verify_attributes( _, _, []).
|
||||
|
||||
/*
|
||||
project_attributes( _, Cvas) :-
|
||||
collect_nonlin( Cvas, L, []),
|
||||
sort( L, Ls),
|
||||
put_atts( _, all_nonlin(Ls)).
|
||||
*/
|
||||
|
||||
%
|
||||
% called from project.pl
|
||||
%
|
||||
project_nonlin( _, Cvas, Reachable) :-
|
||||
collect_nonlin( Cvas, L, []),
|
||||
sort( L, Ls),
|
||||
prolog:term_variables( Ls, Reachable),
|
||||
put_atts( _, all_nonlin(Ls)).
|
||||
|
||||
collect_nonlin( []) --> [].
|
||||
collect_nonlin( [X|Xs]) -->
|
||||
( {get_atts( X, goals(Gx))} ->
|
||||
trans( Gx),
|
||||
collect_nonlin( Xs)
|
||||
;
|
||||
collect_nonlin( Xs)
|
||||
).
|
||||
|
||||
trans( (A,B)) -->
|
||||
trans( A),
|
||||
trans( B).
|
||||
trans( run(Mutex,Gs)) -->
|
||||
( {var(Mutex)} ->
|
||||
{Mutex = done},
|
||||
transg( Gs)
|
||||
;
|
||||
[]
|
||||
).
|
||||
|
||||
transg( (A,B)) --> !,
|
||||
transg( A),
|
||||
transg( B).
|
||||
transg( M:G) --> !,
|
||||
M:transg( G).
|
||||
transg( G) --> [ G ].
|
||||
|
||||
run( Mutex, _) :- nonvar(Mutex).
|
||||
run( Mutex, G) :- var(Mutex), Mutex=done, call( G).
|
||||
|
||||
:- meta_predicate geler(+,:).
|
||||
%
|
||||
geler( Vars, Goal) :-
|
||||
attach( Vars, run(_Mutex,Goal)).
|
||||
|
||||
attach( [], _).
|
||||
attach( [V|Vs], Goal) :-
|
||||
( var(V), get_atts( V, goals(Gv)) ->
|
||||
put_atts( V, goals((Goal,Gv)))
|
||||
;
|
||||
put_atts( V, goals(Goal))
|
||||
),
|
||||
attach( Vs, Goal).
|
@ -1,126 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.3 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: geler.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
:- module( geler_q,
|
||||
[
|
||||
geler/2,
|
||||
project_nonlin/3,
|
||||
collect_nonlin/3
|
||||
]).
|
||||
|
||||
:- use_module( library(atts)).
|
||||
:- use_module( library(terms)).
|
||||
|
||||
:- attribute goals/1, all_nonlin/1.
|
||||
|
||||
attribute_goal( X, Goals) :-
|
||||
get_atts( X, goals(Gs)),
|
||||
nonexhausted( Gs, Goals, []),
|
||||
Goals = [_|_].
|
||||
attribute_goal( X, Conj) :-
|
||||
get_atts( X, all_nonlin(Goals)),
|
||||
l2conj( Goals, Conj).
|
||||
|
||||
l2conj( [X|Xs], Conj) :-
|
||||
( Xs = [], Conj = X
|
||||
; Xs = [_|_], Conj = (X,Xc), l2conj( Xs, Xc)
|
||||
).
|
||||
|
||||
nonexhausted( run(Mutex,G)) -->
|
||||
( {
|
||||
var(Mutex)
|
||||
} ->
|
||||
[ G ]
|
||||
;
|
||||
[]
|
||||
).
|
||||
nonexhausted( (A,B)) -->
|
||||
nonexhausted( A),
|
||||
nonexhausted( B).
|
||||
|
||||
verify_attributes( X, Y, Later) :-
|
||||
get_atts( X, goals(Gx)),
|
||||
!,
|
||||
( var(Y),
|
||||
( get_atts( Y, goals(Gy)) ->
|
||||
Later = [Gx,Gy],
|
||||
put_atts( Y, -goals(_))
|
||||
;
|
||||
Later = [],
|
||||
put_atts( Y, goals(Gx))
|
||||
)
|
||||
; nonvar( Y),
|
||||
Later = [Gx]
|
||||
).
|
||||
verify_attributes( _, _, []).
|
||||
|
||||
/*
|
||||
project_attributes( _, Cvas) :-
|
||||
collect_nonlin( Cvas, L, []),
|
||||
sort( L, Ls),
|
||||
put_atts( _, all_nonlin(Ls)).
|
||||
*/
|
||||
|
||||
%
|
||||
% called from project.pl
|
||||
%
|
||||
project_nonlin( _, Cvas, Reachable) :-
|
||||
collect_nonlin( Cvas, L, []),
|
||||
sort( L, Ls),
|
||||
term_variables( Ls, Reachable),
|
||||
put_atts( _, all_nonlin(Ls)).
|
||||
|
||||
collect_nonlin( []) --> [].
|
||||
collect_nonlin( [X|Xs]) -->
|
||||
( {get_atts( X, goals(Gx))} ->
|
||||
trans( Gx),
|
||||
collect_nonlin( Xs)
|
||||
;
|
||||
collect_nonlin( Xs)
|
||||
).
|
||||
|
||||
trans( (A,B)) -->
|
||||
trans( A),
|
||||
trans( B).
|
||||
trans( run(Mutex,Gs)) -->
|
||||
( {var(Mutex)} ->
|
||||
{Mutex = done},
|
||||
transg( Gs)
|
||||
;
|
||||
[]
|
||||
).
|
||||
|
||||
transg( (A,B)) --> !,
|
||||
transg( A),
|
||||
transg( B).
|
||||
transg( M:G) --> !,
|
||||
M:transg( G).
|
||||
transg( G) --> [ G ].
|
||||
|
||||
%vsc: added ! (01/06/06)
|
||||
run( Mutex, _) :- nonvar(Mutex), !.
|
||||
run( Mutex, G) :- var(Mutex), Mutex=done, call( G).
|
||||
|
||||
:- meta_predicate geler(+,:).
|
||||
%
|
||||
geler( Vars, Goal) :-
|
||||
attach( Vars, run(_Mutex,Goal)).
|
||||
|
||||
attach( [], _).
|
||||
attach( [V|Vs], Goal) :-
|
||||
( var(V), get_atts( V, goals(Gv)) ->
|
||||
put_atts( V, goals((Goal,Gv)))
|
||||
;
|
||||
put_atts( V, goals(Goal))
|
||||
),
|
||||
attach( Vs, Goal).
|
@ -1,76 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.3 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: nfq.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
:- module( nfq,
|
||||
[
|
||||
{}/1,
|
||||
entailed/1,
|
||||
wait_linear/3,
|
||||
|
||||
nf/2,
|
||||
repair/2,
|
||||
nf_constant/2,
|
||||
split/3,
|
||||
transg/3
|
||||
]).
|
||||
|
||||
:- use_module( arith_q).
|
||||
|
||||
:- use_module( clpq, '../clpq',
|
||||
[
|
||||
'solve_<'/1,
|
||||
'solve_=<'/1,
|
||||
'solve_=\='/1,
|
||||
add_linear_11/3,
|
||||
export_binding/2,
|
||||
ineq_one/4,
|
||||
ineq_one_n_n_0/1,
|
||||
ineq_one_n_p_0/1,
|
||||
ineq_one_s_n_0/1,
|
||||
ineq_one_s_p_0/1,
|
||||
log_deref/4,
|
||||
normalize_scalar/2,
|
||||
solve/1
|
||||
]).
|
||||
|
||||
:- ensure_loaded( nf).
|
||||
|
||||
transg( resubmit_eq(Nf)) -->
|
||||
{
|
||||
nf2term( [], Z),
|
||||
nf2term( Nf, Term)
|
||||
},
|
||||
[ clpq:{Term=Z} ].
|
||||
transg( resubmit_lt(Nf)) -->
|
||||
{
|
||||
nf2term( [], Z),
|
||||
nf2term( Nf, Term)
|
||||
},
|
||||
[ clpq:{Term<Z} ].
|
||||
transg( resubmit_le(Nf)) -->
|
||||
{
|
||||
nf2term( [], Z),
|
||||
nf2term( Nf, Term)
|
||||
},
|
||||
[ clpq:{Term=<Z} ].
|
||||
transg( resubmit_ne(Nf)) -->
|
||||
{
|
||||
nf2term( [], Z),
|
||||
nf2term( Nf, Term)
|
||||
},
|
||||
[ clpq:{Term=\=Z} ].
|
||||
transg( wait_linear_retry(Nf,Res,Goal)) -->
|
||||
{
|
||||
nf2term( Nf, Term)
|
||||
},
|
||||
[ clpq:{Term=Res}, Goal ].
|
@ -1,76 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.3 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: nfq.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
:- module( nfq,
|
||||
[
|
||||
{}/1,
|
||||
entailed/1,
|
||||
wait_linear/3,
|
||||
|
||||
nf/2,
|
||||
repair/2,
|
||||
nf_constant/2,
|
||||
split/3,
|
||||
transg/3
|
||||
]).
|
||||
|
||||
:- use_module( arith_q).
|
||||
|
||||
:- use_module( clpq, '../clpq',
|
||||
[
|
||||
'solve_<'/1,
|
||||
'solve_=<'/1,
|
||||
'solve_=\\='/1,
|
||||
add_linear_11/3,
|
||||
export_binding/2,
|
||||
ineq_one/4,
|
||||
ineq_one_n_n_0/1,
|
||||
ineq_one_n_p_0/1,
|
||||
ineq_one_s_n_0/1,
|
||||
ineq_one_s_p_0/1,
|
||||
log_deref/4,
|
||||
normalize_scalar/2,
|
||||
solve/1
|
||||
]).
|
||||
|
||||
:- ensure_loaded(nf).
|
||||
|
||||
transg( resubmit_eq(Nf)) -->
|
||||
{
|
||||
nf2term( [], Z),
|
||||
nf2term( Nf, Term)
|
||||
},
|
||||
[ clpq:{Term=Z} ].
|
||||
transg( resubmit_lt(Nf)) -->
|
||||
{
|
||||
nf2term( [], Z),
|
||||
nf2term( Nf, Term)
|
||||
},
|
||||
[ clpq:{Term<Z} ].
|
||||
transg( resubmit_le(Nf)) -->
|
||||
{
|
||||
nf2term( [], Z),
|
||||
nf2term( Nf, Term)
|
||||
},
|
||||
[ clpq:{Term=<Z} ].
|
||||
transg( resubmit_ne(Nf)) -->
|
||||
{
|
||||
nf2term( [], Z),
|
||||
nf2term( Nf, Term)
|
||||
},
|
||||
[ clpq:{Term=\=Z} ].
|
||||
transg( wait_linear_retry(Nf,Res,Goal)) -->
|
||||
{
|
||||
nf2term( Nf, Term)
|
||||
},
|
||||
[ clpq:{Term=Res}, Goal ].
|
@ -1,668 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.3 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: arith.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%
|
||||
% common code for R,Q, runtime predicates
|
||||
%
|
||||
% linearize evaluation, collect vars
|
||||
%
|
||||
% Todo: +) limited encoding length option
|
||||
% +) 2 stage compilation: a) linearization
|
||||
% b) specialization to R or Q
|
||||
%
|
||||
%
|
||||
|
||||
l2conj( [], true).
|
||||
l2conj( [X|Xs], Conj) :-
|
||||
( Xs = [], Conj = X
|
||||
; Xs = [_|_], Conj = (X,Xc), l2conj( Xs, Xc)
|
||||
).
|
||||
|
||||
% ----------------------------------------------------------------------
|
||||
|
||||
%
|
||||
% float/1 coercion is allowed only at the outermost level in Q
|
||||
%
|
||||
compile_Q( Term, R, Code) :-
|
||||
linearize( Term, Res, Linear),
|
||||
specialize_Q( Linear, Code, Ct),
|
||||
( Res = boolean, Ct = []
|
||||
; Res = float(R), Ct = []
|
||||
; Res = rat(N,D), Ct = [ putq(D,N,R) ]
|
||||
).
|
||||
|
||||
%
|
||||
% assumes normalized params and puts a normalized result
|
||||
%
|
||||
compile_Qn( Term, R, Code) :-
|
||||
linearize( Term, Res, Linear),
|
||||
specialize_Qn( Linear, Code, Ct),
|
||||
( Res = boolean, Ct = []
|
||||
; Res = float(R), Ct = []
|
||||
; Res = rat(N,D), Ct = [ putq(D,N,R) ]
|
||||
).
|
||||
|
||||
|
||||
compile_case_signum_Qn( Term, Lt,Z,Gt, Code) :-
|
||||
linearize( Term, rat(N,_), Linear),
|
||||
specialize_Qn( Linear, Code,
|
||||
[
|
||||
compare( Rel, N, 0),
|
||||
( Rel = <, Lt
|
||||
; Rel = =, Z
|
||||
; Rel = >, Gt
|
||||
)
|
||||
]).
|
||||
|
||||
|
||||
specialize_Qn( []) --> [].
|
||||
specialize_Qn( [Op|Ops]) -->
|
||||
specialize_Qn( Op),
|
||||
specialize_Qn( Ops).
|
||||
%
|
||||
specialize_Qn( op_var(rat(N,D),Var)) --> [ Var=rat(N,D) ]. % <--- here is the difference ---
|
||||
specialize_Qn( op_integer(rat(I,1),I)) --> [].
|
||||
specialize_Qn( op_rat(rat(N,D),N,D)) --> [].
|
||||
specialize_Qn( op_float(rat(N,D),X)) --> [], { float_rat( X, N,D) }.
|
||||
specialize_Qn( apply(R,Func)) -->
|
||||
specialize_Q_fn( Func, R).
|
||||
|
||||
|
||||
specialize_Q( []) --> [].
|
||||
specialize_Q( [Op|Ops]) -->
|
||||
specialize_Q( Op),
|
||||
specialize_Q( Ops).
|
||||
%
|
||||
specialize_Q( op_var(rat(N,D),Var)) --> [ getq(Var,N,D) ].
|
||||
specialize_Q( op_integer(rat(I,1),I)) --> [].
|
||||
specialize_Q( op_rat(rat(N,D),N,D)) --> [], { D > 0 }.
|
||||
specialize_Q( op_float(rat(N,D),X)) --> [], { float_rat( X, N,D) }.
|
||||
specialize_Q( apply(R,Func)) -->
|
||||
specialize_Q_fn( Func, R).
|
||||
|
||||
specialize_Q_fn( +rat(N,D), rat(N,D)) --> [].
|
||||
specialize_Q_fn( numer(rat(N,_)), rat(N,1)) --> [].
|
||||
specialize_Q_fn( denom(rat(_,D)), rat(D,1)) --> [].
|
||||
specialize_Q_fn( -rat(N0,D), rat(N,D)) --> [ N is -N0 ].
|
||||
specialize_Q_fn( abs(rat(Nx,Dx)), rat(N,D)) --> [ N is abs(Nx) ], {D=Dx}.
|
||||
specialize_Q_fn( signum(rat(Nx,Dx)), rat(N,D)) --> [ signumq( Nx,Dx, N,D) ].
|
||||
specialize_Q_fn( floor(rat(Nx,Dx)), rat(N,D)) --> [ floorq( Nx,Dx, N,D) ].
|
||||
specialize_Q_fn( ceiling(rat(Nx,Dx)), rat(N,D)) --> [ ceilingq( Nx,Dx, N,D) ].
|
||||
specialize_Q_fn( truncate(rat(Nx,Dx)), rat(N,D)) --> [ truncateq( Nx,Dx, N,D) ].
|
||||
specialize_Q_fn( round(rat(Nx,Dx)), rat(N,D)) --> [ roundq( Nx,Dx, N,D) ].
|
||||
specialize_Q_fn( log(rat(Nx,Dx)), rat(N,D)) --> [ logq( Nx,Dx, N,D) ].
|
||||
specialize_Q_fn( exp(rat(Nx,Dx)), rat(N,D)) --> [ expq( Nx,Dx, N,D) ].
|
||||
specialize_Q_fn( sin(rat(Nx,Dx)), rat(N,D)) --> [ sinq( Nx,Dx, N,D) ].
|
||||
specialize_Q_fn( cos(rat(Nx,Dx)), rat(N,D)) --> [ cosq( Nx,Dx, N,D) ].
|
||||
specialize_Q_fn( tan(rat(Nx,Dx)), rat(N,D)) --> [ tanq( Nx,Dx, N,D) ].
|
||||
specialize_Q_fn( asin(rat(Nx,Dx)), rat(N,D)) --> [ asinq( Nx,Dx, N,D) ].
|
||||
specialize_Q_fn( acos(rat(Nx,Dx)), rat(N,D)) --> [ acosq( Nx,Dx, N,D) ].
|
||||
specialize_Q_fn( atan(rat(Nx,Dx)), rat(N,D)) --> [ atanq( Nx,Dx, N,D) ].
|
||||
specialize_Q_fn( float(rat(Nx,Dx)), float(F)) --> [ rat_float( Nx,Dx, F) ].
|
||||
%
|
||||
specialize_Q_fn( rat(Nx,Dx)+rat(Ny,Dy), rat(N,D)) --> [ addq( Nx,Dx, Ny,Dy, N,D) ].
|
||||
specialize_Q_fn( rat(Nx,Dx)-rat(Ny,Dy), rat(N,D)) --> [ subq( Nx,Dx, Ny,Dy, N,D) ].
|
||||
specialize_Q_fn( rat(Nx,Dx)*rat(Ny,Dy), rat(N,D)) --> [ mulq( Nx,Dx, Ny,Dy, N,D) ].
|
||||
specialize_Q_fn( rat(Nx,Dx)/rat(Ny,Dy), rat(N,D)) --> [ divq( Nx,Dx, Ny,Dy, N,D) ].
|
||||
specialize_Q_fn( exp(rat(Nx,Dx),rat(Ny,Dy)), rat(N,D)) --> [ expq( Nx,Dx, Ny,Dy, N,D) ].
|
||||
specialize_Q_fn( min(rat(Nx,Dx),rat(Ny,Dy)), rat(N,D)) --> [ minq( Nx,Dx, Ny,Dy, N,D) ].
|
||||
specialize_Q_fn( max(rat(Nx,Dx),rat(Ny,Dy)), rat(N,D)) --> [ maxq( Nx,Dx, Ny,Dy, N,D) ].
|
||||
%
|
||||
specialize_Q_fn( rat(Nx,Dx) < rat(Ny,Dy), boolean) --> [ comq( Nx,Dx, Ny,Dy, <) ].
|
||||
specialize_Q_fn( rat(Nx,Dx) > rat(Ny,Dy), boolean) --> [ comq( Ny,Dy, Nx,Dx, <) ].
|
||||
specialize_Q_fn( rat(Nx,Dx) =< rat(Ny,Dy), boolean) --> [ comq( Nx,Dx, Ny,Dy, Rel), Rel \== (>) ].
|
||||
specialize_Q_fn( rat(Nx,Dx) >= rat(Ny,Dy), boolean) --> [ comq( Ny,Dy, Nx,Dx, Rel), Rel \== (>) ].
|
||||
specialize_Q_fn( rat(Nx,Dx) =\= rat(Ny,Dy), boolean) --> [ comq( Nx,Dx, Ny,Dy, Rel), Rel \== (=) ].
|
||||
specialize_Q_fn( rat(Nx,Dx) =:= rat(Ny,Dy), boolean) -->
|
||||
%
|
||||
% *normalized* rationals
|
||||
%
|
||||
( {Nx = Ny} -> [] ; [ Nx = Ny ] ),
|
||||
( {Dx = Dy} -> [] ; [ Dx = Dy ] ).
|
||||
|
||||
% ----------------------------------------------------------------------
|
||||
|
||||
compile_R( Term, R, Code) :-
|
||||
linearize( Term, Res, Linear),
|
||||
specialize_R( Linear, Code, Ct),
|
||||
( Res == boolean ->
|
||||
Ct = [], R = boolean
|
||||
; float(Res) ->
|
||||
Ct = [ R=Res ]
|
||||
;
|
||||
Ct = [ R is Res ]
|
||||
).
|
||||
|
||||
compile_case_signum_R( Term, Lt,Z,Gt, Code) :-
|
||||
eps( Eps, NegEps),
|
||||
linearize( Term, Res, Linear),
|
||||
specialize_R( Linear, Code,
|
||||
[
|
||||
Rv is Res,
|
||||
( Rv < NegEps -> Lt
|
||||
; Rv > Eps -> Gt
|
||||
; Z
|
||||
)
|
||||
]).
|
||||
|
||||
specialize_R( []) --> [].
|
||||
specialize_R( [Op|Ops]) -->
|
||||
specialize_R( Op),
|
||||
specialize_R( Ops).
|
||||
%
|
||||
specialize_R( op_var(Var,Var)) --> [].
|
||||
specialize_R( op_integer(R,I)) --> [], { R is float(I) }.
|
||||
specialize_R( op_rat(R,N,D)) --> [], { rat_float( N,D, R) }.
|
||||
specialize_R( op_float(F,F)) --> [].
|
||||
specialize_R( apply(R,Func)) -->
|
||||
specialize_R_fn( Func, R).
|
||||
|
||||
specialize_R_fn( signum(X), S) -->
|
||||
( {var(X)} ->
|
||||
{Xe=X}
|
||||
;
|
||||
[ Xe is X ]
|
||||
),
|
||||
{
|
||||
eps( Eps, NegEps)
|
||||
},
|
||||
[
|
||||
( Xe < NegEps -> S = -1.0
|
||||
; Xe > Eps -> S = 1.0
|
||||
; S = 0.0
|
||||
)
|
||||
].
|
||||
|
||||
specialize_R_fn( +X, X) --> [].
|
||||
specialize_R_fn( -X, -X) --> [].
|
||||
specialize_R_fn( abs(X), abs(X)) --> [].
|
||||
specialize_R_fn( floor(X), float(floor(/*float?*/X))) --> [].
|
||||
specialize_R_fn( ceiling(X), float(ceiling(/*float?*/X))) --> [].
|
||||
specialize_R_fn( truncate(X), float(truncate(/*float?*/X))) --> [].
|
||||
specialize_R_fn( round(X), float(round(/*float?*/X))) --> [].
|
||||
specialize_R_fn( log(X), log(X)) --> [].
|
||||
specialize_R_fn( exp(X), exp(X)) --> [].
|
||||
specialize_R_fn( sin(X), sin(X)) --> [].
|
||||
specialize_R_fn( cos(X), cos(X)) --> [].
|
||||
specialize_R_fn( tan(X), tan(X)) --> [].
|
||||
specialize_R_fn( asin(X), asin(X)) --> [].
|
||||
specialize_R_fn( acos(X), acos(X)) --> [].
|
||||
specialize_R_fn( atan(X), atan(X)) --> [].
|
||||
specialize_R_fn( float(X), float(X)) --> [].
|
||||
%
|
||||
specialize_R_fn( X+Y, X+Y) --> [].
|
||||
specialize_R_fn( X-Y, X-Y) --> [].
|
||||
specialize_R_fn( X*Y, X*Y) --> [].
|
||||
specialize_R_fn( X/Y, X/Y) --> [].
|
||||
specialize_R_fn( exp(X,Y), exp(X,Y)) --> [].
|
||||
specialize_R_fn( min(X,Y), min(X,Y)) --> [].
|
||||
specialize_R_fn( max(X,Y), max(X,Y)) --> [].
|
||||
/**/
|
||||
%
|
||||
% An absolute eps is of course not very meaningful.
|
||||
% An eps scaled by the magnitude of the operands participating
|
||||
% in the comparison is too expensive to support in Prolog on the
|
||||
% other hand ...
|
||||
%
|
||||
%
|
||||
% -eps 0 +eps
|
||||
% ---------------[----|----]----------------
|
||||
% < 0 > 0
|
||||
% <-----------] [----------->
|
||||
% =< 0
|
||||
% <---------------------]
|
||||
% >= 0
|
||||
% [--------------------->
|
||||
%
|
||||
%
|
||||
specialize_R_fn( X < Y, boolean) -->
|
||||
{
|
||||
eps( Eps, NegEps)
|
||||
},
|
||||
( {X==0} ->
|
||||
[ Y > Eps ]
|
||||
; {Y==0} ->
|
||||
[ X < NegEps ]
|
||||
;
|
||||
[ X-Y < NegEps ]
|
||||
).
|
||||
specialize_R_fn( X > Y, boolean) --> specialize_R_fn( Y < X, boolean).
|
||||
specialize_R_fn( X =< Y, boolean) -->
|
||||
{
|
||||
eps( Eps, _)
|
||||
},
|
||||
[ X-Y < Eps ].
|
||||
specialize_R_fn( X >= Y, boolean) --> specialize_R_fn( Y =< X, boolean).
|
||||
specialize_R_fn( X =:= Y, boolean) -->
|
||||
{
|
||||
eps( Eps, NegEps)
|
||||
},
|
||||
( {X==0} ->
|
||||
[ Y >= NegEps, Y =< Eps ]
|
||||
; {Y==0} ->
|
||||
[ X >= NegEps, X =< Eps ]
|
||||
;
|
||||
[
|
||||
Diff is X-Y,
|
||||
Diff =< Eps,
|
||||
Diff >= NegEps
|
||||
]
|
||||
).
|
||||
specialize_R_fn( X =\= Y, boolean) -->
|
||||
{
|
||||
eps( Eps, NegEps)
|
||||
},
|
||||
[
|
||||
Diff is X-Y,
|
||||
( Diff < NegEps -> true ; Diff > Eps )
|
||||
].
|
||||
/**/
|
||||
|
||||
/**
|
||||
%
|
||||
% b30427, pp.218
|
||||
%
|
||||
specialize_R_fn( X > Y, boolean) --> specialize_R_fn( Y < X, boolean).
|
||||
specialize_R_fn( X < Y, boolean) -->
|
||||
[ scaled_eps(X,Y,E), Y-X > E ].
|
||||
|
||||
specialize_R_fn( X >= Y, boolean) --> specialize_R_fn( Y =< X, boolean).
|
||||
specialize_R_fn( X =< Y, boolean) -->
|
||||
[ scaled_eps(X,Y,E), X-Y =< E ]. % \+ >
|
||||
|
||||
specialize_R_fn( X =:= Y, boolean) -->
|
||||
[ scaled_eps(X,Y,E), abs(X-Y) =< E ].
|
||||
|
||||
specialize_R_fn( X =\= Y, boolean) -->
|
||||
[ scaled_eps(X,Y,E), abs(X-Y) > E ].
|
||||
|
||||
|
||||
scaled_eps( X, Y, Eps) :-
|
||||
exponent( X, Ex),
|
||||
exponent( Y, Ey),
|
||||
arith_eps( E),
|
||||
Max is max(Ex,Ey),
|
||||
( Max < 0 ->
|
||||
Eps is E/(1<<Max)
|
||||
;
|
||||
Eps is E*(1<<Max)
|
||||
).
|
||||
|
||||
exponent( X, E) :-
|
||||
A is abs(X),
|
||||
float_rat( A, N, D),
|
||||
E is msb(N+1)-msb(D).
|
||||
**/
|
||||
|
||||
% ----------------------------------------------------------------------
|
||||
|
||||
linearize( Term, Res, Linear) :-
|
||||
linearize( Term, Res, Vs,[], Lin, []),
|
||||
keysort( Vs, Vss),
|
||||
( Vss = [], Linear = Lin
|
||||
; Vss = [V|Vt], join_vars( Vt, V, Linear, Lin)
|
||||
).
|
||||
|
||||
%
|
||||
% flatten the evaluation, collect variables, shared by Q,R,...
|
||||
%
|
||||
linearize( X, R, [X-R|Vs],Vs) --> {var(X)}, !, [ ].
|
||||
linearize( X, R, Vs,Vs) --> {integer(X)}, !, [ op_integer(R,X) ].
|
||||
linearize( X, R, Vs,Vs) --> {float(X)}, !, [ op_float(R,X) ].
|
||||
linearize( rat(N,D), R, Vs,Vs) --> !, [ op_rat(R,N,D) ].
|
||||
linearize( Term, R, V0,V1) -->
|
||||
{
|
||||
functor( Term, N, A),
|
||||
functor( Skeleton, N, A)
|
||||
},
|
||||
linearize_args( A, Term, Skeleton, V0,V1), [ apply(R,Skeleton) ].
|
||||
|
||||
linearize_args( 0, _, _, Vs,Vs) --> [].
|
||||
linearize_args( N, T, S, V0,V2) -->
|
||||
{
|
||||
arg( N, T, Arg),
|
||||
arg( N, S, Res),
|
||||
N1 is N-1
|
||||
},
|
||||
linearize( Arg, Res, V0,V1),
|
||||
linearize_args( N1, T, S, V1,V2).
|
||||
|
||||
join_vars( [], Y-Ry) --> [ op_var(Ry,Y) ].
|
||||
join_vars( [X-Rx|Xs], Y-Ry) -->
|
||||
( {X==Y} ->
|
||||
{Rx=Ry},
|
||||
join_vars( Xs, Y-Ry)
|
||||
;
|
||||
[ op_var(Ry,Y) ],
|
||||
join_vars( Xs, X-Rx)
|
||||
).
|
||||
|
||||
% ---------------------------------- runtime system ---------------------------
|
||||
|
||||
%
|
||||
% C candidate
|
||||
%
|
||||
limit_encoding_length( 0,D, _, 0,D) :- !. % msb ...
|
||||
limit_encoding_length( N,D, Bits, Nl,Dl) :-
|
||||
Shift is min(max(msb(abs(N)),msb(D))-Bits,
|
||||
min(msb(abs(N)),msb(D))),
|
||||
Shift > 0,
|
||||
!,
|
||||
Ns is N>>Shift,
|
||||
Ds is D>>Shift,
|
||||
Gcd is gcd(Ns,Ds),
|
||||
Nl is Ns//Gcd,
|
||||
Dl is Ds//Gcd.
|
||||
limit_encoding_length( N,D, _, N,D).
|
||||
|
||||
|
||||
%
|
||||
% No longer backconvert to integer
|
||||
%
|
||||
% putq( 1, N, N) :- !.
|
||||
putq( D, N, rat(N,D)).
|
||||
|
||||
getq( Exp, N,D) :- var( Exp), !,
|
||||
raise_exception( instantiation_error(getq(Exp,N,D),1)).
|
||||
getq( I, I,1) :- integer(I), !.
|
||||
getq( F, N,D) :- float( F), !, float_rat( F, N,D).
|
||||
getq( rat(N,D), N,D) :-
|
||||
integer( N),
|
||||
integer( D),
|
||||
D > 0,
|
||||
1 =:= gcd(N,D).
|
||||
|
||||
%
|
||||
% actually just a joke to have this stuff in Q ...
|
||||
%
|
||||
expq( N,D, N1,D1) :- rat_float( N,D, X), F is exp(X), float_rat( F, N1,D1).
|
||||
logq( N,D, N1,D1) :- rat_float( N,D, X), F is log(X), float_rat( F, N1,D1).
|
||||
sinq( N,D, N1,D1) :- rat_float( N,D, X), F is sin(X), float_rat( F, N1,D1).
|
||||
cosq( N,D, N1,D1) :- rat_float( N,D, X), F is cos(X), float_rat( F, N1,D1).
|
||||
tanq( N,D, N1,D1) :- rat_float( N,D, X), F is tan(X), float_rat( F, N1,D1).
|
||||
asinq( N,D, N1,D1) :- rat_float( N,D, X), F is asin(X), float_rat( F, N1,D1).
|
||||
acosq( N,D, N1,D1) :- rat_float( N,D, X), F is acos(X), float_rat( F, N1,D1).
|
||||
atanq( N,D, N1,D1) :- rat_float( N,D, X), F is atan(X), float_rat( F, N1,D1).
|
||||
|
||||
%
|
||||
% for integer powers we can do it in Q
|
||||
%
|
||||
expq( Nx,Dx, Ny,Dy, N,D) :-
|
||||
( Dy =:= 1 ->
|
||||
( Ny >= 0 ->
|
||||
powq( Ny, Nx,Dx, 1,1, N,D)
|
||||
;
|
||||
Nabs is -Ny,
|
||||
powq( Nabs, Nx,Dx, 1,1, N1,D1),
|
||||
( N1 < 0 ->
|
||||
N is -D1, D is -N1
|
||||
;
|
||||
N = D1, D = N1
|
||||
)
|
||||
)
|
||||
;
|
||||
rat_float( Nx,Dx, Fx),
|
||||
rat_float( Ny,Dy, Fy),
|
||||
F is exp(Fx,Fy),
|
||||
float_rat( F, N, D)
|
||||
).
|
||||
|
||||
%
|
||||
% positive integer powers of rational
|
||||
%
|
||||
powq( 0, _, _, Nt,Dt, Nt,Dt) :- !.
|
||||
powq( 1, Nx,Dx, Nt,Dt, Nr,Dr) :- !, mulq( Nx,Dx, Nt,Dt, Nr,Dr).
|
||||
powq( N, Nx,Dx, Nt,Dt, Nr,Dr) :-
|
||||
N1 is N >> 1,
|
||||
( N /\ 1 =:= 0 ->
|
||||
Nt1 = Nt, Dt1 = Dt
|
||||
;
|
||||
mulq( Nx,Dx, Nt,Dt, Nt1,Dt1)
|
||||
),
|
||||
mulq( Nx,Dx, Nx,Dx, Nxx,Dxx),
|
||||
powq( N1, Nxx,Dxx, Nt1,Dt1, Nr,Dr).
|
||||
|
||||
|
||||
/*
|
||||
%
|
||||
% the choicepoint ruins the party ...
|
||||
%
|
||||
mulq( Na,Da, Nb,Db, Nc,Dc) :-
|
||||
Gcd1 is gcd(Na,Db),
|
||||
( Gcd1 =:= 1 -> Na1=Na,Db1=Db; Na1 is Na//Gcd1,Db1 is Db//Gcd1 ),
|
||||
Gcd2 is gcd(Nb,Da),
|
||||
( Gcd2 =:= 1 -> Nb1=Nb,Da1=Da; Nb1 is Nb//Gcd2,Da1 is Da//Gcd2 ),
|
||||
Nc is Na1 * Nb1,
|
||||
Dc is Da1 * Db1.
|
||||
*/
|
||||
mulq( Na,Da, Nb,Db, Nc,Dc) :-
|
||||
Gcd1 is gcd(Na,Db),
|
||||
Na1 is Na//Gcd1,
|
||||
Db1 is Db//Gcd1,
|
||||
Gcd2 is gcd(Nb,Da),
|
||||
Nb1 is Nb//Gcd2,
|
||||
Da1 is Da//Gcd2,
|
||||
Nc is Na1 * Nb1,
|
||||
Dc is Da1 * Db1.
|
||||
|
||||
/*
|
||||
divq( Na,Da, Nb,Db, Nc,Dc) :-
|
||||
Gcd1 is gcd(Na,Nb),
|
||||
( Gcd1 =:= 1 -> Na1=Na,Nb1=Nb; Na1 is Na//Gcd1,Nb1 is Nb//Gcd1 ),
|
||||
Gcd2 is gcd(Da,Db),
|
||||
( Gcd2 =:= 1 -> Da1=Da,Db1=Db; Da1 is Da//Gcd2,Db1 is Db//Gcd2 ),
|
||||
( Nb1 < 0 -> % keep denom positive !!!
|
||||
Nc is -(Na1 * Db1),
|
||||
Dc is Da1 * (-Nb1)
|
||||
;
|
||||
Nc is Na1 * Db1,
|
||||
Dc is Da1 * Nb1
|
||||
).
|
||||
*/
|
||||
divq( Na,Da, Nb,Db, Nc,Dc) :-
|
||||
Gcd1 is gcd(Na,Nb),
|
||||
Na1 is Na//Gcd1,
|
||||
Nb1 is Nb//Gcd1,
|
||||
Gcd2 is gcd(Da,Db),
|
||||
Da1 is Da//Gcd2,
|
||||
Db1 is Db//Gcd2,
|
||||
( Nb1 < 0 -> % keep denom positive !!!
|
||||
Nc is -(Na1 * Db1),
|
||||
Dc is Da1 * (-Nb1)
|
||||
;
|
||||
Nc is Na1 * Db1,
|
||||
Dc is Da1 * Nb1
|
||||
).
|
||||
|
||||
%
|
||||
% divq_11( Nb,Db, Nc,Dc) :- divq( 1,1, Nb,Db, Nc,Dc).
|
||||
%
|
||||
divq_11( Nb,Db, Nc,Dc) :-
|
||||
( Nb < 0 -> % keep denom positive !!!
|
||||
Nc is -Db,
|
||||
Dc is -Nb
|
||||
;
|
||||
Nc is Db,
|
||||
Dc is Nb
|
||||
).
|
||||
|
||||
'divq_-11'( Nb,Db, Nc,Dc) :-
|
||||
( Nb < 0 -> % keep denom positive !!!
|
||||
Nc is Db,
|
||||
Dc is -Nb
|
||||
;
|
||||
Nc is -Db,
|
||||
Dc is Nb
|
||||
).
|
||||
|
||||
/*
|
||||
addq( Na,Da, Nb,Db, Nc,Dc) :-
|
||||
Gcd1 is gcd(Da,Db),
|
||||
( Gcd1 =:= 1 -> % This is the case (for random input) with
|
||||
% probability 6/(pi**2).
|
||||
Nc is Na*Db + Nb*Da,
|
||||
Dc is Da*Db
|
||||
;
|
||||
T is Na*(Db//Gcd1) + Nb*(Da//Gcd1),
|
||||
Gcd2 is gcd(T,Gcd1),
|
||||
Nc is T//Gcd2,
|
||||
Dc is (Da//Gcd1) * (Db//Gcd2)
|
||||
).
|
||||
*/
|
||||
addq( Na,Da, Nb,Db, Nc,Dc) :-
|
||||
Gcd1 is gcd(Da,Db),
|
||||
T is Na*(Db//Gcd1) + Nb*(Da//Gcd1),
|
||||
Gcd2 is gcd(T,Gcd1),
|
||||
Nc is T//Gcd2,
|
||||
Dc is (Da//Gcd1) * (Db//Gcd2).
|
||||
|
||||
/*
|
||||
subq( Na,Da, Nb,Db, Nc,Dc) :-
|
||||
Gcd1 is gcd(Da,Db),
|
||||
( Gcd1 =:= 1 -> % This is the case (for random input) with
|
||||
% probability 6/(pi**2).
|
||||
Nc is Na*Db - Nb*Da,
|
||||
Dc is Da*Db
|
||||
;
|
||||
T is Na*(Db//Gcd1) - Nb*(Da//Gcd1),
|
||||
Gcd2 is gcd(T,Gcd1),
|
||||
Nc is T//Gcd2,
|
||||
Dc is (Da//Gcd1) * (Db//Gcd2)
|
||||
).
|
||||
*/
|
||||
subq( Na,Da, Nb,Db, Nc,Dc) :-
|
||||
Gcd1 is gcd(Da,Db),
|
||||
T is Na*(Db//Gcd1) - Nb*(Da//Gcd1),
|
||||
Gcd2 is gcd(T,Gcd1),
|
||||
Nc is T//Gcd2,
|
||||
Dc is (Da//Gcd1) * (Db//Gcd2).
|
||||
|
||||
comq( Na,Da, Nb,Db, S) :- % todo: avoid multiplication by looking a signs first !!!
|
||||
Xa is Na * Db,
|
||||
Xb is Nb * Da,
|
||||
compare( S, Xa, Xb).
|
||||
|
||||
minq( Na,Da, Nb,Db, N,D) :-
|
||||
comq( Na,Da, Nb,Db, Rel),
|
||||
( Rel = =, N=Na, D=Da
|
||||
; Rel = <, N=Na, D=Da
|
||||
; Rel = >, N=Nb, D=Db
|
||||
).
|
||||
|
||||
maxq( Na,Da, Nb,Db, N,D) :-
|
||||
comq( Na,Da, Nb,Db, Rel),
|
||||
( Rel = =, N=Nb, D=Db
|
||||
; Rel = <, N=Nb, D=Db
|
||||
; Rel = >, N=Na, D=Da
|
||||
).
|
||||
|
||||
signumq( N,_, S,1) :-
|
||||
compare( Rel, N, 0),
|
||||
rel2sig( Rel, S).
|
||||
|
||||
rel2sig( <, -1).
|
||||
rel2sig( >, 1).
|
||||
rel2sig( =, 0).
|
||||
|
||||
|
||||
|
||||
% -----------------------------------------------------------------------------
|
||||
|
||||
truncateq( N,D, R,1) :-
|
||||
R is N // D.
|
||||
|
||||
%
|
||||
% returns the greatest integral value less than or
|
||||
% equal to x. This corresponds to IEEE rounding toward nega-
|
||||
% tive infinity
|
||||
%
|
||||
floorq( N,1, N,1) :- !.
|
||||
floorq( N,D, R,1) :-
|
||||
( N < 0 ->
|
||||
R is N // D - 1
|
||||
;
|
||||
R is N // D
|
||||
).
|
||||
|
||||
%
|
||||
% returns the least integral value greater than or
|
||||
% equal to x. This corresponds to IEEE rounding toward posi-
|
||||
% tive infinity
|
||||
%
|
||||
ceilingq( N,1, N,1) :- !.
|
||||
ceilingq( N,D, R,1) :-
|
||||
( N > 0 ->
|
||||
R is N // D + 1
|
||||
;
|
||||
R is N // D
|
||||
).
|
||||
|
||||
%
|
||||
% rounding towards zero
|
||||
%
|
||||
roundq( N,D, R,1) :-
|
||||
% rat_float( N,D, F), % cheating, can do that in Q
|
||||
% R is integer(round(F)).
|
||||
I is N//D,
|
||||
subq( N,D, I,1, Rn,Rd),
|
||||
Rna is abs(Rn),
|
||||
( comq( Rna,Rd, 1,2, <) ->
|
||||
R = I
|
||||
; I >= 0 ->
|
||||
R is I+1
|
||||
;
|
||||
R is I-1
|
||||
).
|
||||
|
||||
% ------------------------------- rational -> float -------------------------------
|
||||
%
|
||||
% The problem here is that SICStus converts BIG fractions N/D into +-nan
|
||||
% if it does not fit into a float
|
||||
%
|
||||
% | ?- X is msb(integer(1.0e+308)).
|
||||
% X = 1023
|
||||
%
|
||||
|
||||
rat_float( Nx,Dx, F) :-
|
||||
limit_encoding_length( Nx,Dx, 1023, Nxl,Dxl),
|
||||
F is Nxl / Dxl.
|
||||
|
||||
% ------------------------------- float -> rational -------------------------------
|
||||
|
||||
float_rat( F, N, D) :-
|
||||
float_rat( 100, F, F, 1,0,0,1, N0,D0), % at most 100 iterations
|
||||
( D0 < 0 -> % sign normalization
|
||||
D is -D0,
|
||||
N is -N0
|
||||
;
|
||||
D = D0,
|
||||
N = N0
|
||||
).
|
||||
|
||||
float_rat( 0, _, _, Na,_,Da,_, Na,Da) :- !.
|
||||
float_rat( _, _, X, Na,_,Da,_, Na,Da) :-
|
||||
0.0 =:= abs(X-Na/Da),
|
||||
!.
|
||||
float_rat( N, F, X, Na,Nb,Da,Db, Nar,Dar) :-
|
||||
I is integer(F),
|
||||
( I =:= F -> % guard against zero division
|
||||
Nar is Na*I+Nb, % 1.0 -> 1/1 and not 0/1 (first iter.) !!!
|
||||
Dar is Da*I+Db
|
||||
;
|
||||
Na1 is Na*I+Nb,
|
||||
Da1 is Da*I+Db,
|
||||
F1 is 1/(F-I),
|
||||
N1 is N-1,
|
||||
float_rat( N1, F1, X, Na1,Na,Da1,Da, Nar,Dar)
|
||||
).
|
||||
|
@ -1,128 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.3 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: bb.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
bb_inf( Is, Term, Inf) :-
|
||||
bb_inf( Is, Term, Inf, _, 0.001).
|
||||
|
||||
bb_inf( Is, Term, Inf, Vertex, Eps) :-
|
||||
nf( Eps, ENf),
|
||||
nf_constant( ENf, EpsN),
|
||||
wait_linear( Term, Nf, bb_inf_internal(Is,Nf,EpsN,Inf,Vertex)).
|
||||
|
||||
% ---------------------------------------------------------------------
|
||||
|
||||
bb_inf_internal( Is, Lin, Eps, _, _) :-
|
||||
bb_intern( Is, IsNf),
|
||||
( bb_delete( incumbent, _) -> true ; true ),
|
||||
repair( Lin, LinR), % bb_narrow ...
|
||||
deref( LinR, Lind),
|
||||
var_with_def_assign( Dep, Lind),
|
||||
determine_active_dec( Lind),
|
||||
bb_loop( Dep, IsNf, Eps),
|
||||
fail.
|
||||
bb_inf_internal( _, _, _, Inf, Vertex) :-
|
||||
bb_delete( incumbent, InfVal-Vertex), % GC
|
||||
{ Inf =:= InfVal }.
|
||||
|
||||
bb_loop( Opt, Is, Eps) :-
|
||||
bb_reoptimize( Opt, Inf),
|
||||
bb_better_bound( Inf),
|
||||
vertex_value( Is, Ivs),
|
||||
( bb_first_nonint( Is, Ivs, Eps, Viol, Floor, Ceiling) ->
|
||||
bb_branch( Viol, Floor, Ceiling),
|
||||
bb_loop( Opt, Is, Eps)
|
||||
;
|
||||
round_values( Ivs, RoundVertex),
|
||||
% print( incumbent( Inf-RoundVertex)), nl,
|
||||
bb_put( incumbent, Inf-RoundVertex)
|
||||
).
|
||||
|
||||
%
|
||||
% added ineqs may have led to binding
|
||||
%
|
||||
bb_reoptimize( Obj, Inf) :- var( Obj), iterate_dec( Obj, Inf).
|
||||
bb_reoptimize( Obj, Inf) :- nonvar( Obj), Inf = Obj.
|
||||
|
||||
bb_better_bound( Inf) :-
|
||||
bb_get( incumbent, Inc-_),
|
||||
!,
|
||||
arith_eval( Inf < Inc).
|
||||
bb_better_bound( _).
|
||||
|
||||
bb_branch( V, U, _) :- { V =< U }.
|
||||
bb_branch( V, _, L) :- { V >= L }.
|
||||
|
||||
vertex_value( [], []).
|
||||
vertex_value( [X|Xs], [V|Vs]) :-
|
||||
rhs_value( X, V),
|
||||
vertex_value( Xs, Vs).
|
||||
|
||||
rhs_value( Xn, Value) :- nonvar(Xn), Value=Xn.
|
||||
rhs_value( Xn, Value) :- var(Xn),
|
||||
deref_var( Xn, Xd),
|
||||
decompose( Xd, _, R, I),
|
||||
arith_eval( R+I, Value).
|
||||
|
||||
%
|
||||
% Need only one as we branch on the first anyway ...
|
||||
%
|
||||
bb_first_nonint( [I|Is], [Rhs|Rhss], Eps, Viol, F, C) :-
|
||||
( arith_eval( floor(Rhs), Floor),
|
||||
arith_eval( ceiling(Rhs), Ceiling),
|
||||
arith_eval(min(Rhs-Floor,Ceiling-Rhs) > Eps) ->
|
||||
Viol = I,
|
||||
F = Floor,
|
||||
C = Ceiling
|
||||
;
|
||||
bb_first_nonint( Is, Rhss, Eps, Viol, F, C)
|
||||
).
|
||||
|
||||
round_values( [], []).
|
||||
round_values( [X|Xs], [Y|Ys]) :-
|
||||
arith_eval( round(X), Y),
|
||||
round_values( Xs, Ys).
|
||||
|
||||
bb_intern( [], []).
|
||||
bb_intern( [X|Xs], [Xi|Xis]) :-
|
||||
nf( X, Xnf),
|
||||
bb_intern( Xnf, Xi, X),
|
||||
bb_intern( Xs, Xis).
|
||||
|
||||
%
|
||||
% allow more general expressions and conditions? integral(Exp) ???
|
||||
%
|
||||
bb_intern( [], X, _) :- !, arith_eval( 0, X).
|
||||
bb_intern( [v(I,[])], X, _) :- !, X=I.
|
||||
bb_intern( [v(One,[X^1])], X, _) :-
|
||||
arith_eval(One=:=1),
|
||||
!,
|
||||
get_atts( X, [type(T),strictness(S)]),
|
||||
bb_narrow( T, S, X).
|
||||
bb_intern( _, _, Term) :-
|
||||
raise_exception( instantiation_error(bb_inf(Term,_,_),1)).
|
||||
|
||||
bb_narrow( t_l(L), S, V) :-
|
||||
S /\ 2'10 =\= 0,
|
||||
!,
|
||||
arith_eval( floor(1+L), B),
|
||||
{ V >= B }.
|
||||
bb_narrow( t_u(U), S, V) :-
|
||||
S /\ 2'01 =\= 0,
|
||||
!,
|
||||
arith_eval( ceiling(U-1), B),
|
||||
{ V =< B }.
|
||||
bb_narrow( t_lu(L,U), S, V) :- !,
|
||||
bb_narrow( t_l(L), S, V),
|
||||
bb_narrow( t_u(U), S, V).
|
||||
bb_narrow( _, _, _).
|
||||
|
@ -1,132 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.3 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: bb.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
bb_inf( Is, Term, Inf) :-
|
||||
bb_inf( Is, Term, Inf, _, 0.001).
|
||||
|
||||
bb_inf( Is, Term, Inf, Vertex, Eps) :-
|
||||
nf( Eps, ENf),
|
||||
nf_constant( ENf, EpsN),
|
||||
wait_linear( Term, Nf, bb_inf_internal(Is,Nf,EpsN,Inf,Vertex)).
|
||||
|
||||
% ---------------------------------------------------------------------
|
||||
|
||||
bb_inf_internal( Is, Lin, Eps, _, _) :-
|
||||
bb_intern( Is, IsNf),
|
||||
( bb_delete( incumbent, _) -> true ; true ),
|
||||
repair( Lin, LinR), % bb_narrow ...
|
||||
deref( LinR, Lind),
|
||||
var_with_def_assign( Dep, Lind),
|
||||
determine_active_dec( Lind),
|
||||
bb_loop( Dep, IsNf, Eps),
|
||||
fail.
|
||||
bb_inf_internal( _, _, _, Inf, Vertex) :-
|
||||
bb_delete( incumbent, InfVal-Vertex), % GC
|
||||
{ Inf =:= InfVal }.
|
||||
|
||||
bb_loop( Opt, Is, Eps) :-
|
||||
bb_reoptimize( Opt, Inf),
|
||||
bb_better_bound( Inf),
|
||||
vertex_value( Is, Ivs),
|
||||
( bb_first_nonint( Is, Ivs, Eps, Viol, Floor, Ceiling) ->
|
||||
bb_branch( Viol, Floor, Ceiling),
|
||||
bb_loop( Opt, Is, Eps)
|
||||
;
|
||||
round_values( Ivs, RoundVertex),
|
||||
% print( incumbent( Inf-RoundVertex)), nl,
|
||||
bb_put( incumbent, Inf-RoundVertex)
|
||||
).
|
||||
|
||||
%
|
||||
% added ineqs may have led to binding
|
||||
%
|
||||
%vsc: added ! (01/06/06)
|
||||
bb_reoptimize( Obj, Inf) :- var( Obj), !, iterate_dec( Obj, Inf).
|
||||
bb_reoptimize( Obj, Inf) :- nonvar( Obj), Inf = Obj.
|
||||
|
||||
bb_better_bound( Inf) :-
|
||||
bb_get( incumbent, Inc-_),
|
||||
!,
|
||||
arith_eval( Inf < Inc).
|
||||
bb_better_bound( _).
|
||||
|
||||
% :- parallel(bb_branch/3).
|
||||
|
||||
bb_branch( V, U, _) :- { V =< U }.
|
||||
bb_branch( V, _, L) :- { V >= L }.
|
||||
|
||||
vertex_value( [], []).
|
||||
vertex_value( [X|Xs], [V|Vs]) :-
|
||||
rhs_value( X, V),
|
||||
vertex_value( Xs, Vs).
|
||||
|
||||
%vsc: added ! (01/06/06)
|
||||
rhs_value( Xn, Value) :- nonvar(Xn), !, Value=Xn.
|
||||
rhs_value( Xn, Value) :- var(Xn),
|
||||
deref_var( Xn, Xd),
|
||||
decompose( Xd, _, R, I),
|
||||
arith_eval( R+I, Value).
|
||||
|
||||
%
|
||||
% Need only one as we branch on the first anyway ...
|
||||
%
|
||||
bb_first_nonint( [I|Is], [Rhs|Rhss], Eps, Viol, F, C) :-
|
||||
( arith_eval( floor(Rhs), Floor),
|
||||
arith_eval( ceiling(Rhs), Ceiling),
|
||||
arith_eval(min(Rhs-Floor,Ceiling-Rhs) > Eps) ->
|
||||
Viol = I,
|
||||
F = Floor,
|
||||
C = Ceiling
|
||||
;
|
||||
bb_first_nonint( Is, Rhss, Eps, Viol, F, C)
|
||||
).
|
||||
|
||||
round_values( [], []).
|
||||
round_values( [X|Xs], [Y|Ys]) :-
|
||||
arith_eval( round(X), Y),
|
||||
round_values( Xs, Ys).
|
||||
|
||||
bb_intern( [], []).
|
||||
bb_intern( [X|Xs], [Xi|Xis]) :-
|
||||
nf( X, Xnf),
|
||||
bb_intern( Xnf, Xi, X),
|
||||
bb_intern( Xs, Xis).
|
||||
|
||||
%
|
||||
% allow more general expressions and conditions? integral(Exp) ???
|
||||
%
|
||||
bb_intern( [], X, _) :- !, arith_eval( 0, X).
|
||||
bb_intern( [v(I,[])], X, _) :- !, X=I.
|
||||
bb_intern( [v(One,[X^1])], X, _) :-
|
||||
arith_eval(One=:=1),
|
||||
!,
|
||||
get_atts( X, [type(T),strictness(S)]),
|
||||
bb_narrow( T, S, X).
|
||||
bb_intern( _, _, Term) :-
|
||||
raise_exception( instantiation_error(bb_inf(Term,_,_),1)).
|
||||
|
||||
bb_narrow( t_l(L), S, V) :-
|
||||
S /\ 2'10 =\= 0,
|
||||
!,
|
||||
arith_eval( floor(1+L), B),
|
||||
{ V >= B }.
|
||||
bb_narrow( t_u(U), S, V) :-
|
||||
S /\ 2'01 =\= 0,
|
||||
!,
|
||||
arith_eval( ceiling(U-1), B),
|
||||
{ V =< B }.
|
||||
bb_narrow( t_lu(L,U), S, V) :- !,
|
||||
bb_narrow( t_l(L), S, V),
|
||||
bb_narrow( t_u(U), S, V).
|
||||
bb_narrow( _, _, _).
|
||||
|
1256
CLPQR/clpqr/bv.pl
1256
CLPQR/clpqr/bv.pl
File diff suppressed because it is too large
Load Diff
1266
CLPQR/clpqr/bv.yap
1266
CLPQR/clpqr/bv.yap
File diff suppressed because it is too large
Load Diff
@ -1,86 +0,0 @@
|
||||
% Copyright (C) 1994, Swedish Institute of Computer Science.
|
||||
|
||||
% Provides compile time environment for fcompiling clpq/clpr
|
||||
|
||||
:- meta_predicate nfq:geler(?,:).
|
||||
:- meta_predicate nfr:geler(?,:).
|
||||
:- meta_predicate clpq:wait_linear(?,?,:).
|
||||
:- meta_predicate clpr:wait_linear(?,?,:).
|
||||
|
||||
%
|
||||
% Don't report export of private predicates from clpq
|
||||
%
|
||||
:- multifile
|
||||
user:portray_message/2.
|
||||
|
||||
:- dynamic
|
||||
user:portray_message/2.
|
||||
%
|
||||
user:portray_message( warning, import(_,_,From,private)) :-
|
||||
clpqr( From).
|
||||
|
||||
clpqr( clpq).
|
||||
clpqr( clpr).
|
||||
|
||||
env_fcompile( Name, Arith) :-
|
||||
compile_time_env( Name, Arith, Module),
|
||||
fcompile( Module:Name).
|
||||
|
||||
compile_time_env(File, Arith, Module) :-
|
||||
file_mod(Arith, File, Module),
|
||||
load_expansions(Module, Arith).
|
||||
|
||||
load_expansions(user, _).
|
||||
load_expansions(arith_q, _).
|
||||
load_expansions(arith_r, _).
|
||||
load_expansions(classq, _) :- [class]. % atts
|
||||
load_expansions(classr, _) :- [class]. % atts
|
||||
load_expansions(geler_q, _) :- [geler]. % atts
|
||||
load_expansions(geler_r, _) :- [geler]. % atts
|
||||
load_expansions(nfq, Arith) :-
|
||||
nfq:[Arith]. % macros
|
||||
load_expansions(nfr, Arith) :-
|
||||
nfr:[Arith]. % macros
|
||||
load_expansions(clpr, Arith) :-
|
||||
clpr:[Arith], % macros
|
||||
clpr:[itf3], % atts
|
||||
clpr:[store]. % macros
|
||||
load_expansions(clpq, Arith) :-
|
||||
clpq:[Arith], % macros
|
||||
clpq:[itf3], % atts
|
||||
clpq:[store]. % macros
|
||||
|
||||
file_mod(arith_q, arith, arith_q).
|
||||
file_mod(arith_r, arith, arith_r).
|
||||
file_mod(arith_q, arith_q, arith_q).
|
||||
file_mod(arith_r, arith_r, arith_r).
|
||||
file_mod(arith_q, bb, clpq).
|
||||
file_mod(arith_r, bb, clpr).
|
||||
file_mod(arith_q, bv, clpq).
|
||||
file_mod(arith_r, bv, clpr).
|
||||
file_mod(arith_q, class, classq).
|
||||
file_mod(arith_r, class, classr).
|
||||
file_mod(_, compenv, user).
|
||||
file_mod(arith_q, dump, clpq).
|
||||
file_mod(arith_r, dump, clpr).
|
||||
file_mod(arith_q, fourmotz, clpq).
|
||||
file_mod(arith_r, fourmotz, clpr).
|
||||
file_mod(arith_q, geler, geler_q).
|
||||
file_mod(arith_r, geler, geler_r).
|
||||
file_mod(arith_q, ineq, clpq).
|
||||
file_mod(arith_r, ineq, clpr).
|
||||
file_mod(arith_q, itf3, clpq).
|
||||
file_mod(arith_r, itf3, clpr).
|
||||
file_mod(arith_q, nf, nfq).
|
||||
file_mod(arith_r, nf, nfr).
|
||||
file_mod(arith_q, nfq, nfq).
|
||||
file_mod(arith_r, nfr, nfr).
|
||||
file_mod(arith_q, ordering, classq).
|
||||
file_mod(arith_r, ordering, classr).
|
||||
file_mod(arith_q, project, clpq).
|
||||
file_mod(arith_r, project, clpr).
|
||||
file_mod(arith_q, redund, clpq).
|
||||
file_mod(arith_r, redund, clpr).
|
||||
file_mod(arith_q, store, clpq).
|
||||
file_mod(arith_r, store, clpr).
|
||||
|
@ -1,147 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.3 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: dump.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
/*
|
||||
dump( +Target, ?NewVars, ?CodedAnswer)
|
||||
|
||||
where Target and NewVars are lists of variables of equal length and
|
||||
CodedAnswer is the term representation of the projection of constraints
|
||||
onto the target variables where the target variables are replaced by
|
||||
the corresponding variables from NewVars.
|
||||
*/
|
||||
|
||||
:- use_module( library(terms), [term_variables/2]).
|
||||
|
||||
:- use_module( library(assoc),
|
||||
[
|
||||
empty_assoc/1,
|
||||
get_assoc/3,
|
||||
put_assoc/4,
|
||||
assoc_to_list/2
|
||||
]).
|
||||
|
||||
dump( Target, NewVars, Constraints) :-
|
||||
(
|
||||
( proper_varlist( Target) ->
|
||||
true
|
||||
;
|
||||
raise_exception(instantiation_error(dump(Target,NewVars,Constraints),1))
|
||||
),
|
||||
ordering( Target),
|
||||
related_linear_vars( Target, All),
|
||||
nonlin_crux( All, Nonlin),
|
||||
project_attributes( Target, All),
|
||||
related_linear_vars( Target, Again), % project drops/adds vars
|
||||
all_attribute_goals( Again, Gs, Nonlin),
|
||||
empty_assoc( D0),
|
||||
mapping( Target, NewVars, D0,D1), % late (AVL suffers from put_atts)
|
||||
copy( Gs, Copy, D1,_), % strip constraints
|
||||
bb_put( copy, NewVars/Copy),
|
||||
fail % undo projection
|
||||
;
|
||||
bb_delete( copy, NewVars/Constraints) % garbage collect
|
||||
).
|
||||
|
||||
proper_varlist( X) :- var( X), !, fail.
|
||||
proper_varlist( []).
|
||||
proper_varlist( [X|Xs]) :-
|
||||
var( X),
|
||||
proper_varlist( Xs).
|
||||
|
||||
related_linear_vars( Vs, All) :-
|
||||
empty_assoc( S0),
|
||||
related_linear_sys( Vs, S0,Sys),
|
||||
related_linear_vars( Sys, All, []).
|
||||
|
||||
related_linear_sys( [], S0,L0) :- assoc_to_list( S0, L0).
|
||||
related_linear_sys( [V|Vs], S0,S2) :-
|
||||
( get_atts( V, class(C)) ->
|
||||
put_assoc( C, S0, C, S1)
|
||||
;
|
||||
S1 = S0
|
||||
),
|
||||
related_linear_sys( Vs, S1,S2).
|
||||
|
||||
related_linear_vars( []) --> [].
|
||||
related_linear_vars( [S-_|Ss]) -->
|
||||
{
|
||||
class_allvars( S, Otl)
|
||||
},
|
||||
cpvars( Otl),
|
||||
related_linear_vars( Ss).
|
||||
|
||||
cpvars( Xs) --> {var(Xs)}, !.
|
||||
cpvars( [X|Xs]) -->
|
||||
( {var(X)} -> [X] ; [] ),
|
||||
cpvars( Xs).
|
||||
|
||||
nonlin_crux( All, Gss) :-
|
||||
collect_nonlin( All, Gs, []), % destructive
|
||||
this_linear_solver( Solver),
|
||||
nonlin_strip( Gs, Solver, Gss).
|
||||
|
||||
nonlin_strip( [], _, []).
|
||||
nonlin_strip( [M:What|Gs], Solver, Res) :-
|
||||
( M == Solver ->
|
||||
( What = {G} ->
|
||||
Res = [G|Gss]
|
||||
;
|
||||
Res = [What|Gss]
|
||||
)
|
||||
;
|
||||
Res = Gss
|
||||
),
|
||||
nonlin_strip( Gs, Solver, Gss).
|
||||
|
||||
all_attribute_goals( []) --> [].
|
||||
all_attribute_goals( [V|Vs]) -->
|
||||
dump_linear( V, toplevel),
|
||||
dump_nonzero( V, toplevel),
|
||||
all_attribute_goals( Vs).
|
||||
|
||||
mapping( [], [], D0,D0).
|
||||
mapping( [T|Ts], [N|Ns], D0,D2) :-
|
||||
put_assoc( T, D0, N, D1),
|
||||
mapping( Ts, Ns, D1,D2).
|
||||
|
||||
copy( Term, Copy, D0,D1) :- var( Term),
|
||||
( get_assoc( Term, D0, New) ->
|
||||
Copy = New,
|
||||
D1 = D0
|
||||
;
|
||||
put_assoc( Term, D0, Copy, D1)
|
||||
).
|
||||
copy( Term, Copy, D0,D1) :- nonvar( Term),
|
||||
functor( Term, N, A),
|
||||
functor( Copy, N, A),
|
||||
copy( A, Term, Copy, D0,D1).
|
||||
|
||||
copy( 0, _, _, D0,D0) :- !.
|
||||
copy( 1, T, C, D0,D1) :- !,
|
||||
arg( 1, T, At1),
|
||||
arg( 1, C, Ac1),
|
||||
copy( At1, Ac1, D0,D1).
|
||||
copy( 2, T, C, D0,D2) :- !,
|
||||
arg( 1, T, At1),
|
||||
arg( 1, C, Ac1),
|
||||
copy( At1, Ac1, D0,D1),
|
||||
arg( 2, T, At2),
|
||||
arg( 2, C, Ac2),
|
||||
copy( At2, Ac2, D1,D2).
|
||||
copy( N, T, C, D0,D2) :-
|
||||
arg( N, T, At),
|
||||
arg( N, C, Ac),
|
||||
copy( At, Ac, D0,D1),
|
||||
N1 is N-1,
|
||||
copy( N1, T, C, D1,D2).
|
||||
|
||||
end_of_file.
|
@ -1,3 +0,0 @@
|
||||
The SESSION directory contains some recorded clp(q,r) sessions.
|
||||
They were primarily used for regression testing, but they can
|
||||
get you started on how to interact with the solver(s).
|
@ -1,66 +0,0 @@
|
||||
/tmp/clpr
|
||||
|
||||
yes
|
||||
| ?- use_module(library('clpqr/monash')).
|
||||
{compiling /freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl...}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql in module printf, 30 msec 27216 bytes}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql in module expand, 30 msec 26832 bytes}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl compiled, 100 msec 54848 bytes}
|
||||
|
||||
yes
|
||||
| ?- expand, [library('clpqr/examples/monash/air')], noexpand.
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/air...}
|
||||
{Warning: [T] - singleton variables in comp/3 in lines 27-28}
|
||||
{Warning: [X] - singleton variables in zero/1 in lines 38-40}
|
||||
{Warning: [T] - singleton variables in bal_side/3 in lines 45-50}
|
||||
{Warning: [X] - singleton variables in add_species/4 in lines 56-57}
|
||||
{Warning: [NUM] - singleton variables in add_elements/5 in lines 57-60}
|
||||
{Warning: [PROP,X] - singleton variables in add_elements/5 in lines 68-70}
|
||||
{Warning: [F1] - singleton variables in go/0 in lines 76-87}
|
||||
|
||||
>>> Sample goal: go/0
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/air consulted, 110 msec 10384 bytes}
|
||||
|
||||
yes
|
||||
| ?- go.
|
||||
species air
|
||||
molecule n2
|
||||
molecule o2
|
||||
atom o
|
||||
species fuel
|
||||
molecule c
|
||||
atom c
|
||||
species flue
|
||||
molecule co2
|
||||
atom c
|
||||
atom o
|
||||
molecule co
|
||||
atom c
|
||||
atom o
|
||||
molecule o2
|
||||
atom o
|
||||
molecule n2
|
||||
With base of 1.000000 mol of fuel
|
||||
air (just to burn the carbon) = 5.317460 mol
|
||||
flue (mol) :6.666667
|
||||
|
||||
species air
|
||||
molecule n2
|
||||
molecule o2
|
||||
atom o
|
||||
species fuel
|
||||
molecule c
|
||||
atom c
|
||||
species full_comb
|
||||
molecule co2
|
||||
atom c
|
||||
atom o
|
||||
molecule n2
|
||||
Compared with theoretical air (for complete combustion):
|
||||
4.761905 mol
|
||||
Excess = 11.666667%
|
||||
|
||||
yes
|
||||
| ?- ^D
|
@ -1,64 +0,0 @@
|
||||
/tmp/clpr
|
||||
|
||||
yes
|
||||
| ?- use_module(library('clpqr/monash')).
|
||||
{compiling /freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl...}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql in module printf, 30 msec 27216 bytes}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql in module expand, 40 msec 26832 bytes}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl compiled, 100 msec 54848 bytes}
|
||||
|
||||
yes
|
||||
| ?- expand, [library('clpqr/examples/monash/amplif')], noexpand.
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/amplif...}
|
||||
{Warning: [Collector_Currents] - singleton variables in dc_analysis/3 in lines 1-31}
|
||||
{Warning: [Type,Vc] - singleton variables in component_ss/6 in lines 70-75}
|
||||
{Warning: [V1,V2] - singleton variables in component_dc/7 in lines 89-90}
|
||||
{Warning: [Vbreak,Vreak] - singleton variables in component_dc/7 in lines 93-96}
|
||||
{Warning: [Vbreak] - singleton variables in diode_state/5 in lines 96-104}
|
||||
{Warning: [Beta] - singleton variables in transistor_state/7 in lines 122-127}
|
||||
{Warning: [Beta] - singleton variables in transistor_state/7 in lines 127-133}
|
||||
{Warning: [Beta,Vc,Vcesat] - singleton variables in transistor_state/7 in lines 133-139}
|
||||
{Warning: [Beta,Vc,Vcesat] - singleton variables in transistor_state/7 in lines 139-144}
|
||||
{Warning: [Points] - singleton variables in print_circuit/1 in lines 202-205}
|
||||
{Warning: [R1,R2,Rc,Re] - singleton variables in circuit/6 in lines 233-244}
|
||||
{Warning: [C1,C2,C3,R1,R2,Rc,Re] - singleton variables in circuit/6 in lines 244-255}
|
||||
{Warning: [C1,C3,R1,R2,Re] - singleton variables in circuit/6 in lines 255-264}
|
||||
{Warning: [St1,St2,St3,St4,State] - singleton variables in go1/0 in lines 264-274}
|
||||
|
||||
>>> Sample goals: go1/0, go2/0
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/amplif consulted, 360 msec 22640 bytes}
|
||||
|
||||
yes
|
||||
| ?- go1.
|
||||
cc1 at 15 [0.0,0.14400000000000002,0.0,-0.14400000000000002]
|
||||
cc2 at -12 [-0.114,0.114]
|
||||
gnd at 0 [0.0,-0.030000000000000013,0.030000000000000013]
|
||||
a at 0.6 [0.114,-0.14400000000000002,0.0,0.030000000000000013]
|
||||
p1 at 0 [0.114,-0.114]
|
||||
b at -0.6 [0.0,0.114,-0.114]
|
||||
c at 15 [0.0,0.0]
|
||||
diode at d1 [di1,forward]
|
||||
diode at d2 [di1,reverse]
|
||||
resistor at r1 100
|
||||
diode at d3 [di1,forward]
|
||||
diode at d4 [di1,forward]
|
||||
resistor at r2 100
|
||||
transistor at tr [npn,tr0,cutoff]
|
||||
resistor at rc 100
|
||||
|
||||
yes
|
||||
| ?- go2.
|
||||
Stab 0.0019465
|
||||
Outresist 0.85711
|
||||
capacitor at c1 _1483
|
||||
resistor at r1 100
|
||||
resistor at r2 100
|
||||
transistor at tr [npn,tr0,active]
|
||||
resistor at re 100
|
||||
capacitor at c3 _1405
|
||||
[[capacitor,c1,_1483,[in,b]],[resistor,r1,100.0,[b,cc1]],[resistor,r2,100.0,[b,gnd]],[transistor,tr,[npn,tr0,active],[b,cc1,e]],[resistor,re,100.0,[e,gnd]],[capacitor,c3,_1405,[e,out]]]
|
||||
|
||||
yes
|
||||
| ?- ^D
|
@ -1,27 +0,0 @@
|
||||
/tmp/clpr
|
||||
|
||||
yes
|
||||
| ?- use_module(library('clpqr/monash')).
|
||||
{compiling /freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl...}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql in module printf, 50 msec 27216 bytes}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql in module expand, 50 msec 26832 bytes}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl compiled, 130 msec 54848 bytes}
|
||||
|
||||
yes
|
||||
| ?- expand, [library('clpqr/examples/monash/complex')], noexpand.
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/complex...}
|
||||
|
||||
>>> Sample goal: go/0
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/complex consulted, 30 msec 1760 bytes}
|
||||
|
||||
yes
|
||||
| ?- go.
|
||||
|
||||
[32,88,32,61,32]c(1.0,1.0)
|
||||
[32,89,32,61,32]c(2.0,2.0)
|
||||
[32,90,32,61,32]c(0.0,4.0)
|
||||
|
||||
yes
|
||||
| ?- ^D
|
@ -1,138 +0,0 @@
|
||||
/tmp/clpr
|
||||
|
||||
yes
|
||||
| ?- use_module(library('clpqr/monash')).
|
||||
{compiling /freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl...}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql in module printf, 30 msec 27216 bytes}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql in module expand, 40 msec 26832 bytes}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl compiled, 120 msec 54848 bytes}
|
||||
|
||||
yes
|
||||
| ?- expand, [library('clpqr/examples/monash/critical')], noexpand.
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/critical...}
|
||||
{Warning: [End] - singleton variables in cpm/2 in lines 62-67}
|
||||
{Warning: [Es,From,Lc,T] - singleton variables in buildv/3 in lines 81-83}
|
||||
{Warning: [H] - singleton variables in buildv/3 in lines 83-85}
|
||||
{Warning: [Es,Lc,T,To] - singleton variables in buildv/3 in lines 85-87}
|
||||
{Warning: [H] - singleton variables in buildv/3 in lines 87-89}
|
||||
{Warning: [H] - singleton variables in addedg/3 in lines 91-93}
|
||||
{Warning: [T] - singleton variables in addedg/3 in lines 93-94}
|
||||
{Warning: [H] - singleton variables in addedg/3 in lines 94-96}
|
||||
{Warning: [I] - singleton variables in early_late/4 in lines 102-106}
|
||||
{Warning: [I] - singleton variables in early_late/3 in lines 108-112}
|
||||
{Warning: [End] - singleton variables in setearly/5 in lines 118-121}
|
||||
{Warning: [Last] - singleton variables in setlate/4 in lines 128-131}
|
||||
{Warning: [T] - singleton variables in getnode/4 in lines 136-139}
|
||||
{Warning: [H] - singleton variables in getnode/4 in lines 139-141}
|
||||
{Warning: [G] - singleton variables in analyse/2 in lines 141-148}
|
||||
{Warning: [I] - singleton variables in analyse/2 in lines 148-151}
|
||||
{Warning: [Lci] - singleton variables in compute/9 in lines 157-166}
|
||||
{Warning: [From] - singleton variables in print_node/1 in lines 176-180}
|
||||
{Warning: [From] - singleton variables in print_node/1 in lines 186-191}
|
||||
|
||||
>>> Sample goals: go1/0, go2/0, go3/0
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/critical consulted, 330 msec 16368 bytes}
|
||||
|
||||
yes
|
||||
| ?- go1.
|
||||
Node Es Lc
|
||||
Node1 Node2 T Ls Ec Tf Ff
|
||||
--------------------------------------------------
|
||||
START NODE n1 0 0
|
||||
--------------------------------------------------
|
||||
n1 n2 3 2 3 2 0
|
||||
n1 n3 2 0 2 0 0 *
|
||||
--------------------------------------------------
|
||||
n2 3 5
|
||||
--------------------------------------------------
|
||||
n2 n4 2 5 5 2 2
|
||||
--------------------------------------------------
|
||||
n3 2 2
|
||||
--------------------------------------------------
|
||||
n3 n4 5 2 7 0 0 *
|
||||
--------------------------------------------------
|
||||
END NODE n4 7 7
|
||||
|
||||
yes
|
||||
| ?- go2.
|
||||
Node Es Lc
|
||||
Node1 Node2 T Ls Ec Tf Ff
|
||||
--------------------------------------------------
|
||||
n5 8 8
|
||||
--------------------------------------------------
|
||||
n5 n6 9 8 17 0 0 *
|
||||
n5 n7 5 12 13 4 4
|
||||
--------------------------------------------------
|
||||
n6 17 17
|
||||
--------------------------------------------------
|
||||
n6 n7 0 17 17 0 0 *
|
||||
n6 n8 4 19 21 2 2
|
||||
--------------------------------------------------
|
||||
n7 17 17
|
||||
--------------------------------------------------
|
||||
n7 n8 6 17 23 0 0 *
|
||||
--------------------------------------------------
|
||||
n4 3 8
|
||||
--------------------------------------------------
|
||||
n4 n7 4 13 7 10 10
|
||||
n4 n5 0 8 3 5 5
|
||||
n4 n8 3 20 6 17 17
|
||||
--------------------------------------------------
|
||||
START NODE n1 0 0
|
||||
--------------------------------------------------
|
||||
n1 n2 2 4 2 4 0
|
||||
n1 n3 6 0 6 0 0 *
|
||||
n1 n4 3 5 3 5 0
|
||||
--------------------------------------------------
|
||||
n2 2 6
|
||||
--------------------------------------------------
|
||||
n2 n3 0 6 2 4 4
|
||||
n2 n5 1 7 3 5 5
|
||||
n2 n6 4 13 6 11 11
|
||||
--------------------------------------------------
|
||||
n3 6 6
|
||||
--------------------------------------------------
|
||||
n3 n5 2 6 8 0 0 *
|
||||
--------------------------------------------------
|
||||
END NODE n8 23 23
|
||||
|
||||
yes
|
||||
| ?- go3.
|
||||
Node Es Lc
|
||||
Node1 Node2 T Ls Ec Tf Ff
|
||||
--------------------------------------------------
|
||||
START NODE n1 0 0
|
||||
--------------------------------------------------
|
||||
n1 n2 4 0 4 0 0 *
|
||||
n1 n3 3 4 3 4 2
|
||||
n1 n4 4 6 4 6 0
|
||||
--------------------------------------------------
|
||||
n2 4 4
|
||||
--------------------------------------------------
|
||||
n2 n5 7 4 11 0 0 *
|
||||
n2 n3 1 6 5 2 0
|
||||
n2 n7 8 8 12 4 4
|
||||
--------------------------------------------------
|
||||
n3 5 7
|
||||
--------------------------------------------------
|
||||
n3 n5 4 7 9 2 2
|
||||
--------------------------------------------------
|
||||
n4 4 10
|
||||
--------------------------------------------------
|
||||
n4 n6 2 10 6 6 6
|
||||
--------------------------------------------------
|
||||
n5 11 11
|
||||
--------------------------------------------------
|
||||
n5 n6 1 11 12 0 0 *
|
||||
n5 n7 3 13 14 2 2
|
||||
--------------------------------------------------
|
||||
END NODE n7 16 16
|
||||
--------------------------------------------------
|
||||
n6 12 12
|
||||
--------------------------------------------------
|
||||
n6 n7 4 12 16 0 0 *
|
||||
|
||||
yes
|
||||
| ?- ^D
|
@ -1,25 +0,0 @@
|
||||
/tmp/clpr
|
||||
|
||||
yes
|
||||
| ?- use_module(library('clpqr/monash')).
|
||||
{compiling /freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl...}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql in module printf, 30 msec 27216 bytes}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql in module expand, 30 msec 26832 bytes}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl compiled, 100 msec 54848 bytes}
|
||||
|
||||
yes
|
||||
| ?- expand, [library('clpqr/examples/monash/fib')], noexpand.
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/fib...}
|
||||
|
||||
>>> Sample goal: go/0
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/fib consulted, 10 msec 1664 bytes}
|
||||
|
||||
yes
|
||||
| ?- go.
|
||||
forward: fib(10) = 89
|
||||
backward: fib(10) = 89
|
||||
|
||||
yes
|
||||
| ?- ^D
|
@ -1,29 +0,0 @@
|
||||
/tmp/clpr
|
||||
|
||||
yes
|
||||
| ?- use_module(library('clpqr/monash')).
|
||||
{compiling /freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl...}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql in module printf, 40 msec 27216 bytes}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql in module expand, 50 msec 26832 bytes}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl compiled, 150 msec 54848 bytes}
|
||||
|
||||
yes
|
||||
| ?- expand, [library('clpqr/examples/monash/findroot')], noexpand.
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/findroot...}
|
||||
|
||||
>>> Sample goal: go/0
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/findroot consulted, 30 msec 4528 bytes}
|
||||
|
||||
yes
|
||||
| ?- go.
|
||||
1.70000000
|
||||
0.44834437
|
||||
0.91953538
|
||||
0.99701354
|
||||
0.99999555
|
||||
1.00000000
|
||||
|
||||
yes
|
||||
| ?- ^D
|
@ -1,35 +0,0 @@
|
||||
/tmp/clpr
|
||||
|
||||
yes
|
||||
| ?- use_module(library('clpqr/monash')).
|
||||
{compiling /freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl...}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql in module printf, 40 msec 27216 bytes}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql in module expand, 40 msec 26832 bytes}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl compiled, 120 msec 54848 bytes}
|
||||
|
||||
yes
|
||||
| ?- expand, [library('clpqr/examples/monash/invert')], noexpand.
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/invert...}
|
||||
{Warning: [C] - singleton variables in allvec/2 in lines 21-23}
|
||||
{Warning: [H] - singleton variables in mylength/2 in lines 27-28}
|
||||
{Warning: [H] - singleton variables in mylength/2 in lines 28-31}
|
||||
{Warning: [A] - singleton variables in rowtocol/2 in lines 50-51}
|
||||
|
||||
>>> Sample goal: go/0
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/invert consulted, 100 msec 8288 bytes}
|
||||
|
||||
yes
|
||||
| ?- go.
|
||||
NR =
|
||||
0.2917 0.0417 -0.2083
|
||||
-0.0833 0.4167 -0.0833
|
||||
0.0417 -0.3750 0.2083
|
||||
T =
|
||||
1.0000 0.0000 0.0000
|
||||
0.0000 1.0000 0.0000
|
||||
0.0000 0.0000 1.0000
|
||||
|
||||
yes
|
||||
| ?- ^D
|
@ -1,53 +0,0 @@
|
||||
/tmp/clpr
|
||||
|
||||
yes
|
||||
| ?- use_module(library('clpqr/monash')).
|
||||
{compiling /freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl...}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql in module printf, 40 msec 27216 bytes}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql in module expand, 40 msec 26832 bytes}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl compiled, 100 msec 54848 bytes}
|
||||
|
||||
yes
|
||||
| ?- expand, [library('clpqr/examples/monash/laplace')], noexpand.
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/laplace...}
|
||||
{Warning: [BL,TL] - singleton variables in laplace_vec/3 in lines 24-28}
|
||||
{Warning: [B11,B12,B13,B14,B21,B24,B31,B34,B42,B43,M22,M23,M32,M33] - singleton variables in go2/0 in lines 58-81}
|
||||
|
||||
>>> Sample goals: go1/0, go2/0
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/laplace consulted, 100 msec 7408 bytes}
|
||||
|
||||
yes
|
||||
| ?- go1.
|
||||
|
||||
0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
|
||||
100.00 51.11 32.52 24.56 21.11 20.12 21.11 24.56 32.52 51.11 100.00
|
||||
100.00 71.91 54.41 44.63 39.74 38.26 39.74 44.63 54.41 71.91 100.00
|
||||
100.00 82.12 68.59 59.80 54.97 53.44 54.97 59.80 68.59 82.12 100.00
|
||||
100.00 87.97 78.03 71.00 66.90 65.56 66.90 71.00 78.03 87.97 100.00
|
||||
100.00 91.71 84.58 79.28 76.07 75.00 76.07 79.28 84.58 91.71 100.00
|
||||
100.00 94.30 89.29 85.47 83.10 82.30 83.10 85.47 89.29 94.30 100.00
|
||||
100.00 96.20 92.82 90.20 88.56 88.00 88.56 90.20 92.82 96.20 100.00
|
||||
100.00 97.67 95.59 93.96 92.93 92.58 92.93 93.96 95.59 97.67 100.00
|
||||
100.00 98.89 97.90 97.12 96.63 96.46 96.63 97.12 97.90 98.89 100.00
|
||||
100.00 100.00 100.00 100.00 100.00 100.00 100.00 100.00 100.00 100.00 100.00
|
||||
|
||||
yes
|
||||
| ?- go2.
|
||||
|
||||
yes
|
||||
| ?- laplace([
|
||||
[B11, B12, B13, B14],
|
||||
[B21, M22, M23, B24],
|
||||
[B31, M32, M33, B34],
|
||||
[B44, B42, B43, B44]
|
||||
]).
|
||||
|
||||
{M32= -(B12)-B21+4.0*M22-M23},
|
||||
{M33= -(M22)+4.0*M23-B13-B24},
|
||||
{B42= -4.0*B12-4.0*B21+16.0*M22-8.0*M23+B13+B24-B31},
|
||||
{B43=B12+B21-8.0*M22+16.0*M23-4.0*B13-4.0*B24-B34} ?
|
||||
|
||||
yes
|
||||
| ?- ^D
|
@ -1,46 +0,0 @@
|
||||
/tmp/clpr
|
||||
|
||||
yes
|
||||
| ?- use_module(library('clpqr/monash')).
|
||||
{compiling /freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl...}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql in module printf, 40 msec 27216 bytes}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql in module expand, 30 msec 26832 bytes}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl compiled, 130 msec 54848 bytes}
|
||||
|
||||
yes
|
||||
| ?- expand, [library('clpqr/examples/monash/mortgage')], noexpand.
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/mortgage...}
|
||||
{Warning: [Int] - singleton variables in go4/0 in lines 45-51}
|
||||
|
||||
>>> Sample goals: go1/0, go2/0, go3/0, go4/0
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/mortgage consulted, 40 msec 4992 bytes}
|
||||
|
||||
yes
|
||||
| ?- go1.
|
||||
Forward: MP = 1721.65
|
||||
Backward: P = 120000
|
||||
|
||||
yes
|
||||
| ?- go2.
|
||||
|
||||
yes
|
||||
| ?- mg(P,120,0.01,0,MP), dump([P,MP]).
|
||||
|
||||
{P=69.7005220313972*MP} ?
|
||||
|
||||
yes
|
||||
| ?- mg(P,120,0.01,B,MP), dump([P,B,MP]).
|
||||
|
||||
{P=0.30299477968602706*B+69.7005220313972*MP} ?
|
||||
|
||||
yes
|
||||
| ?- mg(999, 3, Int, 0, 400), dump.
|
||||
|
||||
nonlin:{_B-_B*Int+_A+400.0=0.0},
|
||||
nonlin:{_A-_A*Int+400.0=0.0},
|
||||
{_B=599.0+999.0*Int} ?
|
||||
|
||||
yes
|
||||
| ?- ^D
|
@ -1,76 +0,0 @@
|
||||
/tmp/clpr
|
||||
|
||||
yes
|
||||
| ?- use_module(library('clpqr/monash')).
|
||||
{compiling /freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl...}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql in module printf, 40 msec 27216 bytes}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql in module expand, 40 msec 26832 bytes}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl compiled, 130 msec 54848 bytes}
|
||||
|
||||
yes
|
||||
| ?- expand, [library('clpqr/examples/monash/option')], noexpand.
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/option...}
|
||||
{Warning: [B,C,P,X] - singleton variables in table/13 in lines 47-54}
|
||||
{Warning: [B,P,S] - singleton variables in table/13 in lines 54-55}
|
||||
{Warning: [B,C,S] - singleton variables in table/13 in lines 55-56}
|
||||
{Warning: [C,P,S,X] - singleton variables in table/13 in lines 56-57}
|
||||
|
||||
>>> Sample goals (some with multiple answers):
|
||||
go1(W), go2(S, W), go3(S, W), go4(S, W), go5(S, W)
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/option consulted, 160 msec 10032 bytes}
|
||||
|
||||
yes
|
||||
| ?- go1(W).
|
||||
|
||||
W = -4.75 ? ;
|
||||
|
||||
no
|
||||
| ?- go2(S,W).
|
||||
|
||||
W = 5.25,
|
||||
{S>=0.0},
|
||||
{S<50.0} ? ;
|
||||
|
||||
{W>5.0},
|
||||
{S=55.25-W},
|
||||
{W=<5.25} ? ;
|
||||
|
||||
no
|
||||
| ?- go3(S,W).
|
||||
|
||||
{W>=10.0},
|
||||
{S=37.4-W},
|
||||
{W=<37.4} ? ;
|
||||
|
||||
{W>=10.0},
|
||||
{S=62.6+W} ? ;
|
||||
|
||||
no
|
||||
| ?- go4(S,W).
|
||||
|
||||
W = 5.699999999999999,
|
||||
{S>=0.0},
|
||||
{S<20.0} ? ;
|
||||
|
||||
{S>=20.0},
|
||||
{S<40.0},
|
||||
{W=25.7-S} ? ;
|
||||
|
||||
W = -14.3,
|
||||
{S>=40.0},
|
||||
{S<60.0} ? ;
|
||||
|
||||
{S>=60.0},
|
||||
{S<80.0},
|
||||
{W= -74.3+S} ? ;
|
||||
|
||||
W = 5.699999999999999,
|
||||
{S>=80.0} ? ;
|
||||
|
||||
no
|
||||
| ?- go5(S,W).
|
||||
|
||||
no
|
||||
| ?- ^D
|
@ -1,64 +0,0 @@
|
||||
/tmp/clpr
|
||||
|
||||
yes
|
||||
| ?- use_module(library('clpqr/monash')).
|
||||
{compiling /freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl...}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql in module printf, 30 msec 27216 bytes}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql in module expand, 40 msec 26832 bytes}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl compiled, 120 msec 54848 bytes}
|
||||
|
||||
yes
|
||||
| ?- expand, [library('clpqr/examples/monash/pictures')], noexpand.
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/pictures...}
|
||||
{Warning: [DotDashInvis,Text] - singleton variables in box/3 in lines 66-73}
|
||||
|
||||
>>> Sample goals: go1/0, go2/0
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/pictures consulted, 110 msec 12768 bytes}
|
||||
|
||||
yes
|
||||
| ?- go1.
|
||||
.PS 2i
|
||||
line from 3.2,1.8 to 0.688979,1.17224
|
||||
line from 0.688979,1.17224 to 2.30239,4.19362
|
||||
line from 2.30239,4.19362 to 3.2,1.8
|
||||
line from 0,1 to 4,2 dashed
|
||||
line from 3.5,1 to 2,5 dashed
|
||||
line from 0.33,0.5 to 3,5.5 dashed
|
||||
" c1 " at 0,1 rjust
|
||||
" c2 " at 3.5,1 rjust
|
||||
" c3 " at 0.33,0.5 rjust
|
||||
.PE
|
||||
|
||||
yes
|
||||
| ?- go2.
|
||||
.PS 3i
|
||||
line from 0,0 to 8,10
|
||||
line from 8,10 to 10,10
|
||||
line from 10,10 to 10,1
|
||||
line from 10,1 to 0,0
|
||||
line from 4,5 to 9,10 dashed
|
||||
line from 9,10 to 10,5.5 dashed
|
||||
line from 10,5.5 to 5,0.5 dashed
|
||||
line from 5,0.5 to 4,5 dashed
|
||||
line from 0,20 to 0,15
|
||||
line from 0,15 to 10,15
|
||||
line from 10,15 to 10,20
|
||||
line from 10,20 to 0,20
|
||||
line from 0,17.5 to 5,15 dashed
|
||||
line from 5,15 to 10,17.5 dashed
|
||||
line from 10,17.5 to 5,20 dashed
|
||||
line from 5,20 to 0,17.5 dashed
|
||||
line from 5,30 to 10,23
|
||||
line from 10,23 to 15,30
|
||||
line from 15,30 to 10,25
|
||||
line from 10,25 to 5,30
|
||||
line from 7.5,26.5 to 12.5,26.5 dashed
|
||||
line from 12.5,26.5 to 12.5,27.5 dashed
|
||||
line from 12.5,27.5 to 7.5,27.5 dashed
|
||||
line from 7.5,27.5 to 7.5,26.5 dashed
|
||||
.PE
|
||||
|
||||
yes
|
||||
| ?- ^D
|
@ -1,55 +0,0 @@
|
||||
/tmp/clpr
|
||||
|
||||
yes
|
||||
| ?- use_module(library('clpqr/monash')).
|
||||
{compiling /freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl...}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql in module printf, 30 msec 27216 bytes}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql in module expand, 40 msec 26832 bytes}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl compiled, 110 msec 54848 bytes}
|
||||
|
||||
yes
|
||||
| ?- expand, [library('clpqr/examples/monash/rkf45')], noexpand.
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/rkf45...}
|
||||
{Warning: [Abserr,Incr,Mode,T,Tend,Y] - singleton variables in solve1/2 in lines 77-81}
|
||||
{Warning: [Incr,Mode,Relerr,T,Tend,Y] - singleton variables in solve1/2 in lines 87-90}
|
||||
{Warning: [Mode] - singleton variables in solve1/2 in lines 95-102}
|
||||
{Warning: [Hmode,Out] - singleton variables in iter1/2 in lines 141-148}
|
||||
{Warning: [Hmode,Out] - singleton variables in stop_or_iter1/5 in lines 153-157}
|
||||
{Warning: [Sum] - singleton variables in stop_or_iter1/5 in lines 157-163}
|
||||
{Warning: [Y,Yp] - singleton variables in stop_or_iter1/5 in lines 163-171}
|
||||
{Warning: [Out] - singleton variables in check_h/2 in lines 191-194}
|
||||
{Warning: [Work] - singleton variables in check_out/3 in lines 204-209}
|
||||
{Warning: [Relerr] - singleton variables in check_out/3 in lines 209-215}
|
||||
{Warning: [Kop] - singleton variables in check_out/3 in lines 231-235}
|
||||
{Warning: [Other] - singleton variables in check_out/3 in lines 244-246}
|
||||
{Warning: [Yp] - singleton variables in set_maxtol/6 in lines 289-293}
|
||||
{Warning: [H] - singleton variables in set_h1/5 in lines 298-305}
|
||||
{Warning: [S,Y,Yp] - singleton variables in check_err/11 in lines 453-456}
|
||||
{Warning: [S,Y] - singleton variables in check_err/11 in lines 456-462}
|
||||
{Warning: [T] - singleton variables in eval/3 in lines 473-478}
|
||||
{Warning: [Y3,Y4] - singleton variables in user_output/2 in lines 478-481}
|
||||
{Warning: [Abs,H,Incr,Kop,Nfe,Rer,T,Tend,Tout,Y,Yp] - singleton variables in user_error/3 in lines 481-485}
|
||||
{Warning: [Abs,H,Incr,Kop,Nfe,Rer,T,Tend,Tout,Y,Yp] - singleton variables in user_error/3 in lines 485-489}
|
||||
{Warning: [Abs,H,Incr,Kop,Nfe,Rer,T,Tend,Tout,Y,Yp] - singleton variables in user_error/3 in lines 489-493}
|
||||
|
||||
>>> Sample goal: go/0
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/rkf45 consulted, 590 msec 41376 bytes}
|
||||
|
||||
yes
|
||||
| ?- go.
|
||||
Point 0.00000 : 0.75000 0.00000
|
||||
Point 0.50000 : 0.61969 0.47793
|
||||
Point 1.00000 : 0.29417 0.81233
|
||||
Point 1.50000 : -0.10556 0.95809
|
||||
Point 2.00000 : -0.49076 0.93977
|
||||
Point 2.50000 : -0.81440 0.79929
|
||||
Point 3.00000 : -1.05440 0.57522
|
||||
|
||||
Iteration finished
|
||||
------------------
|
||||
439 derivative evaluations
|
||||
|
||||
yes
|
||||
| ?- ^D
|
@ -1,160 +0,0 @@
|
||||
/tmp/clpr
|
||||
|
||||
yes
|
||||
| ?- use_module(library('clpqr/monash')).
|
||||
{compiling /freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl...}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql in module printf, 50 msec 27216 bytes}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql in module expand, 40 msec 26832 bytes}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl compiled, 110 msec 54848 bytes}
|
||||
|
||||
yes
|
||||
| ?- expand, [library('clpqr/examples/monash/rlc')], noexpand.
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/rlc...}
|
||||
{Warning: [Comp,Num,X] - singleton variables in get_node_vars/2 in lines 22-26}
|
||||
{Warning: [V] - singleton variables in insert/3 in lines 36-37}
|
||||
{Warning: [W] - singleton variables in solve/5 in lines 43-47}
|
||||
{Warning: [N,V] - singleton variables in zero_currents/1 in lines 47-52}
|
||||
{Warning: [Vs] - singleton variables in ground_nodes/2 in lines 69-70}
|
||||
{Warning: [I,Vs] - singleton variables in ground_node/2 in lines 70-71}
|
||||
{Warning: [I,N1,V] - singleton variables in ground_node/2 in lines 71-72}
|
||||
{Warning: [W] - singleton variables in iv_reln/5 in lines 85-89}
|
||||
{Warning: [I,W] - singleton variables in iv_reln/5 in lines 89-89}
|
||||
{Warning: [V,W] - singleton variables in iv_reln/5 in lines 89-90}
|
||||
{Warning: [I,L,W] - singleton variables in iv_reln/5 in lines 95-96}
|
||||
{Warning: [L,V,W] - singleton variables in iv_reln/5 in lines 96-97}
|
||||
{Warning: [W] - singleton variables in iv_reln/5 in lines 97-98}
|
||||
{Warning: [I4,NV4,W] - singleton variables in addcomp/5 in lines 111-127}
|
||||
{Warning: [W] - singleton variables in addcomp/5 in lines 129-145}
|
||||
{Warning: [L2,X,Y] - singleton variables in subst/4 in lines 150-152}
|
||||
{Warning: [Im] - singleton variables in c_real/2 in lines 169-171}
|
||||
{Warning: [Re] - singleton variables in c_imag/2 in lines 171-173}
|
||||
{Warning: [Ls] - singleton variables in selective_print/2 in lines 190-191}
|
||||
{Warning: [Comp,Nodes,Num,X] - singleton variables in print_nodes/3 in lines 198-200}
|
||||
{Warning: [Heading_flag,N1] - singleton variables in print_nodes/3 in lines 200-201}
|
||||
{Warning: [Comp,Nodes,Num,X] - singleton variables in print_comps/2 in lines 205-207}
|
||||
{Warning: [Num] - singleton variables in print_comps/2 in lines 207-208}
|
||||
{Warning: [N,X] - singleton variables in heading/2 in lines 212-213}
|
||||
{Warning: [I,Ls,V] - singleton variables in member/2 in lines 213-215}
|
||||
{Warning: [I,N2,V] - singleton variables in member/2 in lines 215-217}
|
||||
{Warning: [R3,W] - singleton variables in go2/0 in lines 285-359}
|
||||
|
||||
>>> Sample goals: go1/0, go2/0
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/rlc consulted, 410 msec 26416 bytes}
|
||||
|
||||
yes
|
||||
| ?- go1.
|
||||
resistor r1: 10 Ohms
|
||||
Node n1
|
||||
Voltage c(10.0,0.0)
|
||||
Current c(0.5524861878453038,-0.4972375690607733)
|
||||
Node n2
|
||||
Voltage c(4.475138121546962,4.972375690607734)
|
||||
Current c(-0.5524861878453038,0.4972375690607733)
|
||||
|
||||
resistor r3: 10 Ohms
|
||||
Node n1
|
||||
Voltage c(10.0,0.0)
|
||||
Current c(0.5524861878453038,-0.49723756906077343)
|
||||
Node n4
|
||||
Voltage c(4.475138121546961,4.972375690607734)
|
||||
Current c(-0.5524861878453038,0.49723756906077343)
|
||||
|
||||
inductor l1: 0.9 Henrys
|
||||
Node n2
|
||||
Voltage c(4.475138121546962,4.972375690607734)
|
||||
Current c(0.5524861878453038,-0.49723756906077354)
|
||||
Node n7
|
||||
Voltage c(0.0,0.0)
|
||||
Current c(-0.5524861878453038,0.49723756906077354)
|
||||
|
||||
inductor l3: 0.9 Henrys
|
||||
Node n4
|
||||
Voltage c(4.475138121546961,4.972375690607734)
|
||||
Current c(0.5524861878453039,-0.49723756906077354)
|
||||
Node n7
|
||||
Voltage c(0.0,0.0)
|
||||
Current c(-0.5524861878453039,0.49723756906077354)
|
||||
|
||||
capacitor c8: 0.007 Farads
|
||||
Node n4
|
||||
Voltage c(4.475138121546961,4.972375690607734)
|
||||
Current c(0.0,0.0)
|
||||
Node n5
|
||||
Voltage c(4.475138121546961,4.972375690607735)
|
||||
Current c(0.0,0.0)
|
||||
|
||||
inductor l5: 0.9 Henrys
|
||||
Node n6
|
||||
Voltage c(4.475138121546961,4.972375690607736)
|
||||
Current c(0.5524861878453039,-0.49723756906077343)
|
||||
Node n7
|
||||
Voltage c(0.0,0.0)
|
||||
Current c(-0.5524861878453039,0.49723756906077343)
|
||||
|
||||
|
||||
yes
|
||||
| ?- go2.
|
||||
|
||||
COMPONENT CONNECTIONS TO NODE n4
|
||||
transistor q1: type bc108 (base, emitter, collector)
|
||||
Node base
|
||||
Voltage c(1.9092219020172907,0.0)
|
||||
Current c(9.005763688760816e-05,0.0)
|
||||
Node n3
|
||||
Voltage c(1.8191642651296822,0.0)
|
||||
Current c(-0.009095821325648411,0.0)
|
||||
Node n4
|
||||
Voltage c(-0.010742461656573443,0.0)
|
||||
Current c(0.009005763688760804,0.0)
|
||||
|
||||
resistor r3: 200 Ohms
|
||||
Node n4
|
||||
Voltage c(-0.010742461656573443,0.0)
|
||||
Current c(-5.3712308282867614e-05,0.0)
|
||||
Node ground2
|
||||
Voltage c(0.0,0.0)
|
||||
Current c(5.3712308282867614e-05,0.0)
|
||||
|
||||
transformer t2: ratio of 0.2
|
||||
Node n4
|
||||
Voltage c(-0.010742461656573443,0.0)
|
||||
Current c(-0.008952051380477936,0.0)
|
||||
Node ground2
|
||||
Voltage c(0.0,0.0)
|
||||
Current c(0.008952051380477936,0.0)
|
||||
Node out
|
||||
Voltage c(-0.05371230828286761,0.0)
|
||||
Current c(0.001790410276095587,0.0)
|
||||
Node ground3
|
||||
Voltage c(0.0,0.0)
|
||||
Current c(-0.001790410276095587,0.0)
|
||||
|
||||
|
||||
COMPONENT CONNECTIONS TO NODE out
|
||||
transformer t2: ratio of 0.2
|
||||
Node n4
|
||||
Voltage c(-0.010742461656573443,0.0)
|
||||
Current c(-0.008952051380477936,0.0)
|
||||
Node ground2
|
||||
Voltage c(0.0,0.0)
|
||||
Current c(0.008952051380477936,0.0)
|
||||
Node out
|
||||
Voltage c(-0.05371230828286761,0.0)
|
||||
Current c(0.001790410276095587,0.0)
|
||||
Node ground3
|
||||
Voltage c(0.0,0.0)
|
||||
Current c(-0.001790410276095587,0.0)
|
||||
|
||||
resistor r5: 30 Ohms
|
||||
Node out
|
||||
Voltage c(-0.05371230828286761,0.0)
|
||||
Current c(-0.001790410276095587,0.0)
|
||||
Node ground3
|
||||
Voltage c(0.0,0.0)
|
||||
Current c(0.001790410276095587,0.0)
|
||||
|
||||
|
||||
yes
|
||||
| ?- ^D
|
@ -1,51 +0,0 @@
|
||||
/tmp/clpr
|
||||
|
||||
yes
|
||||
| ?- use_module(library('clpqr/monash')).
|
||||
{compiling /freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl...}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql in module printf, 40 msec 27216 bytes}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql in module expand, 30 msec 26832 bytes}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl compiled, 110 msec 54848 bytes}
|
||||
|
||||
yes
|
||||
| ?- expand, [library('clpqr/examples/monash/smm')], noexpand.
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/smm...}
|
||||
{Warning: [X] - singleton variables in notmem/2 in lines 61-62}
|
||||
|
||||
>>> Sample goal: go/0
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/smm consulted, 70 msec 8976 bytes}
|
||||
|
||||
yes
|
||||
| ?- go.
|
||||
S = 9, E = 8, N = 9, D = 9, M = 1, O = 0, R = 8, Y = 7
|
||||
S = 9, E = 8, N = 9, D = 8, M = 1, O = 0, R = 8, Y = 6
|
||||
S = 9, E = 8, N = 9, D = 7, M = 1, O = 0, R = 8, Y = 5
|
||||
S = 9, E = 8, N = 9, D = 6, M = 1, O = 0, R = 8, Y = 4
|
||||
S = 9, E = 8, N = 9, D = 5, M = 1, O = 0, R = 8, Y = 3
|
||||
S = 9, E = 8, N = 9, D = 4, M = 1, O = 0, R = 8, Y = 2
|
||||
S = 9, E = 8, N = 9, D = 3, M = 1, O = 0, R = 8, Y = 1
|
||||
S = 9, E = 8, N = 9, D = 2, M = 1, O = 0, R = 8, Y = 0
|
||||
S = 9, E = 7, N = 8, D = 9, M = 1, O = 0, R = 8, Y = 6
|
||||
S = 9, E = 7, N = 8, D = 8, M = 1, O = 0, R = 8, Y = 5
|
||||
S = 9, E = 7, N = 8, D = 7, M = 1, O = 0, R = 8, Y = 4
|
||||
S = 9, E = 7, N = 8, D = 6, M = 1, O = 0, R = 8, Y = 3
|
||||
S = 9, E = 7, N = 8, D = 5, M = 1, O = 0, R = 8, Y = 2
|
||||
S = 9, E = 7, N = 8, D = 4, M = 1, O = 0, R = 8, Y = 1
|
||||
S = 9, E = 7, N = 8, D = 3, M = 1, O = 0, R = 8, Y = 0
|
||||
S = 9, E = 6, N = 7, D = 9, M = 1, O = 0, R = 8, Y = 5
|
||||
S = 9, E = 6, N = 7, D = 8, M = 1, O = 0, R = 8, Y = 4
|
||||
S = 9, E = 6, N = 7, D = 7, M = 1, O = 0, R = 8, Y = 3
|
||||
S = 9, E = 6, N = 7, D = 6, M = 1, O = 0, R = 8, Y = 2
|
||||
S = 9, E = 6, N = 7, D = 5, M = 1, O = 0, R = 8, Y = 1
|
||||
S = 9, E = 6, N = 7, D = 4, M = 1, O = 0, R = 8, Y = 0
|
||||
S = 9, E = 5, N = 6, D = 9, M = 1, O = 0, R = 8, Y = 4
|
||||
S = 9, E = 5, N = 6, D = 8, M = 1, O = 0, R = 8, Y = 3
|
||||
S = 9, E = 5, N = 6, D = 7, M = 1, O = 0, R = 8, Y = 2
|
||||
|
||||
Ans:
|
||||
S = 9, E = 5, N = 6, D = 7, M = 1, O = 0, R = 8, Y = 2
|
||||
|
||||
yes
|
||||
| ?- ^D
|
@ -1,33 +0,0 @@
|
||||
/tmp/clpr
|
||||
|
||||
yes
|
||||
| ?- use_module(library('clpqr/monash')).
|
||||
{compiling /freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl...}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql in module printf, 40 msec 27216 bytes}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql in module expand, 40 msec 26832 bytes}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl compiled, 120 msec 54848 bytes}
|
||||
|
||||
yes
|
||||
| ?- expand, [library('clpqr/examples/monash/toolpath')], noexpand.
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/toolpath...}
|
||||
{Warning: [T] - singleton variables in lookup/2 in lines 20-22}
|
||||
{Warning: [H] - singleton variables in lookup/2 in lines 22-24}
|
||||
{Warning: [A,B,X,Y] - singleton variables in get_vars/2 in lines 42-43}
|
||||
{Warning: [A,B,C,M] - singleton variables in get_vars/2 in lines 44-45}
|
||||
{Warning: [Y2] - singleton variables in get_constraint/2 in lines 57-64}
|
||||
{Warning: [C,M,N] - singleton variables in make_db/3 in lines 79-81}
|
||||
|
||||
>>> Sample goal: go/0
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/toolpath consulted, 130 msec 9904 bytes}
|
||||
|
||||
yes
|
||||
| ?- go.
|
||||
G00 X10.000 Y10.000
|
||||
G01 X10.000 Y20.000
|
||||
G01 X15.000 Y15.000
|
||||
G01 X10.000 Y10.000
|
||||
|
||||
yes
|
||||
| ?- ^D
|
@ -1,27 +0,0 @@
|
||||
/tmp/clpr
|
||||
|
||||
yes
|
||||
| ?- [library('clpqr/examples/caneghem')].
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/caneghem.pl...}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/caneghem.pl consulted, 2520 msec 74144 bytes}
|
||||
|
||||
yes
|
||||
| ?- time(caneghem(10,L)).
|
||||
%%% Timing 00:00:00.060 0.060
|
||||
|
||||
L = [1.180361618569526,-0.1898247042801352,-0.030994722136251738,-0.009616196004351119,0.08947578301403712,-0.05816832474193178,0.05131550710891376,-0.048661569893130585,-0.09665282648248967,0.112765434845812] ?
|
||||
|
||||
yes
|
||||
| ?- time(caneghem(20,L)).
|
||||
%%% Timing 00:00:00.240 0.240
|
||||
|
||||
L = [1.1771991533526154,-0.3677642194714706,-0.22059024017411974,0.07214096754607921,-0.04111968920165934,-0.004177226166045676,0.04879867086682026,-0.13423890971551566,0.02001872640660113,0.22953375242084173,-0.10544851408837679,0.12811597449720158,0.16864165436232448,0.06723448901855214,-0.07013899425181176,0.050157028592082514,-0.12728007887627196,0.135793403876429,0.1498397702858789,-0.17671571928015453] ?
|
||||
|
||||
yes
|
||||
| ?- time(caneghem(50,L)).
|
||||
%%% Timing 00:00:02.600 2.600
|
||||
|
||||
L = [2.508741846655168,0.9593654809880335,-0.3292365950578988,-0.06906112306788492,0.048323810270536505,0.6234464234295257,0.5846853367908995,0.1323953951743464,-0.4662055884466053,0.18150850965382204,-0.055933552069652115,0.6875968078160808,-1.196189723326641,-0.33344551191813265,-0.12299286303639723,-0.10478366723139865,-0.06355266206797038,-0.3434680164467263,-0.533938161282979,0.4511468891304816,-0.5823641186858809,0.6574493037432098,0.548047843404309,0.15401834452420127,-0.19926797646772515,-0.5235145627726111,1.1031281203771333,-0.5022272273019587,0.14907899497507549,0.08019445782741186,-0.9014009232330955,0.6013394766470118,-0.37457184037407687,-0.07351165783697981,-0.15808699797945325,0.3020665769523162,0.3492022324403419,-0.2063460453723508,-0.15919364319134321,-0.5248918818200423,0.27589725065363346,-0.5212003750683581,-0.534258112209033,-0.209811998058725,0.08983278566538411,-0.254457055946412,0.2833915592612968,-0.508674809981534,0.14974083758131862,-0.06801159370968507] ?
|
||||
|
||||
yes
|
||||
| ?- ^D
|
@ -1,32 +0,0 @@
|
||||
/tmp/clpr
|
||||
|
||||
yes
|
||||
| ?- [library('clpqr/examples/matmul')].
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/matmul.pl...}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/matmul.pl consulted, 50 msec 5216 bytes}
|
||||
|
||||
yes
|
||||
| ?- inv_hilbert(5).
|
||||
% took 110 msec
|
||||
[25.000000000022382,-300.00000000049715,1050.0000000024052,-1400.0000000039422,630.000000002048]
|
||||
[-300.0000000002686,4800.000000006132,-18900.00000003017,26880.000000050026,-12600.000000026208]
|
||||
[1050.0000000010832,-18900.000000024073,79380.0000001167,-117600.00000019174,56700.00000009983]
|
||||
[-1400.0000000012533,26880.000000028263,-117600.00000013839,179200.00000022893,-88200.00000011979]
|
||||
[630.0000000007072,-12600.000000015554,56700.00000007495,-88200.00000012267,44100.00000006371]
|
||||
|
||||
yes
|
||||
| ?- inv_hilbert(10).
|
||||
% took 730 msec
|
||||
[100.06764055606595,-4955.746750893468,79320.87311277707,-601688.1288004466,2527669.331989608,-6320363.588467166,9632548.1069225,-8773673.357856564,4387341.655298468,-926309.2549045784]
|
||||
[-4954.583263505397,327088.43938125984,-5888755.171243939,47640829.722639784,-208454422.6267876,536080106.3050636,-833973190.0816677,771622619.5092161,-390658135.1887325,83309806.45795152]
|
||||
[79282.65010987384,-5887588.611728508,113053989.38333344,-952665276.8719503,4287285196.6575603,-11254751273.977966,17786114554.87667,-16661528858.771124,8520389134.607941,-1832112969.2769487]
|
||||
[-601278.28283175,47624803.379886195,-952549872.4286704,8255797058.086059,-37926415443.20429,101140061646.08708,-161828052714.71478,153124339918.90198,-78956146207.99248,17096182731.586212]
|
||||
[2525510.463987293,-208360168.57612622,4286354582.629362,-37922951901.82854,176976129763.71933,-477840819028.144,772275161958.0231,-736819388616.1226,382581917280.6937,-83331832395.71211]
|
||||
[-6314069.480648408,535789562.6820037,-11251522186.754816,101124429258.4978,-477811689383.5447,1303120253648.7231,-2123600181570.822,2040253943986.3867,-1065667328185.2559,233306407256.48602]
|
||||
[9621777.540831676,-833457524.1493945,17779983322.230595,-161794800592.89096,772191081502.5444,-2123500324124.862,3484684566848.1865,-3367823701794.478,1768095223156.5308,-388814926368.6053]
|
||||
[-8762948.703959834,771096470.9348224,-16655008795.382607,153086775081.8679,-736712226467.4573,2040086157995.643,-3367706777384.1885,3271442141044.1406,-1725154609484.48,380858222342.8272]
|
||||
[4381581.535326206,-390370462.83225214,8516721017.329105,-78934185276.29749,382514968210.1026,-1065549816609.6667,1767985562818.6477,-1725107944970.8896,913278439265.5413,-202321697134.3589]
|
||||
[-925019.6256684132,83244518.21734402,-1831262894.88349,17090956320.177563,-83315214328.6161,233275346511.60562,-388782247484.8793,380839681227.99866,-202317350053.5215,44958695698.27329]
|
||||
|
||||
yes
|
||||
| ?- ^D
|
@ -1,86 +0,0 @@
|
||||
/tmp/clpr
|
||||
|
||||
yes
|
||||
| ?- [library('clpqr/examples/simplex')].
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/simplex.pl...}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/simplex.pl consulted, 230 msec 15360 bytes}
|
||||
|
||||
yes
|
||||
| ?- time(example(N,V,O)).
|
||||
%%% Timing 00:00:00.010 0.010
|
||||
|
||||
N = 1,
|
||||
O = 17200.0,
|
||||
V = [40.0,160.0] ? ;
|
||||
%%% Timing 00:00:00.020 0.020
|
||||
|
||||
N = 2,
|
||||
O = 7.0,
|
||||
V = [1.0,0.0,1.5] ? ;
|
||||
%%% Timing 00:00:00.020 0.020
|
||||
|
||||
N = 3,
|
||||
O = 18850.0,
|
||||
V = [38.0,170.0] ? ;
|
||||
%%% Timing 00:00:00.030 0.030
|
||||
|
||||
N = 4,
|
||||
O = 310.0,
|
||||
V = [7.0,2.0] ? ;
|
||||
%%% Timing 00:00:00.030 0.030
|
||||
|
||||
N = 5,
|
||||
O = 5.0,
|
||||
V = [0.0,0.0,2.5000000000000004] ? ;
|
||||
%%% Timing 00:00:00.020 0.020
|
||||
|
||||
N = 6,
|
||||
O = -7.0,
|
||||
V = [1.0,0.0,1.5] ? ;
|
||||
%%% Timing 00:00:00.070 0.070
|
||||
|
||||
N = 7,
|
||||
O = -70.0,
|
||||
V = [3.000000000000003,0.0,0.0,4.0,1.9999999999999998,0.0,5.0] ? ;
|
||||
%%% Timing 00:00:00.070 0.070
|
||||
|
||||
N = 8,
|
||||
O = -19.500000000000007,
|
||||
V = [0.0,3.4999999999999982,0.0,0.0,0.0,0.5000000000000009,0.0] ? ;
|
||||
%%% Timing 00:00:00.220 0.220
|
||||
|
||||
N = 9,
|
||||
O = 1167185.7255923203,
|
||||
V = [9.462945942265794,5.194418913398691,13.466605392156858,4.31985294117647,10.36764705882353,0.0,60.0,63.4629459422658,62.311070261437905,69.54656862745097,66.91176470588235,70.58823529411765,0.0,0.0,0.0,0.0,0.0,1411.7647058823532] ? ;
|
||||
%%% Timing 00:00:00.390 0.390
|
||||
|
||||
N = utility,
|
||||
O = 46554.76190476336,
|
||||
V = [0.0,161.90476190476357,28.571428571428214,142.8571428571422,666.6666666666667,0.0,0.0,0.0,999.9999999999999,0.0,1914.2857142857135,1928.5714285714234,0.0,1985.7142857142862,3999.9999999999973,397.6190476190506,2180.9523809523735,0.0,0.0,1000.0,500.00000000000006,2000.0000000000002,100.0,5000.000000000001,250.0000000000009,600.0,114.28571428571195,0.0] ? ;
|
||||
%%% Timing 00:00:00.220 0.220
|
||||
|
||||
N = electricity,
|
||||
O = 15628.571428582796,
|
||||
V = [0.0,428.5714285714289,28.57142857142867,_A,_B,0.0,0.0,0.0,_C,_D,_E,_F,_G,_H,1000.0,500.0,2000.0,100.0],
|
||||
{_A+0.6923076923076922*_G=<235.16483516483487},
|
||||
{_G>=0.0},
|
||||
{_A>=0.0},
|
||||
{_D=185.71428571428618+1.5*_A+0.4999999999999999*_G},
|
||||
{_F=1128.571428571429-_G},
|
||||
{_H=1985.7142857142853+_G},
|
||||
{_C=814.285714285714-1.5*_A-0.4999999999999999*_G},
|
||||
{_E=1914.2857142857165-_G},
|
||||
{_B=542.8571428571427-_A} ? ;
|
||||
%%% Timing 00:00:00.300 0.300
|
||||
|
||||
N = water,
|
||||
O = 23449.999999986194,
|
||||
V = [0.0,0.0,0.0,999.9999999944121,5.587935447700301e-09,0.0,49.999999999999545,_A,333.333333337678,_B,3999.999999999989,0.0,2483.333333332131,0.0,0.0,5000.0,250.0,600.0,_C,0.0],
|
||||
{_C=5.000000000000014*_A},
|
||||
{_A>=6.08224581810644e-13},
|
||||
{_B=616.666666662262-_A},
|
||||
{_A=<22.222222222222626} ? ;
|
||||
%%% Timing 00:00:00.050 0.050
|
||||
|
||||
no
|
||||
| ?- ^D
|
@ -1,21 +0,0 @@
|
||||
/tmp/clpr
|
||||
|
||||
yes
|
||||
| ?- [library('clpqr/examples/squares')].
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/squares.pl...}
|
||||
{Warning: [X1,X2,X3,X4,X5,X6,X7,X8,X9] - singleton variables in rectangle/2 in lines 1-40}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/squares.pl consulted, 50 msec 2928 bytes}
|
||||
|
||||
yes
|
||||
| ?- time(rectangle(A,Rs)).
|
||||
%%% Timing 00:00:40.060 40.060
|
||||
|
||||
A = 1.03125,
|
||||
Rs = [0.46875000000000006,0.5625000000000001,0.24999999999999967,0.21875000000000006,0.1250000000000001,0.4375,0.03124999999999989,0.3124999999999998,0.28124999999999933] ? ;
|
||||
%%% Timing 00:00:05.020 5.020
|
||||
|
||||
A = 1.131147540983607,
|
||||
Rs = [0.5409836065573771,0.5901639344262297,0.45901639344262296,0.08196721311475422,0.032786885245901544,0.14754098360655746,0.409836065573771,0.11475409836065581,0.2622950819672133] ?
|
||||
|
||||
yes
|
||||
| ?- ^D
|
@ -1,52 +0,0 @@
|
||||
/tmp/clpr
|
||||
|
||||
yes
|
||||
| ?- [library('clpqr/examples/mip')].
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/mip.pl...}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/mip.pl consulted, 2560 msec 97008 bytes}
|
||||
|
||||
yes
|
||||
| ?- example(1).
|
||||
incumbent(14.0,[1.0,2.0])
|
||||
incumbent(13.0,[2.0,0.9999999999999998])
|
||||
1:13.0
|
||||
%%% Timing 00:00:00.020 0.020
|
||||
|
||||
yes
|
||||
| ?- example(2).
|
||||
incumbent(-41.999999999999915,[4.440892098500626e-16,1.9999999999999987])
|
||||
2: -41.999999999999915
|
||||
%%% Timing 00:00:00.010 0.010
|
||||
|
||||
yes
|
||||
| ?- example(flugpl).
|
||||
incumbent(1202699.9999999995,[70.99999999999999,69.99999999999999,70.00000000000001,60.00000000000003,60.00000000000006,0.0,8.000000000000028,7.000000000000014,15.999999999999986,6.0,6.00000000000005])
|
||||
incumbent(1202399.9999999995,[72.0,70.00000000000001,70.00000000000001,60.00000000000004,60.00000000000005,0.0,9.000000000000002,7.0,15.999999999999986,6.000000000000007,6.000000000000043])
|
||||
incumbent(1202100.0,[73.0,70.00000000000001,70.00000000000001,60.000000000000014,60.000000000000014,0.0,10.0,7.000000000000043,15.999999999999986,6.000000000000007,6.000000000000007])
|
||||
incumbent(1201800.0,[74.0,70.0,70.0,60.00000000000007,60.0,0.0,11.000000000000014,6.9999999999999725,15.999999999999986,6.0000000000000036,5.999999999999993])
|
||||
incumbent(1201500.0000000005,[75.0,70.00000000000001,70.0,60.00000000000007,60.0,0.0,12.0,6.999999999999986,15.999999999999986,6.0000000000000036,5.999999999999993])
|
||||
flugpl:1201500.0000000005
|
||||
%%% Timing 00:00:30.150 30.150
|
||||
|
||||
yes
|
||||
| ?- example(flugplan).
|
||||
incumbent(1202700.0000000007,[70.0,7.000000000000007,69.99999999999999,7.999999999999998,71.00000000000013,0.0,5.99999999999999,59.99999999999999,6.000000000000001,60.000000000000014,15.999999999999991])
|
||||
incumbent(1202400.0000000007,[70.0,7.0000000000000275,70.0,8.999999999999838,72.0,0.0,6.000000000000004,59.99999999999999,6.0,60.000000000000014,15.999999999999988])
|
||||
incumbent(1202099.9999999995,[70.0,6.999999999999851,69.99999999999983,10.0,73.0,0.0,6.000000000000004,59.99999999999999,6.0,60.000000000000014,15.999999999999988])
|
||||
incumbent(1201799.9999999993,[70.0,6.999999999999854,69.99999999999989,11.000000000000089,74.0,0.0,6.000000000000002,60.000000000000014,6.0,60.00000000000002,15.999999999999986])
|
||||
incumbent(1201499.9999999993,[70.0,6.999999999999854,69.99999999999991,12.000000000000004,75.0,0.0,6.000000000000002,60.000000000000014,6.0,60.00000000000002,15.999999999999986])
|
||||
flugplan:1201499.9999999993
|
||||
%%% Timing 00:00:11.800 11.800
|
||||
|
||||
yes
|
||||
| ?- example(sample2).
|
||||
incumbent(450.0000000000001,[0.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.9999999999999998,0.0,0.0,0.9999999999999997,0.0,1.0,-6.661338147750939e-16])
|
||||
incumbent(430.00000000000006,[0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,0.9999999999999997,1.0000000000000004,0.0,0.0,0.0,1.0,-6.661338147750939e-16])
|
||||
incumbent(400.0000000000001,[0.0,0.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,1.0000000000000002,0.0,0.0,1.0,-6.661338147750939e-16])
|
||||
incumbent(385.0000000000001,[0.0,0.0,1.0,0.0,0.0,0.0,1.0000000000000002,0.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,0.9999999999999998,0.0,1.0,-6.661338147750939e-16])
|
||||
incumbent(375.0000000000001,[0.0,1.0,0.0,0.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,-1.1102230246251585e-16,0.0,0.0,0.0,1.0,0.0,-6.661338147750939e-16])
|
||||
sample2:375.0000000000001
|
||||
%%% Timing 00:00:41.730 41.730
|
||||
|
||||
yes
|
||||
| ?- ^D
|
@ -1,256 +0,0 @@
|
||||
/tmp/clpr
|
||||
|
||||
yes
|
||||
| ?- [library('clpqr/examples/eliminat')].
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/eliminat.pl...}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/eliminat.pl consulted, 170 msec 15600 bytes}
|
||||
|
||||
yes
|
||||
| ?- hull([X,Y]).
|
||||
|
||||
{Y=<2.0},
|
||||
{X+0.5*Y=<3.0},
|
||||
{X>=1.0},
|
||||
{Y>= -0.0},
|
||||
{X+Y>=2.0} ?
|
||||
|
||||
yes
|
||||
| ?- example(1,[_,_,X3,X4]).
|
||||
|
||||
{X3-0.3333333333333328*X4>= -0.33333333333333365},
|
||||
{X3-1.2222222222222185*X4=<0.1111111111111095},
|
||||
{X3-0.8888888888888873*X4=<0.11111111111110945},
|
||||
{X3-0.7222222222222214*X4>= -0.2222222222222217},
|
||||
{X3-0.16666666666667848*X4=<0.33333333333332205} ?
|
||||
|
||||
yes
|
||||
| ?- example(2,[X0,X1|_]).
|
||||
|
||||
{X0+0.1467030889468301*X1>= -0.047670549229302576},
|
||||
{X0+0.3879120532395401*X1=< -0.7691743524189323},
|
||||
{X0+0.01576973710784565*X1>=1.967054191675273},
|
||||
{X0-0.31633069046036744*X1>=5.333044707442825},
|
||||
{X0+0.14129088466591355*X1>=0.46689259039239467} ?
|
||||
|
||||
yes
|
||||
| ?- proj(1).
|
||||
%%% Timing 00:00:00.060 0.060
|
||||
[A,B,C,D]:6
|
||||
{B>=0.0}
|
||||
{A>=0.0}
|
||||
{D-2.999999999999997*C+B+11.999999999999977*A=<0.9999999999999978}
|
||||
{D-1.2857142857142863*C+0.142857142857143*B+2.5714285714285734*A>=0.142857142857143}
|
||||
{D-1.6363636363636367*C+0.18181818181818196*B+3.2727272727272747*A>=0.18181818181818196}
|
||||
{D-1.3846153846153857*C+0.30769230769230776*B+3.4615384615384635*A=<0.30769230769230776}
|
||||
|
||||
%%% Timing 00:00:00.170 0.170
|
||||
[A,B,C]:6
|
||||
{A>=0.0}
|
||||
{C-6.000000000000002*B-2.000000000000002*A>= -2.000000000000002}
|
||||
{C-1.3846153846153848*B+0.30769230769230765*A=<0.30769230769230765}
|
||||
{C-0.818181818181818*B-0.09090909090909093*A>= -0.09090909090909093}
|
||||
{C-1.1249999999999998*B-0.12500000000000003*A>= -0.12500000000000003}
|
||||
{C-2.999999999999995*B+A=<0.999999999999998}
|
||||
|
||||
%%% Timing 00:00:00.160 0.160
|
||||
[A,B]:5
|
||||
{B-2.9999999999999996*A=<0.9999999999999988}
|
||||
{B-0.8181818181818189*A>= -0.09090909090909098}
|
||||
{B-1.1250000000000009*A>= -0.1250000000000004}
|
||||
{B-1.384615384615386*A=<0.3076923076923073}
|
||||
{B-6.000000000000392*A>= -2.0000000000001537}
|
||||
|
||||
%%% Timing 00:00:00.160 0.160
|
||||
[A]:2
|
||||
{A=<1.0000000000000016}
|
||||
{A>= -0.4999999999999999}
|
||||
|
||||
%%% Timing 00:00:00.040 0.040
|
||||
[]:0
|
||||
|
||||
%%% Timing 00:00:00.150 0.150
|
||||
[A]:2
|
||||
{A=<0.5000000000000004}
|
||||
{A>= -0.5}
|
||||
|
||||
%%% Timing 00:00:00.150 0.150
|
||||
[A,B]:3
|
||||
{A>=0.0}
|
||||
{B-0.49999999999999994*A>= -0.49999999999999994}
|
||||
{B+A=<1.0000000000000056}
|
||||
|
||||
%%% Timing 00:00:00.120 0.120
|
||||
[A]:2
|
||||
{A>=0.0}
|
||||
{A=<1.0}
|
||||
|
||||
%%% Timing 00:00:00.150 0.150
|
||||
[A,B]:3
|
||||
{A>=0.0}
|
||||
{B-0.4999999999999997*A>= -0.49999999999999983}
|
||||
{B+0.5000000000000008*A=<0.5000000000000007}
|
||||
|
||||
%%% Timing 00:00:00.140 0.140
|
||||
[A,B,C]:6
|
||||
{A>=0.0}
|
||||
{C-1.9999999999999998*B+2.999999999999999*A>= -0.0}
|
||||
{C-1.384615384615385*B+3.461538461538463*A=<0.3076923076923077}
|
||||
{C-B+A>= -0.0}
|
||||
{C-1.3333333333333335*B+1.3333333333333341*A>= -0.0}
|
||||
{C-2.999999999999997*B+11.999999999999982*A=<0.9999999999999984}
|
||||
|
||||
%%% Timing 00:00:00.140 0.140
|
||||
[A,B]:4
|
||||
{A>=0.0}
|
||||
{B-7.199999999999999*A>= -0.7999999999999998}
|
||||
{B-4.499999999999999*A>= -0.4999999999999999}
|
||||
{B+4.500000000000004*A=<1.0000000000000007}
|
||||
|
||||
%%% Timing 00:00:00.110 0.110
|
||||
[A]:2
|
||||
{A>=0.0}
|
||||
{A=<0.1538461538461539}
|
||||
|
||||
%%% Timing 00:00:00.130 0.130
|
||||
[A,B]:4
|
||||
{A>=0.0}
|
||||
{B-6.400000000000002*A>= -0.6000000000000002}
|
||||
{B-5.500000000000002*A>= -0.5000000000000001}
|
||||
{B+0.7500000000000011*A=<0.5000000000000001}
|
||||
|
||||
%%% Timing 00:00:00.130 0.130
|
||||
[A,B,C]:5
|
||||
{B>=0.0}
|
||||
{A>=0.0}
|
||||
{C+B+4.500000000000005*A=<1.0000000000000013}
|
||||
{C-0.49999999999999994*B-4.5*A>= -0.49999999999999994}
|
||||
{C-0.7999999999999999*B-7.2*A>= -0.7999999999999999}
|
||||
|
||||
%%% Timing 00:00:00.100 0.100
|
||||
[A,B]:3
|
||||
{B>= -1.1102230246251568e-16}
|
||||
{A>=0.0}
|
||||
{B+6.499999999999998*A=<1.0}
|
||||
|
||||
%%% Timing 00:00:00.130 0.130
|
||||
[A,B,C]:5
|
||||
{B>=0.0}
|
||||
{A>=0.0}
|
||||
{C+0.49999999999999806*B+0.7499999999999849*A=<0.49999999999999806}
|
||||
{C-0.5*B-5.499999999999998*A>= -0.5}
|
||||
{C-0.5999999999999998*B-6.399999999999999*A>= -0.5999999999999998}
|
||||
|
||||
%%% Timing 00:00:00.020 0.020
|
||||
|
||||
no
|
||||
| ?- proj(3).
|
||||
%%% Timing 00:00:00.060 0.060
|
||||
[A,B,C,D]:6
|
||||
{B>=0.0}
|
||||
{A>0.0}
|
||||
{D-2.999999999999997*C+B+11.999999999999977*A=<0.9999999999999978}
|
||||
{D-1.2857142857142863*C+0.142857142857143*B+2.5714285714285734*A>=0.142857142857143}
|
||||
{D-1.6363636363636367*C+0.18181818181818196*B+3.2727272727272747*A>=0.18181818181818196}
|
||||
{D-1.3846153846153857*C+0.30769230769230776*B+3.4615384615384635*A=<0.30769230769230776}
|
||||
|
||||
%%% Timing 00:00:00.160 0.160
|
||||
[A,B,C]:6
|
||||
{A>=0.0}
|
||||
{C-6.000000000000002*B-2.000000000000002*A>= -2.000000000000002}
|
||||
{C-1.3846153846153848*B+0.30769230769230765*A<0.30769230769230765}
|
||||
{C-0.818181818181818*B-0.09090909090909093*A>= -0.09090909090909093}
|
||||
{C-1.1249999999999998*B-0.12500000000000003*A>= -0.12500000000000003}
|
||||
{C-2.999999999999995*B+A<0.999999999999998}
|
||||
|
||||
%%% Timing 00:00:00.170 0.170
|
||||
[A,B]:5
|
||||
{B-2.9999999999999996*A<0.9999999999999988}
|
||||
{B-0.8181818181818189*A>= -0.09090909090909098}
|
||||
{B-1.1250000000000009*A>= -0.1250000000000004}
|
||||
{B-1.384615384615386*A<0.3076923076923073}
|
||||
{B-6.000000000000392*A>= -2.0000000000001537}
|
||||
|
||||
%%% Timing 00:00:00.180 0.180
|
||||
[A]:2
|
||||
{A<1.0000000000000016}
|
||||
{A> -0.4999999999999999}
|
||||
|
||||
%%% Timing 00:00:00.030 0.030
|
||||
[]:0
|
||||
|
||||
%%% Timing 00:00:00.150 0.150
|
||||
[A]:2
|
||||
{A<0.5000000000000004}
|
||||
{A> -0.5}
|
||||
|
||||
%%% Timing 00:00:00.140 0.140
|
||||
[A,B]:3
|
||||
{A>=0.0}
|
||||
{B-0.49999999999999994*A> -0.49999999999999994}
|
||||
{B+A<1.0000000000000056}
|
||||
|
||||
%%% Timing 00:00:00.130 0.130
|
||||
[A]:2
|
||||
{A>=0.0}
|
||||
{A<1.0}
|
||||
|
||||
%%% Timing 00:00:00.140 0.140
|
||||
[A,B]:3
|
||||
{A>=0.0}
|
||||
{B-0.4999999999999997*A> -0.49999999999999983}
|
||||
{B+0.5000000000000008*A<0.5000000000000007}
|
||||
|
||||
%%% Timing 00:00:00.120 0.120
|
||||
[A,B,C]:6
|
||||
{A>0.0}
|
||||
{C-1.9999999999999998*B+2.999999999999999*A>= -0.0}
|
||||
{C-1.384615384615385*B+3.461538461538463*A=<0.3076923076923077}
|
||||
{C-B+A>= -0.0}
|
||||
{C-1.3333333333333335*B+1.3333333333333341*A>= -0.0}
|
||||
{C-2.999999999999997*B+11.999999999999982*A=<0.9999999999999984}
|
||||
|
||||
%%% Timing 00:00:00.140 0.140
|
||||
[A,B]:4
|
||||
{A>0.0}
|
||||
{B-7.199999999999999*A>= -0.7999999999999998}
|
||||
{B-4.499999999999999*A>= -0.4999999999999999}
|
||||
{B+4.500000000000004*A=<1.0000000000000007}
|
||||
|
||||
%%% Timing 00:00:00.120 0.120
|
||||
[A]:2
|
||||
{A>0.0}
|
||||
{A=<0.1538461538461539}
|
||||
|
||||
%%% Timing 00:00:00.120 0.120
|
||||
[A,B]:4
|
||||
{A>0.0}
|
||||
{B-6.400000000000002*A>= -0.6000000000000002}
|
||||
{B-5.500000000000002*A>= -0.5000000000000001}
|
||||
{B+0.7500000000000011*A=<0.5000000000000001}
|
||||
|
||||
%%% Timing 00:00:00.110 0.110
|
||||
[A,B,C]:5
|
||||
{B>=0.0}
|
||||
{A>0.0}
|
||||
{C+B+4.500000000000005*A=<1.0000000000000013}
|
||||
{C-0.49999999999999994*B-4.5*A>= -0.49999999999999994}
|
||||
{C-0.7999999999999999*B-7.2*A>= -0.7999999999999999}
|
||||
|
||||
%%% Timing 00:00:00.130 0.130
|
||||
[A,B]:3
|
||||
{B>= -1.1102230246251568e-16}
|
||||
{A>0.0}
|
||||
{B+6.499999999999998*A=<1.0}
|
||||
|
||||
%%% Timing 00:00:00.110 0.110
|
||||
[A,B,C]:5
|
||||
{B>=0.0}
|
||||
{A>0.0}
|
||||
{C+0.49999999999999806*B+0.7499999999999849*A=<0.49999999999999806}
|
||||
{C-0.5*B-5.499999999999998*A>= -0.5}
|
||||
{C-0.5999999999999998*B-6.399999999999999*A>= -0.5999999999999998}
|
||||
|
||||
%%% Timing 00:00:00.020 0.020
|
||||
|
||||
no
|
||||
| ?- ^D
|
@ -1,66 +0,0 @@
|
||||
/tmp/clpq
|
||||
|
||||
yes
|
||||
| ?- use_module(library('clpqr/monash')).
|
||||
{compiling /freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl...}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql in module printf, 40 msec 27216 bytes}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql in module expand, 50 msec 26832 bytes}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl compiled, 130 msec 54848 bytes}
|
||||
|
||||
yes
|
||||
| ?- expand, [library('clpqr/examples/monash/air')], noexpand.
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/air...}
|
||||
{Warning: [T] - singleton variables in comp/3 in lines 27-28}
|
||||
{Warning: [X] - singleton variables in zero/1 in lines 38-40}
|
||||
{Warning: [T] - singleton variables in bal_side/3 in lines 45-50}
|
||||
{Warning: [X] - singleton variables in add_species/4 in lines 56-57}
|
||||
{Warning: [NUM] - singleton variables in add_elements/5 in lines 57-60}
|
||||
{Warning: [PROP,X] - singleton variables in add_elements/5 in lines 68-70}
|
||||
{Warning: [F1] - singleton variables in go/0 in lines 76-87}
|
||||
|
||||
>>> Sample goal: go/0
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/air consulted, 130 msec 10384 bytes}
|
||||
|
||||
yes
|
||||
| ?- go.
|
||||
species air
|
||||
molecule n2
|
||||
molecule o2
|
||||
atom o
|
||||
species fuel
|
||||
molecule c
|
||||
atom c
|
||||
species flue
|
||||
molecule co2
|
||||
atom c
|
||||
atom o
|
||||
molecule co
|
||||
atom c
|
||||
atom o
|
||||
molecule o2
|
||||
atom o
|
||||
molecule n2
|
||||
With base of 1.000000 mol of fuel
|
||||
air (just to burn the carbon) = 5.317460 mol
|
||||
flue (mol) :6.666667
|
||||
|
||||
species air
|
||||
molecule n2
|
||||
molecule o2
|
||||
atom o
|
||||
species fuel
|
||||
molecule c
|
||||
atom c
|
||||
species full_comb
|
||||
molecule co2
|
||||
atom c
|
||||
atom o
|
||||
molecule n2
|
||||
Compared with theoretical air (for complete combustion):
|
||||
4.761905 mol
|
||||
Excess = 11.666667%
|
||||
|
||||
yes
|
||||
| ?-
|
@ -1,64 +0,0 @@
|
||||
/tmp/clpq
|
||||
|
||||
yes
|
||||
| ?- use_module(library('clpqr/monash')).
|
||||
{compiling /freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl...}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql in module printf, 30 msec 27216 bytes}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql in module expand, 50 msec 26832 bytes}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl compiled, 120 msec 54848 bytes}
|
||||
|
||||
yes
|
||||
| ?- expand, [library('clpqr/examples/monash/amplif')], noexpand.
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/amplif...}
|
||||
{Warning: [Collector_Currents] - singleton variables in dc_analysis/3 in lines 1-31}
|
||||
{Warning: [Type,Vc] - singleton variables in component_ss/6 in lines 70-75}
|
||||
{Warning: [V1,V2] - singleton variables in component_dc/7 in lines 89-90}
|
||||
{Warning: [Vbreak,Vreak] - singleton variables in component_dc/7 in lines 93-96}
|
||||
{Warning: [Vbreak] - singleton variables in diode_state/5 in lines 96-104}
|
||||
{Warning: [Beta] - singleton variables in transistor_state/7 in lines 122-127}
|
||||
{Warning: [Beta] - singleton variables in transistor_state/7 in lines 127-133}
|
||||
{Warning: [Beta,Vc,Vcesat] - singleton variables in transistor_state/7 in lines 133-139}
|
||||
{Warning: [Beta,Vc,Vcesat] - singleton variables in transistor_state/7 in lines 139-144}
|
||||
{Warning: [Points] - singleton variables in print_circuit/1 in lines 202-205}
|
||||
{Warning: [R1,R2,Rc,Re] - singleton variables in circuit/6 in lines 233-244}
|
||||
{Warning: [C1,C2,C3,R1,R2,Rc,Re] - singleton variables in circuit/6 in lines 244-255}
|
||||
{Warning: [C1,C3,R1,R2,Re] - singleton variables in circuit/6 in lines 255-264}
|
||||
{Warning: [St1,St2,St3,St4,State] - singleton variables in go1/0 in lines 264-274}
|
||||
|
||||
>>> Sample goals: go1/0, go2/0
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/amplif consulted, 410 msec 22640 bytes}
|
||||
|
||||
yes
|
||||
| ?- go1.
|
||||
cc1 at 15 [0,18/125,0,-18/125]
|
||||
cc2 at -12 [-57/500,57/500]
|
||||
gnd at 0 [0,-3/100,3/100]
|
||||
a at 3/5 [57/500,-18/125,0,3/100]
|
||||
p1 at 0 [57/500,-57/500]
|
||||
b at -3/5 [0,57/500,-57/500]
|
||||
c at 15 [0,0]
|
||||
diode at d1 [di1,forward]
|
||||
diode at d2 [di1,reverse]
|
||||
resistor at r1 100
|
||||
diode at d3 [di1,forward]
|
||||
diode at d4 [di1,forward]
|
||||
resistor at r2 100
|
||||
transistor at tr [npn,tr0,cutoff]
|
||||
resistor at rc 100
|
||||
|
||||
yes
|
||||
| ?- go2.
|
||||
Stab 407/209090
|
||||
Outresist 47500/55419
|
||||
capacitor at c1 _1412
|
||||
resistor at r1 100
|
||||
resistor at r2 100
|
||||
transistor at tr [npn,tr0,active]
|
||||
resistor at re 100
|
||||
capacitor at c3 _1334
|
||||
[[capacitor,c1,_1412,[in,b]],[resistor,r1,rat(100,1),[b,cc1]],[resistor,r2,rat(100,1),[b,gnd]],[transistor,tr,[npn,tr0,active],[b,cc1,e]],[resistor,re,rat(100,1),[e,gnd]],[capacitor,c3,_1334,[e,out]]]
|
||||
|
||||
yes
|
||||
| ?-
|
@ -1,27 +0,0 @@
|
||||
/tmp/clpq
|
||||
|
||||
yes
|
||||
| ?- use_module(library('clpqr/monash')).
|
||||
{compiling /freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl...}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql in module printf, 30 msec 27216 bytes}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql in module expand, 40 msec 26832 bytes}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl compiled, 100 msec 54848 bytes}
|
||||
|
||||
yes
|
||||
| ?- expand, [library('clpqr/examples/monash/complex')], noexpand.
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/complex...}
|
||||
|
||||
>>> Sample goal: go/0
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/complex consulted, 20 msec 3808 bytes}
|
||||
|
||||
yes
|
||||
| ?- go.
|
||||
|
||||
[32,88,32,61,32]c(rat(1,1),rat(1,1))
|
||||
[32,89,32,61,32]c(rat(2,1),rat(2,1))
|
||||
[32,90,32,61,32]c(rat(0,1),rat(4,1))
|
||||
|
||||
yes
|
||||
| ?-
|
@ -1,138 +0,0 @@
|
||||
/tmp/clpq
|
||||
|
||||
yes
|
||||
| ?- use_module(library('clpqr/monash')).
|
||||
{compiling /freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl...}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql in module printf, 30 msec 27216 bytes}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql in module expand, 40 msec 26832 bytes}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl compiled, 100 msec 54848 bytes}
|
||||
|
||||
yes
|
||||
| ?- expand, [library('clpqr/examples/monash/critical')], noexpand.
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/critical...}
|
||||
{Warning: [End] - singleton variables in cpm/2 in lines 62-67}
|
||||
{Warning: [Es,From,Lc,T] - singleton variables in buildv/3 in lines 81-83}
|
||||
{Warning: [H] - singleton variables in buildv/3 in lines 83-85}
|
||||
{Warning: [Es,Lc,T,To] - singleton variables in buildv/3 in lines 85-87}
|
||||
{Warning: [H] - singleton variables in buildv/3 in lines 87-89}
|
||||
{Warning: [H] - singleton variables in addedg/3 in lines 91-93}
|
||||
{Warning: [T] - singleton variables in addedg/3 in lines 93-94}
|
||||
{Warning: [H] - singleton variables in addedg/3 in lines 94-96}
|
||||
{Warning: [I] - singleton variables in early_late/4 in lines 102-106}
|
||||
{Warning: [I] - singleton variables in early_late/3 in lines 108-112}
|
||||
{Warning: [End] - singleton variables in setearly/5 in lines 118-121}
|
||||
{Warning: [Last] - singleton variables in setlate/4 in lines 128-131}
|
||||
{Warning: [T] - singleton variables in getnode/4 in lines 136-139}
|
||||
{Warning: [H] - singleton variables in getnode/4 in lines 139-141}
|
||||
{Warning: [G] - singleton variables in analyse/2 in lines 141-148}
|
||||
{Warning: [I] - singleton variables in analyse/2 in lines 148-151}
|
||||
{Warning: [Lci] - singleton variables in compute/9 in lines 157-166}
|
||||
{Warning: [From] - singleton variables in print_node/1 in lines 176-180}
|
||||
{Warning: [From] - singleton variables in print_node/1 in lines 186-191}
|
||||
|
||||
>>> Sample goals: go1/0, go2/0, go3/0
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/critical consulted, 210 msec 18416 bytes}
|
||||
|
||||
yes
|
||||
| ?- go1.
|
||||
Node Es Lc
|
||||
Node1 Node2 T Ls Ec Tf Ff
|
||||
--------------------------------------------------
|
||||
START NODE n1 0 0
|
||||
--------------------------------------------------
|
||||
n1 n2 3 2 3 2 0
|
||||
n1 n3 2 0 2 0 0 *
|
||||
--------------------------------------------------
|
||||
n2 3 5
|
||||
--------------------------------------------------
|
||||
n2 n4 2 5 5 2 2
|
||||
--------------------------------------------------
|
||||
n3 2 2
|
||||
--------------------------------------------------
|
||||
n3 n4 5 2 7 0 0 *
|
||||
--------------------------------------------------
|
||||
END NODE n4 7 7
|
||||
|
||||
yes
|
||||
| ?- go2.
|
||||
Node Es Lc
|
||||
Node1 Node2 T Ls Ec Tf Ff
|
||||
--------------------------------------------------
|
||||
n5 8 8
|
||||
--------------------------------------------------
|
||||
n5 n6 9 8 17 0 0 *
|
||||
n5 n7 5 12 13 4 4
|
||||
--------------------------------------------------
|
||||
n6 17 17
|
||||
--------------------------------------------------
|
||||
n6 n7 0 17 17 0 0 *
|
||||
n6 n8 4 19 21 2 2
|
||||
--------------------------------------------------
|
||||
n7 17 17
|
||||
--------------------------------------------------
|
||||
n7 n8 6 17 23 0 0 *
|
||||
--------------------------------------------------
|
||||
n4 3 8
|
||||
--------------------------------------------------
|
||||
n4 n7 4 13 7 10 10
|
||||
n4 n5 0 8 3 5 5
|
||||
n4 n8 3 20 6 17 17
|
||||
--------------------------------------------------
|
||||
START NODE n1 0 0
|
||||
--------------------------------------------------
|
||||
n1 n2 2 4 2 4 0
|
||||
n1 n3 6 0 6 0 0 *
|
||||
n1 n4 3 5 3 5 0
|
||||
--------------------------------------------------
|
||||
n2 2 6
|
||||
--------------------------------------------------
|
||||
n2 n3 0 6 2 4 4
|
||||
n2 n5 1 7 3 5 5
|
||||
n2 n6 4 13 6 11 11
|
||||
--------------------------------------------------
|
||||
n3 6 6
|
||||
--------------------------------------------------
|
||||
n3 n5 2 6 8 0 0 *
|
||||
--------------------------------------------------
|
||||
END NODE n8 23 23
|
||||
|
||||
yes
|
||||
| ?- go3.
|
||||
Node Es Lc
|
||||
Node1 Node2 T Ls Ec Tf Ff
|
||||
--------------------------------------------------
|
||||
START NODE n1 0 0
|
||||
--------------------------------------------------
|
||||
n1 n2 4 0 4 0 0 *
|
||||
n1 n3 3 4 3 4 2
|
||||
n1 n4 4 6 4 6 0
|
||||
--------------------------------------------------
|
||||
n2 4 4
|
||||
--------------------------------------------------
|
||||
n2 n5 7 4 11 0 0 *
|
||||
n2 n3 1 6 5 2 0
|
||||
n2 n7 8 8 12 4 4
|
||||
--------------------------------------------------
|
||||
n3 5 7
|
||||
--------------------------------------------------
|
||||
n3 n5 4 7 9 2 2
|
||||
--------------------------------------------------
|
||||
n4 4 10
|
||||
--------------------------------------------------
|
||||
n4 n6 2 10 6 6 6
|
||||
--------------------------------------------------
|
||||
n5 11 11
|
||||
--------------------------------------------------
|
||||
n5 n6 1 11 12 0 0 *
|
||||
n5 n7 3 13 14 2 2
|
||||
--------------------------------------------------
|
||||
END NODE n7 16 16
|
||||
--------------------------------------------------
|
||||
n6 12 12
|
||||
--------------------------------------------------
|
||||
n6 n7 4 12 16 0 0 *
|
||||
|
||||
yes
|
||||
| ?-
|
@ -1,25 +0,0 @@
|
||||
/tmp/clpq
|
||||
|
||||
yes
|
||||
| ?- use_module(library('clpqr/monash')).
|
||||
{compiling /freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl...}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql in module printf, 30 msec 27216 bytes}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql in module expand, 30 msec 26832 bytes}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl compiled, 110 msec 54848 bytes}
|
||||
|
||||
yes
|
||||
| ?- expand, [library('clpqr/examples/monash/fib')], noexpand.
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/fib...}
|
||||
|
||||
>>> Sample goal: go/0
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/fib consulted, 20 msec 3712 bytes}
|
||||
|
||||
yes
|
||||
| ?- go.
|
||||
forward: fib(10) = 89
|
||||
backward: fib(10) = 89
|
||||
|
||||
yes
|
||||
| ?-
|
@ -1,29 +0,0 @@
|
||||
/tmp/clpq
|
||||
|
||||
yes
|
||||
| ?- use_module(library('clpqr/monash')).
|
||||
{compiling /freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl...}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql in module printf, 30 msec 27216 bytes}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql in module expand, 40 msec 26832 bytes}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl compiled, 120 msec 54848 bytes}
|
||||
|
||||
yes
|
||||
| ?- expand, [library('clpqr/examples/monash/findroot')], noexpand.
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/findroot...}
|
||||
|
||||
>>> Sample goal: go/0
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/findroot consulted, 30 msec 4528 bytes}
|
||||
|
||||
yes
|
||||
| ?- go.
|
||||
1.70000000
|
||||
0.44834437
|
||||
0.91953538
|
||||
0.99701354
|
||||
0.99999555
|
||||
1.00000000
|
||||
|
||||
yes
|
||||
| ?-
|
@ -1,35 +0,0 @@
|
||||
/tmp/clpq
|
||||
|
||||
yes
|
||||
| ?- use_module(library('clpqr/monash')).
|
||||
{compiling /freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl...}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql in module printf, 30 msec 27216 bytes}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql in module expand, 40 msec 26832 bytes}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl compiled, 110 msec 54848 bytes}
|
||||
|
||||
yes
|
||||
| ?- expand, [library('clpqr/examples/monash/invert')], noexpand.
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/invert...}
|
||||
{Warning: [C] - singleton variables in allvec/2 in lines 21-23}
|
||||
{Warning: [H] - singleton variables in mylength/2 in lines 27-28}
|
||||
{Warning: [H] - singleton variables in mylength/2 in lines 28-31}
|
||||
{Warning: [A] - singleton variables in rowtocol/2 in lines 50-51}
|
||||
|
||||
>>> Sample goal: go/0
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/invert consulted, 90 msec 8288 bytes}
|
||||
|
||||
yes
|
||||
| ?- go.
|
||||
NR =
|
||||
0.2917 0.0417 -0.2083
|
||||
-0.0833 0.4167 -0.0833
|
||||
0.0417 -0.3750 0.2083
|
||||
T =
|
||||
1.0000 0.0000 0.0000
|
||||
0.0000 1.0000 0.0000
|
||||
0.0000 0.0000 1.0000
|
||||
|
||||
yes
|
||||
| ?-
|
@ -1,53 +0,0 @@
|
||||
/tmp/clpq
|
||||
|
||||
yes
|
||||
| ?- use_module(library('clpqr/monash')).
|
||||
{compiling /freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl...}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql in module printf, 30 msec 27216 bytes}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql in module expand, 40 msec 26832 bytes}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl compiled, 110 msec 54848 bytes}
|
||||
|
||||
yes
|
||||
| ?- expand, [library('clpqr/examples/monash/laplace')], noexpand.
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/laplace...}
|
||||
{Warning: [BL,TL] - singleton variables in laplace_vec/3 in lines 24-28}
|
||||
{Warning: [B11,B12,B13,B14,B21,B24,B31,B34,B42,B43,M22,M23,M32,M33] - singleton variables in go2/0 in lines 58-81}
|
||||
|
||||
>>> Sample goals: go1/0, go2/0
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/laplace consulted, 80 msec 7408 bytes}
|
||||
|
||||
yes
|
||||
| ?- go1.
|
||||
|
||||
0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
|
||||
100.00 51.11 32.52 24.56 21.11 20.12 21.11 24.56 32.52 51.11 100.00
|
||||
100.00 71.91 54.41 44.63 39.74 38.26 39.74 44.63 54.41 71.91 100.00
|
||||
100.00 82.12 68.59 59.80 54.97 53.44 54.97 59.80 68.59 82.12 100.00
|
||||
100.00 87.97 78.03 71.00 66.90 65.56 66.90 71.00 78.03 87.97 100.00
|
||||
100.00 91.71 84.58 79.28 76.07 75.00 76.07 79.28 84.58 91.71 100.00
|
||||
100.00 94.30 89.29 85.47 83.10 82.30 83.10 85.47 89.29 94.30 100.00
|
||||
100.00 96.20 92.82 90.20 88.56 88.00 88.56 90.20 92.82 96.20 100.00
|
||||
100.00 97.67 95.59 93.96 92.93 92.58 92.93 93.96 95.59 97.67 100.00
|
||||
100.00 98.89 97.90 97.12 96.63 96.46 96.63 97.12 97.90 98.89 100.00
|
||||
100.00 100.00 100.00 100.00 100.00 100.00 100.00 100.00 100.00 100.00 100.00
|
||||
|
||||
yes
|
||||
| ?- go2.
|
||||
|
||||
yes
|
||||
| ?- laplace([
|
||||
[B11, B12, B13, B14],
|
||||
[B21, M22, M23, B24],
|
||||
[B31, M32, M33, B34],
|
||||
[B44, B42, B43, B44]
|
||||
]).
|
||||
|
||||
{M32= -(B12)-B21+4*M22-M23},
|
||||
{M33= -(M22)+4*M23-B13-B24},
|
||||
{B42=-4*B12-4*B21+16*M22-8*M23+B13+B24-B31},
|
||||
{B43=B12+B21-8*M22+16*M23-4*B13-4*B24-B34} ?
|
||||
|
||||
yes
|
||||
| ?- ^D
|
@ -1,46 +0,0 @@
|
||||
/tmp/clpq
|
||||
|
||||
yes
|
||||
| ?- use_module(library('clpqr/monash')).
|
||||
{compiling /freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl...}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql in module printf, 30 msec 27216 bytes}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql in module expand, 40 msec 26832 bytes}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl compiled, 90 msec 54848 bytes}
|
||||
|
||||
yes
|
||||
| ?- expand, [library('clpqr/examples/monash/mortgage')], noexpand.
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/mortgage...}
|
||||
{Warning: [Int] - singleton variables in go4/0 in lines 45-51}
|
||||
|
||||
>>> Sample goals: go1/0, go2/0, go3/0, go4/0
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/mortgage consulted, 20 msec 4992 bytes}
|
||||
|
||||
yes
|
||||
| ?- go1.
|
||||
Forward: MP = 1721.65
|
||||
Backward: P = 120000
|
||||
|
||||
yes
|
||||
| ?- go2.
|
||||
|
||||
yes
|
||||
| ?- mg(P,120,0.01,0,MP), dump([P,MP]).
|
||||
|
||||
{P=230038689457366504787696421844051916348685607672853885051027633046922230334437656640810235469538098584320203208140788877352356725532780953940525919735874426790409432648433950808597819868060753380384018578968864514756271928149406197791141200100/3300386894573665047876964218440519163486856076728538850510276330469222303344376566408102354695380985843202032081407888773523567255327809539405259197358744267904094326484339508085978198680607533803840185789688645147562719281494061977911412001*MP} ?
|
||||
|
||||
yes
|
||||
| ?- mg(P,120,0.01,B,MP), dump([P,B,MP]).
|
||||
|
||||
{P=1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000/3300386894573665047876964218440519163486856076728538850510276330469222303344376566408102354695380985843202032081407888773523567255327809539405259197358744267904094326484339508085978198680607533803840185789688645147562719281494061977911412001*B+230038689457366504787696421844051916348685607672853885051027633046922230334437656640810235469538098584320203208140788877352356725532780953940525919735874426790409432648433950808597819868060753380384018578968864514756271928149406197791141200100/3300386894573665047876964218440519163486856076728538850510276330469222303344376566408102354695380985843202032081407888773523567255327809539405259197358744267904094326484339508085978198680607533803840185789688645147562719281494061977911412001*MP} ?
|
||||
|
||||
yes
|
||||
| ?- mg(999, 3, Int, 0, 400), dump.
|
||||
|
||||
nonlin:{_B-_B*Int+_A+400=0},
|
||||
nonlin:{_A-_A*Int+400=0},
|
||||
{_B=599+999*Int} ?
|
||||
|
||||
yes
|
||||
| ?-
|
@ -1,76 +0,0 @@
|
||||
/tmp/clpq
|
||||
|
||||
yes
|
||||
| ?- use_module(library('clpqr/monash')).
|
||||
{compiling /freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl...}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql in module printf, 30 msec 27216 bytes}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql in module expand, 40 msec 26832 bytes}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl compiled, 90 msec 54848 bytes}
|
||||
|
||||
yes
|
||||
| ?- expand, [library('clpqr/examples/monash/option')], noexpand.
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/option...}
|
||||
{Warning: [B,C,P,X] - singleton variables in table/13 in lines 47-54}
|
||||
{Warning: [B,P,S] - singleton variables in table/13 in lines 54-55}
|
||||
{Warning: [B,C,S] - singleton variables in table/13 in lines 55-56}
|
||||
{Warning: [C,P,S,X] - singleton variables in table/13 in lines 56-57}
|
||||
|
||||
>>> Sample goals (some with multiple answers):
|
||||
go1(W), go2(S, W), go3(S, W), go4(S, W), go5(S, W)
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/option consulted, 130 msec 10032 bytes}
|
||||
|
||||
yes
|
||||
| ?- go1(W).
|
||||
|
||||
W = -19/4 ? ;
|
||||
|
||||
no
|
||||
| ?- go2(S,W).
|
||||
|
||||
W = 21/4,
|
||||
{S>=0},
|
||||
{S<50} ? ;
|
||||
|
||||
{W>5},
|
||||
{S=221/4-W},
|
||||
{W=<21/4} ? ;
|
||||
|
||||
no
|
||||
| ?- go3(S,W).
|
||||
|
||||
{W>=10},
|
||||
{S=187/5-W},
|
||||
{W=<187/5} ? ;
|
||||
|
||||
{W>=10},
|
||||
{S=313/5+W} ? ;
|
||||
|
||||
no
|
||||
| ?- go4(S,W).
|
||||
|
||||
W = 57/10,
|
||||
{S>=0},
|
||||
{S<20} ? ;
|
||||
|
||||
{S>=20},
|
||||
{S<40},
|
||||
{W=257/10-S} ? ;
|
||||
|
||||
W = -143/10,
|
||||
{S>=40},
|
||||
{S<60} ? ;
|
||||
|
||||
{S>=60},
|
||||
{S<80},
|
||||
{W=-743/10+S} ? ;
|
||||
|
||||
W = 57/10,
|
||||
{S>=80} ? ;
|
||||
|
||||
no
|
||||
| ?- go5(S,W).
|
||||
|
||||
no
|
||||
| ?-
|
@ -1,64 +0,0 @@
|
||||
/tmp/clpq
|
||||
|
||||
yes
|
||||
| ?- use_module(library('clpqr/monash')).
|
||||
{compiling /freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl...}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql in module printf, 30 msec 27216 bytes}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql in module expand, 30 msec 26832 bytes}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl compiled, 130 msec 54848 bytes}
|
||||
|
||||
yes
|
||||
| ?- expand, [library('clpqr/examples/monash/pictures')], noexpand.
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/pictures...}
|
||||
{Warning: [DotDashInvis,Text] - singleton variables in box/3 in lines 66-73}
|
||||
|
||||
>>> Sample goals: go1/0, go2/0
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/pictures consulted, 110 msec 12768 bytes}
|
||||
|
||||
yes
|
||||
| ?- go1.
|
||||
.PS 2i
|
||||
line from 3.2,1.8 to 0.688979,1.17224
|
||||
line from 0.688979,1.17224 to 2.30239,4.19362
|
||||
line from 2.30239,4.19362 to 3.2,1.8
|
||||
line from 0,1 to 4,2 dashed
|
||||
line from 3.5,1 to 2,5 dashed
|
||||
line from 0.33,0.5 to 3,5.5 dashed
|
||||
" c1 " at 0,1 rjust
|
||||
" c2 " at 3.5,1 rjust
|
||||
" c3 " at 0.33,0.5 rjust
|
||||
.PE
|
||||
|
||||
yes
|
||||
| ?- go2.
|
||||
.PS 3i
|
||||
line from 0,0 to 8,10
|
||||
line from 8,10 to 10,10
|
||||
line from 10,10 to 10,1
|
||||
line from 10,1 to 0,0
|
||||
line from 4,5 to 9,10 dashed
|
||||
line from 9,10 to 10,5.5 dashed
|
||||
line from 10,5.5 to 5,0.5 dashed
|
||||
line from 5,0.5 to 4,5 dashed
|
||||
line from 0,20 to 0,15
|
||||
line from 0,15 to 10,15
|
||||
line from 10,15 to 10,20
|
||||
line from 10,20 to 0,20
|
||||
line from 0,17.5 to 5,15 dashed
|
||||
line from 5,15 to 10,17.5 dashed
|
||||
line from 10,17.5 to 5,20 dashed
|
||||
line from 5,20 to 0,17.5 dashed
|
||||
line from 5,30 to 10,23
|
||||
line from 10,23 to 15,30
|
||||
line from 15,30 to 10,25
|
||||
line from 10,25 to 5,30
|
||||
line from 7.5,26.5 to 12.5,26.5 dashed
|
||||
line from 12.5,26.5 to 12.5,27.5 dashed
|
||||
line from 12.5,27.5 to 7.5,27.5 dashed
|
||||
line from 7.5,27.5 to 7.5,26.5 dashed
|
||||
.PE
|
||||
|
||||
yes
|
||||
| ?-
|
@ -1,160 +0,0 @@
|
||||
/tmp/clpq
|
||||
|
||||
yes
|
||||
| ?- use_module(library('clpqr/monash')).
|
||||
{compiling /freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl...}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql in module printf, 30 msec 27216 bytes}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql in module expand, 30 msec 26832 bytes}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl compiled, 100 msec 54848 bytes}
|
||||
|
||||
yes
|
||||
| ?- expand, [library('clpqr/examples/monash/rlc')], noexpand.
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/rlc...}
|
||||
{Warning: [Comp,Num,X] - singleton variables in get_node_vars/2 in lines 22-26}
|
||||
{Warning: [V] - singleton variables in insert/3 in lines 36-37}
|
||||
{Warning: [W] - singleton variables in solve/5 in lines 43-47}
|
||||
{Warning: [N,V] - singleton variables in zero_currents/1 in lines 47-52}
|
||||
{Warning: [Vs] - singleton variables in ground_nodes/2 in lines 69-70}
|
||||
{Warning: [I,Vs] - singleton variables in ground_node/2 in lines 70-71}
|
||||
{Warning: [I,N1,V] - singleton variables in ground_node/2 in lines 71-72}
|
||||
{Warning: [W] - singleton variables in iv_reln/5 in lines 85-89}
|
||||
{Warning: [I,W] - singleton variables in iv_reln/5 in lines 89-89}
|
||||
{Warning: [V,W] - singleton variables in iv_reln/5 in lines 89-90}
|
||||
{Warning: [I,L,W] - singleton variables in iv_reln/5 in lines 95-96}
|
||||
{Warning: [L,V,W] - singleton variables in iv_reln/5 in lines 96-97}
|
||||
{Warning: [W] - singleton variables in iv_reln/5 in lines 97-98}
|
||||
{Warning: [I4,NV4,W] - singleton variables in addcomp/5 in lines 111-127}
|
||||
{Warning: [W] - singleton variables in addcomp/5 in lines 129-145}
|
||||
{Warning: [L2,X,Y] - singleton variables in subst/4 in lines 150-152}
|
||||
{Warning: [Im] - singleton variables in c_real/2 in lines 169-171}
|
||||
{Warning: [Re] - singleton variables in c_imag/2 in lines 171-173}
|
||||
{Warning: [Ls] - singleton variables in selective_print/2 in lines 190-191}
|
||||
{Warning: [Comp,Nodes,Num,X] - singleton variables in print_nodes/3 in lines 198-200}
|
||||
{Warning: [Heading_flag,N1] - singleton variables in print_nodes/3 in lines 200-201}
|
||||
{Warning: [Comp,Nodes,Num,X] - singleton variables in print_comps/2 in lines 205-207}
|
||||
{Warning: [Num] - singleton variables in print_comps/2 in lines 207-208}
|
||||
{Warning: [N,X] - singleton variables in heading/2 in lines 212-213}
|
||||
{Warning: [I,Ls,V] - singleton variables in member/2 in lines 213-215}
|
||||
{Warning: [I,N2,V] - singleton variables in member/2 in lines 215-217}
|
||||
{Warning: [R3,W] - singleton variables in go2/0 in lines 285-359}
|
||||
|
||||
>>> Sample goals: go1/0, go2/0
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/rlc consulted, 380 msec 26416 bytes}
|
||||
|
||||
yes
|
||||
| ?- go1.
|
||||
resistor r1: 10 Ohms
|
||||
Node n1
|
||||
Voltage c(10,0)
|
||||
Current c(100/181,-90/181)
|
||||
Node n2
|
||||
Voltage c(810/181,900/181)
|
||||
Current c(-100/181,90/181)
|
||||
|
||||
resistor r3: 10 Ohms
|
||||
Node n1
|
||||
Voltage c(10,0)
|
||||
Current c(100/181,-90/181)
|
||||
Node n4
|
||||
Voltage c(810/181,900/181)
|
||||
Current c(-100/181,90/181)
|
||||
|
||||
inductor l1: 9/10 Henrys
|
||||
Node n2
|
||||
Voltage c(810/181,900/181)
|
||||
Current c(100/181,-90/181)
|
||||
Node n7
|
||||
Voltage c(0,0)
|
||||
Current c(-100/181,90/181)
|
||||
|
||||
inductor l3: 9/10 Henrys
|
||||
Node n4
|
||||
Voltage c(810/181,900/181)
|
||||
Current c(100/181,-90/181)
|
||||
Node n7
|
||||
Voltage c(0,0)
|
||||
Current c(-100/181,90/181)
|
||||
|
||||
capacitor c8: 7/1000 Farads
|
||||
Node n4
|
||||
Voltage c(810/181,900/181)
|
||||
Current c(0,0)
|
||||
Node n5
|
||||
Voltage c(810/181,900/181)
|
||||
Current c(0,0)
|
||||
|
||||
inductor l5: 9/10 Henrys
|
||||
Node n6
|
||||
Voltage c(810/181,900/181)
|
||||
Current c(100/181,-90/181)
|
||||
Node n7
|
||||
Voltage c(0,0)
|
||||
Current c(-100/181,90/181)
|
||||
|
||||
|
||||
yes
|
||||
| ?- go2.
|
||||
|
||||
COMPONENT CONNECTIONS TO NODE n4
|
||||
transistor q1: type bc108 (base, emitter, collector)
|
||||
Node base
|
||||
Voltage c(1325/694,0)
|
||||
Current c(1/11104,0)
|
||||
Node n3
|
||||
Voltage c(2525/1388,0)
|
||||
Current c(-101/11104,0)
|
||||
Node n4
|
||||
Voltage c(-1875/174541,0)
|
||||
Current c(25/2776,0)
|
||||
|
||||
resistor r3: 200 Ohms
|
||||
Node n4
|
||||
Voltage c(-1875/174541,0)
|
||||
Current c(-75/1396328,0)
|
||||
Node ground2
|
||||
Voltage c(0,0)
|
||||
Current c(75/1396328,0)
|
||||
|
||||
transformer t2: ratio of 1/5
|
||||
Node n4
|
||||
Voltage c(-1875/174541,0)
|
||||
Current c(-3125/349082,0)
|
||||
Node ground2
|
||||
Voltage c(0,0)
|
||||
Current c(3125/349082,0)
|
||||
Node out
|
||||
Voltage c(-9375/174541,0)
|
||||
Current c(625/349082,0)
|
||||
Node ground3
|
||||
Voltage c(0,0)
|
||||
Current c(-625/349082,0)
|
||||
|
||||
|
||||
COMPONENT CONNECTIONS TO NODE out
|
||||
transformer t2: ratio of 1/5
|
||||
Node n4
|
||||
Voltage c(-1875/174541,0)
|
||||
Current c(-3125/349082,0)
|
||||
Node ground2
|
||||
Voltage c(0,0)
|
||||
Current c(3125/349082,0)
|
||||
Node out
|
||||
Voltage c(-9375/174541,0)
|
||||
Current c(625/349082,0)
|
||||
Node ground3
|
||||
Voltage c(0,0)
|
||||
Current c(-625/349082,0)
|
||||
|
||||
resistor r5: 30 Ohms
|
||||
Node out
|
||||
Voltage c(-9375/174541,0)
|
||||
Current c(-625/349082,0)
|
||||
Node ground3
|
||||
Voltage c(0,0)
|
||||
Current c(625/349082,0)
|
||||
|
||||
|
||||
yes
|
||||
| ?-
|
@ -1,51 +0,0 @@
|
||||
/tmp/clpq
|
||||
|
||||
yes
|
||||
| ?- use_module(library('clpqr/monash')).
|
||||
{compiling /freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl...}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql in module printf, 40 msec 27216 bytes}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql in module expand, 40 msec 26832 bytes}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl compiled, 120 msec 54848 bytes}
|
||||
|
||||
yes
|
||||
| ?- expand, [library('clpqr/examples/monash/smm')], noexpand.
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/smm...}
|
||||
{Warning: [X] - singleton variables in notmem/2 in lines 61-62}
|
||||
|
||||
>>> Sample goal: go/0
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/smm consulted, 70 msec 8976 bytes}
|
||||
|
||||
yes
|
||||
| ?- go.
|
||||
S = 9, E = 8, N = 9, D = 9, M = 1, O = 0, R = 8, Y = 7
|
||||
S = 9, E = 8, N = 9, D = 8, M = 1, O = 0, R = 8, Y = 6
|
||||
S = 9, E = 8, N = 9, D = 7, M = 1, O = 0, R = 8, Y = 5
|
||||
S = 9, E = 8, N = 9, D = 6, M = 1, O = 0, R = 8, Y = 4
|
||||
S = 9, E = 8, N = 9, D = 5, M = 1, O = 0, R = 8, Y = 3
|
||||
S = 9, E = 8, N = 9, D = 4, M = 1, O = 0, R = 8, Y = 2
|
||||
S = 9, E = 8, N = 9, D = 3, M = 1, O = 0, R = 8, Y = 1
|
||||
S = 9, E = 8, N = 9, D = 2, M = 1, O = 0, R = 8, Y = 0
|
||||
S = 9, E = 7, N = 8, D = 9, M = 1, O = 0, R = 8, Y = 6
|
||||
S = 9, E = 7, N = 8, D = 8, M = 1, O = 0, R = 8, Y = 5
|
||||
S = 9, E = 7, N = 8, D = 7, M = 1, O = 0, R = 8, Y = 4
|
||||
S = 9, E = 7, N = 8, D = 6, M = 1, O = 0, R = 8, Y = 3
|
||||
S = 9, E = 7, N = 8, D = 5, M = 1, O = 0, R = 8, Y = 2
|
||||
S = 9, E = 7, N = 8, D = 4, M = 1, O = 0, R = 8, Y = 1
|
||||
S = 9, E = 7, N = 8, D = 3, M = 1, O = 0, R = 8, Y = 0
|
||||
S = 9, E = 6, N = 7, D = 9, M = 1, O = 0, R = 8, Y = 5
|
||||
S = 9, E = 6, N = 7, D = 8, M = 1, O = 0, R = 8, Y = 4
|
||||
S = 9, E = 6, N = 7, D = 7, M = 1, O = 0, R = 8, Y = 3
|
||||
S = 9, E = 6, N = 7, D = 6, M = 1, O = 0, R = 8, Y = 2
|
||||
S = 9, E = 6, N = 7, D = 5, M = 1, O = 0, R = 8, Y = 1
|
||||
S = 9, E = 6, N = 7, D = 4, M = 1, O = 0, R = 8, Y = 0
|
||||
S = 9, E = 5, N = 6, D = 9, M = 1, O = 0, R = 8, Y = 4
|
||||
S = 9, E = 5, N = 6, D = 8, M = 1, O = 0, R = 8, Y = 3
|
||||
S = 9, E = 5, N = 6, D = 7, M = 1, O = 0, R = 8, Y = 2
|
||||
|
||||
Ans:
|
||||
S = 9, E = 5, N = 6, D = 7, M = 1, O = 0, R = 8, Y = 2
|
||||
|
||||
yes
|
||||
| ?-
|
@ -1,33 +0,0 @@
|
||||
/tmp/clpq
|
||||
|
||||
yes
|
||||
| ?- use_module(library('clpqr/monash')).
|
||||
{compiling /freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl...}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/printf.ql in module printf, 40 msec 27216 bytes}
|
||||
{loading /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql...}
|
||||
{loaded /freyung/christian/sicstus2.1.9.clp/library/clpqr/expand.ql in module expand, 40 msec 26832 bytes}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/monash.pl compiled, 150 msec 54848 bytes}
|
||||
|
||||
yes
|
||||
| ?- expand, [library('clpqr/examples/monash/toolpath')], noexpand.
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/toolpath...}
|
||||
{Warning: [T] - singleton variables in lookup/2 in lines 20-22}
|
||||
{Warning: [H] - singleton variables in lookup/2 in lines 22-24}
|
||||
{Warning: [A,B,X,Y] - singleton variables in get_vars/2 in lines 42-43}
|
||||
{Warning: [A,B,C,M] - singleton variables in get_vars/2 in lines 44-45}
|
||||
{Warning: [Y2] - singleton variables in get_constraint/2 in lines 57-64}
|
||||
{Warning: [C,M,N] - singleton variables in make_db/3 in lines 79-81}
|
||||
|
||||
>>> Sample goal: go/0
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/monash/toolpath consulted, 120 msec 9904 bytes}
|
||||
|
||||
yes
|
||||
| ?- go.
|
||||
G00 X10.000 Y10.000
|
||||
G01 X10.000 Y20.000
|
||||
G01 X15.000 Y15.000
|
||||
G01 X10.000 Y10.000
|
||||
|
||||
yes
|
||||
| ?-
|
File diff suppressed because one or more lines are too long
@ -1,32 +0,0 @@
|
||||
/tmp/clpq
|
||||
|
||||
yes
|
||||
| ?- [library('clpqr/examples/matmul')].
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/matmul.pl...}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/matmul.pl consulted, 50 msec 5216 bytes}
|
||||
|
||||
yes
|
||||
| ?- inv_hilbert(5).
|
||||
% took 130 msec
|
||||
[25,-300,1050,-1400,630]
|
||||
[-300,4800,-18900,26880,-12600]
|
||||
[1050,-18900,79380,-117600,56700]
|
||||
[-1400,26880,-117600,179200,-88200]
|
||||
[630,-12600,56700,-88200,44100]
|
||||
|
||||
yes
|
||||
| ?- inv_hilbert(10).
|
||||
% took 1410 msec
|
||||
[100,-4950,79200,-600600,2522520,-6306300,9609600,-8751600,4375800,-923780]
|
||||
[-4950,326700,-5880600,47567520,-208107900,535134600,-832431600,770140800,-389883780,83140200]
|
||||
[79200,-5880600,112907520,-951350400,4281076800,-11237826600,17758540800,-16635041280,8506555200,-1829084400]
|
||||
[-600600,47567520,-951350400,8245036800,-37875637800,101001700800,-161602721280,152907955200,-78843164400,17071454400]
|
||||
[2522520,-208107900,4281076800,-37875637800,176752976400,-477233036280,771285715200,-735869534400,382086104400,-83223340200]
|
||||
[-6306300,535134600,-11237826600,101001700800,-477233036280,1301544644400,-2121035716800,2037792556800,-1064382719400,233025352560]
|
||||
[9609600,-832431600,17758540800,-161602721280,771285715200,-2121035716800,3480673996800,-3363975014400,1766086882560,-388375587600]
|
||||
[-8751600,770140800,-16635041280,152907955200,-735869534400,2037792556800,-3363975014400,3267861442560,-1723286307600,380449555200]
|
||||
[4375800,-389883780,8506555200,-78843164400,382086104400,-1064382719400,1766086882560,-1723286307600,912328045200,-202113826200]
|
||||
[-923780,83140200,-1829084400,17071454400,-83223340200,233025352560,-388375587600,380449555200,-202113826200,44914183600]
|
||||
|
||||
yes
|
||||
| ?-
|
@ -1,86 +0,0 @@
|
||||
/tmp/clpq
|
||||
|
||||
yes
|
||||
| ?- [library('clpqr/examples/simplex')].
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/simplex.pl...}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/simplex.pl consulted, 240 msec 15360 bytes}
|
||||
|
||||
yes
|
||||
| ?- time(example(N,V,O)).
|
||||
%%% Timing 00:00:00.020 0.020
|
||||
|
||||
N = 1,
|
||||
O = 17200,
|
||||
V = [40,160] ? ;
|
||||
%%% Timing 00:00:00.040 0.040
|
||||
|
||||
N = 2,
|
||||
O = 7,
|
||||
V = [1,0,3/2] ? ;
|
||||
%%% Timing 00:00:00.030 0.030
|
||||
|
||||
N = 3,
|
||||
O = 18850,
|
||||
V = [38,170] ? ;
|
||||
%%% Timing 00:00:00.030 0.030
|
||||
|
||||
N = 4,
|
||||
O = 310,
|
||||
V = [7,2] ? ;
|
||||
%%% Timing 00:00:00.030 0.030
|
||||
|
||||
N = 5,
|
||||
O = 5,
|
||||
V = [0,0,5/2] ? ;
|
||||
%%% Timing 00:00:00.040 0.040
|
||||
|
||||
N = 6,
|
||||
O = -7,
|
||||
V = [1,0,3/2] ? ;
|
||||
%%% Timing 00:00:00.110 0.110
|
||||
|
||||
N = 7,
|
||||
O = -70,
|
||||
V = [3,0,0,4,2,0,5] ? ;
|
||||
%%% Timing 00:00:00.110 0.110
|
||||
|
||||
N = 8,
|
||||
O = -39/2,
|
||||
V = [0,7/2,0,0,0,1/2,0] ? ;
|
||||
%%% Timing 00:00:00.410 0.410
|
||||
|
||||
N = 9,
|
||||
O = 11429082625/9792,
|
||||
V = [555967/58752,203455/39168,43955/3264,1175/272,705/68,0,60,3728575/58752,305075/4896,28375/408,2275/34,1200/17,0,0,0,0,0,24000/17] ? ;
|
||||
%%% Timing 00:00:00.620 0.620
|
||||
|
||||
N = utility,
|
||||
O = 977650/21,
|
||||
V = [0,3400/21,200/7,1000/7,2000/3,0,0,0,1000,0,13400/7,13500/7,0,13900/7,4000,8350/21,45800/21,0,0,1000,500,2000,100,5000,250,600,800/7,0] ? ;
|
||||
%%% Timing 00:00:00.330 0.330
|
||||
|
||||
N = electricity,
|
||||
O = 109400/7,
|
||||
V = [0,3000/7,200/7,_A,_B,0,0,0,_C,_D,_E,_F,_G,_H,1000,500,2000,100],
|
||||
{_A+9/13*_G=<21400/91},
|
||||
{_G>=0},
|
||||
{_A>=0},
|
||||
{_D=1300/7+3/2*_A+1/2*_G},
|
||||
{_F=7900/7-_G},
|
||||
{_H=13900/7+_G},
|
||||
{_C=5700/7-3/2*_A-1/2*_G},
|
||||
{_E=13400/7-_G},
|
||||
{_B=3800/7-_A} ? ;
|
||||
%%% Timing 00:00:00.440 0.440
|
||||
|
||||
N = water,
|
||||
O = 23450,
|
||||
V = [0,0,0,1000,0,0,50,_A,1000/3,_B,4000,0,7450/3,0,0,5000,250,600,_C,0],
|
||||
{_C=5*_A},
|
||||
{_A>=0},
|
||||
{_B=1850/3-_A},
|
||||
{_A=<200/9} ? ;
|
||||
%%% Timing 00:00:00.070 0.070
|
||||
|
||||
no
|
||||
| ?-
|
@ -1,21 +0,0 @@
|
||||
/tmp/clpq
|
||||
|
||||
yes
|
||||
| ?- [library('clpqr/examples/squares')].
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/squares.pl...}
|
||||
{Warning: [X1,X2,X3,X4,X5,X6,X7,X8,X9] - singleton variables in rectangle/2 in lines 1-40}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/squares.pl consulted, 30 msec 2928 bytes}
|
||||
|
||||
yes
|
||||
| ?- time(rectangle(A,Rs)).
|
||||
%%% Timing 00:01:10.950 70.950
|
||||
|
||||
A = 33/32,
|
||||
Rs = [15/32,9/16,1/4,7/32,1/8,7/16,1/32,5/16,9/32] ? ;
|
||||
%%% Timing 00:00:08.730 8.730
|
||||
|
||||
A = 69/61,
|
||||
Rs = [33/61,36/61,28/61,5/61,2/61,9/61,25/61,7/61,16/61] ?
|
||||
|
||||
yes
|
||||
| ?- ^D
|
@ -1,52 +0,0 @@
|
||||
/tmp/clpq
|
||||
|
||||
yes
|
||||
| ?- [library('clpqr/examples/mip')].
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/mip.pl...}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/mip.pl consulted, 2700 msec 97008 bytes}
|
||||
|
||||
yes
|
||||
| ?- example(1).
|
||||
incumbent(14,[1,2])
|
||||
incumbent(13,[2,1])
|
||||
1:13
|
||||
%%% Timing 00:00:00.030 0.030
|
||||
|
||||
yes
|
||||
| ?- example(2).
|
||||
incumbent(-42,[0,2])
|
||||
2:-42
|
||||
%%% Timing 00:00:00.020 0.020
|
||||
|
||||
yes
|
||||
| ?- example(flugpl).
|
||||
incumbent(1202700,[71,70,70,60,60,0,8,7,16,6,6])
|
||||
incumbent(1202400,[72,70,70,60,60,0,9,7,16,6,6])
|
||||
incumbent(1202100,[73,70,70,60,60,0,10,7,16,6,6])
|
||||
incumbent(1201800,[74,70,70,60,60,0,11,7,16,6,6])
|
||||
incumbent(1201500,[75,70,70,60,60,0,12,7,16,6,6])
|
||||
flugpl:1201500
|
||||
%%% Timing 00:00:45.920 45.920
|
||||
|
||||
yes
|
||||
| ?- example(flugplan).
|
||||
incumbent(1202700,[70,7,70,8,71,0,6,60,6,60,16])
|
||||
incumbent(1202400,[70,7,70,9,72,0,6,60,6,60,16])
|
||||
incumbent(1202100,[70,7,70,10,73,0,6,60,6,60,16])
|
||||
incumbent(1201800,[70,7,70,11,74,0,6,60,6,60,16])
|
||||
incumbent(1201500,[70,7,70,12,75,0,6,60,6,60,16])
|
||||
flugplan:1201500
|
||||
%%% Timing 00:00:19.230 19.230
|
||||
|
||||
yes
|
||||
| ?- example(sample2).
|
||||
incumbent(450,[0,0,1,1,0,0,1,0,1,0,0,0,0,0,1,0,0,1,0,1,0])
|
||||
incumbent(430,[0,0,1,0,0,0,1,0,1,0,1,0,0,1,1,1,0,0,0,1,0])
|
||||
incumbent(400,[0,0,1,0,0,0,1,1,0,0,1,0,0,1,1,0,1,0,0,1,0])
|
||||
incumbent(385,[0,0,1,0,0,0,1,0,1,0,1,1,0,0,1,0,0,1,0,1,0])
|
||||
incumbent(375,[0,1,0,0,0,1,1,0,1,0,1,1,0,0,0,0,0,0,1,0,0])
|
||||
sample2:375
|
||||
%%% Timing 00:00:58.940 58.940
|
||||
|
||||
yes
|
||||
| ?-
|
@ -1,256 +0,0 @@
|
||||
/tmp/clpq
|
||||
|
||||
yes
|
||||
| ?- [library('clpqr/examples/eliminat')].
|
||||
{consulting /freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/eliminat.pl...}
|
||||
{/freyung/christian/sicstus2.1.9.clp/library/clpqr/examples/eliminat.pl consulted, 200 msec 15600 bytes}
|
||||
|
||||
yes
|
||||
| ?- hull([X,Y]).
|
||||
|
||||
{Y=<2},
|
||||
{X+1/2*Y=<3},
|
||||
{X>=1},
|
||||
{Y>=0},
|
||||
{X+Y>=2} ?
|
||||
|
||||
yes
|
||||
| ?- example(1,[_,_,X3,X4]).
|
||||
|
||||
{X3-1/3*X4>=-1/3},
|
||||
{X3-11/9*X4=<1/9},
|
||||
{X3-8/9*X4=<1/9},
|
||||
{X3-13/18*X4>=-2/9},
|
||||
{X3-1/6*X4=<1/3} ?
|
||||
|
||||
yes
|
||||
| ?- example(2,[X0,X1|_]).
|
||||
|
||||
{X0+2619277/17854273*X1>=-851123/17854273},
|
||||
{X0+6429953/16575801*X1=<-12749681/16575801},
|
||||
{X0+19130/1213083*X1>=795400/404361},
|
||||
{X0-1251619/3956679*X1>=21101146/3956679},
|
||||
{X0+601502/4257189*X1>=220850/473021} ?
|
||||
|
||||
yes
|
||||
| ?- proj(1).
|
||||
%%% Timing 00:00:00.100 0.100
|
||||
[A,B,C,D]:6
|
||||
{B>=0}
|
||||
{A>=0}
|
||||
{D-3*C+B+12*A=<1}
|
||||
{D-9/7*C+1/7*B+18/7*A>=1/7}
|
||||
{D-18/11*C+2/11*B+36/11*A>=2/11}
|
||||
{D-18/13*C+4/13*B+45/13*A=<4/13}
|
||||
|
||||
%%% Timing 00:00:00.270 0.270
|
||||
[A,B,C]:6
|
||||
{A>=0}
|
||||
{C-6*B-2*A>=-2}
|
||||
{C-18/13*B+4/13*A=<4/13}
|
||||
{C-9/11*B-1/11*A>=-1/11}
|
||||
{C-9/8*B-1/8*A>=-1/8}
|
||||
{C-3*B+A=<1}
|
||||
|
||||
%%% Timing 00:00:00.320 0.320
|
||||
[A,B]:5
|
||||
{B-3*A=<1}
|
||||
{B-9/11*A>=-1/11}
|
||||
{B-9/8*A>=-1/8}
|
||||
{B-18/13*A=<4/13}
|
||||
{B-6*A>=-2}
|
||||
|
||||
%%% Timing 00:00:00.290 0.290
|
||||
[A]:2
|
||||
{A=<1}
|
||||
{A>=-1/2}
|
||||
|
||||
%%% Timing 00:00:00.030 0.030
|
||||
[]:0
|
||||
|
||||
%%% Timing 00:00:00.260 0.260
|
||||
[A]:2
|
||||
{A=<1/2}
|
||||
{A>=-1/2}
|
||||
|
||||
%%% Timing 00:00:00.250 0.250
|
||||
[A,B]:3
|
||||
{A>=0}
|
||||
{B-1/2*A>=-1/2}
|
||||
{B+A=<1}
|
||||
|
||||
%%% Timing 00:00:00.190 0.190
|
||||
[A]:2
|
||||
{A>=0}
|
||||
{A=<1}
|
||||
|
||||
%%% Timing 00:00:00.270 0.270
|
||||
[A,B]:3
|
||||
{A>=0}
|
||||
{B-1/2*A>=-1/2}
|
||||
{B+1/2*A=<1/2}
|
||||
|
||||
%%% Timing 00:00:00.260 0.260
|
||||
[A,B,C]:6
|
||||
{A>=0}
|
||||
{C-2*B+3*A>=0}
|
||||
{C-18/13*B+45/13*A=<4/13}
|
||||
{C-B+A>=0}
|
||||
{C-4/3*B+4/3*A>=0}
|
||||
{C-3*B+12*A=<1}
|
||||
|
||||
%%% Timing 00:00:00.250 0.250
|
||||
[A,B]:4
|
||||
{A>=0}
|
||||
{B-36/5*A>=-4/5}
|
||||
{B-9/2*A>=-1/2}
|
||||
{B+9/2*A=<1}
|
||||
|
||||
%%% Timing 00:00:00.200 0.200
|
||||
[A]:2
|
||||
{A>=0}
|
||||
{A=<2/13}
|
||||
|
||||
%%% Timing 00:00:00.230 0.230
|
||||
[A,B]:4
|
||||
{A>=0}
|
||||
{B-32/5*A>=-3/5}
|
||||
{B-11/2*A>=-1/2}
|
||||
{B+3/4*A=<1/2}
|
||||
|
||||
%%% Timing 00:00:00.230 0.230
|
||||
[A,B,C]:5
|
||||
{B>=0}
|
||||
{A>=0}
|
||||
{C+B+9/2*A=<1}
|
||||
{C-1/2*B-9/2*A>=-1/2}
|
||||
{C-4/5*B-36/5*A>=-4/5}
|
||||
|
||||
%%% Timing 00:00:00.200 0.200
|
||||
[A,B]:3
|
||||
{B>=0}
|
||||
{A>=0}
|
||||
{B+13/2*A=<1}
|
||||
|
||||
%%% Timing 00:00:00.210 0.210
|
||||
[A,B,C]:5
|
||||
{B>=0}
|
||||
{A>=0}
|
||||
{C+1/2*B+3/4*A=<1/2}
|
||||
{C-1/2*B-11/2*A>=-1/2}
|
||||
{C-3/5*B-32/5*A>=-3/5}
|
||||
|
||||
%%% Timing 00:00:00.000 0.000
|
||||
|
||||
no
|
||||
| ?- proj(3).
|
||||
%%% Timing 00:00:00.100 0.100
|
||||
[A,B,C,D]:6
|
||||
{B>=0}
|
||||
{A>0}
|
||||
{D-3*C+B+12*A=<1}
|
||||
{D-9/7*C+1/7*B+18/7*A>=1/7}
|
||||
{D-18/11*C+2/11*B+36/11*A>=2/11}
|
||||
{D-18/13*C+4/13*B+45/13*A=<4/13}
|
||||
|
||||
%%% Timing 00:00:00.260 0.260
|
||||
[A,B,C]:6
|
||||
{A>=0}
|
||||
{C-6*B-2*A>=-2}
|
||||
{C-18/13*B+4/13*A<4/13}
|
||||
{C-9/11*B-1/11*A>=-1/11}
|
||||
{C-9/8*B-1/8*A>=-1/8}
|
||||
{C-3*B+A<1}
|
||||
|
||||
%%% Timing 00:00:00.290 0.290
|
||||
[A,B]:5
|
||||
{B-3*A<1}
|
||||
{B-9/11*A>=-1/11}
|
||||
{B-9/8*A>=-1/8}
|
||||
{B-18/13*A<4/13}
|
||||
{B-6*A>=-2}
|
||||
|
||||
%%% Timing 00:00:00.280 0.280
|
||||
[A]:2
|
||||
{A<1}
|
||||
{A>-1/2}
|
||||
|
||||
%%% Timing 00:00:00.040 0.040
|
||||
[]:0
|
||||
|
||||
%%% Timing 00:00:00.250 0.250
|
||||
[A]:2
|
||||
{A<1/2}
|
||||
{A>-1/2}
|
||||
|
||||
%%% Timing 00:00:00.260 0.260
|
||||
[A,B]:3
|
||||
{A>=0}
|
||||
{B-1/2*A>-1/2}
|
||||
{B+A<1}
|
||||
|
||||
%%% Timing 00:00:00.190 0.190
|
||||
[A]:2
|
||||
{A>=0}
|
||||
{A<1}
|
||||
|
||||
%%% Timing 00:00:00.260 0.260
|
||||
[A,B]:3
|
||||
{A>=0}
|
||||
{B-1/2*A>-1/2}
|
||||
{B+1/2*A<1/2}
|
||||
|
||||
%%% Timing 00:00:00.260 0.260
|
||||
[A,B,C]:6
|
||||
{A>0}
|
||||
{C-2*B+3*A>=0}
|
||||
{C-18/13*B+45/13*A=<4/13}
|
||||
{C-B+A>=0}
|
||||
{C-4/3*B+4/3*A>=0}
|
||||
{C-3*B+12*A=<1}
|
||||
|
||||
%%% Timing 00:00:00.260 0.260
|
||||
[A,B]:4
|
||||
{A>0}
|
||||
{B-36/5*A>=-4/5}
|
||||
{B-9/2*A>=-1/2}
|
||||
{B+9/2*A=<1}
|
||||
|
||||
%%% Timing 00:00:00.210 0.210
|
||||
[A]:2
|
||||
{A>0}
|
||||
{A=<2/13}
|
||||
|
||||
%%% Timing 00:00:00.230 0.230
|
||||
[A,B]:4
|
||||
{A>0}
|
||||
{B-32/5*A>=-3/5}
|
||||
{B-11/2*A>=-1/2}
|
||||
{B+3/4*A=<1/2}
|
||||
|
||||
%%% Timing 00:00:00.220 0.220
|
||||
[A,B,C]:5
|
||||
{B>=0}
|
||||
{A>0}
|
||||
{C+B+9/2*A=<1}
|
||||
{C-1/2*B-9/2*A>=-1/2}
|
||||
{C-4/5*B-36/5*A>=-4/5}
|
||||
|
||||
%%% Timing 00:00:00.200 0.200
|
||||
[A,B]:3
|
||||
{B>=0}
|
||||
{A>0}
|
||||
{B+13/2*A=<1}
|
||||
|
||||
%%% Timing 00:00:00.230 0.230
|
||||
[A,B,C]:5
|
||||
{B>=0}
|
||||
{A>0}
|
||||
{C+1/2*B+3/4*A=<1/2}
|
||||
{C-1/2*B-11/2*A>=-1/2}
|
||||
{C-3/5*B-32/5*A>=-3/5}
|
||||
|
||||
%%% Timing 00:00:00.020 0.020
|
||||
|
||||
no
|
||||
| ?-
|
@ -1,105 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.2 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: caneghem.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
caneghem(10,[_176,_178,_180,_182,_184,_186,_188,_190,_192,_194]) :-
|
||||
{
|
||||
_176*1 + _178*1 + _180*1 + _182*1 + _184*1 + _186*1 + _188*1 + _190*1 + _192*1 + _194*1 = 1,
|
||||
_176*2 + _178*4 + _180*8 + _182*16 + _184*32 + _186*64 + _188*27 + _190*54 + _192*7 + _194*14 = 0,
|
||||
_176*3 + _178*9 + _180*27 + _182*81 + _184*41 + _186*22 + _188*66 + _190*97 + _192*89 + _194*65 = 0,
|
||||
_176*4 + _178*16 + _180*64 + _182*54 + _184*14 + _186*56 + _188*22 + _190*88 + _192*49 + _194*95 = 0,
|
||||
_176*5 + _178*25 + _180*24 + _182*19 + _184*95 + _186*71 + _188*52 + _190*58 + _192*88 + _194*36 = 0,
|
||||
_176*6 + _178*36 + _180*14 + _182*84 + _184*100 + _186*95 + _188*65 + _190*87 + _192*17 + _194*1 = 0,
|
||||
_176*7 + _178*49 + _180*40 + _182*78 + _184*41 + _186*85 + _188*90 + _190*24 + _192*67 + _194*65 = 0,
|
||||
_176*8 + _178*64 + _180*7 + _182*56 + _184*44 + _186*49 + _188*89 + _190*5 + _192*40 + _194*17 = 0,
|
||||
_176*9 + _178*81 + _180*22 + _182*97 + _184*65 + _186*80 + _188*13 + _190*16 + _192*43 + _194*84 = 0,
|
||||
_176*10 + _178*100 + _180*91 + _182*1 + _184*10 + _186*100 + _188*91 + _190*1 + _192*10 + _194*100 = 0
|
||||
}.
|
||||
|
||||
caneghem(20,[_176,_178,_180,_182,_184,_186,_188,_190,_192,_194,_196,_198,_200,_202,_204,_206,_208,_210,_212,_214]) :-
|
||||
{
|
||||
_176*1 + _178*1 + _180*1 + _182*1 + _184*1 + _186*1 + _188*1 + _190*1 + _192*1 + _194*1 + _196*1 + _198*1 + _200*1 + _202*1 + _204*1 + _206*1 + _208*1 + _210*1 + _212*1 + _214*1 = 1,
|
||||
_176*2 + _178*4 + _180*8 + _182*16 + _184*32 + _186*64 + _188*27 + _190*54 + _192*7 + _194*14 + _196*28 + _198*56 + _200*11 + _202*22 + _204*44 + _206*88 + _208*75 + _210*49 + _212*98 + _214*95 = 0,
|
||||
_176*3 + _178*9 + _180*27 + _182*81 + _184*41 + _186*22 + _188*66 + _190*97 + _192*89 + _194*65 + _196*94 + _198*80 + _200*38 + _202*13 + _204*39 + _206*16 + _208*48 + _210*43 + _212*28 + _214*84 = 0,
|
||||
_176*4 + _178*16 + _180*64 + _182*54 + _184*14 + _186*56 + _188*22 + _190*88 + _192*49 + _194*95 + _196*77 + _198*5 + _200*20 + _202*80 + _204*17 + _206*68 + _208*70 + _210*78 + _212*9 + _214*36 = 0,
|
||||
_176*5 + _178*25 + _180*24 + _182*19 + _184*95 + _186*71 + _188*52 + _190*58 + _192*88 + _194*36 + _196*79 + _198*92 + _200*56 + _202*78 + _204*87 + _206*31 + _208*54 + _210*68 + _212*37 + _214*84 = 0,
|
||||
_176*6 + _178*36 + _180*14 + _182*84 + _184*100 + _186*95 + _188*65 + _190*87 + _192*17 + _194*1 + _196*6 + _198*36 + _200*14 + _202*84 + _204*100 + _206*95 + _208*65 + _210*87 + _212*17 + _214*1 = 0,
|
||||
_176*7 + _178*49 + _180*40 + _182*78 + _184*41 + _186*85 + _188*90 + _190*24 + _192*67 + _194*65 + _196*51 + _198*54 + _200*75 + _202*20 + _204*39 + _206*71 + _208*93 + _210*45 + _212*12 + _214*84 = 0,
|
||||
_176*8 + _178*64 + _180*7 + _182*56 + _184*44 + _186*49 + _188*89 + _190*5 + _192*40 + _194*17 + _196*35 + _198*78 + _200*18 + _202*43 + _204*41 + _206*25 + _208*99 + _210*85 + _212*74 + _214*87 = 0,
|
||||
_176*9 + _178*81 + _180*22 + _182*97 + _184*65 + _186*80 + _188*13 + _190*16 + _192*43 + _194*84 + _196*49 + _198*37 + _200*30 + _202*68 + _204*6 + _206*54 + _208*82 + _210*31 + _212*77 + _214*87 = 0,
|
||||
_176*10 + _178*100 + _180*91 + _182*1 + _184*10 + _186*100 + _188*91 + _190*1 + _192*10 + _194*100 + _196*91 + _198*1 + _200*10 + _202*100 + _204*91 + _206*1 + _208*10 + _210*100 + _212*91 + _214*1 = 0,
|
||||
_176*11 + _178*20 + _180*18 + _182*97 + _184*57 + _186*21 + _188*29 + _190*16 + _192*75 + _194*17 + _196*86 + _198*37 + _200*3 + _202*33 + _204*60 + _206*54 + _208*89 + _210*70 + _212*63 + _214*87 = 0,
|
||||
_176*12 + _178*43 + _180*11 + _182*31 + _184*69 + _186*20 + _188*38 + _190*52 + _192*18 + _194*14 + _196*67 + _198*97 + _200*53 + _202*30 + _204*57 + _206*78 + _208*27 + _210*21 + _212*50 + _214*95 = 0,
|
||||
_176*13 + _178*68 + _180*76 + _182*79 + _184*17 + _186*19 + _188*45 + _190*80 + _192*30 + _194*87 + _196*20 + _198*58 + _200*47 + _202*5 + _204*65 + _206*37 + _208*77 + _210*92 + _212*85 + _214*95 = 0,
|
||||
_176*14 + _178*95 + _180*17 + _182*36 + _184*100 + _186*87 + _188*6 + _190*84 + _192*65 + _194*1 + _196*14 + _198*95 + _200*17 + _202*36 + _204*100 + _206*87 + _208*6 + _210*84 + _212*65 + _214*1 = 0,
|
||||
_176*15 + _178*23 + _180*42 + _182*24 + _184*57 + _186*47 + _188*99 + _190*71 + _192*55 + _194*17 + _196*53 + _198*88 + _200*7 + _202*4 + _204*60 + _206*92 + _208*67 + _210*96 + _212*26 + _214*87 = 0,
|
||||
_176*16 + _178*54 + _180*56 + _182*88 + _184*95 + _186*5 + _188*80 + _190*68 + _192*78 + _194*36 + _196*71 + _198*25 + _200*97 + _202*37 + _204*87 + _206*79 + _208*52 + _210*24 + _212*81 + _214*84 = 0,
|
||||
_176*17 + _178*87 + _180*65 + _182*95 + _184*100 + _186*84 + _188*14 + _190*36 + _192*6 + _194*1 + _196*17 + _198*87 + _200*65 + _202*95 + _204*100 + _206*84 + _208*14 + _210*36 + _212*6 + _214*1 = 0,
|
||||
_176*18 + _178*21 + _180*75 + _182*37 + _184*60 + _186*70 + _188*48 + _190*56 + _192*99 + _194*65 + _196*59 + _198*52 + _200*27 + _202*82 + _204*62 + _206*5 + _208*90 + _210*4 + _212*72 + _214*84 = 0,
|
||||
_176*19 + _178*58 + _180*92 + _182*31 + _184*84 + _186*81 + _188*24 + _190*52 + _192*79 + _194*87 + _196*37 + _198*97 + _200*25 + _202*71 + _204*36 + _206*78 + _208*68 + _210*80 + _212*5 + _214*95 = 0,
|
||||
_176*20 + _178*97 + _180*21 + _182*16 + _184*17 + _186*37 + _188*33 + _190*54 + _192*70 + _194*87 + _196*23 + _198*56 + _200*9 + _202*79 + _204*65 + _206*88 + _208*43 + _210*52 + _212*30 + _214*95 = 0
|
||||
}.
|
||||
|
||||
caneghem(50,[_108,_110,_112,_114,_116,_118,_120,_122,_124,_126,_128,_130,_132,_134,_136,_138,_140,_142,_144,_146,_148,_150,_152,_154,_156,_158,_160,_162,_164,_166,_168,_170,_172,_174,_176,_178,_180,_182,_184,_186,_188,_190,_192,_194,_196,_198,_200,_202,_204,_206]) :-
|
||||
{
|
||||
_108*1 + _110*1 + _112*1 + _114*1 + _116*1 + _118*1 + _120*1 + _122*1 + _124*1 + _126*1 + _128*1 + _130*1 + _132*1 + _134*1 + _136*1 + _138*1 + _140*1 + _142*1 + _144*1 + _146*1 + _148*1 + _150*1 + _152*1 + _154*1 + _156*1 + _158*1 + _160*1 + _162*1 + _164*1 + _166*1 + _168*1 + _170*1 + _172*1 + _174*1 + _176*1 + _178*1 + _180*1 + _182*1 + _184*1 + _186*1 + _188*1 + _190*1 + _192*1 + _194*1 + _196*1 + _198*1 + _200*1 + _202*1 + _204*1 + _206*1 = 1,
|
||||
_108*2 + _110*4 + _112*8 + _114*16 + _116*32 + _118*64 + _120*27 + _122*54 + _124*7 + _126*14 + _128*28 + _130*56 + _132*11 + _134*22 + _136*44 + _138*88 + _140*75 + _142*49 + _144*98 + _146*95 + _148*89 + _150*77 + _152*53 + _154*5 + _156*10 + _158*20 + _160*40 + _162*80 + _164*59 + _166*17 + _168*34 + _170*68 + _172*35 + _174*70 + _176*39 + _178*78 + _180*55 + _182*9 + _184*18 + _186*36 + _188*72 + _190*43 + _192*86 + _194*71 + _196*41 + _198*82 + _200*63 + _202*25 + _204*50 + _206*100 = 0,
|
||||
_108*3 + _110*9 + _112*27 + _114*81 + _116*41 + _118*22 + _120*66 + _122*97 + _124*89 + _126*65 + _128*94 + _130*80 + _132*38 + _134*13 + _136*39 + _138*16 + _140*48 + _142*43 + _144*28 + _146*84 + _148*50 + _150*49 + _152*46 + _154*37 + _156*10 + _158*30 + _160*90 + _162*68 + _164*2 + _166*6 + _168*18 + _170*54 + _172*61 + _174*82 + _176*44 + _178*31 + _180*93 + _182*77 + _184*29 + _186*87 + _188*59 + _190*76 + _192*26 + _194*78 + _196*32 + _198*96 + _200*86 + _202*56 + _204*67 + _206*100 = 0,
|
||||
_108*4 + _110*16 + _112*64 + _114*54 + _116*14 + _118*56 + _120*22 + _122*88 + _124*49 + _126*95 + _128*77 + _130*5 + _132*20 + _134*80 + _136*17 + _138*68 + _140*70 + _142*78 + _144*9 + _146*36 + _148*43 + _150*71 + _152*82 + _154*25 + _156*100 + _158*97 + _160*85 + _162*37 + _164*47 + _166*87 + _168*45 + _170*79 + _172*13 + _174*52 + _176*6 + _178*24 + _180*96 + _182*81 + _184*21 + _186*84 + _188*33 + _190*31 + _192*23 + _194*92 + _196*65 + _198*58 + _200*30 + _202*19 + _204*76 + _206*1 = 0,
|
||||
_108*5 + _110*25 + _112*24 + _114*19 + _116*95 + _118*71 + _120*52 + _122*58 + _124*88 + _126*36 + _128*79 + _130*92 + _132*56 + _134*78 + _136*87 + _138*31 + _140*54 + _142*68 + _144*37 + _146*84 + _148*16 + _150*80 + _152*97 + _154*81 + _156*1 + _158*5 + _160*25 + _162*24 + _164*19 + _166*95 + _168*71 + _170*52 + _172*58 + _174*88 + _176*36 + _178*79 + _180*92 + _182*56 + _184*78 + _186*87 + _188*31 + _190*54 + _192*68 + _194*37 + _196*84 + _198*16 + _200*80 + _202*97 + _204*81 + _206*1 = 0,
|
||||
_108*6 + _110*36 + _112*14 + _114*84 + _116*100 + _118*95 + _120*65 + _122*87 + _124*17 + _126*1 + _128*6 + _130*36 + _132*14 + _134*84 + _136*100 + _138*95 + _140*65 + _142*87 + _144*17 + _146*1 + _148*6 + _150*36 + _152*14 + _154*84 + _156*100 + _158*95 + _160*65 + _162*87 + _164*17 + _166*1 + _168*6 + _170*36 + _172*14 + _174*84 + _176*100 + _178*95 + _180*65 + _182*87 + _184*17 + _186*1 + _188*6 + _190*36 + _192*14 + _194*84 + _196*100 + _198*95 + _200*65 + _202*87 + _204*17 + _206*1 = 0,
|
||||
_108*7 + _110*49 + _112*40 + _114*78 + _116*41 + _118*85 + _120*90 + _122*24 + _124*67 + _126*65 + _128*51 + _130*54 + _132*75 + _134*20 + _136*39 + _138*71 + _140*93 + _142*45 + _144*12 + _146*84 + _148*83 + _150*76 + _152*27 + _154*88 + _156*10 + _158*70 + _160*86 + _162*97 + _164*73 + _166*6 + _168*42 + _170*92 + _172*38 + _174*64 + _176*44 + _178*5 + _180*35 + _182*43 + _184*99 + _186*87 + _188*3 + _190*21 + _192*46 + _194*19 + _196*32 + _198*22 + _200*53 + _202*68 + _204*72 + _206*100 = 0,
|
||||
_108*8 + _110*64 + _112*7 + _114*56 + _116*44 + _118*49 + _120*89 + _122*5 + _124*40 + _126*17 + _128*35 + _130*78 + _132*18 + _134*43 + _136*41 + _138*25 + _140*99 + _142*85 + _144*74 + _146*87 + _148*90 + _150*13 + _152*3 + _154*24 + _156*91 + _158*21 + _160*67 + _162*31 + _164*46 + _166*65 + _168*15 + _170*19 + _172*51 + _174*4 + _176*32 + _178*54 + _180*28 + _182*22 + _184*75 + _186*95 + _188*53 + _190*20 + _192*59 + _194*68 + _196*39 + _198*9 + _200*72 + _202*71 + _204*63 + _206*100 = 0,
|
||||
_108*9 + _110*81 + _112*22 + _114*97 + _116*65 + _118*80 + _120*13 + _122*16 + _124*43 + _126*84 + _128*49 + _130*37 + _132*30 + _134*68 + _136*6 + _138*54 + _140*82 + _142*31 + _144*77 + _146*87 + _148*76 + _150*78 + _152*96 + _154*56 + _156*100 + _158*92 + _160*20 + _162*79 + _164*4 + _166*36 + _168*21 + _170*88 + _172*85 + _174*58 + _176*17 + _178*52 + _180*64 + _182*71 + _184*33 + _186*95 + _188*47 + _190*19 + _192*70 + _194*24 + _196*14 + _198*25 + _200*23 + _202*5 + _204*45 + _206*1 = 0,
|
||||
_108*10 + _110*100 + _112*91 + _114*1 + _116*10 + _118*100 + _120*91 + _122*1 + _124*10 + _126*100 + _128*91 + _130*1 + _132*10 + _134*100 + _136*91 + _138*1 + _140*10 + _142*100 + _144*91 + _146*1 + _148*10 + _150*100 + _152*91 + _154*1 + _156*10 + _158*100 + _160*91 + _162*1 + _164*10 + _166*100 + _168*91 + _170*1 + _172*10 + _174*100 + _176*91 + _178*1 + _180*10 + _182*100 + _184*91 + _186*1 + _188*10 + _190*100 + _192*91 + _194*1 + _196*10 + _198*100 + _200*91 + _202*1 + _204*10 + _206*100 = 0,
|
||||
_108*11 + _110*20 + _112*18 + _114*97 + _116*57 + _118*21 + _120*29 + _122*16 + _124*75 + _126*17 + _128*86 + _130*37 + _132*3 + _134*33 + _136*60 + _138*54 + _140*89 + _142*70 + _144*63 + _146*87 + _148*48 + _150*23 + _152*51 + _154*56 + _156*10 + _158*9 + _160*99 + _162*79 + _164*61 + _166*65 + _168*8 + _170*88 + _172*59 + _174*43 + _176*69 + _178*52 + _180*67 + _182*30 + _184*27 + _186*95 + _188*35 + _190*82 + _192*94 + _194*24 + _196*62 + _198*76 + _200*28 + _202*5 + _204*55 + _206*100 = 0,
|
||||
_108*12 + _110*43 + _112*11 + _114*31 + _116*69 + _118*20 + _120*38 + _122*52 + _124*18 + _126*14 + _128*67 + _130*97 + _132*53 + _134*30 + _136*57 + _138*78 + _140*27 + _142*21 + _144*50 + _146*95 + _148*29 + _150*45 + _152*35 + _154*16 + _156*91 + _158*82 + _160*75 + _162*92 + _164*94 + _166*17 + _168*2 + _170*24 + _172*86 + _174*22 + _176*62 + _178*37 + _180*40 + _182*76 + _184*3 + _186*36 + _188*28 + _190*33 + _192*93 + _194*5 + _196*60 + _198*13 + _200*55 + _202*54 + _204*42 + _206*100 = 0,
|
||||
_108*13 + _110*68 + _112*76 + _114*79 + _116*17 + _118*19 + _120*45 + _122*80 + _124*30 + _126*87 + _128*20 + _130*58 + _132*47 + _134*5 + _136*65 + _138*37 + _140*77 + _142*92 + _144*85 + _146*95 + _148*23 + _150*97 + _152*49 + _154*31 + _156*100 + _158*88 + _160*33 + _162*25 + _164*22 + _166*84 + _168*82 + _170*56 + _172*21 + _174*71 + _176*14 + _178*81 + _180*43 + _182*54 + _184*96 + _186*36 + _188*64 + _190*24 + _192*9 + _194*16 + _196*6 + _198*78 + _200*4 + _202*52 + _204*70 + _206*1 = 0,
|
||||
_108*14 + _110*95 + _112*17 + _114*36 + _116*100 + _118*87 + _120*6 + _122*84 + _124*65 + _126*1 + _128*14 + _130*95 + _132*17 + _134*36 + _136*100 + _138*87 + _140*6 + _142*84 + _144*65 + _146*1 + _148*14 + _150*95 + _152*17 + _154*36 + _156*100 + _158*87 + _160*6 + _162*84 + _164*65 + _166*1 + _168*14 + _170*95 + _172*17 + _174*36 + _176*100 + _178*87 + _180*6 + _182*84 + _184*65 + _186*1 + _188*14 + _190*95 + _192*17 + _194*36 + _196*100 + _198*87 + _200*6 + _202*84 + _204*65 + _206*1 = 0,
|
||||
_108*15 + _110*23 + _112*42 + _114*24 + _116*57 + _118*47 + _120*99 + _122*71 + _124*55 + _126*17 + _128*53 + _130*88 + _132*7 + _134*4 + _136*60 + _138*92 + _140*67 + _142*96 + _144*26 + _146*87 + _148*93 + _150*82 + _152*18 + _154*68 + _156*10 + _158*49 + _160*28 + _162*16 + _164*38 + _166*65 + _168*66 + _170*81 + _172*3 + _174*45 + _176*69 + _178*25 + _180*72 + _182*70 + _184*40 + _186*95 + _188*11 + _190*64 + _192*51 + _194*58 + _196*62 + _198*21 + _200*12 + _202*79 + _204*74 + _206*100 = 0,
|
||||
_108*16 + _110*54 + _112*56 + _114*88 + _116*95 + _118*5 + _120*80 + _122*68 + _124*78 + _126*36 + _128*71 + _130*25 + _132*97 + _134*37 + _136*87 + _138*79 + _140*52 + _142*24 + _144*81 + _146*84 + _148*31 + _150*92 + _152*58 + _154*19 + _156*1 + _158*16 + _160*54 + _162*56 + _164*88 + _166*95 + _168*5 + _170*80 + _172*68 + _174*78 + _176*36 + _178*71 + _180*25 + _182*97 + _184*37 + _186*87 + _188*79 + _190*52 + _192*24 + _194*81 + _196*84 + _198*31 + _200*92 + _202*58 + _204*19 + _206*1 = 0,
|
||||
_108*17 + _110*87 + _112*65 + _114*95 + _116*100 + _118*84 + _120*14 + _122*36 + _124*6 + _126*1 + _128*17 + _130*87 + _132*65 + _134*95 + _136*100 + _138*84 + _140*14 + _142*36 + _144*6 + _146*1 + _148*17 + _150*87 + _152*65 + _154*95 + _156*100 + _158*84 + _160*14 + _162*36 + _164*6 + _166*1 + _168*17 + _170*87 + _172*65 + _174*95 + _176*100 + _178*84 + _180*14 + _182*36 + _184*6 + _186*1 + _188*17 + _190*87 + _192*65 + _194*95 + _196*100 + _198*84 + _200*14 + _202*36 + _204*6 + _206*1 = 0,
|
||||
_108*18 + _110*21 + _112*75 + _114*37 + _116*60 + _118*70 + _120*48 + _122*56 + _124*99 + _126*65 + _128*59 + _130*52 + _132*27 + _134*82 + _136*62 + _138*5 + _140*90 + _142*4 + _144*72 + _146*84 + _148*98 + _150*47 + _152*38 + _154*78 + _156*91 + _158*22 + _160*93 + _162*58 + _164*34 + _166*6 + _168*7 + _170*25 + _172*46 + _174*20 + _176*57 + _178*16 + _180*86 + _182*33 + _184*89 + _186*87 + _188*51 + _190*9 + _192*61 + _194*88 + _196*69 + _198*30 + _200*35 + _202*24 + _204*28 + _206*100 = 0,
|
||||
_108*19 + _110*58 + _112*92 + _114*31 + _116*84 + _118*81 + _120*24 + _122*52 + _124*79 + _126*87 + _128*37 + _130*97 + _132*25 + _134*71 + _136*36 + _138*78 + _140*68 + _142*80 + _144*5 + _146*95 + _148*88 + _150*56 + _152*54 + _154*16 + _156*1 + _158*19 + _160*58 + _162*92 + _164*31 + _166*84 + _168*81 + _170*24 + _172*52 + _174*79 + _176*87 + _178*37 + _180*97 + _182*25 + _184*71 + _186*36 + _188*78 + _190*68 + _192*80 + _194*5 + _196*95 + _198*88 + _200*56 + _202*54 + _204*16 + _206*1 = 0,
|
||||
_108*20 + _110*97 + _112*21 + _114*16 + _116*17 + _118*37 + _120*33 + _122*54 + _124*70 + _126*87 + _128*23 + _130*56 + _132*9 + _134*79 + _136*65 + _138*88 + _140*43 + _142*52 + _144*30 + _146*95 + _148*82 + _150*24 + _152*76 + _154*5 + _156*100 + _158*81 + _160*4 + _162*80 + _164*85 + _166*84 + _168*64 + _170*68 + _172*47 + _174*31 + _176*14 + _178*78 + _180*45 + _182*92 + _184*22 + _186*36 + _188*13 + _190*58 + _192*49 + _194*71 + _196*6 + _198*19 + _200*77 + _202*25 + _204*96 + _206*1 = 0,
|
||||
_108*21 + _110*37 + _112*70 + _114*56 + _116*65 + _118*52 + _120*82 + _122*5 + _124*4 + _126*84 + _128*47 + _130*78 + _132*22 + _134*58 + _136*6 + _138*25 + _140*20 + _142*16 + _144*33 + _146*87 + _148*9 + _150*88 + _152*30 + _154*24 + _156*100 + _158*80 + _160*64 + _162*31 + _164*45 + _166*36 + _168*49 + _170*19 + _172*96 + _174*97 + _176*17 + _178*54 + _180*23 + _182*79 + _184*43 + _186*95 + _188*76 + _190*81 + _192*85 + _194*68 + _196*14 + _198*92 + _200*13 + _202*71 + _204*77 + _206*1 = 0,
|
||||
_108*22 + _110*80 + _112*43 + _114*37 + _116*6 + _118*31 + _120*76 + _122*56 + _124*20 + _126*36 + _128*85 + _130*52 + _132*33 + _134*19 + _136*14 + _138*5 + _140*9 + _142*97 + _144*13 + _146*84 + _148*30 + _150*54 + _152*77 + _154*78 + _156*100 + _158*79 + _160*21 + _162*58 + _164*64 + _166*95 + _168*70 + _170*25 + _172*45 + _174*81 + _176*65 + _178*16 + _180*49 + _182*68 + _184*82 + _186*87 + _188*96 + _190*92 + _192*4 + _194*88 + _196*17 + _198*71 + _200*47 + _202*24 + _204*23 + _206*1 = 0,
|
||||
_108*23 + _110*24 + _112*47 + _114*71 + _116*17 + _118*88 + _120*4 + _122*92 + _124*96 + _126*87 + _128*82 + _130*68 + _132*49 + _134*16 + _136*65 + _138*81 + _140*45 + _142*25 + _144*70 + _146*95 + _148*64 + _150*58 + _152*21 + _154*79 + _156*100 + _158*78 + _160*77 + _162*54 + _164*30 + _166*84 + _168*13 + _170*97 + _172*9 + _174*5 + _176*14 + _178*19 + _180*33 + _182*52 + _184*85 + _186*36 + _188*20 + _190*56 + _192*76 + _194*31 + _196*6 + _198*37 + _200*43 + _202*80 + _204*22 + _206*1 = 0,
|
||||
_108*24 + _110*71 + _112*88 + _114*92 + _116*87 + _118*68 + _120*16 + _122*81 + _124*25 + _126*95 + _128*58 + _130*79 + _132*78 + _134*54 + _136*84 + _138*97 + _140*5 + _142*19 + _144*52 + _146*36 + _148*56 + _150*31 + _152*37 + _154*80 + _156*1 + _158*24 + _160*71 + _162*88 + _164*92 + _166*87 + _168*68 + _170*16 + _172*81 + _174*25 + _176*95 + _178*58 + _180*79 + _182*78 + _184*54 + _186*84 + _188*97 + _190*5 + _192*19 + _194*52 + _196*36 + _198*56 + _200*31 + _202*37 + _204*80 + _206*1 = 0,
|
||||
_108*25 + _110*19 + _112*71 + _114*58 + _116*36 + _118*92 + _120*78 + _122*31 + _124*68 + _126*84 + _128*80 + _130*81 + _132*5 + _134*24 + _136*95 + _138*52 + _140*88 + _142*79 + _144*56 + _146*87 + _148*54 + _150*37 + _152*16 + _154*97 + _156*1 + _158*25 + _160*19 + _162*71 + _164*58 + _166*36 + _168*92 + _170*78 + _172*31 + _174*68 + _176*84 + _178*80 + _180*81 + _182*5 + _184*24 + _186*95 + _188*52 + _190*88 + _192*79 + _194*56 + _196*87 + _198*54 + _200*37 + _202*16 + _204*97 + _206*1 = 0,
|
||||
_108*26 + _110*70 + _112*2 + _114*52 + _116*39 + _118*4 + _120*3 + _122*78 + _124*8 + _126*6 + _128*55 + _130*16 + _132*12 + _134*9 + _136*32 + _138*24 + _140*18 + _142*64 + _144*48 + _146*36 + _148*27 + _150*96 + _152*72 + _154*54 + _156*91 + _158*43 + _160*7 + _162*81 + _164*86 + _166*14 + _168*61 + _170*71 + _172*28 + _174*21 + _176*41 + _178*56 + _180*42 + _182*82 + _184*11 + _186*84 + _188*63 + _190*22 + _192*67 + _194*25 + _196*44 + _198*33 + _200*50 + _202*88 + _204*66 + _206*100 = 0,
|
||||
_108*27 + _110*22 + _112*89 + _114*80 + _116*39 + _118*43 + _120*50 + _122*37 + _124*90 + _126*6 + _128*61 + _130*31 + _132*29 + _134*76 + _136*32 + _138*56 + _140*98 + _142*20 + _144*35 + _146*36 + _148*63 + _150*85 + _152*73 + _154*52 + _156*91 + _158*33 + _160*83 + _162*19 + _164*8 + _166*14 + _168*75 + _170*5 + _172*34 + _174*9 + _176*41 + _178*97 + _180*94 + _182*13 + _184*48 + _186*84 + _188*46 + _190*30 + _192*2 + _194*54 + _196*44 + _198*77 + _200*59 + _202*78 + _204*86 + _206*100 = 0,
|
||||
_108*28 + _110*77 + _112*35 + _114*71 + _116*69 + _118*13 + _120*61 + _122*92 + _124*51 + _126*14 + _128*89 + _130*68 + _132*86 + _134*85 + _136*57 + _138*81 + _140*46 + _142*76 + _144*7 + _146*95 + _148*34 + _150*43 + _152*93 + _154*79 + _156*91 + _158*23 + _160*38 + _162*54 + _164*98 + _166*17 + _168*72 + _170*97 + _172*90 + _174*96 + _176*62 + _178*19 + _180*27 + _182*49 + _184*59 + _186*36 + _188*99 + _190*45 + _192*48 + _194*31 + _196*60 + _198*64 + _200*75 + _202*80 + _204*18 + _206*100 = 0,
|
||||
_108*29 + _110*33 + _112*48 + _114*79 + _116*69 + _118*82 + _120*55 + _122*80 + _124*98 + _126*14 + _128*2 + _130*58 + _132*66 + _134*96 + _136*57 + _138*37 + _140*63 + _142*9 + _144*59 + _146*95 + _148*28 + _150*4 + _152*15 + _154*31 + _156*91 + _158*13 + _160*74 + _162*25 + _164*18 + _166*17 + _168*89 + _170*56 + _172*8 + _174*30 + _176*62 + _178*81 + _180*26 + _182*47 + _184*50 + _186*36 + _188*34 + _190*77 + _192*11 + _194*16 + _196*60 + _198*23 + _200*61 + _202*52 + _204*94 + _206*100 = 0,
|
||||
_108*30 + _110*92 + _112*33 + _114*81 + _116*6 + _118*79 + _120*47 + _122*97 + _124*82 + _126*36 + _128*70 + _130*80 + _132*77 + _134*88 + _136*14 + _138*16 + _140*76 + _142*58 + _144*23 + _146*84 + _148*96 + _150*52 + _152*45 + _154*37 + _156*100 + _158*71 + _160*9 + _162*68 + _164*20 + _166*95 + _168*22 + _170*54 + _172*4 + _174*19 + _176*65 + _178*31 + _180*21 + _182*24 + _184*13 + _186*87 + _188*85 + _190*25 + _192*43 + _194*78 + _196*17 + _198*5 + _200*49 + _202*56 + _204*64 + _206*1 = 0,
|
||||
_108*31 + _110*52 + _112*97 + _114*78 + _116*95 + _118*16 + _120*92 + _122*24 + _124*37 + _126*36 + _128*5 + _130*54 + _132*58 + _134*81 + _136*87 + _138*71 + _140*80 + _142*56 + _144*19 + _146*84 + _148*79 + _150*25 + _152*68 + _154*88 + _156*1 + _158*31 + _160*52 + _162*97 + _164*78 + _166*95 + _168*16 + _170*92 + _172*24 + _174*37 + _176*36 + _178*5 + _180*54 + _182*58 + _184*81 + _186*87 + _188*71 + _190*80 + _192*56 + _194*19 + _196*84 + _198*79 + _200*25 + _202*68 + _204*88 + _206*1 = 0,
|
||||
_108*32 + _110*14 + _112*44 + _114*95 + _116*10 + _118*17 + _120*39 + _122*36 + _124*41 + _126*100 + _128*69 + _130*87 + _132*57 + _134*6 + _136*91 + _138*84 + _140*62 + _142*65 + _144*60 + _146*1 + _148*32 + _150*14 + _152*44 + _154*95 + _156*10 + _158*17 + _160*39 + _162*36 + _164*41 + _166*100 + _168*69 + _170*87 + _172*57 + _174*6 + _176*91 + _178*84 + _180*62 + _182*65 + _184*60 + _186*1 + _188*32 + _190*14 + _192*44 + _194*95 + _196*10 + _198*17 + _200*39 + _202*36 + _204*41 + _206*100 = 0,
|
||||
_108*33 + _110*79 + _112*82 + _114*80 + _116*14 + _118*58 + _120*96 + _122*37 + _124*9 + _126*95 + _128*4 + _130*31 + _132*13 + _134*25 + _136*17 + _138*56 + _140*30 + _142*81 + _144*47 + _146*36 + _148*77 + _150*16 + _152*23 + _154*52 + _156*100 + _158*68 + _160*22 + _162*19 + _164*21 + _166*87 + _168*43 + _170*5 + _172*64 + _174*92 + _176*6 + _178*97 + _180*70 + _182*88 + _184*76 + _186*84 + _188*45 + _190*71 + _192*20 + _194*54 + _196*65 + _198*24 + _200*85 + _202*78 + _204*49 + _206*1 = 0,
|
||||
_108*34 + _110*45 + _112*15 + _114*5 + _116*69 + _118*23 + _120*75 + _122*25 + _124*42 + _126*14 + _128*72 + _130*24 + _132*8 + _134*70 + _136*57 + _138*19 + _140*40 + _142*47 + _144*83 + _146*95 + _148*99 + _150*33 + _152*11 + _154*71 + _156*91 + _158*64 + _160*55 + _162*52 + _164*51 + _166*17 + _168*73 + _170*58 + _172*53 + _174*85 + _176*62 + _178*88 + _180*63 + _182*21 + _184*7 + _186*36 + _188*12 + _190*4 + _192*35 + _194*79 + _196*60 + _198*20 + _200*74 + _202*92 + _204*98 + _206*100 = 0,
|
||||
_108*35 + _110*13 + _112*51 + _114*68 + _116*57 + _118*76 + _120*34 + _122*79 + _124*38 + _126*17 + _128*90 + _130*19 + _132*59 + _134*45 + _136*60 + _138*80 + _140*73 + _142*30 + _144*40 + _146*87 + _148*15 + _150*20 + _152*94 + _154*58 + _156*10 + _158*47 + _160*29 + _162*5 + _164*74 + _166*65 + _168*53 + _170*37 + _172*83 + _174*77 + _176*69 + _178*92 + _180*89 + _182*85 + _184*46 + _186*95 + _188*93 + _190*23 + _192*98 + _194*97 + _196*62 + _198*49 + _200*99 + _202*31 + _204*75 + _206*100 = 0,
|
||||
_108*36 + _110*84 + _112*95 + _114*87 + _116*1 + _118*36 + _120*84 + _122*95 + _124*87 + _126*1 + _128*36 + _130*84 + _132*95 + _134*87 + _136*1 + _138*36 + _140*84 + _142*95 + _144*87 + _146*1 + _148*36 + _150*84 + _152*95 + _154*87 + _156*1 + _158*36 + _160*84 + _162*95 + _164*87 + _166*1 + _168*36 + _170*84 + _172*95 + _174*87 + _176*1 + _178*36 + _180*84 + _182*95 + _184*87 + _186*1 + _188*36 + _190*84 + _192*95 + _194*87 + _196*1 + _198*36 + _200*84 + _202*95 + _204*87 + _206*1 = 0,
|
||||
_108*37 + _110*56 + _112*52 + _114*5 + _116*84 + _118*78 + _120*58 + _122*25 + _124*16 + _126*87 + _128*88 + _130*24 + _132*80 + _134*31 + _136*36 + _138*19 + _140*97 + _142*54 + _144*79 + _146*95 + _148*81 + _150*68 + _152*92 + _154*71 + _156*1 + _158*37 + _160*56 + _162*52 + _164*5 + _166*84 + _168*78 + _170*58 + _172*25 + _174*16 + _176*87 + _178*88 + _180*24 + _182*80 + _184*31 + _186*36 + _188*19 + _190*97 + _192*54 + _194*79 + _196*95 + _198*81 + _200*68 + _202*92 + _204*71 + _206*1 = 0,
|
||||
_108*38 + _110*30 + _112*29 + _114*92 + _116*62 + _118*33 + _120*42 + _122*81 + _124*48 + _126*6 + _128*26 + _130*79 + _132*73 + _134*47 + _136*69 + _138*97 + _140*50 + _142*82 + _144*86 + _146*36 + _148*55 + _150*70 + _152*34 + _154*80 + _156*10 + _158*77 + _160*98 + _162*88 + _164*11 + _166*14 + _168*27 + _170*16 + _172*2 + _174*76 + _176*60 + _178*58 + _180*83 + _182*23 + _184*66 + _186*84 + _188*61 + _190*96 + _192*12 + _194*52 + _196*57 + _198*45 + _200*94 + _202*37 + _204*93 + _206*100 = 0,
|
||||
_108*39 + _110*6 + _112*32 + _114*36 + _116*91 + _118*14 + _120*41 + _122*84 + _124*44 + _126*100 + _128*62 + _130*95 + _132*69 + _134*65 + _136*10 + _138*87 + _140*60 + _142*17 + _144*57 + _146*1 + _148*39 + _150*6 + _152*32 + _154*36 + _156*91 + _158*14 + _160*41 + _162*84 + _164*44 + _166*100 + _168*62 + _170*95 + _172*69 + _174*65 + _176*10 + _178*87 + _180*60 + _182*17 + _184*57 + _186*1 + _188*39 + _190*6 + _192*32 + _194*36 + _196*91 + _198*14 + _200*41 + _202*84 + _204*44 + _206*100 = 0,
|
||||
_108*40 + _110*85 + _112*67 + _114*54 + _116*39 + _118*45 + _120*83 + _122*88 + _124*86 + _126*6 + _128*38 + _130*5 + _132*99 + _134*21 + _136*32 + _138*68 + _140*94 + _142*23 + _144*11 + _146*36 + _148*26 + _150*30 + _152*89 + _154*25 + _156*91 + _158*4 + _160*59 + _162*37 + _164*66 + _166*14 + _168*55 + _170*79 + _172*29 + _174*49 + _176*41 + _178*24 + _180*51 + _182*20 + _184*93 + _186*84 + _188*27 + _190*70 + _192*73 + _194*92 + _196*44 + _198*43 + _200*3 + _202*19 + _204*53 + _206*100 = 0,
|
||||
_108*41 + _110*65 + _112*39 + _114*84 + _116*10 + _118*6 + _120*44 + _122*87 + _124*32 + _126*100 + _128*60 + _130*36 + _132*62 + _134*17 + _136*91 + _138*95 + _140*57 + _142*14 + _144*69 + _146*1 + _148*41 + _150*65 + _152*39 + _154*84 + _156*10 + _158*6 + _160*44 + _162*87 + _164*32 + _166*100 + _168*60 + _170*36 + _172*62 + _174*17 + _176*91 + _178*95 + _180*57 + _182*14 + _184*69 + _186*1 + _188*41 + _190*65 + _192*39 + _194*84 + _196*10 + _198*6 + _200*44 + _202*87 + _204*32 + _206*100 = 0,
|
||||
_108*42 + _110*47 + _112*55 + _114*88 + _116*60 + _118*96 + _120*93 + _122*68 + _124*28 + _126*65 + _128*3 + _130*25 + _132*40 + _134*64 + _136*62 + _138*79 + _140*86 + _142*77 + _144*2 + _146*84 + _148*94 + _150*9 + _152*75 + _154*19 + _156*91 + _158*85 + _160*35 + _162*56 + _164*29 + _166*6 + _168*50 + _170*80 + _172*27 + _174*23 + _176*57 + _178*71 + _180*53 + _182*4 + _184*67 + _186*87 + _188*18 + _190*49 + _192*38 + _194*81 + _196*69 + _198*70 + _200*11 + _202*58 + _204*12 + _206*100 = 0,
|
||||
_108*43 + _110*31 + _112*20 + _114*52 + _116*14 + _118*97 + _120*30 + _122*78 + _124*21 + _126*95 + _128*45 + _130*16 + _132*82 + _134*92 + _136*17 + _138*24 + _140*22 + _142*37 + _144*76 + _146*36 + _148*33 + _150*5 + _152*13 + _154*54 + _156*100 + _158*58 + _160*70 + _162*81 + _164*49 + _166*87 + _168*4 + _170*71 + _172*23 + _174*80 + _176*6 + _178*56 + _180*85 + _182*19 + _184*9 + _186*84 + _188*77 + _190*79 + _192*64 + _194*25 + _196*65 + _198*68 + _200*96 + _202*88 + _204*47 + _206*1 = 0,
|
||||
_108*44 + _110*17 + _112*41 + _114*87 + _116*91 + _118*65 + _120*32 + _122*95 + _124*39 + _126*100 + _128*57 + _130*84 + _132*60 + _134*14 + _136*10 + _138*36 + _140*69 + _142*6 + _144*62 + _146*1 + _148*44 + _150*17 + _152*41 + _154*87 + _156*91 + _158*65 + _160*32 + _162*95 + _164*39 + _166*100 + _168*57 + _170*84 + _172*60 + _174*14 + _176*10 + _178*36 + _180*69 + _182*6 + _184*62 + _186*1 + _188*44 + _190*17 + _192*41 + _194*87 + _196*91 + _198*65 + _200*32 + _202*95 + _204*39 + _206*100 = 0,
|
||||
_108*45 + _110*5 + _112*23 + _114*25 + _116*14 + _118*24 + _120*70 + _122*19 + _124*47 + _126*95 + _128*33 + _130*71 + _132*64 + _134*52 + _136*17 + _138*58 + _140*85 + _142*88 + _144*21 + _146*36 + _148*4 + _150*79 + _152*20 + _154*92 + _156*100 + _158*56 + _160*96 + _162*78 + _164*76 + _166*87 + _168*77 + _170*31 + _172*82 + _174*54 + _176*6 + _178*68 + _180*30 + _182*37 + _184*49 + _186*84 + _188*43 + _190*16 + _192*13 + _194*80 + _196*65 + _198*97 + _200*22 + _202*81 + _204*9 + _206*1 = 0,
|
||||
_108*46 + _110*96 + _112*73 + _114*25 + _116*39 + _118*77 + _120*7 + _122*19 + _124*66 + _126*6 + _128*74 + _130*71 + _132*34 + _134*49 + _136*32 + _138*58 + _140*42 + _142*13 + _144*93 + _146*36 + _148*40 + _150*22 + _152*2 + _154*92 + _156*91 + _158*45 + _160*50 + _162*78 + _164*53 + _166*14 + _168*38 + _170*31 + _172*12 + _174*47 + _176*41 + _178*68 + _180*98 + _182*64 + _184*15 + _186*84 + _188*26 + _190*85 + _192*72 + _194*80 + _196*44 + _198*4 + _200*83 + _202*81 + _204*90 + _206*100 = 0,
|
||||
_108*47 + _110*88 + _112*96 + _114*68 + _116*65 + _118*25 + _120*64 + _122*79 + _124*77 + _126*84 + _128*9 + _130*19 + _132*85 + _134*56 + _136*6 + _138*80 + _140*23 + _142*71 + _144*4 + _146*87 + _148*49 + _150*81 + _152*70 + _154*58 + _156*100 + _158*54 + _160*13 + _162*5 + _164*33 + _166*36 + _168*76 + _170*37 + _172*22 + _174*24 + _176*17 + _178*92 + _180*82 + _182*16 + _184*45 + _186*95 + _188*21 + _190*78 + _192*30 + _194*97 + _196*14 + _198*52 + _200*20 + _202*31 + _204*43 + _206*1 = 0,
|
||||
_108*48 + _110*82 + _112*98 + _114*58 + _116*57 + _118*9 + _120*28 + _122*31 + _124*74 + _126*17 + _128*8 + _130*81 + _132*50 + _134*77 + _136*60 + _138*52 + _140*72 + _142*22 + _144*46 + _146*87 + _148*35 + _150*64 + _152*42 + _154*97 + _156*10 + _158*76 + _160*12 + _162*71 + _164*75 + _166*65 + _168*90 + _170*78 + _172*7 + _174*33 + _176*69 + _178*80 + _180*2 + _182*96 + _184*63 + _186*95 + _188*15 + _190*13 + _192*18 + _194*56 + _196*62 + _198*47 + _200*34 + _202*16 + _204*61 + _206*100 = 0,
|
||||
_108*49 + _110*78 + _112*85 + _114*24 + _116*65 + _118*54 + _120*20 + _122*71 + _124*45 + _126*84 + _128*76 + _130*88 + _132*70 + _134*97 + _136*6 + _138*92 + _140*64 + _142*5 + _144*43 + _146*87 + _148*21 + _150*19 + _152*22 + _154*68 + _156*100 + _158*52 + _160*23 + _162*16 + _164*77 + _166*36 + _168*47 + _170*81 + _172*30 + _174*56 + _176*17 + _178*25 + _180*13 + _182*31 + _184*4 + _186*95 + _188*9 + _190*37 + _192*96 + _194*58 + _196*14 + _198*80 + _200*82 + _202*79 + _204*33 + _206*1 = 0,
|
||||
_108*50 + _110*76 + _112*63 + _114*19 + _116*41 + _118*30 + _120*86 + _122*58 + _124*72 + _126*65 + _128*18 + _130*92 + _132*55 + _134*23 + _136*39 + _138*31 + _140*35 + _142*33 + _144*34 + _146*84 + _148*59 + _150*21 + _152*40 + _154*81 + _156*10 + _158*96 + _160*53 + _162*24 + _164*89 + _166*6 + _168*98 + _170*52 + _172*75 + _174*13 + _176*44 + _178*79 + _180*11 + _182*45 + _184*28 + _186*87 + _188*7 + _190*47 + _192*27 + _194*37 + _196*32 + _198*85 + _200*8 + _202*97 + _204*2 + _206*100 = 0
|
||||
}.
|
||||
|
@ -1,315 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.2 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: eliminat.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
/*
|
||||
|
||||
If you want to learn more about the subject of quantifier elimination
|
||||
you should read:
|
||||
|
||||
Huynh T., Lassez J.L.: Practical Issues on the Projection of Polyhedral Sets,
|
||||
IBM Research Division, RC 15872 (#70560), 1990.
|
||||
|
||||
|
||||
The predicate example/1 below relates the four variables X1,X2,X3,X4
|
||||
in some way. The query 'example( [X1,X2,X3,X4])' just returns the
|
||||
normalized set of constraints (there is no redundancy).
|
||||
Now suppose you want to know: what are the implied relations
|
||||
between X3 and X4? The following query expresses this projection:
|
||||
|
||||
[Clp(Q)] ?- example( 1, [_,_,X3,X4]).
|
||||
|
||||
X4=<1+3*X3,
|
||||
X4=<4/13+18/13*X3,
|
||||
X4>=-1/8+9/8*X3,
|
||||
X4>= -2+6*X3,
|
||||
X4>=-1/11+9/11*X3
|
||||
|
||||
*/
|
||||
|
||||
%
|
||||
% taken from the reference above
|
||||
%
|
||||
example( 1, [X1,X2,X3,X4]) :-
|
||||
{
|
||||
12*X1 + X2 - 3*X3 + X4 =< 1,
|
||||
-36*X1 - 2*X2 + 18*X3 - 11*X4 =< -2,
|
||||
-18*X1 - X2 + 9*X3 - 7*X4 =< -1,
|
||||
45*X1 + 4*X2 - 18*X3 + 13*X4 =< 4,
|
||||
X1 >= 0,
|
||||
X2 >= 0
|
||||
}.
|
||||
|
||||
example( 2, [X0,X1,X2,X3,X4]) :-
|
||||
{ % supremum for the row
|
||||
+87*X0 +52*X1 +27*X2 -54*X3 +56*X4 =< -93, % r -1108
|
||||
+33*X0 -10*X1 +61*X2 -28*X3 -29*X4 =< 63, % r - 595
|
||||
-68*X0 +8*X1 +35*X2 +68*X3 +35*X4 =< -85, % - 85
|
||||
+90*X0 +60*X1 -76*X2 -53*X3 +24*X4 =< -68, % - 68
|
||||
-95*X0 -10*X1 +64*X2 +76*X3 -24*X4 =< 33, % 33
|
||||
+43*X0 -22*X1 +67*X2 -68*X3 -92*X4 =< -97, % r - 709
|
||||
+39*X0 +7*X1 +62*X2 +54*X3 -26*X4 =< -27, % - 27
|
||||
+48*X0 -13*X1 +7*X2 -61*X3 -59*X4 =< -2, % r - 211
|
||||
+49*X0 -23*X1 -31*X2 -76*X3 +27*X4 =< 3, % 3
|
||||
-50*X0 +58*X1 -1*X2 +57*X3 +20*X4 =< 6, % 6
|
||||
-13*X0 -63*X1 +81*X2 -3*X3 +70*X4 =< 64, % r - 385
|
||||
+20*X0 +67*X1 -23*X2 -41*X3 -66*X4 =< 52, % r - 489
|
||||
-81*X0 -44*X1 +19*X2 -22*X3 -73*X4 =< -17, % - 17
|
||||
-43*X0 -9*X1 +14*X2 +27*X3 +40*X4 =< 39, % 39
|
||||
+16*X0 +83*X1 +89*X2 +25*X3 +55*X4 =< 36, % r -1474
|
||||
+2*X0 +40*X1 +65*X2 +59*X3 -32*X4 =< 13, % r - 378
|
||||
-65*X0 -11*X1 +10*X2 -13*X3 +91*X4 =< 49, % r - 366
|
||||
+93*X0 -73*X1 +91*X2 -1*X3 +23*X4 =< -87 % - 87
|
||||
}.
|
||||
|
||||
example( 3, [X1,X2,X3,X4]) :-
|
||||
{
|
||||
12*X1 + X2 - 3*X3 + X4 =< 1,
|
||||
-36*X1 - 2*X2 + 18*X3 - 11*X4 =< -2,
|
||||
-18*X1 - X2 + 9*X3 - 7*X4 =< -1,
|
||||
45*X1 + 4*X2 - 18*X3 + 13*X4 =< 4,
|
||||
X1 > 0, % strict !!!
|
||||
X2 >= 0
|
||||
}.
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
The next example deals with the computation of the convex hull of
|
||||
a given set of points. The problem can be formulated as a quantifier
|
||||
elimination problem (for details please refer to the reference).
|
||||
|
||||
Example:
|
||||
|
||||
The set of three points in a 3 dimensional space is represented as
|
||||
|
||||
[ [1,0,0], [0,1,0], [0,0,1] ]
|
||||
|
||||
The following query computes the convex hull.
|
||||
|
||||
[Clp(Q)] ?- conv_hull( [ [1,0,0],[0,1,0],[0,0,1] ], [X1,X2,X3] ).
|
||||
|
||||
X3 = 1-X1-X2,
|
||||
X1=<1-X2,
|
||||
X2>=0,
|
||||
X1>=0
|
||||
|
||||
In two dimensions it is easier to visualize and verify the
|
||||
result:
|
||||
|
||||
|
|
||||
2 - * *
|
||||
|
|
||||
|
|
||||
1 - *
|
||||
|
|
||||
|
|
||||
0 -----|----*----*----
|
||||
1 2 3
|
||||
|
||||
[Clp(Q)] ?- conv_hull([ [1,1], [2,0], [3,0], [1,2], [2,2] ], [X,Y]).
|
||||
|
||||
X=<3-1/2*Y,
|
||||
Y=<2,
|
||||
Y>=0,
|
||||
X>=1,
|
||||
X>=2-Y
|
||||
|
||||
*/
|
||||
|
||||
hull( [X,Y]) :- conv_hull([ [1,1], [2,0], [3,0], [1,2], [2,2] ], [X,Y]).
|
||||
|
||||
conv_hull( Points, Xs) :-
|
||||
lin_comb( Points, Lambdas, Zero, Xs),
|
||||
zero( Zero),
|
||||
polytope( Lambdas).
|
||||
|
||||
polytope( Xs) :-
|
||||
positive_sum( Xs, 1).
|
||||
|
||||
positive_sum( [], Z) :- {Z=0}.
|
||||
positive_sum( [X|Xs], SumX) :-
|
||||
{ X >= 0, SumX = X+Sum },
|
||||
positive_sum( Xs, Sum).
|
||||
|
||||
zero( []).
|
||||
zero( [Z|Zs]) :- {Z=0}, zero( Zs).
|
||||
|
||||
lin_comb( [], [], S1, S1).
|
||||
lin_comb( [Ps|Rest], [K|Ks], S1, S3) :-
|
||||
lin_comb_r( Ps, K, S1, S2),
|
||||
lin_comb( Rest, Ks, S2, S3).
|
||||
|
||||
lin_comb_r( [], _, [], []).
|
||||
lin_comb_r( [P|Ps], K, [S|Ss], [Kps|Ss1]) :-
|
||||
{ Kps = K*P+S },
|
||||
lin_comb_r( Ps, K, Ss, Ss1).
|
||||
|
||||
% -------------------------------- junkyard --------------------------------
|
||||
|
||||
/*
|
||||
subseq0(List, List).
|
||||
subseq0(List, Rest) :-
|
||||
subseq1(List, Rest).
|
||||
|
||||
subseq1([_Head|Tail], Rest) :-
|
||||
subseq0(Tail, Rest).
|
||||
subseq1([ Head|Tail], [Head|Rest]) :-
|
||||
subseq1(Tail, Rest).
|
||||
|
||||
subseq0([A,B,C,D,E],S),portray_clause((proj(2,S):-example(2,[A,B,C,D,E]))),fail.
|
||||
*/
|
||||
|
||||
proj( N) :-
|
||||
time( call_residue( proj(N,P), R)),
|
||||
numbervars(P,0,_),
|
||||
length( R, Rl),
|
||||
print(P:Rl),nl,presi(R),nl,
|
||||
fail.
|
||||
|
||||
presi( []).
|
||||
presi( [_-R|Rs]) :-
|
||||
print( R), nl,
|
||||
presi( Rs).
|
||||
|
||||
proj(1, [A,B,C,D]) :-
|
||||
example(1, [A,B,C,D]).
|
||||
proj(1, [A,B,C]) :-
|
||||
example(1, [_,A,B,C]).
|
||||
proj(1, [A,B]) :-
|
||||
example(1, [_,_,A,B]).
|
||||
proj(1, [A]) :-
|
||||
example(1, [_,_,_,A]).
|
||||
proj(1, []) :-
|
||||
example(1, [_,_,_,_]).
|
||||
proj(1, [A]) :-
|
||||
example(1, [_,_,A,_]).
|
||||
proj(1, [A,B]) :-
|
||||
example(1, [_,A,_,B]).
|
||||
proj(1, [A]) :-
|
||||
example(1, [_,A,_,_]).
|
||||
proj(1, [A,B]) :-
|
||||
example(1, [_,A,B,_]).
|
||||
proj(1, [A,B,C]) :-
|
||||
example(1, [A,_,B,C]).
|
||||
proj(1, [A,B]) :-
|
||||
example(1, [A,_,_,B]).
|
||||
proj(1, [A]) :-
|
||||
example(1, [A,_,_,_]).
|
||||
proj(1, [A,B]) :-
|
||||
example(1, [A,_,B,_]).
|
||||
proj(1, [A,B,C]) :-
|
||||
example(1, [A,B,_,C]).
|
||||
proj(1, [A,B]) :-
|
||||
example(1, [A,B,_,_]).
|
||||
proj(1, [A,B,C]) :-
|
||||
example(1, [A,B,C,_]).
|
||||
|
||||
proj(2, [A,B,C,D,E]) :-
|
||||
example(2, [A,B,C,D,E]).
|
||||
proj(2, [A,B,C,D]) :-
|
||||
example(2, [_,A,B,C,D]).
|
||||
proj(2, [A,B,C]) :-
|
||||
example(2, [_,_,A,B,C]).
|
||||
proj(2, [A,B]) :-
|
||||
example(2, [_,_,_,A,B]).
|
||||
proj(2, [A]) :-
|
||||
example(2, [_,_,_,_,A]).
|
||||
proj(2, []) :-
|
||||
example(2, [_,_,_,_,_]).
|
||||
proj(2, [A]) :-
|
||||
example(2, [_,_,_,A,_]).
|
||||
proj(2, [A,B]) :-
|
||||
example(2, [_,_,A,_,B]).
|
||||
proj(2, [A]) :-
|
||||
example(2, [_,_,A,_,_]).
|
||||
proj(2, [A,B]) :-
|
||||
example(2, [_,_,A,B,_]).
|
||||
proj(2, [A,B,C]) :-
|
||||
example(2, [_,A,_,B,C]).
|
||||
proj(2, [A,B]) :-
|
||||
example(2, [_,A,_,_,B]).
|
||||
proj(2, [A]) :-
|
||||
example(2, [_,A,_,_,_]).
|
||||
proj(2, [A,B]) :-
|
||||
example(2, [_,A,_,B,_]).
|
||||
proj(2, [A,B,C]) :-
|
||||
example(2, [_,A,B,_,C]).
|
||||
proj(2, [A,B]) :-
|
||||
example(2, [_,A,B,_,_]).
|
||||
proj(2, [A,B,C]) :-
|
||||
example(2, [_,A,B,C,_]).
|
||||
proj(2, [A,B,C,D]) :-
|
||||
example(2, [A,_,B,C,D]).
|
||||
proj(2, [A,B,C]) :-
|
||||
example(2, [A,_,_,B,C]).
|
||||
proj(2, [A,B]) :-
|
||||
example(2, [A,_,_,_,B]).
|
||||
proj(2, [A]) :-
|
||||
example(2, [A,_,_,_,_]).
|
||||
proj(2, [A,B]) :-
|
||||
example(2, [A,_,_,B,_]).
|
||||
proj(2, [A,B,C]) :-
|
||||
example(2, [A,_,B,_,C]).
|
||||
proj(2, [A,B]) :-
|
||||
example(2, [A,_,B,_,_]).
|
||||
proj(2, [A,B,C]) :-
|
||||
example(2, [A,_,B,C,_]).
|
||||
proj(2, [A,B,C,D]) :-
|
||||
example(2, [A,B,_,C,D]).
|
||||
proj(2, [A,B,C]) :-
|
||||
example(2, [A,B,_,_,C]).
|
||||
proj(2, [A,B]) :-
|
||||
example(2, [A,B,_,_,_]).
|
||||
proj(2, [A,B,C]) :-
|
||||
example(2, [A,B,_,C,_]).
|
||||
proj(2, [A,B,C,D]) :-
|
||||
example(2, [A,B,C,_,D]).
|
||||
proj(2, [A,B,C]) :-
|
||||
example(2, [A,B,C,_,_]).
|
||||
proj(2, [A,B,C,D]) :-
|
||||
example(2, [A,B,C,D,_]).
|
||||
|
||||
proj(3, [A,B,C,D]) :-
|
||||
example(3, [A,B,C,D]).
|
||||
proj(3, [A,B,C]) :-
|
||||
example(3, [_,A,B,C]).
|
||||
proj(3, [A,B]) :-
|
||||
example(3, [_,_,A,B]).
|
||||
proj(3, [A]) :-
|
||||
example(3, [_,_,_,A]).
|
||||
proj(3, []) :-
|
||||
example(3, [_,_,_,_]).
|
||||
proj(3, [A]) :-
|
||||
example(3, [_,_,A,_]).
|
||||
proj(3, [A,B]) :-
|
||||
example(3, [_,A,_,B]).
|
||||
proj(3, [A]) :-
|
||||
example(3, [_,A,_,_]).
|
||||
proj(3, [A,B]) :-
|
||||
example(3, [_,A,B,_]).
|
||||
proj(3, [A,B,C]) :-
|
||||
example(3, [A,_,B,C]).
|
||||
proj(3, [A,B]) :-
|
||||
example(3, [A,_,_,B]).
|
||||
proj(3, [A]) :-
|
||||
example(3, [A,_,_,_]).
|
||||
proj(3, [A,B]) :-
|
||||
example(3, [A,_,B,_]).
|
||||
proj(3, [A,B,C]) :-
|
||||
example(3, [A,B,_,C]).
|
||||
proj(3, [A,B]) :-
|
||||
example(3, [A,B,_,_]).
|
||||
proj(3, [A,B,C]) :-
|
||||
example(3, [A,B,C,_]).
|
@ -1,89 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.2 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: matmul.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
matmul( [], _, []).
|
||||
matmul( [H|T], B, [H1|T1]) :-
|
||||
rowmul( B, H, H1),
|
||||
matmul( T, B, T1).
|
||||
|
||||
rowmul( [], _, []).
|
||||
rowmul( [H|T], AV, [H1|T1]) :-
|
||||
vecmul( AV, H, 0, H1),
|
||||
rowmul( T, AV, T1).
|
||||
|
||||
/*
|
||||
%
|
||||
% eager
|
||||
%
|
||||
vecmul( [], [], S, S).
|
||||
vecmul( [H1|T1], [H2|T2], In, Out) :-
|
||||
{ Sofar=In+H1*H2 },
|
||||
vecmul( T1, T2, Sofar, Out).
|
||||
*/
|
||||
|
||||
%
|
||||
% lazy
|
||||
%
|
||||
vecmul( [], [], S0, S1) :- { S0=S1 }.
|
||||
vecmul( [H1|T1], [H2|T2], In, Out) :-
|
||||
vecmul( T1, T2, In+H1*H2, Out).
|
||||
|
||||
inv_hilbert( N) :-
|
||||
hilbert( N, H),
|
||||
identity( N, U),
|
||||
statistics( runtime, _),
|
||||
matmul( H, Inv, U),
|
||||
statistics( runtime, [_,Lp_time]),
|
||||
format( "% took ~p msec~n", [Lp_time]),
|
||||
printnl( Inv).
|
||||
|
||||
printnl( []).
|
||||
printnl( [H|T]) :- print( H), nl, printnl( T).
|
||||
|
||||
% ---------- simple matrix generator
|
||||
|
||||
mat( I, N, _, []) :- I > N, !.
|
||||
mat( I, N, Fn, [Row|Rows]) :-
|
||||
mat_row( I, 1, N, Fn, Row),
|
||||
I1 is I+1,
|
||||
mat( I1, N, Fn, Rows).
|
||||
|
||||
mat_row( _, J, N, _, []) :- J > N, !.
|
||||
mat_row( I, J, N, Fn, [Res|Es]) :-
|
||||
Call =.. [Fn,I,J,Res],
|
||||
call( Call),
|
||||
J1 is J+1,
|
||||
mat_row( I, J1, N, Fn, Es).
|
||||
|
||||
identity( N, Mat) :-
|
||||
mat( 1, N, ident, Mat).
|
||||
|
||||
ident( I, I, 1) :- !.
|
||||
ident( _, _, 0).
|
||||
|
||||
caneghem( N, Mat) :-
|
||||
mat( 1, N, can, Mat).
|
||||
|
||||
can( I, J, El) :- can( I, J, 1, 101, El).
|
||||
|
||||
can( I, 1, Curr, Mod, El) :- !, El is (I*Curr) mod Mod.
|
||||
can( I, J, Curr, Mod, El) :-
|
||||
J1 is J-1,
|
||||
C1 is (Curr*I) mod Mod,
|
||||
can( I, J1, C1, Mod, El).
|
||||
|
||||
hilbert( N, Mat) :-
|
||||
mat( 1, N, hilbert, Mat).
|
||||
|
||||
hilbert( I, J, 1/X) :- X is I+J-1.
|
||||
|
@ -1,25 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.2 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: mg.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
mg(P,T,I,B,MP) :-
|
||||
{
|
||||
T = 1,
|
||||
B + MP = P * (1 + I)
|
||||
}.
|
||||
mg(P,T,I,B,MP) :-
|
||||
{
|
||||
T > 1,
|
||||
P1 = P * (1 + I) - MP,
|
||||
T1 = T - 1
|
||||
},
|
||||
mg(P1, T1, I, B, MP).
|
File diff suppressed because it is too large
Load Diff
@ -1,9 +0,0 @@
|
||||
This collection of examples has been distributed with the Monash University
|
||||
Version of clp(r) [Heintze et al. 87], and its inclusion into this
|
||||
distribution was kindly permitted by Roland Yap.
|
||||
|
||||
[Heintze et al. 87]
|
||||
|
||||
Heintze N., Jaffar J., Michaylov S., Stuckey P., Yap R.: The CLP(R)
|
||||
Programmers Manual, Monash University, Clayton, Victoria, Australia,
|
||||
Department of Computer Science, 1987.
|
@ -1,129 +0,0 @@
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CLP(R) Version 2.0 (Example Programs Release)
|
||||
* (C) Copyright, March 1986, Monash University
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
%
|
||||
% Calculate excess air needed for a chemical reaction to proceed in some way
|
||||
% The goal
|
||||
% ?- go.
|
||||
% is a sample reaction.
|
||||
%
|
||||
|
||||
mol_comp(n2, [f(n, 2)]).
|
||||
mol_comp(o2, [f(o, 2)]).
|
||||
mol_comp(co2, [f(c, 1),f(o, 2)]).
|
||||
mol_comp(co, [f(c, 1),f(o, 1)]).
|
||||
mol_comp(c, [f(c, 1)]).
|
||||
mol_comp(h2o, [f(h, 2),f(o, 1)]).
|
||||
|
||||
comp(air, vol, [f(n2, 0.79),f(o2, 0.21)]).
|
||||
comp(flue, vol, [f(co2, 0.125),f(co, 0.025),f(o2, 0.03),f(n2, 0.82)]).
|
||||
comp(full_comb, vol, [f(co2, 1),f(n2, T)]).
|
||||
comp(fuel, vol, [f(c, 1)]).
|
||||
|
||||
basis(1.0).
|
||||
|
||||
bal(LEFT, RIGHT, VARS) :-
|
||||
bal_side(LEFT, VARS, NEW_VARS),
|
||||
bal_side(RIGHT, NEW_VARS, N_VARS),
|
||||
zero(N_VARS).
|
||||
|
||||
zero([]).
|
||||
zero([f(X, 0)|L]) :-
|
||||
zero(L).
|
||||
|
||||
bal_side([], [], []).
|
||||
bal_side([], [f(A, X)| L1], [f(A, MX)| L2]) :-
|
||||
MX = -X,
|
||||
bal_side([], L1, L2).
|
||||
bal_side([f(S,X)| L], VARS, NEW_VARS) :-
|
||||
comp(S, T, COMP_LIST),
|
||||
printf("species %s \n",[S]),
|
||||
add_species(X, COMP_LIST, VARS, N_VARS),
|
||||
bal_side(L,N_VARS, NEW_VARS).
|
||||
|
||||
add_species(X, [f(SPEC, PROP)| L], VARS, NEW_VARS) :-
|
||||
printf("molecule %s \n",[SPEC]),
|
||||
mol_comp(SPEC, ELEMENTS),
|
||||
add_elements(X, PROP, ELEMENTS, VARS, N_VARS),
|
||||
add_species(X, L, N_VARS, NEW_VARS).
|
||||
add_species(X, [], VARS, VARS).
|
||||
|
||||
add_elements(X, PROP, [f(n, NUM)| L], VARS, NEW_VARS) :-
|
||||
add_elements(X, PROP, L, VARS, NEW_VARS).
|
||||
|
||||
add_elements(X, PROP, [f(E, NUM)| L], [f(E, Z)| VARS], [f(E, Z1)| NEW_VARS]):-
|
||||
Z = X*PROP*NUM + Z1 ,
|
||||
printf("atom %s \n",[E]),
|
||||
add_elements(X, PROP, L, VARS, NEW_VARS).
|
||||
|
||||
add_elements(X, PROP, [f(F, NUM)| L], [f(E, Z)| VARS], [f(E, Z)| NEW_VARS]):-
|
||||
add_elements(X, PROP, [f(F, NUM)| L], VARS, NEW_VARS).
|
||||
|
||||
add_elements(X, PROP, [], VARS, VARS).
|
||||
|
||||
excess(A, A1) :-
|
||||
B = A - A1,
|
||||
B = ANS * A1,
|
||||
PERC = ANS * 100 ,
|
||||
printf("Excess = %f%% \n",[PERC]).
|
||||
|
||||
go:- basis(BASE),
|
||||
bal([f(air, A),f(fuel, BASE)], [f(flue, F)], [f(c,0),f(o,0)]),
|
||||
printf("With base of %f mol of fuel\n",[BASE]),
|
||||
printf("air (just to burn the carbon) = %f mol\n",[A]),
|
||||
printf("flue (mol) :%f\n",[F]),
|
||||
nl,
|
||||
bal([f(air, A1),f(fuel, BASE)], [f(full_comb, F1)], [f(c,0),f(o,0)]),
|
||||
printf("Compared with theoretical air (for complete combustion):\n",[]),
|
||||
printf(" %f mol\n",[A1]),
|
||||
excess(A, A1).
|
||||
|
||||
|
||||
% Answer:
|
||||
% species air
|
||||
% molecule n2
|
||||
% molecule o2
|
||||
% atom o
|
||||
% species fuel
|
||||
% molecule c
|
||||
% atom c
|
||||
% species flue
|
||||
% molecule co2
|
||||
% atom c
|
||||
% atom o
|
||||
% molecule co
|
||||
% atom c
|
||||
% atom o
|
||||
% molecule o2
|
||||
% atom o
|
||||
% molecule n2
|
||||
% With base of 1.000000 mol of fuel
|
||||
% air (just to burn the carbon) = 5.317460 mol
|
||||
% flue (mol) :6.666667
|
||||
%
|
||||
% species air
|
||||
% molecule n2
|
||||
% molecule o2
|
||||
% atom o
|
||||
% species fuel
|
||||
% molecule c
|
||||
% atom c
|
||||
% species full_comb
|
||||
% molecule co2
|
||||
% atom c
|
||||
% atom o
|
||||
% molecule n2
|
||||
% Compared with theoretical air (for complete combustion):
|
||||
% 4.761905 mol
|
||||
% Excess = 11.666667%
|
||||
|
||||
|
||||
?- printf("\n>>> Sample goal: go/0\n", []).
|
||||
|
@ -1,313 +0,0 @@
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CLP(R) Version 2.0 (Example Programs Release)
|
||||
* (C) Copyright, March 1986, Monash University
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
%
|
||||
% Transistor amplifier design and analysis package.
|
||||
% The goal
|
||||
% ?- go1.
|
||||
% analyses an existing amplifier circuit, while the goal
|
||||
% ?- go2.
|
||||
% imposes certain design constraints on an amplifier of
|
||||
% a certain form and then determines suitable component values,
|
||||
% by choosing them from a list of available (preffered) components.
|
||||
%
|
||||
|
||||
/****************************************************************************/
|
||||
/* Major goals */
|
||||
/****************************************************************************/
|
||||
dc_analysis(Vcc1,Vcc2,Circuit):-
|
||||
solve_dc(mean,Circuit ,[n(cc1,Vcc1,[_]),n(cc2,Vcc2,[_]),n(gnd,0,[_])],
|
||||
Nodelist,Collector_Currents),
|
||||
current_solve(Nodelist),
|
||||
print_value(Nodelist),
|
||||
print_circuit(Circuit).
|
||||
|
||||
full_analysis(Vcc1,Vcc2,Circuit,In,Out,Type,Stability,Gain,Inresist,Outresist):-
|
||||
Inresist = -1 / Iin,
|
||||
Gain = Vout,
|
||||
Outresist = -1 / Iout,
|
||||
circuit(Vcc1, Vcc2, Circuit,In, Out,Type),
|
||||
solve_dc(mean,Circuit ,[n(cc1,Vcc1,[_]), n(cc2,Vcc2,[_]), n(gnd,0,[_])],
|
||||
Nodelist,Collector_Currents),
|
||||
current_solve(Nodelist),
|
||||
%print_value(Nodelist),
|
||||
stability(Vcc1,Vcc2,Circuit,Collector_Currents,Stability),
|
||||
printf("Stab %\n",[Stability]),
|
||||
solve_ss(Circuit,Collector_Currents,
|
||||
[n(cc1,0,[_]),n(cc2,0,[_]),n(gnd,0,[_]),
|
||||
n(In,1,[Iin]),n(Out,Vout,[])],Nodelist2),
|
||||
current_solve(Nodelist2),
|
||||
%print_value(Nodelist2),
|
||||
solve_ss(Circuit,Collector_Currents,
|
||||
[n(cc1,0,[_]),n(cc2,0,[_]),n(gnd,0,[_]),
|
||||
n(Out,1,[Iout])],Nodelist3),
|
||||
%print_value(Nodelist3),
|
||||
current_solve(Nodelist3),
|
||||
%print_value(Nodelist3),
|
||||
printf("Outresist % \n",[Outresist]),
|
||||
print_circuit(Circuit).
|
||||
|
||||
/****************************************************************************/
|
||||
/* small signal equivalent solve */
|
||||
/****************************************************************************/
|
||||
solve_ss([],[], List,List).
|
||||
solve_ss([[Component,_,Data,Points]|Rest],CCin,Innodes,Outnodes):-
|
||||
connecting(Points,Volts,Amps,Innodes,Tmpnodes),
|
||||
component_ss(Component,Data,Volts,Amps,CCin,CCout),
|
||||
solve_ss(Rest,CCout,Tmpnodes,Outnodes).
|
||||
|
||||
component_ss(resistor,R,[V1,V2],[I,-1*I],Cc,Cc):-
|
||||
V1-V2 = R*I,
|
||||
resistor_val(R).
|
||||
component_ss(capacitor,_,[V,V],[I,-1*I],Cc,Cc).
|
||||
component_ss(transistor,[npn,Code,active],[Vb,Vc,Ve], [Ib,Ic,Ie],[Icol|CC],CC):-
|
||||
Vb - Ve = (Beta * Vt / Icol) * Ib,
|
||||
Ic = Beta * Ib,
|
||||
Ie + Ic + Ib = 0,
|
||||
transistor_type(Type,Code,Beta,_,_,Vt,mean).
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/* dc component solving */
|
||||
/****************************************************************************/
|
||||
solve_dc(_, [], List, List, []).
|
||||
solve_dc(Kind,[[Component,_,Data,Points] | Rest], Inlist,Outlist,CCin):-
|
||||
connecting(Points, Volts, Amps, Inlist,Tmplist),
|
||||
component_dc(Component,Data,Volts,Amps,CCin,CCout,Kind),
|
||||
solve_dc(Kind, Rest, Tmplist,Outlist,CCout).
|
||||
|
||||
component_dc(resistor,R,[V1,V2],[I,-1*I],Cc,Cc,_):-
|
||||
V1-V2 = R*I,
|
||||
resistor_val(R).
|
||||
component_dc(capacitor,_,[V1,V2],[0,0],Cc,Cc,_).
|
||||
component_dc(transistor,[Type,Code,State],Volts, [Ib,Ic,Ie],[Ic|CC],CC,Kind):-
|
||||
transistor_type(Type,Code,Beta,Vbe,Vcesat,_,Kind),
|
||||
transistor_state(Type,State,Beta,Vbe,Vcesat,Volts,[Ib,Ic,Ie]).
|
||||
component_dc(diode,[Code,State],Volts,Amps,Cc,Cc,_):-
|
||||
diode_type(Code,Vf,Vbreak),
|
||||
diode_state(State,Vf,Vreak,Volts,Amps).
|
||||
|
||||
/****************************************************************************/
|
||||
/* diode and transistor states / and relationships */
|
||||
/****************************************************************************/
|
||||
diode_state(forward,Vf,Vbreak,[Vp,Vm],[I, -1*I]):-
|
||||
/* forward biased */
|
||||
Vp - Vm = Vf,
|
||||
I >= 0.
|
||||
diode_state(reverse,Vf,Vbreak,[Vp,Vm],[I, -1*I]):-
|
||||
/* reverse biased */
|
||||
Vp - Vm < Vf,
|
||||
Vm - Vp < Vbreak,
|
||||
I = 0.
|
||||
|
||||
transistor_state(npn, active, Beta, Vbe,_,[Vb, Vc, Ve], [Ib, Ic, Ie]):-
|
||||
Vb = Ve + Vbe,
|
||||
Vc >= Vb,
|
||||
Ib >= 0,
|
||||
Ic = Beta*Ib,
|
||||
Ie+Ib+Ic = 0.
|
||||
transistor_state(pnp, active, Beta, Vbe,_,[Vb, Vc, Ve], [Ib, Ic, Ie]):-
|
||||
Vb = Ve + Vbe,
|
||||
Vc <= Vb,
|
||||
Ib <= 0,
|
||||
Ic = Beta*Ib,
|
||||
Ie+Ib+Ic = 0.
|
||||
transistor_state(npn, saturated, Beta, Vbe, Vcesat,[Vb, Vc, Ve], [Ib, Ic, Ie]):-
|
||||
Vb = Ve + Vbe,
|
||||
Vc = Ve + Vcesat,
|
||||
Ib >= 0,
|
||||
Ic >= 0,
|
||||
Ie+Ib+Ic = 0.
|
||||
transistor_state(pnp, saturated, Beta, Vbe, Vcesat,[Vb, Vc, Ve], [Ib, Ic, Ie]):-
|
||||
Vb = Ve + Vbe,
|
||||
Vc = Ve + Vcesat,
|
||||
Ib <= 0,
|
||||
Ic <= 0,
|
||||
Ie+Ib+Ic = 0.
|
||||
transistor_state(npn, cutoff, Beta, Vbe, Vcesat,[Vb, Vc, Ve], [Ib, Ic, Ie]):-
|
||||
Vb <= Ve + Vbe,
|
||||
Ib = 0,
|
||||
Ic = 0,
|
||||
Ie = 0.
|
||||
transistor_state(pnp, cutoff, Beta, Vbe, Vcesat,[Vb, Vc, Ve], [Ib, Ic, Ie]):-
|
||||
Vb >= Ve + Vbe,
|
||||
Ib = 0,
|
||||
Ic = 0,
|
||||
Ie = 0.
|
||||
|
||||
/****************************************************************************/
|
||||
/* connecting components routines */
|
||||
/****************************************************************************/
|
||||
connecting([],[],[],List,List).
|
||||
connecting([P|PR],[V|VR],[I|IR], Inlist,Outlist):-
|
||||
connect(P,V,I,Inlist,Tmplist),
|
||||
connecting(PR,VR,IR,Tmplist,Outlist).
|
||||
|
||||
connect(P,V,I,[],[n(P,V,[I])]):-!.
|
||||
connect(P,V,I, [n(P,V,Ilist) | Rest],[n(P,V,[I|Ilist])|Rest]):-!.
|
||||
connect(P,V,I, [A|Rest], [A|Newrest]) :-
|
||||
connect(P,V,I, Rest, Newrest).
|
||||
|
||||
/****************************************************************************/
|
||||
/* Stability Analysis */
|
||||
/****************************************************************************/
|
||||
stability(Vcc1,Vcc2,Circuit, CollectorCurrents, Stability):-
|
||||
solve_dc(minn,Circuit ,[n(cc1,Vcc1,[_]),n(cc2,Vcc2,[_]),n(gnd,0,[_])],
|
||||
Nodelist1,MinCurrents),
|
||||
current_solve(Nodelist1),
|
||||
% printf(" Min %\n Minmodes \n",[MinCurrents]),
|
||||
% print_value(Nodelist1),
|
||||
solve_dc(maxx,Circuit ,[n(cc1,Vcc1,[_]),n(cc2,Vcc2,[_]),n(gnd,0,[_])],
|
||||
Nodelist2,MaxCurrents),
|
||||
current_solve(Nodelist2),
|
||||
% printf(" Max %\n Maxnodes\n",[MaxCurrents]),
|
||||
% print_value(Nodelist2),
|
||||
calculate(MinCurrents,MaxCurrents,CollectorCurrents,Stability).
|
||||
|
||||
calculate(MinCurrents,MaxCurrents,CollectorCurrents,Stability):-
|
||||
cal(MinCurrents,MaxCurrents,CollectorCurrents,Percents),
|
||||
% printf(" Percent % \n",[Percents]),
|
||||
maxi(Percents,0,Stability).
|
||||
|
||||
cal([Min|Rin],[Max|Rax],[Ic|Rc],[Pc|Rpc]):-
|
||||
Pc=max(Ic-Min,Max-Ic),
|
||||
cal(Rin,Rax,Rc,Rpc).
|
||||
cal([],[],[],[]).
|
||||
|
||||
maxi([N1|R],N2,P):-
|
||||
M=max(N1,N2),
|
||||
maxi(R,M,P).
|
||||
maxi([],P,P).
|
||||
/****************************************************************************/
|
||||
/* Miscellaneous things */
|
||||
/****************************************************************************/
|
||||
current_solve([]).
|
||||
current_solve([n(_,_,L) | Rest]) :-
|
||||
kcl(L),
|
||||
current_solve(Rest).
|
||||
|
||||
print_value([]).
|
||||
print_value([n(P,V,I) | Rest]) :-
|
||||
printf("% at % %\n",[P,V,I]),
|
||||
print_value(Rest).
|
||||
|
||||
print_circuit([]).
|
||||
print_circuit([[Comp,Name,Data,Points] | Rest]) :-
|
||||
printf(" % at % %\n",[Comp,Name,Data]),
|
||||
print_circuit(Rest).
|
||||
|
||||
sum([X|T],Z) :-
|
||||
X+P = Z,
|
||||
sum(T,P).
|
||||
sum([],0).
|
||||
|
||||
kcl(L) :-
|
||||
sum(L,0).
|
||||
|
||||
/****************************************************************************/
|
||||
/* Database of circuits and components */
|
||||
/****************************************************************************/
|
||||
resistor_val(100).
|
||||
resistor_val(50).
|
||||
resistor_val(27).
|
||||
resistor_val(5).
|
||||
resistor_val(2).
|
||||
resistor_val(1).
|
||||
|
||||
diode_type(di1, 0.6, 100).
|
||||
|
||||
transistor_type(npn, tr0, 100, 0.7, 0.3, 0.025,mean).
|
||||
transistor_type(npn, tr0, 50, 0.8, 0.3, 0.025,minn).
|
||||
transistor_type(npn, tr0, 150, 0.6, 0.3, 0.025,maxx).
|
||||
|
||||
transistor_type(pnp, tr1, 100, -0.7, -0.3, 0.025,mean).
|
||||
transistor_type(pnp, tr1, 50, -0.8, -0.3, 0.025,minn).
|
||||
transistor_type(pnp, tr1, 150, -0.6, -0.3, 0.025,maxx).
|
||||
|
||||
circuit(15,0,[
|
||||
[capacitor,c1,c1,[in,b]],
|
||||
[resistor,r1,R1,[b,cc1]],
|
||||
[resistor,r2,R2,[b,gnd]],
|
||||
[transistor,tr,[npn,tr0,active],[b,c,e]],
|
||||
[resistor,re,Re,[e,gnd]],
|
||||
[capacitor,c2,c2,[c,out]],
|
||||
[resistor,rc,Rc,[c,cc1]],
|
||||
[capacitor,c3,c3,[e,gnd]]],
|
||||
in,out,common_emitter).
|
||||
|
||||
circuit(15,0,[
|
||||
[capacitor,c1,C1,[gnd,b]],
|
||||
[resistor,r1,R1,[b,cc1]],
|
||||
[resistor,r2,R2,[b,gnd]],
|
||||
[transistor,tr,[pnp,tr1,active],[b,c,e]],
|
||||
[resistor,re,Re,[e,gnd]],
|
||||
[capacitor,c2,C2,[c,in]],
|
||||
[resistor,rc,Rc,[c,cc1]],
|
||||
[capacitor,c3,C3,[e,out]]],
|
||||
in,out,common_base).
|
||||
|
||||
circuit(15,0,[
|
||||
[capacitor,c1,C1,[in,b]],
|
||||
[resistor,r1,R1,[b,cc1]],
|
||||
[resistor,r2,R2,[b,gnd]],
|
||||
[transistor,tr,[npn,tr0,active],[b,cc1,e]],
|
||||
[resistor,re,Re,[e,gnd]],
|
||||
[capacitor,c3,C3,[e,out]]],
|
||||
in,out,emitter_follower).
|
||||
|
||||
go1:- dc_analysis(15,-12,[
|
||||
[diode,d1,[di1,St1],[a,gnd]],
|
||||
[diode,d2,[di1,St2],[a,cc1]],
|
||||
[resistor,r1,100,[a,cc1]],
|
||||
[diode,d3,[di1,St3],[a,p1]],
|
||||
[diode,d4,[di1,St4],[p1,b]],
|
||||
[resistor,r2,100,[b,cc2]],
|
||||
[transistor,tr,[npn,tr0,State],[b,c,gnd]],
|
||||
[resistor,rc,100,[c,cc1]]]).
|
||||
|
||||
% Answer:
|
||||
% cc1 at 15 [0, 0.144, 0, -0.144]
|
||||
% cc2 at -12 [-0.114, 0.114]
|
||||
% gnd at 0 [0, -0.03, 0.03]
|
||||
% a at 0.6 [0.114, -0.144, 0, 0.03]
|
||||
% p1 at 0 [0.114, -0.114]
|
||||
% b at -0.6 [0, 0.114, -0.114]
|
||||
% c at 15 [0, 0]
|
||||
% diode at d1 [di1, forward]
|
||||
% diode at d2 [di1, reverse]
|
||||
% resistor at r1 100
|
||||
% diode at d3 [di1, forward]
|
||||
% diode at d4 [di1, forward]
|
||||
% resistor at r2 100
|
||||
% transistor at tr [npn, tr0, cutoff]
|
||||
% resistor at rc 100
|
||||
|
||||
go2:-
|
||||
Vcc = 15, Stability < 0.5, Gain > 0.5,
|
||||
Inresistance >= 25, Outresistance <= 2,
|
||||
full_analysis(Vcc, _, Circuit, _, _, emitter_follower, Stability,
|
||||
Gain, Inresistance, Outresistance),
|
||||
write(Circuit),nl.
|
||||
|
||||
% Answer:
|
||||
% Stab 0.001947
|
||||
% Outresist 0.857107
|
||||
% capacitor at c1 Data_48
|
||||
% resistor at r1 100
|
||||
% resistor at r2 100
|
||||
% transistor at tr [npn, tr0, active]
|
||||
% resistor at re 100
|
||||
% capacitor at c3 Data_52
|
||||
% [[capacitor, c1, C1_48, [in, b]], [resistor, r1, 100, [b, cc1]],
|
||||
% [resistor, r2, 100, [b, gnd]], [transistor, tr, [npn, tr0, active],
|
||||
% [b, cc1, e]], [resistor, re, 100, [e, gnd]], [capacitor, c3, C3_52,
|
||||
% [e, out]]]
|
||||
|
||||
?- printf("\n>>> Sample goals: go1/0, go2/0\n", []).
|
@ -1,41 +0,0 @@
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CLP(R) Version 2.0 (Example Programs Release)
|
||||
* (C) Copyright, March 1986, Monash University
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
%
|
||||
% The rule below describes the relationship between two complex numbers
|
||||
% and their product. The goal ?- go uses the rule
|
||||
% first to multiply two complex numbers, and then to divide one by another,
|
||||
% in two different ways.
|
||||
%
|
||||
|
||||
zmul(c(R1,I1),c(R2,I2),c(R3,I3)) :-
|
||||
R3 = R1 * R2 - I1 * I2 ,
|
||||
I3 = R1 * I2 + R2 * I1 .
|
||||
|
||||
go :- zmul(c(1,1),c(2,2),Z),
|
||||
zmul(c(1,1),Y,c(0,4)),
|
||||
zmul(X,c(2,2),c(0,4)),
|
||||
nl,
|
||||
write(" X = "),
|
||||
write(X),
|
||||
nl,
|
||||
write(" Y = "),
|
||||
write(Y),
|
||||
nl,
|
||||
write(" Z = "),
|
||||
write(Z),
|
||||
nl.
|
||||
|
||||
% Answer:
|
||||
% X = c(1, 1)
|
||||
% Y = c(2, 2)
|
||||
% Z = c(0, 4)
|
||||
|
||||
?- printf("\n>>> Sample goal: go/0\n", []).
|
@ -1,318 +0,0 @@
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CLP(R) Version 2.0 (Example Programs Release)
|
||||
* (C) Copyright, March 1986, Monash University
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
%
|
||||
% cpm critical path routine
|
||||
% Network is an input project network of the form
|
||||
% [ [node1 , node2, time ] .... ]
|
||||
% Graph is the critical path graph produced
|
||||
% Latest is the latest possible completion time is specified
|
||||
% cpm/3 is used if the latest time is specified
|
||||
% otherwise use cpm/2
|
||||
%
|
||||
|
||||
% Explanation of output
|
||||
/*
|
||||
Node Es Lc (Gives the Earliest Start time and Latest Completion
|
||||
time for the particular node)
|
||||
Node1 Node2 T Ls Ec Tf Ff
|
||||
(Details the times relating to the activity between Node1 & Node2
|
||||
T is the time required for the activity
|
||||
Ls the Latest Start time
|
||||
Ec the Earliest Completion time
|
||||
Tf the Total Float
|
||||
Ff the Free Float)
|
||||
Activities on the critical path are marked with an asterix
|
||||
The start node and end node are computed automatically and distinguished
|
||||
*/
|
||||
|
||||
% Sample output
|
||||
/*
|
||||
Node Es Lc
|
||||
Node1 Node2 T Ls Ec Tf Ff
|
||||
--------------------------------------------------
|
||||
START NODE n1 0 0
|
||||
--------------------------------------------------
|
||||
n1 n2 3 2 3 2 0
|
||||
n1 n3 2 0 2 0 0 *
|
||||
--------------------------------------------------
|
||||
n2 3 5
|
||||
--------------------------------------------------
|
||||
n2 n4 2 5 5 2 2
|
||||
--------------------------------------------------
|
||||
n3 2 2
|
||||
--------------------------------------------------
|
||||
n3 n4 5 2 7 0 0 *
|
||||
--------------------------------------------------
|
||||
END NODE n4 7 7
|
||||
*/
|
||||
|
||||
cpm(Network,Graph,Latest) :-
|
||||
build(Network,Graph),
|
||||
early_late(Graph,Graph,End,Latest),
|
||||
Latest >= End,
|
||||
analyse(Graph,Graph).
|
||||
|
||||
cpm(Network,Graph) :-
|
||||
build(Network,Graph),
|
||||
early_late(Graph,Graph,End),
|
||||
analyse(Graph,Graph).
|
||||
|
||||
% build an adjacency graph out of the network
|
||||
build([],Graph) :-
|
||||
buildv([],_,Graph).
|
||||
build([[I,J,C]|T],Graph) :-
|
||||
buildv(ed(I,J,C),to,Graph),
|
||||
buildv(ed(I,J,C),from,Graph),
|
||||
build(T,Graph).
|
||||
|
||||
buildv([],_,[]) :- !.
|
||||
buildv([],_,[ad(_,_,_,To,From)|T]) :-
|
||||
!,addedg([],_,To),
|
||||
addedg([],_,From),
|
||||
buildv([],_,T).
|
||||
buildv(ed(I,J,C),to,[ad(I,Es,Lc,To,From)|T]) :-
|
||||
!,addedg(J,C,To).
|
||||
buildv(Edge,to,[H|T]) :-
|
||||
!,buildv(Edge,to,T).
|
||||
buildv(ed(I,J,C),from,[ad(J,Es,Lc,To,From)|T]) :-
|
||||
!,addedg(I,C,From).
|
||||
buildv(Edge,from,[H|T]) :-
|
||||
!,buildv(Edge,from,T).
|
||||
|
||||
addedg([],_,[]) :- !.
|
||||
addedg([],_,[H|T]) :- !,
|
||||
addedg([],_,T).
|
||||
addedg(V,C,[ed(V,C,_,_,_,_)|T]) :- !.
|
||||
addedg(V,C,[H|T]) :-
|
||||
addedg(V,C,T).
|
||||
|
||||
% Get early start times and latest completion times
|
||||
% early/4 is used when a ending time is given
|
||||
% otherwise early/3 assumes that the early start time
|
||||
% for the end node is equal to the latest completion time
|
||||
early_late([],_,_,_).
|
||||
early_late([ad(I,Es,Lc,To,From)|T],G,End,Latest) :-
|
||||
setearly(From,To,G,End,Es),
|
||||
setlate(To,G,Latest,Lc),
|
||||
early_late(T,G,End,Latest).
|
||||
|
||||
early_late([],_,_).
|
||||
early_late([ad(I,Es,Lc,To,From)|T],G,End) :-
|
||||
setearly(From,To,G,End,Es),
|
||||
setlate(To,G,End,Lc),
|
||||
early_late(T,G,End).
|
||||
|
||||
setearly([],_,_,_,0).
|
||||
setearly([ed(V,C,_,_,_,_)|T],[],G,Es,Es) :-
|
||||
!,
|
||||
getnode(V,G,Es1,_),
|
||||
setmax(T,G,Es1+C,Es).
|
||||
setearly([ed(V,C,_,_,_,_)|T],_,G,End,Es) :-
|
||||
getnode(V,G,Es1,_),
|
||||
setmax(T,G,Es1+C,Es).
|
||||
|
||||
setmax([],_,Max,Max).
|
||||
setmax([ed(V,C,_,_,_,_)|T],G,Max0,Max) :-
|
||||
getnode(V,G,Es1,_),
|
||||
setmax(T,G,max(Max0,Es1+C),Max).
|
||||
|
||||
setlate([],_,Last,Last).
|
||||
setlate([ed(V,C,_,_,_,_)|T],G,Last,Lc) :-
|
||||
getnode(V,G,_,Lc1),
|
||||
setmin(T,G,Lc1-C,Lc).
|
||||
|
||||
setmin([],_,Min,Min).
|
||||
setmin([ed(V,C,_,_,_,_)|T],G,Min0,Min) :-
|
||||
getnode(V,G,_,Lc1),
|
||||
setmin(T,G,min(Min0,Lc1-C),Min).
|
||||
|
||||
% Search graph for the early & late times for a node
|
||||
getnode(I,[ad(I,Es,Lc,_,_)|T],Es,Lc).
|
||||
getnode(I,[H|T],Es,Lc) :-
|
||||
getnode(I,T,Es,Lc).
|
||||
|
||||
% Compute the other times :
|
||||
% Ls - latest start time
|
||||
% Ec - earliest completion time
|
||||
% Tf - total float time
|
||||
% Ff - free float time
|
||||
analyse([],G).
|
||||
analyse([ad(I,Es,Lc,To,_)|T],G) :-
|
||||
analyse_times(To,Es,Lc,G),
|
||||
analyse(T,G).
|
||||
|
||||
analyse_times([],_,_,_).
|
||||
analyse_times([ed(V,C,Ls,Ec,Tf,Ff)|T],Esi,Lci,G) :-
|
||||
getnode(V,G,Esj,Lcj),
|
||||
compute(Ls,Ec,Tf,Ff,Esj,Lcj,Esi,Lci,C),
|
||||
analyse_times(T,Esi,Lci,G).
|
||||
|
||||
% Indirect way of doing the calculation just to speed things up
|
||||
% can be removed and inserted directly in analyse_times
|
||||
compute(Ls,Ec,Tf,Ff,Esj,Lcj,Esi,Lci,C) :-
|
||||
X = Esi+C,
|
||||
Ls = Lcj-C,
|
||||
Ec = Esi+C,
|
||||
Tf = Lcj-X,
|
||||
Ff = Esj-X.
|
||||
|
||||
% display routines
|
||||
print_analysis(G) :-
|
||||
printf("\t\tNode\tEs\tLc\n",[]),
|
||||
printf("Node1\tNode2\tT\tLs\tEc\tTf\tFf\n",[]),
|
||||
print_analysis1(G).
|
||||
print_analysis1([]).
|
||||
print_analysis1([H|T]) :-
|
||||
print_node(H),
|
||||
print_analysis1(T).
|
||||
print_node(ad(I,Es,Lc,[],From)) :-
|
||||
!,
|
||||
printf("--------------------------------------------------\n",[]),
|
||||
printf("END NODE\t%\t%\t%\n",[I,Es,Lc]).
|
||||
print_node(ad(I,Es,Lc,To,[])) :-
|
||||
!,
|
||||
printf("--------------------------------------------------\n",[]),
|
||||
printf("START NODE\t%\t%\t%\n",[I,Es,Lc]),
|
||||
printf("--------------------------------------------------\n",[]),
|
||||
print_times(To,I).
|
||||
print_node(ad(I,Es,Lc,To,From)) :-
|
||||
printf("--------------------------------------------------\n",[]),
|
||||
printf("\t\t%\t%\t%\n",[I,Es,Lc]),
|
||||
printf("--------------------------------------------------\n",[]),
|
||||
print_times(To,I).
|
||||
|
||||
print_times([],_).
|
||||
print_times([ed(V,C,Ls,Ec,Tf,Ff)|T],I) :-
|
||||
printf("%\t%\t%\t%\t%\t%\t%",[I,V,C,Ls,Ec,Tf,Ff]),
|
||||
is_critical(Tf),
|
||||
print_times(T,I).
|
||||
|
||||
is_critical(0) :-
|
||||
printf(" *\n",[]).
|
||||
is_critical(Tf) :-
|
||||
Tf > 0,
|
||||
printf("\n",[]).
|
||||
|
||||
go1 :- cpm([
|
||||
[n1,n2,3],[n1,n3,2],[n3,n4,5],[n2,n4,2]],G),
|
||||
print_analysis(G).
|
||||
|
||||
% Answer:
|
||||
% Node Es Lc
|
||||
% Node1 Node2 T Ls Ec Tf Ff
|
||||
% --------------------------------------------------
|
||||
% START NODE n1 0 0
|
||||
% --------------------------------------------------
|
||||
% n1 n2 3 2 3 2 0
|
||||
% n1 n3 2 0 2 0 0 *
|
||||
% --------------------------------------------------
|
||||
% n2 3 5
|
||||
% --------------------------------------------------
|
||||
% n2 n4 2 5 5 2 2
|
||||
% --------------------------------------------------
|
||||
% n3 2 2
|
||||
% --------------------------------------------------
|
||||
% n3 n4 5 2 7 0 0 *
|
||||
% --------------------------------------------------
|
||||
% END NODE n4 7 7
|
||||
|
||||
go2 :- cpm([
|
||||
[n5,n6,9],[n5,n7,5],[n6,n7,0],[n4,n7,4],
|
||||
[n1,n2,2],[n2,n3,0],[n1,n3,6],[n1,n4,3],
|
||||
[n2,n5,1],[n2,n6,4],[n3,n5,2],[n4,n5,0],[n4,n8,3],
|
||||
[n6,n8,4],[n7,n8,6]],G),
|
||||
print_analysis(G).
|
||||
|
||||
% Answer:
|
||||
% Node Es Lc
|
||||
% Node1 Node2 T Ls Ec Tf Ff
|
||||
% --------------------------------------------------
|
||||
% n5 8 8
|
||||
% --------------------------------------------------
|
||||
% n5 n6 9 8 17 0 0 *
|
||||
% n5 n7 5 12 13 4 4
|
||||
% --------------------------------------------------
|
||||
% n6 17 17
|
||||
% --------------------------------------------------
|
||||
% n6 n7 0 17 17 0 0 *
|
||||
% n6 n8 4 19 21 2 2
|
||||
% --------------------------------------------------
|
||||
% n7 17 17
|
||||
% --------------------------------------------------
|
||||
% n7 n8 6 17 23 0 0 *
|
||||
% --------------------------------------------------
|
||||
% n4 3 8
|
||||
% --------------------------------------------------
|
||||
% n4 n7 4 13 7 10 10
|
||||
% n4 n5 0 8 3 5 5
|
||||
% n4 n8 3 20 6 17 17
|
||||
% --------------------------------------------------
|
||||
% START NODE n1 0 0
|
||||
% --------------------------------------------------
|
||||
% n1 n2 2 4 2 4 0
|
||||
% n1 n3 6 0 6 0 0 *
|
||||
% n1 n4 3 5 3 5 0
|
||||
% --------------------------------------------------
|
||||
% n2 2 6
|
||||
% --------------------------------------------------
|
||||
% n2 n3 0 6 2 4 4
|
||||
% n2 n5 1 7 3 5 5
|
||||
% n2 n6 4 13 6 11 11
|
||||
% --------------------------------------------------
|
||||
% n3 6 6
|
||||
% --------------------------------------------------
|
||||
% n3 n5 2 6 8 0 0 *
|
||||
% --------------------------------------------------
|
||||
% END NODE n8 23 23
|
||||
|
||||
go3 :-
|
||||
cpm([
|
||||
[n1,n2,4],[n1,n3,3],[n1,n4,4], [n2,n5,7],[n2,n3,1],[n2,n7,8],
|
||||
[n3,n5,4], [n4,n6,2], [n5,n6,1],[n5,n7,3], [n6,n7,4]],G),
|
||||
print_analysis(G).
|
||||
|
||||
% Answer:
|
||||
% Node Es Lc
|
||||
% Node1 Node2 T Ls Ec Tf Ff
|
||||
% --------------------------------------------------
|
||||
% START NODE n1 0 0
|
||||
% --------------------------------------------------
|
||||
% n1 n2 4 0 4 0 0 *
|
||||
% n1 n3 3 4 3 4 2
|
||||
% n1 n4 4 6 4 6 0
|
||||
% --------------------------------------------------
|
||||
% n2 4 4
|
||||
% --------------------------------------------------
|
||||
% n2 n5 7 4 11 0 0 *
|
||||
% n2 n3 1 6 5 2 0
|
||||
% n2 n7 8 8 12 4 4
|
||||
% --------------------------------------------------
|
||||
% n3 5 7
|
||||
% --------------------------------------------------
|
||||
% n3 n5 4 7 9 2 2
|
||||
% --------------------------------------------------
|
||||
% n4 4 10
|
||||
% --------------------------------------------------
|
||||
% n4 n6 2 10 6 6 6
|
||||
% --------------------------------------------------
|
||||
% n5 11 11
|
||||
% --------------------------------------------------
|
||||
% n5 n6 1 11 12 0 0 *
|
||||
% n5 n7 3 13 14 2 2
|
||||
% --------------------------------------------------
|
||||
% END NODE n7 16 16
|
||||
% --------------------------------------------------
|
||||
% n6 12 12
|
||||
% --------------------------------------------------
|
||||
% n6 n7 4 12 16 0 0 *
|
||||
|
||||
?- printf("\n>>> Sample goals: go1/0, go2/0, go3/0\n", []).
|
||||
|
@ -1,175 +0,0 @@
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CLP(R) Version 2.0 (Example Programs Release)
|
||||
* (C) Copyright, March 1986, Monash University
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
%
|
||||
% Convert a propositional formula into disjunctive normal form.
|
||||
% There are 15 goals ?- go1 to ?- go 15.
|
||||
% The goal ?- go5 is the most substantial.
|
||||
%
|
||||
|
||||
literal(z0).
|
||||
literal(z1).
|
||||
literal(z2).
|
||||
literal(z3).
|
||||
literal(z4).
|
||||
literal(z5).
|
||||
literal(z6).
|
||||
literal(z7).
|
||||
literal(z8).
|
||||
literal(z9).
|
||||
literal(n(X)) :- literal(X).
|
||||
|
||||
/*---------------------------------------------- base cases ------------------*/
|
||||
|
||||
norm(X, X) :- literal(X).
|
||||
norm(o(X, Y), o(X, Y)) :- literal(X), literal(Y).
|
||||
norm(a(X, Y), a(X, Y)) :- literal(X), literal(Y).
|
||||
|
||||
/*---------------------------------------------- OR cases --------------------*/
|
||||
|
||||
norm(o(X, Y), o(X1, Y)) :-
|
||||
literal(Y),
|
||||
norm(X, X1).
|
||||
norm(o(X, o(Y, Z)), W) :-
|
||||
norm(o(o(X, Y), Z), W).
|
||||
norm(o(X, a(Y1, Y2)), o(X1, Y12)) :-
|
||||
norm(X, X1),
|
||||
norm(a(Y1, Y2), Y12).
|
||||
|
||||
/*---------------------------------------------- AND cases -------------------*/
|
||||
|
||||
norm(a(X, Y), a(X1, Y)) :-
|
||||
literal(Y),
|
||||
norm(X, X1).
|
||||
norm(a(X, a(Y, Z)), W) :-
|
||||
norm(a(a(X, Y), Z), W).
|
||||
norm(a(X, o(Y1, Y2)), a(X1, Y12)) :-
|
||||
norm(X, X1),
|
||||
norm(o(Y1, Y2), Y12).
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------- base cases ------------------*/
|
||||
|
||||
dnf(X, X) :- literal(X).
|
||||
dnf(o(X, Y), o(X, Y)) :- literal(X), literal(Y).
|
||||
dnf(a(X, Y), a(X, Y)) :- literal(X), literal(Y).
|
||||
|
||||
/*---------------------------------------------- compaction ------------------*/
|
||||
|
||||
dnf(n(n(X)), W) :- dnf(X, W).
|
||||
dnf(n(o(X, Y)), W) :- dnf(a(n(X), n(Y)), W).
|
||||
dnf(n(a(X, Y)), W) :- dnf(o(n(X), n(Y)), W).
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
dnf(o(X, Y), W) :-
|
||||
dnf(X, X1),
|
||||
dnf(Y, Y1),
|
||||
norm(o(X1, Y1), W).
|
||||
dnf(a(X, Y), a(a(X1, X2), Y)) :-
|
||||
literal(Y),
|
||||
dnf(X, a(X1, X2)).
|
||||
dnf(a(X, Y), a(a(Y1, Y2), X)) :-
|
||||
literal(X),
|
||||
dnf(Y, a(Y1, Y2)).
|
||||
dnf(a(X, Y), W) :-
|
||||
dnf(X, a(X1, X2)),
|
||||
dnf(Y, a(Y1, Y2)),
|
||||
norm(a(a(X1, X2), a(Y1, Y2)), W).
|
||||
dnf(a(X, Y), W) :-
|
||||
dnf(X, o(X1, X2)),
|
||||
dnf(Y, Y1),
|
||||
dnf(o(a(X1, Y1), a(X2, Y1)), W).
|
||||
dnf(a(X, Y), W) :-
|
||||
dnf(X, X1),
|
||||
dnf(Y, o(Y1, Y2)),
|
||||
dnf(o(a(X1, Y1), a(X1, Y2)), W).
|
||||
|
||||
go1:- dnf(a(z1, a(z2, o(z3, a(z4, a(z5, z6))))), X),
|
||||
printf("%\n", [X]).
|
||||
go2:- dnf(o(o(z1,o(z2,o(z3,z4))),o(z5,o(z6,o(z7,z8)))),X),
|
||||
printf("%\n", [X]).
|
||||
go3:- dnf(o(o(a(z1,z2),z3),o(a(z4,a(a(z5,z6),z7)),o(z8,z9))),X),
|
||||
printf("%\n", [X]).
|
||||
go4:- dnf(a(a(z1,a(o(z2,z3),z4)),a(z5,o(z6,z7))),X),
|
||||
printf("%\n", [X]).
|
||||
go5:- dnf(n(o(a(n(o(z1,z2)),n(a(z3,z4))),a(n(z5),o(a(z6,a(z7,z8)),z9)))),X),
|
||||
dnf(n(o(a(n(o(z1,z2)),n(a(z3,z4))),a(n(z5),o(a(z6,a(z7,z8)),z9)))),X),
|
||||
printf("%\n", [X]).
|
||||
go6:- dnf(n(a(z1,a(z2,z3))),X),
|
||||
printf("%\n", [X]).
|
||||
go7:- dnf(a(a(o(z1,z2),z3),z4),X),
|
||||
printf("%\n", [X]).
|
||||
go8:- dnf(o(a(z1,z2),a(z3,z4)),X),
|
||||
printf("%\n", [X]).
|
||||
go9:- dnf(a(o(z1,z2),o(z3,z4)),X),
|
||||
printf("%\n", [X]).
|
||||
go10:- dnf(o(a(o(z1,z2),a(z3,z4)),z5),X),
|
||||
printf("%\n", [X]).
|
||||
go11:- dnf(o(o(z1,o(z3,o(z4,a(z4,z5)))),z5),X),
|
||||
printf("%\n", [X]).
|
||||
go12:- dnf(o(z1,o(z2,o(z3,z4))),X),
|
||||
printf("%\n", [X]).
|
||||
go13:- dnf(o(a(z1,z2),n(o(z2,a(z3,z4)))),X),
|
||||
printf("%\n", [X]).
|
||||
go14:- dnf(o(a(n(z0),n(z1)),a(n(z0),n(z2))),X),
|
||||
printf("%\n", [X]).
|
||||
go15:- dnf(o(n(a(z1,z2)),a(o(a(o(z1,z2),z3),z4),z5)),X),
|
||||
printf("%\n", [X]).
|
||||
|
||||
% Answers:
|
||||
% 1 ?- go1.
|
||||
% o(a(a(z2, z3), z1), a(a(a(a(z5, z6), z4), z2), z1))
|
||||
%
|
||||
% 2 ?- go2.
|
||||
% o(o(o(o(o(o(o(z1, z2), z3), z4), z5), z6), z7), z8)
|
||||
%
|
||||
% 3 ?- go3.
|
||||
% o(o(o(o(a(z1, z2), z3), a(a(a(z5, z6), z7), z4)), z8), z9)
|
||||
%
|
||||
% 4 ?- go4.
|
||||
% o(o(o(a(a(a(a(z2, z4), z1), z5), z6), a(a(a(a(z2, z4), z1), z5), z7)), a(a(a(a(z3, z4), z1), z5), z6)), a(a(a(a(z3, z4), z1), z5), z7))
|
||||
%
|
||||
% 5 ?- go5.
|
||||
% o(o(o(o(o(o(o(o(o(o(o(a(z1, n(n(z5))), a(a(n(z6), n(z9)), z1)), a(a(n(z7), n(z9)), z1)), a(a(n(z8), n(z9)), z1)), a(z2, n(n(z5)))), a(a(n(z6), n(z9)), z2)), a(a(n(z7), n(z9)), z2)), a(a(n(z8), n(z9)), z2)), a(a(z3, z4), n(n(z5)))), a(a(a(z3, z4), n(z6)), n(z9))), a(a(a(z3, z4), n(z7)), n(z9))), a(a(a(z3, z4), n(z8)), n(z9)))
|
||||
%
|
||||
% 6 ?- go6.
|
||||
% o(o(n(z1), n(z2)), n(z3))
|
||||
%
|
||||
% 7 ?- go7.
|
||||
% o(a(a(z1, z3), z4), a(a(z2, z3), z4))
|
||||
%
|
||||
% 8 ?- go8.
|
||||
% o(a(z1, z2), a(z3, z4))
|
||||
%
|
||||
% 9 ?- go9.
|
||||
% o(o(o(a(z1, z3), a(z1, z4)), a(z2, z3)), a(z2, z4))
|
||||
%
|
||||
% 10 ?- go10.
|
||||
% o(o(a(a(z3, z4), z1), a(a(z3, z4), z2)), z5)
|
||||
%
|
||||
% 11 ?- go11.
|
||||
% o(o(o(o(z1, z3), z4), a(z4, z5)), z5)
|
||||
%
|
||||
% 12 ?- go12.
|
||||
% o(o(o(z1, z2), z3), z4)
|
||||
%
|
||||
% 13 ?- go13.
|
||||
% o(o(a(z1, z2), a(n(z2), n(z3))), a(n(z2), n(z4)))
|
||||
%
|
||||
% 14 ?- go14.
|
||||
% o(a(n(z0), n(z1)), a(n(z0), n(z2)))
|
||||
%
|
||||
% 15 ?- go15.
|
||||
% o(o(o(o(n(z1), n(z2)), a(a(z1, z3), z5)), a(a(z2, z3), z5)), a(z4, z5))
|
||||
%
|
||||
|
||||
?- printf("\n>>> Sample goals: go1/0, ..., go15/0\n", []).
|
@ -1,34 +0,0 @@
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CLP(R) Version 2.0 (Example Programs Release)
|
||||
* (C) Copyright, March 1986, Monash University
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
%
|
||||
% Simple recursive formulation of fibonacci numbers.
|
||||
% The goal ?- go shows how the definition can be used for
|
||||
% both finding a a fibonacci number given its index, and finding the index
|
||||
% of a given fibonacci number.
|
||||
%
|
||||
|
||||
fib(0, 1).
|
||||
fib(1, 1).
|
||||
fib(N, X1 + X2) :-
|
||||
N > 1,
|
||||
fib(N - 1, X1),
|
||||
fib(N - 2, X2).
|
||||
|
||||
go:- fib(10, Z),
|
||||
printf("forward: fib(10) = %d\n",[Z]),
|
||||
fib(Y, Z),
|
||||
printf("backward: fib(%d) = %d\n",[Y,Z]).
|
||||
|
||||
% Answer:
|
||||
% forward: fib(10) = 89
|
||||
% backward: fib(10) = 89
|
||||
|
||||
?- printf("\n>>> Sample goal: go/0\n", []).
|
@ -1,60 +0,0 @@
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CLP(R) Version 2.0 (Example Programs Release)
|
||||
* (C) Copyright, March 1986, Monash University
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
%
|
||||
% This program finds a root of a transcendental function given an initial
|
||||
% guess. It uses the Steffensen algorithm.
|
||||
% The goal ?- go finds a root of
|
||||
%
|
||||
% 2
|
||||
% 1 - X
|
||||
%
|
||||
% given X = 1.7 as an initial guess, requiring that the solution give a value
|
||||
% no more than 0.0000005 from zero.
|
||||
|
||||
getnext(X,NX):-
|
||||
NX = X - (F / G),
|
||||
eval(X,F),
|
||||
getg(X,G).
|
||||
|
||||
getg(X,G):-
|
||||
G = (FF - F)/F,
|
||||
eval(X,F),
|
||||
eval(X+F,FF).
|
||||
|
||||
eval(X,1 - X * X).
|
||||
|
||||
small(X,E):-
|
||||
X < 0,
|
||||
(0-X) < E .
|
||||
small(X,E):-
|
||||
X >= 0,
|
||||
X < E .
|
||||
|
||||
solve(I,E):-
|
||||
eval(I,F),
|
||||
small(F,E),
|
||||
printf("%10.8f\n",[I]).
|
||||
solve(I,E):-
|
||||
printf("%10.8f\n",[I]),
|
||||
getnext(I,X),
|
||||
solve(X,E).
|
||||
|
||||
go:- solve(1.7,0.0000005).
|
||||
|
||||
% Output:
|
||||
% 1.70000000
|
||||
% 0.44834437
|
||||
% 0.91953538
|
||||
% 0.99701354
|
||||
% 0.99999555
|
||||
% 1.00000000
|
||||
|
||||
?- printf("\n>>> Sample goal: go/0\n", []).
|
@ -1,93 +0,0 @@
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CLP(R) Version 2.0 (Example Programs Release)
|
||||
* (C) Copyright, March 1986, Monash University
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
%
|
||||
% Matrix inversion package. The goal ?- go
|
||||
% invers a matrix, prints the inverse, then multiplies the two,
|
||||
% getting the identity matrix, and prints that.
|
||||
%
|
||||
|
||||
|
||||
sizemat(M,R,C):-
|
||||
mylength(M,R),
|
||||
allvec(M,C).
|
||||
|
||||
allvec([],C).
|
||||
allvec([H|T],C):-
|
||||
mylength(H,C),
|
||||
allvec(T,C).
|
||||
|
||||
mylength([],0). % length->mylength by ch
|
||||
mylength([H],1). % to avoid name clash
|
||||
mylength([H|T],L+1):-
|
||||
mylength(T,L).
|
||||
|
||||
matmul([H|T],B,[H1|T1]):-
|
||||
rowmul(H,B,H1),
|
||||
matmul(T,B,T1).
|
||||
matmul([],_,[]).
|
||||
|
||||
rowmul(AV,[H|T],[H1|T1]):-
|
||||
vecmul(AV,H,0,H1),
|
||||
rowmul(AV,T,T1).
|
||||
rowmul(_,[],[]).
|
||||
|
||||
vecmul([H1|T1],[H2|T2],IN,OUT):-
|
||||
TMP = IN + H1 * H2,
|
||||
vecmul(T1,T2,TMP,OUT).
|
||||
vecmul([],[],S,S).
|
||||
|
||||
rowtocol(A,[H|T]):-
|
||||
stripfirst(A,H,REST),
|
||||
rowtocol(REST,T).
|
||||
rowtocol(A,[]).
|
||||
|
||||
stripfirst([H|T],[H1|T1],[H2|T2]):-
|
||||
stripvec(H,H1,H2),
|
||||
stripfirst(T,T1,T2).
|
||||
stripfirst([],[],[]).
|
||||
|
||||
stripvec([H|T],H,T).
|
||||
|
||||
putmat([H|T]):-
|
||||
putvec(H),
|
||||
putmat(T).
|
||||
putmat([]).
|
||||
|
||||
putvec([H|T]):-
|
||||
printf(" %9.4f ",[H]),
|
||||
putvec(T).
|
||||
putvec([]):-
|
||||
nl.
|
||||
|
||||
go:- M = [ [4,5,6], [1,5,3], [1,8,9] ],
|
||||
I = [ [1,0,0], [0,1,0], [0,0,1] ],
|
||||
sizemat(N,3,3),
|
||||
sizemat(NR,3,3),
|
||||
sizemat(T,3,3),
|
||||
matmul(M,N,I),
|
||||
rowtocol(NR,N),
|
||||
matmul(M,N,T),
|
||||
printf(" NR = \n",[]),
|
||||
putmat(NR),
|
||||
printf(" T = \n",[]),
|
||||
putmat(T).
|
||||
|
||||
% Output:
|
||||
% NR =
|
||||
% 0.2917 0.0417 -0.2083
|
||||
% -0.0833 0.4167 -0.0833
|
||||
% 0.0417 -0.3750 0.2083
|
||||
% T =
|
||||
% 1.0000 0.0000 0.0000
|
||||
% 0.0000 1.0000 0.0000
|
||||
% 0.0000 0.0000 1.0000
|
||||
|
||||
?- printf("\n>>> Sample goal: go/0\n", []).
|
@ -1,89 +0,0 @@
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CLP(R) Version 2.0 (Example Programs Release)
|
||||
* (C) Copyright, March 1986, Monash University
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
%
|
||||
% Solve the Dirichlet problem for Laplace's equation using
|
||||
% Leibman's five-point finit-differenc approximation. The goal
|
||||
% ?- go1 is a normal example, while the goal ?- go2
|
||||
% shows output constraints for a small region where the boundary conditions
|
||||
% are not specified.
|
||||
%
|
||||
|
||||
|
||||
laplace([H1,H2,H3|T]):-
|
||||
laplace_vec(H1,H2,H3),
|
||||
laplace([H2,H3|T]).
|
||||
laplace([_,_]).
|
||||
|
||||
laplace_vec([TL,T,TR|T1],[ML,M,MR|T2],[BL,B,BR|T3]):-
|
||||
B + T + ML + MR - 4 * M = 0,
|
||||
laplace_vec([T,TR|T1],[M,MR|T2],[B,BR|T3]).
|
||||
laplace_vec([_,_],[_,_],[_,_]).
|
||||
|
||||
printmat([H|T]):-
|
||||
printvec(H),
|
||||
printmat(T).
|
||||
printmat([]).
|
||||
|
||||
printvec([H|T]):-
|
||||
printf("%7.2f",[H]),
|
||||
printvec(T).
|
||||
printvec([]):-
|
||||
printf("\n",[]).
|
||||
|
||||
go1:-
|
||||
X = [
|
||||
[0,0,0,0,0,0,0,0,0,0,0],
|
||||
[100,_,_,_,_,_,_,_,_,_,100],
|
||||
[100,_,_,_,_,_,_,_,_,_,100],
|
||||
[100,_,_,_,_,_,_,_,_,_,100],
|
||||
[100,_,_,_,_,_,_,_,_,_,100],
|
||||
[100,_,_,_,_,_,_,_,_,_,100],
|
||||
[100,_,_,_,_,_,_,_,_,_,100],
|
||||
[100,_,_,_,_,_,_,_,_,_,100],
|
||||
[100,_,_,_,_,_,_,_,_,_,100],
|
||||
[100,_,_,_,_,_,_,_,_,_,100],
|
||||
[100,100,100,100,100,100,100,100,100,100,100]
|
||||
],
|
||||
laplace(X),
|
||||
printf("\n", []),
|
||||
printmat(X).
|
||||
|
||||
% Answer:
|
||||
% 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
|
||||
% 100.00 51.11 32.52 24.56 21.11 20.12 21.11 24.56 32.52 51.11 100.00
|
||||
% 100.00 71.91 54.41 44.63 39.74 38.26 39.74 44.63 54.41 71.91 100.00
|
||||
% 100.00 82.12 68.59 59.80 54.97 53.44 54.97 59.80 68.59 82.12 100.00
|
||||
% 100.00 87.97 78.03 71.00 66.90 65.56 66.90 71.00 78.03 87.97 100.00
|
||||
% 100.00 91.71 84.58 79.28 76.07 75.00 76.07 79.28 84.58 91.71 100.00
|
||||
% 100.00 94.30 89.29 85.47 83.10 82.30 83.10 85.47 89.29 94.30 100.00
|
||||
% 100.00 96.20 92.82 90.20 88.56 88.00 88.56 90.20 92.82 96.20 100.00
|
||||
% 100.00 97.67 95.59 93.96 92.93 92.58 92.93 93.96 95.59 97.67 100.00
|
||||
% 100.00 98.89 97.90 97.12 96.63 96.46 96.63 97.12 97.90 98.89 100.00
|
||||
% 100.00 100.00 100.00 100.00 100.00 100.00 100.00 100.00 100.00 100.00 100.00
|
||||
|
||||
go2 :-
|
||||
laplace([
|
||||
[B11, B12, B13, B14],
|
||||
[B21, M22, M23, B24],
|
||||
[B31, M32, M33, B34],
|
||||
[B44, B42, B43, B44]
|
||||
]),
|
||||
printf("\n", []),
|
||||
dump.
|
||||
|
||||
% Answer:
|
||||
% B12 = -B21 - 4*B31 + 16*M32 - 8*M33 + B34 - 4*B42 + B43
|
||||
% B13 = -B24 + B31 - 8*M32 + 16*M33 - 4*B34 + B42 - 4*B43
|
||||
% M22 = -B31 + 4*M32 - M33 - B42
|
||||
% M23 = -M32 + 4*M33 - B34 - B43
|
||||
|
||||
?- printf("\n>>> Sample goals: go1/0, go2/0\n", []).
|
||||
|
@ -1,55 +0,0 @@
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CLP(R) Version 2.0 (Example Programs Release)
|
||||
* (C) Copyright, March 1986, Monash University
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
%
|
||||
% Calculate compound interest.
|
||||
% Arguments are Principal, Time (months), Interest (fraction), Balance,
|
||||
% and Monthly Payment.
|
||||
%
|
||||
% The goals ?- go1 demonstrates
|
||||
% obtaining ground answers for two different combinations of inputs.
|
||||
% The goals ?- go2 and ?- go3 deal with getting linear
|
||||
% equations as answers, while ?- go4 produces a
|
||||
% polynomial equation.
|
||||
%
|
||||
|
||||
mg(P,T,I,B,MP):-
|
||||
T > 0,
|
||||
T <= 1,
|
||||
B + MP = P * (1 + I).
|
||||
mg(P,T,I,B,MP):-
|
||||
T > 1,
|
||||
mg(P * (1 + I) - MP, T - 1, I, B, MP).
|
||||
|
||||
go1:- mg(120000,120,0.01,0,MP), printf("Forward: MP = %g\n",[MP]),
|
||||
mg(P,120,0.01,0,MP), printf("Backward: P = %g\n",[P]).
|
||||
|
||||
% Answer:
|
||||
% Forward: MP = 1721.651381
|
||||
% Backward: P = 120000
|
||||
|
||||
go2:- mg(P,120,0.01,0,MP), dump([P,MP]).
|
||||
|
||||
% Answer:
|
||||
% 2 ?- go2.
|
||||
% P = 69.700522*MP
|
||||
|
||||
go3:- mg(P,120,0.01,B,MP), dump([P,B,MP]).
|
||||
|
||||
% Answer:
|
||||
% 3 ?- go3.
|
||||
% P = 0.302995*B + 69.700522*MP
|
||||
|
||||
go4:- mg(999, 3, Int, 0, 400), dump.
|
||||
|
||||
% Answer:
|
||||
% 400 = (-400 + (599 + 999*Int) * (1 + Int)) * (1 + Int)
|
||||
|
||||
?- printf("\n>>> Sample goals: go1/0, go2/0, go3/0, go4/0\n", []).
|
@ -1,30 +0,0 @@
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CLP(R) Version 2.0 (Example Programs Release)
|
||||
* (C) Copyright, March 1986, Monash University
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
app([], L, L).
|
||||
app([H | L1], L2, [H | L]) :- app(L1, L2, L).
|
||||
rev([], []).
|
||||
rev([H | L1], L) :- rev(L1, L2), app(L2, [H], L).
|
||||
|
||||
%
|
||||
% Naive reverse for 100 elements.
|
||||
%
|
||||
|
||||
go:- rev([a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14,
|
||||
a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27, a28,
|
||||
a29, a30, a31, a32, a33, a34, a35, a36, a37, a38, a39, a40, a41, a42,
|
||||
a43, a44, a45, a46, a47, a48, a49, a50, a51, a52, a53, a54, a55, a56,
|
||||
a57, a58, a59, a60, a61, a62, a63, a64, a65, a66, a67, a68, a69, a70,
|
||||
a71, a72, a73, a74, a75, a76, a77, a78, a79, a80, a81, a82, a83, a84,
|
||||
a85, a86, a87, a88, a89, a90, a91, a92, a93, a94, a95, a96, a97, a98,
|
||||
a99, a100], X).
|
||||
|
||||
?- printf("\n>>> Sample goal: go/0\n", []).
|
||||
|
@ -1,162 +0,0 @@
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CLP(R) Version 2.0 (Example Programs Release)
|
||||
* (C) Copyright, March 1986, Monash University
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
%
|
||||
% Algebraic combinations of options: see [Lassez, McAloon & Yap].
|
||||
%
|
||||
|
||||
% Note that buy and sell are the negation of each other
|
||||
|
||||
% heaviside function
|
||||
h(X,Y,Z) :- Y < X , Z = 0.
|
||||
h(X,Y,Z) :- Y >= X, Z = 1.
|
||||
|
||||
% ramp function
|
||||
r(X,Y,Z) :- Y < X , Z = 0.
|
||||
r(X,Y,Z) :- Y >= X, Z = Y - X.
|
||||
|
||||
% option valuation
|
||||
% Variables are as previously described
|
||||
value(Type,Buy_or_Sell,S,C,P,I,X,B,Value) :-
|
||||
check_param(S,C,P,I,X,B),
|
||||
get_sign(Buy_or_Sell,Sign),
|
||||
lookup_option(Type,S,C,P,I,X,B,
|
||||
B1,B2,H1,H2,R1,R2),
|
||||
h(B1,S,T1),h(B2,S,T2),r(B1,S,T3),r(B2,S,T4),
|
||||
Value = Sign*(H1*T1 + H2*T2 + R1*T3 + R2*T4).
|
||||
|
||||
% safety check
|
||||
check_param(S,C,P,I,X,B) :-
|
||||
S >= 0, C >= 0, P >= 0,
|
||||
I >= 0, X >= 0, B >= 0 .
|
||||
|
||||
% Buy or sell are just opposite
|
||||
get_sign(buy,-1).
|
||||
get_sign(sell,1).
|
||||
|
||||
% lookup option vector
|
||||
lookup_option(Type,S,C,P,I,X,B,B1,B2,H1,H2,R1,R2) :-
|
||||
table(Type,S,C,P,I,X,B,B1,B2,H1,H2,R1,R2).
|
||||
|
||||
% Table of values for B1,B2,H1,H2,R1,R2
|
||||
% generic format - lookup_table(Type,Pos_neg,S,C,P,I,X,B,B1,B2,H1,H2,R1,R2).
|
||||
% where K to R21 are obtained from the table
|
||||
% M is a multiplier which is -1 or 1 depending on whether one
|
||||
% is buying or selling the option
|
||||
table( stock, S, C, P, I, X, B, 0, 0, S*(1+I), 0, -1, 0).
|
||||
table( call, S, C, P, I, X, B, 0, X, C*(1+I), 0, 0, -1).
|
||||
table( put, S, C, P, I, X, B, 0, X, P*(1+I)-X, 0, 1, -1).
|
||||
table( bond, S, C, P, I, X, B, 0, 0, B*(1+I), 0, 0, 0).
|
||||
|
||||
|
||||
% A straightforward query is finding the
|
||||
% value of selling a call option where
|
||||
% the call price is 5, exercise price 50,
|
||||
% interest rate 5% and current stock price 60.
|
||||
% Note that this query assigns variables just
|
||||
% to make the query look more readable
|
||||
go1(Value) :-
|
||||
Call=5,Exercise=50,Interest=0.05,Stock=60 ,
|
||||
value(call,sell,Stock,Call,_,Interest,Exercise,_,Value).
|
||||
|
||||
% Answer:
|
||||
% W = -4.75
|
||||
|
||||
% If we just the the question upside down and
|
||||
% ask what should the stock price be in order that
|
||||
% my wealth is more than 5. Then we have
|
||||
|
||||
go2(Stock,W) :-
|
||||
Call=5,Exercise=50,Interest=0.05 ,
|
||||
W > 5,
|
||||
value(call,sell,Stock,Call,_,Interest,Exercise,_,W).
|
||||
|
||||
% Answer 1:
|
||||
% W = 5.25
|
||||
% 50 > S
|
||||
% S >= 0
|
||||
|
||||
% Answer 2:
|
||||
% W = 55.25 - S
|
||||
% 50.25 > S
|
||||
% S >= 50
|
||||
|
||||
|
||||
% straddle
|
||||
% The general query is
|
||||
% ?- Wealth=W1+W2,....
|
||||
% value(call,buy,S,C,_,I,X,_,W1),
|
||||
% value(put,buy,S,_,P,I,X,_,W2).
|
||||
|
||||
go3(Stock,W) :-
|
||||
Call=5,Int=0.05,X=50,Put=7,
|
||||
W >= 10,
|
||||
value(put,buy,Stock,_,Put,Int,X,_,W1),
|
||||
value(call,buy,Stock,Call,_,Int,X,_,W2),
|
||||
W=W1+W2.
|
||||
|
||||
% Answer 1:
|
||||
% S = 37.4 - W
|
||||
% W >= 10
|
||||
% S >= 0
|
||||
|
||||
% Answer 2:
|
||||
% S = 62.6 + W
|
||||
% W >= 10
|
||||
% S >= 0
|
||||
|
||||
|
||||
go4(S,W) :-
|
||||
I=0.1,P1=10,X1=20,
|
||||
value(put,sell,S,_,P1,I,X1,_,W1),
|
||||
P2=18,X2=40,
|
||||
value(put,buy,S,_,P2,I,X2,_,W2),
|
||||
C3=15,X3=60,
|
||||
value(call,buy,S,C3,_,I,X3,_,W3),
|
||||
C4=10,X4=80,
|
||||
value(call,sell,S,C4,_,I,X4,_,W4),
|
||||
W=W1+W2+W3+W4.
|
||||
|
||||
% Answer 1:
|
||||
% W = 5.7
|
||||
% 20 > S
|
||||
% S >= 0
|
||||
|
||||
% Answer 2:
|
||||
% S = 25.7 - W
|
||||
% 5.7 >= W
|
||||
% 14.3 + W > 0
|
||||
% S >= 0
|
||||
|
||||
% Answer 3:
|
||||
% W = -14.3
|
||||
% S >= 40
|
||||
% 60 > S
|
||||
|
||||
% Answer 4:
|
||||
% S = 74.3 + W
|
||||
% 14.3 + W >= 0
|
||||
% 5.7 > W
|
||||
% S >= 0
|
||||
|
||||
% Answer 5:
|
||||
% W = 5.7
|
||||
% S >= 80
|
||||
|
||||
go5(S,W) :-
|
||||
Put=5,Exercise=20,Interest=0.1,
|
||||
S >= 0,
|
||||
W > 100,
|
||||
value(put,buy,S,_,Put,Interest,Exercise,_,W).
|
||||
|
||||
% No solution.
|
||||
|
||||
?- printf("\n>>> Sample goals (some with multiple answers):\n", []),
|
||||
printf(" go1(W), go2(S, W), go3(S, W), go4(S, W), go5(S, W)\n", []).
|
@ -1,164 +0,0 @@
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CLP(R) Version 2.0 (Example Programs Release)
|
||||
* (C) Copyright, March 1986, Monash University
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
* This example is credited to Richard Helm & Kim Marriot
|
||||
*/
|
||||
%
|
||||
% Package which allows rule-based descriptions of pictures to be translated into
|
||||
% commands in the "pic" package.
|
||||
% for example, try ?- tell(picout), go2, told.
|
||||
% and then from the UNIX command line try
|
||||
% pic picout | troff | ...
|
||||
%
|
||||
|
||||
inter( P1, P2 ,P3 ,P4 ,P5 ,P6 ) :-
|
||||
|
||||
intersect(P1, P2, P3, P4, PP1 ) ,
|
||||
intersect(P1, P2, P5, P6, PP2 ) ,
|
||||
intersect(P5, P6, P3, P4, PP3 ) ,
|
||||
|
||||
line( [ PP1, PP2 ] ),
|
||||
line( [ PP2, PP3 ] ),
|
||||
line( [ PP3, PP1 ] ),
|
||||
|
||||
darrow( [ P1, P2 ] , dashed ),
|
||||
darrow( [ P3, P4 ] , dashed ),
|
||||
darrow( [ P5, P6 ] , dashed ),
|
||||
|
||||
text( c1, P1, rjust ),
|
||||
text( c2, P3, rjust ),
|
||||
text( c3, P5, rjust ).
|
||||
|
||||
intersect(P1,P2,P3,P4,PP) :-
|
||||
|
||||
gradient(P1,P2,M1),
|
||||
gradient(P3,P4,M2),
|
||||
|
||||
lineeq(P1,M1,C1),
|
||||
lineeq(P3,M2,C2),
|
||||
|
||||
lineeq( PP, M1, C1 ),
|
||||
lineeq( PP, M2, C2 ).
|
||||
|
||||
lineeq(p(X,Y),M, C ) :- Y = M * X + C.
|
||||
|
||||
gradient(p(P1x,P1y),p(P2x,P2y),M ) :-
|
||||
|
||||
M = ( P2y -P1y ) / ( P2x -P1x ) .
|
||||
|
||||
%--------------------
|
||||
% the required pic interface
|
||||
%--------------------
|
||||
|
||||
pstart(S) :-
|
||||
printf(".PS %gi\n" , [ S ] ).
|
||||
|
||||
pend :-
|
||||
printf(".PE\n", [] ).
|
||||
|
||||
box( box( p(Ox,Oy), p(Cx,Cy) ), DotDashInvis , Text ) :-
|
||||
Mx = (Ox + Cx ) / 2 ,
|
||||
My = (Oy + Cy ) / 2 ,
|
||||
H = Cx - Cy ,
|
||||
W = Cy - Oy ,
|
||||
printf( "box at %g,%g width %g hieght %g \n" , [ Mx,My,W,H ] ) .
|
||||
|
||||
line( [ p(Ox,Oy), p(Cx,Cy) ], Style ) :-
|
||||
printf( "line from %g,%g to %g,%g %\n" , [ Ox,Oy,Cx,Cy,Style ] ) .
|
||||
|
||||
darrow( [ p(Ox,Oy), p(Cx,Cy) ],Style ) :-
|
||||
printf( "line from %g,%g to %g,%g %\n" , [ Ox,Oy,Cx,Cy,Style ] ) .
|
||||
|
||||
arrow( [ p(Ox,Oy), p(Cx,Cy) ],Style ) :-
|
||||
printf( "line from %g,%g to %g,%g %\n" , [ Ox,Oy,Cx,Cy,Style ] ) .
|
||||
|
||||
line( [ p(Ox,Oy), p(Cx,Cy) ] ) :-
|
||||
printf( "line from %g,%g to %g,%g \n" , [ Ox,Oy,Cx,Cy ] ) .
|
||||
|
||||
text( Text , p(Ox,Oy), Just ) :-
|
||||
printf( " %s %s %s at %g,%g %s \n" , [ '"', Text, '"', Ox, Oy, Just] ) .
|
||||
|
||||
quadrilateral( Pt1, Pt2, Pt3, Pt4, MPt1, MPt2, MPt3, MPt4) :-
|
||||
parallelogram(MPt1, MPt2, MPt3, MPt4) ,
|
||||
lineWithMidPoint(Pt1,Pt2,MPt1) ,
|
||||
lineWithMidPoint(Pt2,Pt3,MPt2) ,
|
||||
lineWithMidPoint(Pt3,Pt4,MPt3) ,
|
||||
lineWithMidPoint(Pt4,Pt1,MPt4) ,
|
||||
line([ MPt1, MPt2 ], dashed),
|
||||
line([ MPt2, MPt3 ], dashed),
|
||||
line([ MPt3, MPt4 ], dashed),
|
||||
line([ MPt4, MPt1 ], dashed).
|
||||
|
||||
lineWithMidPoint( p(P1x,P1y), p(P2x,P2y) , p(Mx,My) ) :-
|
||||
P1x - Mx = Mx - P2x ,
|
||||
P1y - My = My - P2y ,
|
||||
line([ p(P1x,P1y) , p(P2x,P2y) ]).
|
||||
|
||||
parallelogram(p(P1x,P1y), p(P2x,P2y), p(P3x,P3y), p(P4x,P4y)) :-
|
||||
P1x - P2x = P4x - P3x,
|
||||
P1y - P2y = P4y - P3y,
|
||||
P1x - P4x = P2x - P3x,
|
||||
P1y - P4y = P2y - P3y.
|
||||
|
||||
go1:-
|
||||
pstart(2),
|
||||
inter( p(0,1), p(4,2) ,p(3.5,1) ,p(2,5) ,p(0.33,0.5) ,p(3,5.5 ) ),
|
||||
pend.
|
||||
|
||||
% Output:
|
||||
% .PS 2i
|
||||
% line from 3.2,1.8 to 0.688979,1.172245
|
||||
% line from 0.688979,1.172245 to 2.302393,4.193619
|
||||
% line from 2.302393,4.193619 to 3.2,1.8
|
||||
% line from 0,1 to 4,2 dashed
|
||||
% line from 3.5,1 to 2,5 dashed
|
||||
% line from 0.33,0.5 to 3,5.5 dashed
|
||||
% " c1 " at 0,1 rjust
|
||||
% " c2 " at 3.5,1 rjust
|
||||
% " c3 " at 0.33,0.5 rjust
|
||||
% .PE
|
||||
|
||||
go2:-
|
||||
pstart(3),
|
||||
quadrilateral( p(0,0), p(8,10) ,p(10,10) ,p(10,1) ,_, _, _, _ ),
|
||||
quadrilateral( p(0,20), p(0,15) ,p(10,15) ,p(10,20) ,_, _, _, _ ),
|
||||
quadrilateral( p(5,30), p(10,23), p(15,30), p(10,25), _, _, _, _),
|
||||
pend.
|
||||
|
||||
% Output:
|
||||
% .PS 3i
|
||||
% line from 0,0 to 8,10
|
||||
% line from 8,10 to 10,10
|
||||
% line from 10,10 to 10,1
|
||||
% line from 10,1 to 0,0
|
||||
% line from 4,5 to 9,10 dashed
|
||||
% line from 9,10 to 10,5.5 dashed
|
||||
% line from 10,5.5 to 5,0.5 dashed
|
||||
% line from 5,0.5 to 4,5 dashed
|
||||
% line from 0,20 to 0,15
|
||||
% line from 0,15 to 10,15
|
||||
% line from 10,15 to 10,20
|
||||
% line from 10,20 to 0,20
|
||||
% line from 0,17.5 to 5,15 dashed
|
||||
% line from 5,15 to 10,17.5 dashed
|
||||
% line from 10,17.5 to 5,20 dashed
|
||||
% line from 5,20 to 0,17.5 dashed
|
||||
% line from 5,30 to 10,23
|
||||
% line from 10,23 to 15,30
|
||||
% line from 15,30 to 10,25
|
||||
% line from 10,25 to 5,30
|
||||
% line from 7.5,26.5 to 12.5,26.5 dashed
|
||||
% line from 12.5,26.5 to 12.5,27.5 dashed
|
||||
% line from 12.5,27.5 to 7.5,27.5 dashed
|
||||
% line from 7.5,27.5 to 7.5,26.5 dashed
|
||||
% .PE
|
||||
|
||||
?- printf("\n>>> Sample goals: go1/0, go2/0\n", []).
|
@ -1,511 +0,0 @@
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CLP(R) Version 2.0 (Example Programs Release)
|
||||
* (C) Copyright, March 1986, Monash University
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
% use clpr -z 1e-20
|
||||
|
||||
/*
|
||||
* RKF45 implementation in CLP(R): See [Harland & Michaylov].
|
||||
*
|
||||
* Assumes that the function is evaluated by a predicate of the form
|
||||
*
|
||||
* eval(T, Y, Yp), where T is the independent variable,
|
||||
* Y the current vector of solutions,
|
||||
* Yp the new vector derivative
|
||||
*
|
||||
* e.g. eval(T, [Y1,Y2], [T*T + Y1*Y1, T*T - Y2*Y2]).
|
||||
*
|
||||
* Note: machine epsilon is available as #zero (pre-defined constant).
|
||||
*
|
||||
* Separate "mode" from the rest - may help efficiency
|
||||
*/
|
||||
|
||||
/*
|
||||
* solve(Y, T, Tout, Incr, Relerr, Abserr)
|
||||
* Predicate called by the user - if he wants to specify a mode, he calls
|
||||
* solve/7 direct (only needed for single_step mode).
|
||||
*
|
||||
* Y - initial position vector
|
||||
* T - starting point for independent variable
|
||||
* Tout - last point at which output is desired
|
||||
* Incr - default output increment
|
||||
* Relerr - relative error tolerance
|
||||
* Abserr - absolute error tolerance
|
||||
*/
|
||||
|
||||
solve(Y, Tstart, Tend, Incr, Relerr, Abserr) :-
|
||||
solve(Y, Tstart, Tend, Incr, Relerr, Abserr, normal).
|
||||
|
||||
/*
|
||||
* Error checks
|
||||
*/
|
||||
solve(_, _, _, 0, _, _, normal) :-
|
||||
printf("Increment must be non-zero for normal mode\n",[]).
|
||||
solve(_, _, _, _, Relerr, _, _) :-
|
||||
Relerr < 0,
|
||||
printf("Relative error must be non-negative\n",[]).
|
||||
solve(_, _, _, _, _, Abserr, _) :-
|
||||
Abserr < 0,
|
||||
printf("Relative error must be non-negative\n",[]).
|
||||
solve(_, T, T, _, _, _, _) :-
|
||||
printf("No interval\n",[]).
|
||||
|
||||
/*
|
||||
* Everything seems ok, so proceed
|
||||
*/
|
||||
solve(Y, T, Tend, Incr, Relerr, Abserr, Mode) :-
|
||||
set_yp(T, Y, Yp), % Nfe = Nfe + 1
|
||||
output(T, Y),
|
||||
solve1(user(Y, T, Tend, Incr, Relerr, Abserr, Mode),
|
||||
work(Yp, 1, 0)). % Work out the rest
|
||||
% Nfe = 1
|
||||
% Kop = 0
|
||||
|
||||
/*
|
||||
* Commence main iteration
|
||||
*/
|
||||
solve1(user(_, T, Tend, Incr, _, _, _), work(_, _, Nfe, _, _)) :-
|
||||
abs(T - Tend) < Incr / 4,
|
||||
printf("\nIteration finished\n------------------\n",[]),
|
||||
printf(" %d derivative evaluations\n",[Nfe]).
|
||||
solve1(user(Y, T, Tend, Incr, Relerr, Abserr, reset(Mode, relerr)), _) :-
|
||||
remin(Remin),
|
||||
Relerr < 2* #zero + Remin,
|
||||
printf("Warned you to reset it larger than %f\n", [Relerr]).
|
||||
solve1(user(Y, T, Tend, Incr, Relerr, Abserr, reset(Mode, relerr)),
|
||||
work(Yp, H, Nfe, Kop, Tout)) :-
|
||||
remin(Remin),
|
||||
Relerr >= 2* #zero + Remin,
|
||||
solve1(user(Y, T, Tend, Incr, Relerr, Abserr, Mode),
|
||||
work(Yp, H, Nfe, Kop, Tout)).
|
||||
solve1(user(Y, T, Tend, Incr, Relerr, Abserr, reset(Mode, abserr, Oerr)), _) :-
|
||||
Abserr <= Oerr,
|
||||
printf("Abserr must be increased - not set to %f\n", [Abserr]).
|
||||
solve1(user(Y, T, Tend, Incr, Relerr, Abserr, reset(Mode, abserr, Oerr)),
|
||||
work(Yp, H, Nfe, Kop, Tout)) :-
|
||||
Abserr > Oerr,
|
||||
solve1(user(Y, T, Tend, Incr, Relerr, Abserr, Mode),
|
||||
work(Yp, H, Nfe, Kop, Tout)).
|
||||
solve1(user(Y, T, Tend, Incr, Relerr, Abserr, Mode), work(Yp, Nfe, Kop)) :-
|
||||
% First time - need to set H
|
||||
set_tout(T, Tend, Incr, Tout), % Next output point
|
||||
set_hinit(T, Tout-T, Y, Yp, Relerr, Abserr, H),
|
||||
set_kop(Kop, H, Tout-T, Newkop),
|
||||
stop_or_iter(user(Y, T, Tend, Incr, Relerr, Abserr, normal),
|
||||
work(Yp, H, Nfe, Newkop, Tout)).
|
||||
solve1(user(Y, T, Tend, Incr, Relerr, Abserr, Mode),
|
||||
% H already set - continue on
|
||||
work(Yp, H, Nfe, Kop, _)) :-
|
||||
set_tout(T, Tend, Incr, Tout),
|
||||
sign(Tout-T, S),
|
||||
set_kop(Kop, S*H, Tout-T, Newkop),
|
||||
stop_or_iter(user(Y, T, Tend, Incr, Relerr, Abserr, Mode),
|
||||
work(Yp, S*H, Nfe, Newkop, Tout)).
|
||||
|
||||
/*
|
||||
* Perform certain error checks
|
||||
*/
|
||||
stop_or_iter(User, work(Yp, H, Nfe, Kop, Tout)) :-
|
||||
Kop >= 100,
|
||||
check_out(User, work(Yp, H, Nfe, 0, Tout), output_excess).
|
||||
stop_or_iter(user(Y, T, Tend, Incr, Relerr, Abserr, Mode), Work) :-
|
||||
remin(Remin),
|
||||
Relerr < 2* #zero + Remin,
|
||||
check_out(user(Y, T, Tend, Incr, Relerr, Abserr, Mode), Work, relerr).
|
||||
stop_or_iter(user(Y, T, Tend, Incr, Relerr, Abserr, Mode),
|
||||
work(Yp, H, Nfe, Kop, Tout)) :-
|
||||
Abs = abs(Tout-T),
|
||||
Tabs = abs(T),
|
||||
% Use Euler approximation
|
||||
Abs <= 26* #zero*Tabs,
|
||||
set_euler(Tout-T, Y, Yp, NewY),
|
||||
% Nfe = Nfe + 1
|
||||
set_yp(Tout, NewY, NewYp),
|
||||
print_or_it(user(NewY, Tout, Tend, Incr, Relerr, Abserr,
|
||||
mode(Mode, output)), work(NewYp, H, Nfe+1, Kop, Tout)).
|
||||
stop_or_iter(User, Work) :-
|
||||
% Go on with main loop .......
|
||||
iter(User, Work).
|
||||
|
||||
iter(user(Y, T, Tend, Incr, Relerr, Abserr, Mode),
|
||||
work(Yp, H, Nfe, Kop, Tout)) :-
|
||||
set_modeh(Tout-T, H, NewH, Out),
|
||||
iter1(user(Y, T, Tend, Incr, Relerr, Abserr, mode(Mode, Out, nofail)),
|
||||
work(Yp, NewH, Nfe, Kop, Tout)).
|
||||
|
||||
iter1(user(Y, T, Tend, Incr, Relerr, Abserr, mode(Mode, Out, Hmode)),
|
||||
work(Yp, H, Nfe, Kop, Tout)) :-
|
||||
max_func_eval(Maxfunc),
|
||||
Nfe >= Maxfunc,
|
||||
check_out(user(Y, T, Tend, Incr, Relerr, Abserr, Mode),
|
||||
work(Yp, H, Nfe, Kop, Tout), max_func).
|
||||
iter1(user(Y, T, Tend, Incr, Relerr, Abserr, Mode),
|
||||
work(Yp, H, Nfe, Kop, Tout)) :-
|
||||
fehl(Y, T, Yp, H, Sum, Abserr, Relerr, Errest, Ind),
|
||||
stop_or_iter1(user(Y, T, Tend, Incr, Relerr, Abserr, Mode),
|
||||
work(Yp, H, Nfe+5, Kop, Tout), Sum, Errest, Ind).
|
||||
|
||||
stop_or_iter1(user(Y, T, Tend, Incr, Relerr, Abserr, mode(Mode, Out, Hmode)),
|
||||
Work, _, _, vanished) :-
|
||||
check_out(user(Y, T, Tend, Incr, Relerr, Abserr, Mode), Work, vanished).
|
||||
stop_or_iter1(user(Y, T, Tend, Incr, Relerr, Abserr, Mode),
|
||||
work(Yp, H, Nfe, Kop, Tout), Sum, Esttol, okay) :-
|
||||
Esttol > 1,
|
||||
set_smin(Esttol, S),
|
||||
check_h(user(Y, T, Tend, Incr, Relerr, Abserr, Mode),
|
||||
work(Yp, S*H, Nfe, Kop, Tout)).
|
||||
stop_or_iter1(user(Y, T, Tend, Incr, Relerr, Abserr, mode(Mode, Out, Hmode)),
|
||||
work(Yp, H, Nfe, Kop, Tout), Sum, Esttol, okay) :-
|
||||
Esttol <= 1,
|
||||
% Nfe = Nfe+1
|
||||
set_yp(T+H, Sum, NewYp),
|
||||
set_hmax(Esttol, Hmode, T, H, NewH),
|
||||
print_or_it(user(Sum, T+H, Tend, Incr, Relerr, Abserr,
|
||||
mode(Mode, Out)), work(NewYp, NewH, Nfe+1, Kop, Tout)).
|
||||
|
||||
print_or_it(user(Y, T, Tend, Incr, Relerr, Abserr,
|
||||
mode(normal,proceed)), Work) :-
|
||||
iter(user(Y, T, Tend, Incr, Relerr, Abserr, normal), Work).
|
||||
print_or_it(user(Y, T, Tend, Incr, Relerr, Abserr,
|
||||
mode(normal, output)), Work) :-
|
||||
output(T, Y),
|
||||
solve1(user(Y, T, Tend, Incr, Relerr, Abserr, normal), Work).
|
||||
print_or_it(user(Y, T, Tend, Incr, Relerr, Abserr,
|
||||
mode(single_step, _)), Work) :-
|
||||
check_out(user(Y, T, Tend, Incr, Relerr, Abserr, single_step), Work).
|
||||
|
||||
check_h(user(Y, T, Tend, Incr, Relerr, Abserr, mode(Mode, _, _)),
|
||||
work(Yp, H, Nfe, Kop, Tout)) :-
|
||||
Habs = abs(H),
|
||||
Tabs = abs(T),
|
||||
Habs <= 26* #zero*Tabs,
|
||||
printf("Tabs = %e , Habs = %e , #zero = %e \n",[Tabs,Habs,#zero]),
|
||||
check_out(user(Y, T, Tend, Incr, Relerr, Abserr, Mode),
|
||||
work(Yp, H, Nfe, Kop, Tout), step_small).
|
||||
check_h(user(Y, T, Tend, Incr, Relerr, Abserr, mode(Mode, Out, _)), Work) :-
|
||||
iter1(user(Y, T, Tend, Incr, Relerr, Abserr, mode(Mode,proceed,hfail)),
|
||||
Work).
|
||||
|
||||
/*
|
||||
* check_out(user(Y, Tstart, Tend, Incr, Relerr, Abserr, Mode),
|
||||
* work(Yp, H, Nfe, Kop, Tout), Flag)
|
||||
* Checks the status variable Flag, and takes appropriate action.
|
||||
* See if there is a user-defined procedure
|
||||
*/
|
||||
check_out(User, Work, Flag) :-
|
||||
user_error(User, Work, Flag),
|
||||
!.
|
||||
% No user procedure, so use the default ones.
|
||||
check_out(user(Y, T, Tend, Incr, Relerr, Abserr, single_step),
|
||||
Work, single_step) :-
|
||||
printf("(single_step) T: %10.6f Y: %10.6f\n",[T,Y]),
|
||||
solve(Y, T, Tend, Incr, Relerr, Abserr, single_step),!.
|
||||
check_out(user(Y, T, Tend, Incr, Relerr, Abserr, Mode), Work, relerr) :-
|
||||
% Iflag = 3
|
||||
remin(Remin),
|
||||
Rer = 3* #zero + Remin,
|
||||
printf("Relative error too small - reset to %f\n", [Rer]),
|
||||
solve1(user(Y, T, Tend, Incr, Rer, Abserr, reset(Mode, relerr)), Work).
|
||||
check_out(User, work(Yp, H, Nfe, Kop, Tout), max_func) :-
|
||||
% Iflag = 4
|
||||
max_func_eval(Max),
|
||||
Nfe >= Max,
|
||||
printf("Lots of function evaluations - %f needed so far\n",[Max]),
|
||||
solve1(User, work(Yp, H, 0, Kop, Tout)).
|
||||
check_out(user(Y, T, Tend, Incr, Relerr, Abserr, Mode), Work, vanished) :-
|
||||
% Iflag = 5
|
||||
abmin(Absmin),
|
||||
printf("Abserr reset to %f\n", [Absmin]),
|
||||
solve1(user(Y, T, Tend, Incr, Relerr, 10*Abserr + Absmin,
|
||||
reset(Mode, abserr, Abserr)), Work).
|
||||
check_out(user(Y, T, Tend, Incr, Relerr, Abserr, normal), Work, step_small) :-
|
||||
% Iflag = 6
|
||||
printf("Relerr too small; reset to %f\n", [10*Relerr]),
|
||||
solve1(user(Y, T, Tend, Incr, 10*Relerr, Abserr, normal), Work).
|
||||
check_out(User, work(Yp, H, Nfe, Kop, Tout), output_excess) :-
|
||||
% Iflag = 7
|
||||
printf("Excessive output; this will be inefficient",[]),
|
||||
solve1(User, work(Yp, H, Nfe, 0, Tout)).
|
||||
check_out(_, _, stuffed) :-
|
||||
% Iflag = 8
|
||||
printf("Improper call - wrong number of arguments?\n").
|
||||
check_out(_, _, missing) :-
|
||||
printf("User-supplied predicate eval is missing or wrong\n"),
|
||||
printf("Format is eval(T, Y, Yp),\n",[]),
|
||||
printf("where T is the independent variable, ",[]),
|
||||
printf("Y the vector, and Yp its derivative.",[]),
|
||||
printf("Y and Yp are CLP lists - [Y1, Y2, Y3], [Yp1, Yp2, Yp3] etc.",[]).
|
||||
check_out(_, _, Other) :-
|
||||
printf("Damned if I know what''s wrong!\n",[]).
|
||||
|
||||
/*
|
||||
* output(T, Y).
|
||||
* output(user(Y, T, Tend, Incr, Relerr, Abserr), work(Yp, H, Nfe, Kop, Tout))
|
||||
* Output predicate. If there is a user_output predicate (matching the above
|
||||
* format), then it is used. Otherwise, T and Y are written to standard output.
|
||||
*/
|
||||
output(T, Y) :-
|
||||
user_output(T, Y),
|
||||
!.
|
||||
output(T, Y) :-
|
||||
printf("T: %10.6f Y: ",[T]),
|
||||
write_list(Y).
|
||||
|
||||
write_list([L|List]) :-
|
||||
printf(" %10.6f ",[L]),
|
||||
write_list(List).
|
||||
write_list([]) :-
|
||||
nl.
|
||||
|
||||
/*
|
||||
* Set routines - setting values of variables given certain conditions etc.
|
||||
*/
|
||||
|
||||
set_yp(T, Y, Yp) :-
|
||||
eval(T, Y, Yp).
|
||||
set_yp(T, [Y], [Yp]) :-
|
||||
% For one var case with no list functor
|
||||
eval(T, Y, Yp).
|
||||
|
||||
set_hinit(T, Dt, Y, Yp, Relerr, Abserr, H) :-
|
||||
H1 = abs(Dt),
|
||||
set_maxtol(H1, Y, Yp, Relerr, Abserr, Maxtol),
|
||||
set_h1(H1, T, Dt, Maxtol, H).
|
||||
|
||||
set_maxtol(H, [Y|Yrest], [Yp|Yprest], Relerr, Abserr, Maxtol) :-
|
||||
Yabs = abs(Y),
|
||||
Tol1 = Relerr*Yabs + Abserr,
|
||||
Tol1 > 0,
|
||||
Ypabs = abs(Yp),
|
||||
set_maxh(Ypabs, H, Tol1, H1),
|
||||
set_maxtol(H1, Yrest, Yprest, Relerr, Abserr, Tol2),
|
||||
Maxtol = max(Tol1, Tol2).
|
||||
set_maxtol(H, [Y|Yrest], [Yp|Yprest], Relerr, Abserr, Maxtol) :-
|
||||
Yabs = abs(Y),
|
||||
Relerr*Yabs + Abserr <= 0,
|
||||
set_maxtol(H, Yrest, Yprest, Relerr, Abserr, Maxtol).
|
||||
set_maxtol(_, [], [], _, _, 0).
|
||||
|
||||
set_maxh(0, H, _, H).
|
||||
set_maxh(Ypabs, H, Tol, NewH) :-
|
||||
Ypabs > 0,
|
||||
NewH = min(H, pow(Tol/Ypabs, 1/5)). % From abs(Yp)*h**5 <= Tol
|
||||
|
||||
set_h1(H, T, Dt, Tol, 26* #zero*Max) :-
|
||||
Tol <= 0,
|
||||
Tabs = abs(T),
|
||||
Dtabs = abs(Dt),
|
||||
Max = max(Tabs, Dtabs).
|
||||
set_h1(H, T, Dt, Tol, NewH) :-
|
||||
Tol > 0,
|
||||
Tabs = abs(T),
|
||||
Dtabs = abs(Dt),
|
||||
Max = max(Tabs, Dtabs),
|
||||
NewH = max(H, 26* #zero*Max).
|
||||
|
||||
set_modeh(Dt, H, H, proceed) :-
|
||||
Dtabs = abs(Dt),
|
||||
Habs = abs(H),
|
||||
Dtabs >= 2*Habs.
|
||||
set_modeh(Dt, H, Dt/2, proceed) :-
|
||||
Habs = abs(H),
|
||||
Dtabs = abs(Dt),
|
||||
Dtabs < 2*Habs,
|
||||
Dtabs > Habs.
|
||||
set_modeh(Dt, H, Dt, output) :-
|
||||
Habs = abs(H),
|
||||
Dtabs = abs(Dt),
|
||||
Dtabs <= Habs.
|
||||
|
||||
set_kop(Kop, H, Dt, Kop+1) :-
|
||||
Habs = abs(H),
|
||||
Dabs = abs(Dt),
|
||||
Habs >= 2*Dabs.
|
||||
set_kop(Kop, H, Dt, Kop) :-
|
||||
Habs = abs(H),
|
||||
Dabs = abs(Dt),
|
||||
Habs < 2*Dabs.
|
||||
|
||||
set_smin(Esttol, 0.9/(pow(Esttol, 1/5)) ) :-
|
||||
Esttol < 59049.
|
||||
set_smin(Esttol, 0.1) :-
|
||||
Esttol >= 59049.
|
||||
|
||||
set_hmax(Esttol, Hmode, T, H, Sign*H1) :-
|
||||
set_smax(Esttol, Hmode, S),
|
||||
Habs = abs(H),
|
||||
Tabs = abs(T),
|
||||
H1 = max(S*Habs, 26* #zero*Tabs),
|
||||
sign(H, Sign).
|
||||
|
||||
set_smax(Esttol, nofail, 5) :-
|
||||
Esttol <= 0.0001889568.
|
||||
set_smax(Esttol, nofail, 0.9/(pow(Esttol, 1/5)) ) :-
|
||||
Esttol > 0.0001889568.
|
||||
set_smax(Esttol, hfail, 1) :-
|
||||
Esttol <= 0.0001889568.
|
||||
set_smax(Esttol, hfail, S) :-
|
||||
Esttol > 0.0001889568,
|
||||
S = min(0.9/(pow(Esttol, 1/5)), 1).
|
||||
|
||||
set_euler(Dt, [Y|Yrest], [Yp|Yprest], [NewY|NewYrest]) :-
|
||||
NewY = Y + Dt*Yp,
|
||||
set_euler(Dt, Yrest, Yprest, NewYrest).
|
||||
set_euler(_, [], [], []).
|
||||
|
||||
/*
|
||||
* set_tout(T, Tend, Incr, Tout)
|
||||
* Tout is the next output point, T the current value, Tend the final point
|
||||
* and Incr the set increment.
|
||||
*
|
||||
* If there is a user-supplied predicate user_tout, then it is used.
|
||||
* Otherwise, we add Incr to T and proceed.
|
||||
* Note that Incr may be negative.
|
||||
*/
|
||||
set_tout(T, Tend, Incr, Tout) :-
|
||||
user_tout(T, Tend, Incr, Tout),
|
||||
!.
|
||||
set_tout(T, Tend, Incr, Tend) :-
|
||||
Abs = abs(Tend - (T + Incr)),
|
||||
Abs < Incr.
|
||||
set_tout(T, Tend, Incr, T + Incr) :-
|
||||
Abs = abs(Tend - (T + Incr)),
|
||||
Abs >= Incr.
|
||||
|
||||
/*
|
||||
* fehl(Y, T, Yp, H, Sum, Abserr, Relerr, Errest, Errind)
|
||||
* Predicate to perform the evaluation of Fehlberg formulae
|
||||
*
|
||||
* Sum is the new estimate for Y
|
||||
* Abserr is the absolute error.
|
||||
* Relerr is the relative error.
|
||||
* Errest is the Fehlberg estimate of the error.
|
||||
* Errind indicates whether Abs is too small or not.
|
||||
* If so, Errind is set to "vanished". Otherwise, it is "okay".
|
||||
*/
|
||||
fehl(Y, T, Yp, H, S, Abs, Rel, Err, Ind) :-
|
||||
Ch1 = H/4,
|
||||
Ch2 = H*3/32,
|
||||
Ch3 = H/2197,
|
||||
Ch4 = H/4104,
|
||||
Ch5 = H/20520,
|
||||
Ch6 = H/7618050,
|
||||
fehl1(Y, T, Yp, H, ch(Ch1, Ch2, Ch3, Ch4, Ch5, Ch6),
|
||||
S, Abs, Rel, Err, Ind).
|
||||
|
||||
fehl1(Y, T, Yp, H, ch(Ch1, Ch2, Ch3, Ch4, Ch5, Ch6), S, Abs, Rel, Err, Ind) :-
|
||||
% calculate each of the Fi .....
|
||||
set_f1(Y, Yp, Ch1, P1), set_yp(T+Ch1, P1, F1),
|
||||
set_f2(Y, Yp, Ch2, F1, P2), set_yp(T+ 3*H/8, P2, F2),
|
||||
set_f3(Y, Yp, Ch3, F1, F2, P3), set_yp(T + 12*H/13, P3, F3),
|
||||
set_f4(Y, Yp, Ch4, F1, F2, F3, P4), set_yp(T + H, P4, F4),
|
||||
set_f5(Y, Yp, Ch5, F1, F2, F3, F4, P5), set_yp(T + H/2, P5, F5),
|
||||
% .. then the Y estimate ....
|
||||
set_sum(Y, Yp, Ch6, F2, F3, F4, F5, S),
|
||||
% .. and finally the error
|
||||
set_err(Y, Yp, Abs, Rel, S, f(F2, F3, F4, F5), H, 0, Err, Ind).
|
||||
|
||||
set_f1([Y|Yr], [Yp|Ypr], Ch, [P|Pr]) :-
|
||||
P = Y + Ch*Yp,
|
||||
set_f1(Yr, Ypr, Ch, Pr).
|
||||
set_f1([], [], _, []).
|
||||
|
||||
set_f2([Y|Yr], [Yp|Ypr], Ch, [F1|F1r], [P|Pr]) :-
|
||||
P = Y + Ch*(Yp + 3*F1),
|
||||
set_f2(Yr, Ypr, Ch, F1r, Pr).
|
||||
set_f2([], [], _, [], []).
|
||||
|
||||
set_f3([Y|Yr], [Yp|Ypr], Ch, [F1|F1r], [F2|F2r], [P|Pr]) :-
|
||||
P = Y + Ch*(1932*Yp + (7296*F2 - 7200*F1)),
|
||||
set_f3(Yr, Ypr, Ch, F1r, F2r, Pr).
|
||||
set_f3([], [], _, [], [], []).
|
||||
|
||||
set_f4([Y|Yr], [Yp|Ypr], Ch, [F1|F1r], [F2|F2r], [F3|F3r], [P|Pr]) :-
|
||||
P = Y + Ch*((8341*Yp - 845*F3) + (29440*F2 - 32832*F1)),
|
||||
set_f4(Yr, Ypr, Ch, F1r, F2r, F3r, Pr).
|
||||
set_f4([], [], _, [], [], [], []).
|
||||
|
||||
set_f5([Y|Yr], [Yp|Ypr], Ch, [F1|F1r], [F2|F2r], [F3|F3r], [F4|F4r], [P|Pr]) :-
|
||||
P = Y + Ch*((0-6080*Yp + (9295*F3 - 5643*F4)) + (41040*F1-28352*F2)),
|
||||
set_f5(Yr, Ypr, Ch, F1r, F2r, F3r, F4r, Pr).
|
||||
set_f5([], [], _, [], [], [], [], []).
|
||||
|
||||
set_sum([Y|Yr], [Yp|Ypr], Ch, [F2|F2r], [F3|F3r], [F4|F4r], [F5|F5r], [S|Sr]) :-
|
||||
S = Y + Ch*((902880*Yp + (3855735*F3 - 1371249*F4)) + (3953664*F2 +
|
||||
277020*F5)),
|
||||
set_sum(Yr, Ypr, Ch, F2r, F3r, F4r, F5r, Sr).
|
||||
set_sum([], [], _, [], [], [], [], []).
|
||||
|
||||
set_err([Y|Yr], Yp, Abs, Rel, [S|Sr], f(F2, F3, F4, F5), H, Oerr, Err, Ind) :-
|
||||
Yabs = abs(Y),
|
||||
Sabs = abs(S),
|
||||
Et = Yabs + Sabs + Abs,
|
||||
check_err(Et, [Y|Yr], Yp, [S|Sr], f(F2, F3, F4, F5),
|
||||
Abs, Rel, H, Oerr, Err, Ind).
|
||||
set_err([], [], _, Rel, [], _, H, Err, Habs*Err*(2/Rel)/752400, okay) :-
|
||||
Habs = abs(H).
|
||||
|
||||
check_err(Et, Y, Yp, S, _, _, _, _, _, _, vanished) :-
|
||||
Et <= 0.
|
||||
check_err(Et, [Y|Yr], [Yp|Ypr], [S|Sr], f([F2|R2], [F3|R3], [F4|R4], [F5|R5]),
|
||||
Abs, Rel, H, Oerr, Err, Ind) :-
|
||||
Et > 0,
|
||||
Ee = abs( (0-2090*Yp + (21970*F3 - 15048*F4)) + (22528*F2 - 27360*F5)),
|
||||
Nerr = max(Oerr, Ee/Et),
|
||||
set_err(Yr, Ypr, Abs, Rel, Sr, f(R2, R3, R4, R5), H, Nerr, Err, Ind).
|
||||
|
||||
% Low level stuff - primitives etc.
|
||||
|
||||
sign(V, 1) :-
|
||||
V >= 0.
|
||||
sign(V, 0-1) :-
|
||||
V < 0.
|
||||
|
||||
% Magic numbers
|
||||
remin(0.000000000001). % 1.0e-012 - from FM&M.
|
||||
abmin(0.000000001). % 1.0e-009 - from FM&M.
|
||||
max_func_eval(3000). % Also from FF&M.
|
||||
|
||||
eval(T, [Y1, Y2, Y3, Y4], [Y3, Y4, 0-Y1/R, 0-Y2/R]) :-
|
||||
R1 = Y1*Y1 + Y2*Y2,
|
||||
R = R1*pow(R1, 0.5)/((#p/4)*(#p/4)).
|
||||
|
||||
user_output(T, [Y1, Y2, Y3, Y4]) :-
|
||||
printf("Point %10.5f : %10.5f %10.5f\n",[T,Y1,Y2]).
|
||||
|
||||
user_error(user(Y, T, Tend, Incr, Rer, Abs),
|
||||
work(Yp, H, Nfe, Kop, Tout), max_func) :-
|
||||
printf("Too hard for me - try something more accurate\n",[]).
|
||||
|
||||
user_error(user(Y, T, Tend, Incr, Rer, Abs),
|
||||
work(Yp, H, Nfe, Kop, Tout), output_excess) :-
|
||||
printf("Outputs too often - try another method\n",[]).
|
||||
|
||||
user_error(user(Y, T, Tend, Incr, Rer, Abs),
|
||||
work(Yp, H, Nfe, Kop, Tout), step_small) :-
|
||||
printf("Can''t achieve required accuracy\n",[]).
|
||||
|
||||
go:- Ecc = 0.25, solve([1-Ecc, 0, 0, (#p/4)*pow((1+Ecc)/(1-Ecc), 0.5)],
|
||||
0, 3, 0.5, 0.000000001, 0).
|
||||
|
||||
% Output:
|
||||
%
|
||||
% Point 0.00000 : 0.75000 0.00000
|
||||
% Point 0.50000 : 0.61977 0.47779
|
||||
% Point 1.00000 : 0.29442 0.81218
|
||||
% Point 1.50000 : -0.10518 0.95804
|
||||
% Point 2.00000 : -0.49030 0.93987
|
||||
% Point 2.50000 : -0.81394 0.79959
|
||||
% Point 3.00000 : -1.05403 0.57571
|
||||
%
|
||||
% Iteration finished
|
||||
% ------------------
|
||||
% 439 derivative evaluations
|
||||
|
||||
?- printf("\n>>> Sample goal: go/0\n", []).
|
@ -1,420 +0,0 @@
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CLP(R) Version 2.0 (Example Programs Release)
|
||||
* (C) Copyright, March 1986, Monash University
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
%
|
||||
% Package for sinusoidal steady state analysis of RLC circuits.
|
||||
% The two goals ?- go1 and ?- go2 analyse two
|
||||
% circuits of moderate complexity.
|
||||
%
|
||||
|
||||
|
||||
circuit_solve(W, L, G, Selection) :-
|
||||
get_node_vars(L, NV),
|
||||
solve(W, L, NV, Handles, G),
|
||||
format_print(Handles, Selection).
|
||||
|
||||
get_node_vars([[Comp, Num, X, Ns]|Ls], NV) :-
|
||||
get_node_vars(Ls, NV1),
|
||||
insert_list(Ns, NV1, NV).
|
||||
get_node_vars([], []).
|
||||
|
||||
insert_list([N|Ns], NV1, NV3) :-
|
||||
insert_list(Ns, NV1, NV2),
|
||||
insert(N, NV2, NV3).
|
||||
insert_list([], NV, NV).
|
||||
|
||||
insert(N, [[N, V, I]|NV1], [[N, V, I]|NV1]) :- !.
|
||||
insert(N, [[N1, V, I]|NV1], [[N1, V, I]|NV2]) :-
|
||||
insert(N, NV1, NV2).
|
||||
insert(N, [], [[N, V, c(0,0)]]).
|
||||
|
||||
eps(0.001).
|
||||
|
||||
solve(W, [X|Xs], NV, [H|Hs], G) :-
|
||||
addcomp(W, X, NV, NV1,H),
|
||||
solve(W, Xs, NV1, Hs, G).
|
||||
solve(W, [], NV, [], G) :-
|
||||
!,
|
||||
zero_currents(NV),
|
||||
ground_nodes(NV, G).
|
||||
|
||||
zero_currents([[N, V, c(X,Y)]|Ls]) :-
|
||||
zero(X),
|
||||
zero(Y),
|
||||
zero_currents(Ls).
|
||||
zero_currents([]).
|
||||
|
||||
zero(0).
|
||||
zero(X) :-
|
||||
ground(X),
|
||||
%printf("Is it ground: % ?\n", [X]),
|
||||
eps(EPS),
|
||||
X > -EPS,
|
||||
X < EPS.
|
||||
|
||||
/* There is some redundancy setting all node current sums to zero - We only
|
||||
need to some of them to zero. Setting all of them to zero can cause some
|
||||
problems because of numerical instability. */
|
||||
|
||||
ground_nodes(Vs,[N|Ns]) :-
|
||||
ground_node(Vs, N),
|
||||
ground_nodes(Vs, Ns).
|
||||
ground_nodes(Vs, []).
|
||||
ground_node([[N, c(0,0), I]|Vs], N) :- !.
|
||||
ground_node([[N1, V, I]|Vs], N) :- ground_node(Vs, N).
|
||||
ground_node([], N) :- printf("Error could be: node %doesn't exist\n", [N]).
|
||||
|
||||
|
||||
% ***** CLAUSES TO DEFINE COMPONENT CHARACTERISTICS *****
|
||||
|
||||
addcomp(W, [Comp2, Num, X, [N1, N2]], NV, NV2, [Comp2, Num, X, [N1, V1, I1], [N2, V2, I2]]):-
|
||||
c_neg(I1, I2),
|
||||
iv_reln(Comp2, I1, V, X, W),
|
||||
c_add(V, V2, V1),
|
||||
subst([N1, V1, Iold1], [N1, V1, Inew1], NV, NV1),
|
||||
subst([N2, V2, Iold2], [N2, V2, Inew2], NV1, NV2),
|
||||
c_add(I1,Iold1,Inew1),
|
||||
c_add(I2,Iold2,Inew2).
|
||||
|
||||
% Specific current/voltage relations for the two terminal components
|
||||
iv_reln(resistor, I, V, R, W) :-
|
||||
c_mult(I,c(R,0),V).
|
||||
iv_reln(voltage_source, I, V, V, W).
|
||||
iv_reln(isource, I, V, I, W).
|
||||
iv_reln(capacitor, I, V, C, W) :-
|
||||
c_mult( c(0,W * C),V,I).
|
||||
iv_reln(inductor, I, V, L, W) :-
|
||||
c_mult(c(0,W * L),I,V).
|
||||
iv_reln(connection, I, c(0,0), L, W).
|
||||
iv_reln(open, c(0,0), V, L, W).
|
||||
iv_reln(diode, I, V, D, W) :- diode(D, I, V).
|
||||
|
||||
diode(in914, c(I,0), c(V, 0)) :-
|
||||
V < -100,
|
||||
DV = V + 100,
|
||||
I = 10*DV.
|
||||
diode(in914, c(I,0), c(V, 0)) :-
|
||||
V >= -100,
|
||||
V < 0.6,
|
||||
I = 0.001*V.
|
||||
diode(in914, c(I,0), c(V, 0)) :-
|
||||
V >= 0.6,
|
||||
DV = V - 0.6,
|
||||
I = 100*DV.
|
||||
|
||||
addcomp(W, [transistor, Num, X, [N1, N2, N3]], NV, NV3, [transistor, Num, X, [N1, V1, I1], [N2, V2, I2], [N3, V3, I3]]):-
|
||||
transistor(X, R, Gain),
|
||||
c_add(I1, I3, IT),
|
||||
c_neg(I2, IT),
|
||||
c_add(Vin, V2, V1),
|
||||
c_mult(I1, c(R, 0), Vin),
|
||||
c_mult(I1, c(Gain, 0), I3),
|
||||
subst([N1, V1, Iold1], [N1, V1, Inew1], NV, NV1),
|
||||
subst([N2, V2, Iold2], [N2, V2, Inew2], NV1, NV2),
|
||||
subst([N3, V3, Iold3], [N3, V3, Inew3], NV2, NV3),
|
||||
subst([N4, V4, Iold4], [N4, V4, Inew4], NV3, NV4),
|
||||
c_add(I1,Iold1,Inew1),
|
||||
c_add(I2,Iold2,Inew2),
|
||||
c_add(I3,Iold3,Inew3),
|
||||
c_add(I4,Iold4,Inew4).
|
||||
|
||||
transistor(bc108, 1000, 100).
|
||||
|
||||
addcomp(W, [transformer, Num, X, [N1, N2, N3, N4]], NV, NV4, [transformer, Num, X, [N1, V1, I1], [N2, V2, I2], [N3, V3, I3], [N4, V4, I4]]):-
|
||||
c_neg(I1, I2),
|
||||
c_neg(I3, I4),
|
||||
c_add(Vin, V2, V1),
|
||||
c_add(Vout, V4, V3),
|
||||
c_mult(Vout, c(X, 0), Vin),
|
||||
c_mult(I1, c(X, 0), I4),
|
||||
subst([N1, V1, Iold1], [N1, V1, Inew1], NV, NV1),
|
||||
subst([N2, V2, Iold2], [N2, V2, Inew2], NV1, NV2),
|
||||
subst([N3, V3, Iold3], [N3, V3, Inew3], NV2, NV3),
|
||||
subst([N4, V4, Iold4], [N4, V4, Inew4], NV3, NV4),
|
||||
c_add(I1,Iold1,Inew1),
|
||||
c_add(I2,Iold2,Inew2),
|
||||
c_add(I3,Iold3,Inew3),
|
||||
c_add(I4,Iold4,Inew4).
|
||||
|
||||
|
||||
subst(X, Y, [X|L1], [Y|L1]) :- !.
|
||||
subst(X, Y, [Z|L1], [Z|L2]) :-
|
||||
subst(X,Y,L1,L2).
|
||||
subst(X, Y, [], L2) :-
|
||||
printf("Node list incomplete\n", []).
|
||||
|
||||
|
||||
% ***** COMPLEX NUMBER ARITHMETIC *****
|
||||
|
||||
c_mult(c(Re1,Im1),c(Re2,Im2),c(Re3,Im3)) :-
|
||||
Re3 = Re1*Re2 - Im1*Im2,
|
||||
Im3 = Re1*Im2 + Re2*Im1.
|
||||
|
||||
c_add(c(Re1,Im1),c(Re2,Im2),c(Re3,Im3)) :-
|
||||
Re3 = Re1 + Re2,
|
||||
Im3 = Im1 + Im2.
|
||||
|
||||
c_neg(c(Re,Im),c(Re1,Im1)) :-
|
||||
Re1 = -Re, Im1 = -Im .
|
||||
|
||||
c_eq(c(Re1,Im1),c(Re2,Im2)) :-
|
||||
Re1 = Re2, Im1 = Im2 .
|
||||
|
||||
c_real(c(Re,Im),Re).
|
||||
|
||||
c_imag(c(Re,Im),Im).
|
||||
|
||||
|
||||
% ****** PRINTOUT ROUTINES ******
|
||||
|
||||
format_print(H, []) :-
|
||||
!,
|
||||
all_print(H).
|
||||
% If no selection is given then
|
||||
% print out all nodes.
|
||||
format_print(H, Selection) :-
|
||||
selective_print(H, Selection).
|
||||
% Otherwise print the selection.
|
||||
|
||||
selective_print(Ls, [N|Ns]) :-
|
||||
print_nodes(Ls, N, 0),
|
||||
print_comps(Ls, N),
|
||||
selective_print(Ls, Ns).
|
||||
selective_print(Ls, []).
|
||||
|
||||
print_nodes([[Comp, Num, X|Nodes]|L], N1, Heading_flag_1) :-
|
||||
member(N1, Nodes),
|
||||
Heading_flag_2 = Heading_flag_1 + 1,
|
||||
heading(N1, Heading_flag_2),
|
||||
all_print([[Comp, Num, X|Nodes]]),
|
||||
print_nodes(L, N1, Heading_flag_2).
|
||||
print_nodes([[Comp, Num, X|Nodes]|L], N1, Heading_flag) :-
|
||||
print_nodes(L, N1, Heading_flag).
|
||||
print_nodes([], N1, Heading_flag).
|
||||
|
||||
print_comps([[Comp, Num, X|Nodes]|L], Num) :-
|
||||
all_print([[Comp, Num, X|Nodes]]),
|
||||
print_comps(L, Num).
|
||||
print_comps([[Comp, Num, X|Nodes]|L], Num1) :-
|
||||
print_comps(L, Num1).
|
||||
print_comps([], Num).
|
||||
|
||||
heading(N, 1) :-
|
||||
!,
|
||||
printf("\nCOMPONENT CONNECTIONS TO NODE %\n", [N]).
|
||||
heading(N, X).
|
||||
|
||||
member(N1, [[N1, V, I]|Ls]).
|
||||
member(N1, [[N2, V, I]|Ls]) :-
|
||||
member(N1, Ls).
|
||||
|
||||
write_units(resistor, X) :-
|
||||
printf("% Ohms",[X]).
|
||||
write_units(capacitor, X) :-
|
||||
printf("% Farads",[X]).
|
||||
write_units(inductor, X) :-
|
||||
printf("% Henrys", [X]).
|
||||
write_units(current_source, X) :-
|
||||
printf("% Ampere", [X]).
|
||||
write_units(voltage_source, X) :-
|
||||
printf("% Volts", [X]).
|
||||
write_units(diode, X) :-
|
||||
printf("type %", [X]).
|
||||
write_units(transistor, X) :-
|
||||
printf("type % (base, emitter, collector)", [X]).
|
||||
write_units(transformer, X) :-
|
||||
printf("ratio of %", [X]).
|
||||
|
||||
all_print([[Comp, Num, X|Nodes]|L]) :-
|
||||
printf("% %: ", [Comp, Num]),
|
||||
write_units(Comp, X),
|
||||
printf("\n", []),
|
||||
pr_nodes(Nodes),
|
||||
all_print(L).
|
||||
all_print([]).
|
||||
|
||||
pr_nodes([[N1, V1, I1]|X]) :-
|
||||
printf(" Node %\n", [N1]),
|
||||
printf(" Voltage %\n", [V1]),
|
||||
printf(" Current %\n", [I1]),
|
||||
pr_nodes(X).
|
||||
pr_nodes([]) :-
|
||||
printf("\n", []).
|
||||
|
||||
|
||||
go1:-
|
||||
W = 10,
|
||||
Vs = 10,
|
||||
R = 10,
|
||||
L = 0.9,
|
||||
C = 0.007,
|
||||
circuit_solve(W,
|
||||
[
|
||||
[voltage_source,v1,c(Vs,0),[n1,n7]],
|
||||
[resistor,r1,R,[n1,n2]],
|
||||
[resistor,r2,R,[n1,n3]],
|
||||
[resistor,r3,R,[n1,n4]],
|
||||
[resistor,r4,R,[n1,n5]],
|
||||
[resistor,r5,R,[n1,n6]],
|
||||
[inductor,l1,L,[n2,n7]],
|
||||
[inductor,l2,L,[n3,n7]],
|
||||
[inductor,l3,L,[n4,n7]],
|
||||
[inductor,l4,L,[n5,n7]],
|
||||
[inductor,l5,L,[n6,n7]],
|
||||
[capacitor,c1,C,[n2,n3]],
|
||||
[capacitor,c2,C,[n2,n4]],
|
||||
[capacitor,c3,C,[n2,n5]],
|
||||
[capacitor,c4,C,[n2,n6]],
|
||||
[capacitor,c5,C,[n3,n4]],
|
||||
[capacitor,c6,C,[n3,n5]],
|
||||
[capacitor,c7,C,[n3,n6]],
|
||||
[capacitor,c8,C,[n4,n5]],
|
||||
[capacitor,c9,C,[n4,n6]],
|
||||
[capacitor,c10,C,[n5,n6]]
|
||||
],
|
||||
[n7],
|
||||
[r1, r3, l1, l3, c8, l5]
|
||||
).
|
||||
|
||||
% Output:
|
||||
% resistor r1: 10 Ohms
|
||||
% Node n1
|
||||
% Voltage c(10, 0)
|
||||
% Current c(0.552486, -0.497238)
|
||||
% Node n2
|
||||
% Voltage c(4.475138, 4.972376)
|
||||
% Current c(-0.552486, 0.497238)
|
||||
%
|
||||
% resistor r3: 10 Ohms
|
||||
% Node n1
|
||||
% Voltage c(10, 0)
|
||||
% Current c(0.552486, -0.497238)
|
||||
% Node n4
|
||||
% Voltage c(4.475138, 4.972376)
|
||||
% Current c(-0.552486, 0.497238)
|
||||
%
|
||||
% inductor l1: 0.9 Henrys
|
||||
% Node n2
|
||||
% Voltage c(4.475138, 4.972376)
|
||||
% Current c(0.552486, -0.497238)
|
||||
% Node n7
|
||||
% Voltage c(0, 0)
|
||||
% Current c(-0.552486, 0.497238)
|
||||
%
|
||||
% inductor l3: 0.9 Henrys
|
||||
% Node n4
|
||||
% Voltage c(4.475138, 4.972376)
|
||||
% Current c(0.552486, -0.497238)
|
||||
% Node n7
|
||||
% Voltage c(0, 0)
|
||||
% Current c(-0.552486, 0.497238)
|
||||
%
|
||||
% capacitor c8: 0.007 Farads
|
||||
% Node n4
|
||||
% Voltage c(4.475138, 4.972376)
|
||||
% Current c(0, 0)
|
||||
% Node n5
|
||||
% Voltage c(4.475138, 4.972376)
|
||||
% Current c(0, 0)
|
||||
%
|
||||
% inductor l5: 0.9 Henrys
|
||||
% Node n6
|
||||
% Voltage c(4.475138, 4.972376)
|
||||
% Current c(0.552486, -0.497238)
|
||||
% Node n7
|
||||
% Voltage c(0, 0)
|
||||
% Current c(-0.552486, 0.497238)
|
||||
%
|
||||
|
||||
|
||||
go2:-
|
||||
Vs = 10,
|
||||
Tr1 = 5,
|
||||
Tr2 = 0.2,
|
||||
R1 = 1000,
|
||||
R2 = 200,
|
||||
R3 = 50,
|
||||
R4 = 30,
|
||||
circuit_solve(W,
|
||||
[
|
||||
[voltage_source, v1, c(Vs,0),[in, ground1]],
|
||||
[resistor, r1, R2, [in, n1]],
|
||||
[transformer, t1, Tr1,[n1, ground1, n2, ground2]],
|
||||
[resistor, r2, R1, [n2, base]],
|
||||
[transistor, q1, bc108, [base, n3, n4]],
|
||||
[resistor, r3, R2, [n3, ground2]],
|
||||
[resistor, r3, R2, [n4, ground2]],
|
||||
[transformer, t2, Tr2,[n4, ground2, out, ground3]],
|
||||
[resistor, r5, R4, [out, ground3]]
|
||||
],
|
||||
[ground1, ground2, ground3],
|
||||
[n4, out]).
|
||||
|
||||
% Output:
|
||||
% COMPONENT CONNECTIONS TO NODE n4
|
||||
% transistor q1: type bc108 (base, emitter, collector)
|
||||
% Node base
|
||||
% Voltage c(1.909222, 0)
|
||||
% Current c(9.005764e-005, 0)
|
||||
% Node n3
|
||||
% Voltage c(1.819164, 0)
|
||||
% Current c(-0.009096, 0)
|
||||
% Node n4
|
||||
% Voltage c(-0.010742, 0)
|
||||
% Current c(0.009006, 0)
|
||||
%
|
||||
% resistor r3: 200 Ohms
|
||||
% Node n4
|
||||
% Voltage c(-0.010742, 0)
|
||||
% Current c(-5.371231e-005, 0)
|
||||
% Node ground2
|
||||
% Voltage c(0, 0)
|
||||
% Current c(5.371231e-005, 0)
|
||||
%
|
||||
% transformer t2: ratio of 0.2
|
||||
% Node n4
|
||||
% Voltage c(-0.010742, 0)
|
||||
% Current c(-0.008952, 0)
|
||||
% Node ground2
|
||||
% Voltage c(0, 0)
|
||||
% Current c(0.008952, 0)
|
||||
% Node out
|
||||
% Voltage c(-0.053712, 0)
|
||||
% Current c(0.00179, 0)
|
||||
% Node ground3
|
||||
% Voltage c(0, 0)
|
||||
% Current c(-0.00179, 0)
|
||||
%
|
||||
%
|
||||
% COMPONENT CONNECTIONS TO NODE out
|
||||
% transformer t2: ratio of 0.2
|
||||
% Node n4
|
||||
% Voltage c(-0.010742, 0)
|
||||
% Current c(-0.008952, 0)
|
||||
% Node ground2
|
||||
% Voltage c(0, 0)
|
||||
% Current c(0.008952, 0)
|
||||
% Node out
|
||||
% Voltage c(-0.053712, 0)
|
||||
% Current c(0.00179, 0)
|
||||
% Node ground3
|
||||
% Voltage c(0, 0)
|
||||
% Current c(-0.00179, 0)
|
||||
%
|
||||
% resistor r5: 30 Ohms
|
||||
% Node out
|
||||
% Voltage c(-0.053712, 0)
|
||||
% Current c(-0.00179, 0)
|
||||
% Node ground3
|
||||
% Voltage c(0, 0)
|
||||
% Current c(0.00179, 0)
|
||||
%
|
||||
|
||||
?- printf("\n>>> Sample goals: go1/0, go2/0\n", []).
|
@ -1,101 +0,0 @@
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CLP(R) Version 2.0 (Example Programs Release)
|
||||
* (C) Copyright, March 1986, Monash University
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
%
|
||||
% Crypto-arithmetic puzzle:
|
||||
% Need to assign integers from 0 to 9 to the letters S, E, N, D, M, O, R, Y
|
||||
% without duplicates such that the equation
|
||||
%
|
||||
% S E N D
|
||||
% + M O R E
|
||||
% ---------
|
||||
% M O N E Y
|
||||
%
|
||||
% is satisfied.
|
||||
%
|
||||
|
||||
p(S, E, N, D, M, O, R, Y) :-
|
||||
S > 0, E >= 0, N >= 0, D >= 0, M > 0, O >= 0, R >= 0, Y >= 0,
|
||||
S <= 9, E <= 9, N <= 9, D <= 9, M <= 9, O <= 9, R <= 9, Y <= 9,
|
||||
D + E = Y + 10*C1,
|
||||
C1 + N + R = E + 10*C2,
|
||||
C2 + E + O = N + 10*C3,
|
||||
C3 + S + M = O + 10*M,
|
||||
carry(C1, C2, C3),
|
||||
dig(S), dig(E), dig(N), dig(D), dig(M), dig(O), dig(R), dig(Y),
|
||||
printf("S = %d, E = %d, N = %d, D = %d, M = %d, O = %d, R = %d, Y = %d \n",[S, E, N, D, M, O, R, Y]),
|
||||
difflist([S, E, N, D, M, O, R, Y]).
|
||||
|
||||
carry(1, 1, 1).
|
||||
carry(1, 1, 0).
|
||||
carry(1, 0, 1).
|
||||
carry(1, 0, 0).
|
||||
carry(0, 1, 1).
|
||||
carry(0, 1, 0).
|
||||
carry(0, 0, 1).
|
||||
carry(0, 0, 0).
|
||||
|
||||
dig(9).
|
||||
dig(8).
|
||||
dig(7).
|
||||
dig(6).
|
||||
dig(5).
|
||||
dig(4).
|
||||
dig(3).
|
||||
dig(2).
|
||||
dig(1).
|
||||
dig(0).
|
||||
|
||||
difflist([X | T]) :- notmem(X, T), difflist(T).
|
||||
difflist([]).
|
||||
|
||||
notmem(X, [Y | Z]) :- X < Y, notmem(X, Z).
|
||||
notmem(X, [Y | Z]) :- X > Y, notmem(X, Z).
|
||||
notmem(X, []).
|
||||
|
||||
/**************************************************************/
|
||||
/*** S = 9, E = 5, N = 6, D = 7, M = 1, O = 0, R = 8, Y = 2 ***/
|
||||
/**************************************************************/
|
||||
|
||||
go:-
|
||||
p(S, E, N, D, M, O, R, Y),
|
||||
printf("\nAns:\n",[]),
|
||||
printf("S = %d, E = %d, N = %d, D = %d, M = %d, O = %d, R = %d, Y = %d \n",[S, E, N, D, M, O, R, Y]).
|
||||
|
||||
% Output:
|
||||
% S = 9, E = 8, N = 9, D = 9, M = 1, O = 0, R = 8, Y = 7
|
||||
% S = 9, E = 8, N = 9, D = 8, M = 1, O = 0, R = 8, Y = 6
|
||||
% S = 9, E = 8, N = 9, D = 7, M = 1, O = 0, R = 8, Y = 5
|
||||
% S = 9, E = 8, N = 9, D = 6, M = 1, O = 0, R = 8, Y = 4
|
||||
% S = 9, E = 8, N = 9, D = 5, M = 1, O = 0, R = 8, Y = 3
|
||||
% S = 9, E = 8, N = 9, D = 4, M = 1, O = 0, R = 8, Y = 2
|
||||
% S = 9, E = 8, N = 9, D = 3, M = 1, O = 0, R = 8, Y = 1
|
||||
% S = 9, E = 8, N = 9, D = 2, M = 1, O = 0, R = 8, Y = 0
|
||||
% S = 9, E = 7, N = 8, D = 9, M = 1, O = 0, R = 8, Y = 6
|
||||
% S = 9, E = 7, N = 8, D = 8, M = 1, O = 0, R = 8, Y = 5
|
||||
% S = 9, E = 7, N = 8, D = 7, M = 1, O = 0, R = 8, Y = 4
|
||||
% S = 9, E = 7, N = 8, D = 6, M = 1, O = 0, R = 8, Y = 3
|
||||
% S = 9, E = 7, N = 8, D = 5, M = 1, O = 0, R = 8, Y = 2
|
||||
% S = 9, E = 7, N = 8, D = 4, M = 1, O = 0, R = 8, Y = 1
|
||||
% S = 9, E = 7, N = 8, D = 3, M = 1, O = 0, R = 8, Y = 0
|
||||
% S = 9, E = 6, N = 7, D = 9, M = 1, O = 0, R = 8, Y = 5
|
||||
% S = 9, E = 6, N = 7, D = 8, M = 1, O = 0, R = 8, Y = 4
|
||||
% S = 9, E = 6, N = 7, D = 7, M = 1, O = 0, R = 8, Y = 3
|
||||
% S = 9, E = 6, N = 7, D = 6, M = 1, O = 0, R = 8, Y = 2
|
||||
% S = 9, E = 6, N = 7, D = 5, M = 1, O = 0, R = 8, Y = 1
|
||||
% S = 9, E = 6, N = 7, D = 4, M = 1, O = 0, R = 8, Y = 0
|
||||
% S = 9, E = 5, N = 6, D = 9, M = 1, O = 0, R = 8, Y = 4
|
||||
% S = 9, E = 5, N = 6, D = 8, M = 1, O = 0, R = 8, Y = 3
|
||||
% S = 9, E = 5, N = 6, D = 7, M = 1, O = 0, R = 8, Y = 2
|
||||
%
|
||||
% Ans:
|
||||
% S = 9, E = 5, N = 6, D = 7, M = 1, O = 0, R = 8, Y = 2
|
||||
|
||||
?- printf("\n>>> Sample goal: go/0\n", []).
|
@ -1,116 +0,0 @@
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CLP(R) Version 2.0 (Example Programs Release)
|
||||
* (C) Copyright, March 1986, Monash University
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
%
|
||||
% Program to translate declarative machine tool path descriptions into
|
||||
% code for a programmable controller.
|
||||
%
|
||||
|
||||
move_p(p(_,X,Y)):-
|
||||
printf("G00 X%-.3f Y%-.3f\n",[X,Y]).
|
||||
draw_p(p(_,X,Y)):-
|
||||
printf("G01 X%-.3f Y%-.3f\n",[X,Y]).
|
||||
|
||||
lookup(X,[X|T]).
|
||||
lookup(X,[H|T]):-
|
||||
lookup(X,T).
|
||||
|
||||
path([p(N)|T],DB):-
|
||||
lookup(p(N,X,Y),DB),
|
||||
move_p(p(N,X,Y)),
|
||||
rest_path(T,DB).
|
||||
|
||||
rest_path([p(N)|T],DB):-
|
||||
lookup(p(N,X,Y),DB),
|
||||
draw_p(p(N,X,Y)),
|
||||
rest_path(T,DB).
|
||||
rest_path([],_).
|
||||
|
||||
make_vars([H|T],V,[NV|EV]):-
|
||||
get_vars(H,NV),
|
||||
make_vars(T,V,EV).
|
||||
make_vars([],V,V).
|
||||
|
||||
get_vars(p(N,xy(X,Y)),p(N,X,Y)).
|
||||
get_vars(p(N,l(A),l(B)),p(N,X,Y)).
|
||||
get_vars(l(N,mc(M,C)),l(N,M,C)).
|
||||
get_vars(l(N,p(A),p(B)),l(N,M,C)).
|
||||
|
||||
make_constraints([H|T],V):-
|
||||
get_constraint(H,V),
|
||||
make_constraints(T,V).
|
||||
make_constraints([],_).
|
||||
|
||||
get_constraint(p(N,l(A),l(B)),V):-
|
||||
Y = M1 * X + C1,
|
||||
Y = M2 * X + C2,
|
||||
lookup(p(N,X,Y),V),
|
||||
lookup(l(A,M1,C1),V),
|
||||
lookup(l(B,M2,C2),V).
|
||||
get_constraint(l(N,p(A),p(B)),V):-
|
||||
X1 = X2,
|
||||
M = 10000000,
|
||||
Y1 = M * X1 + C,
|
||||
lookup(l(N,M,C),V),
|
||||
lookup(p(A,X1,Y1),V),
|
||||
lookup(p(B,X2,Y2),V).
|
||||
get_constraint(l(N,p(A),p(B)),V):-
|
||||
Y1 = M * X1 + C,
|
||||
Y2 = M * X2 + C,
|
||||
neq_r(X1,X2),
|
||||
lookup(l(N,M,C),V),
|
||||
lookup(p(A,X1,Y1),V),
|
||||
lookup(p(B,X2,Y2),V).
|
||||
get_constraint(p(_,xy(_,_)),_).
|
||||
get_constraint(l(_,mc(_,_)),_).
|
||||
|
||||
neq_r(X,Y):- Y > X .
|
||||
neq_r(X,Y):- X > Y .
|
||||
|
||||
make_db([p(N,X,Y)|T],DB,[p(N,X,Y)|EDB]):-
|
||||
make_db(T,DB,EDB).
|
||||
make_db([l(N,M,C)|T],DB,EDB):-
|
||||
make_db(T,DB,EDB).
|
||||
make_db([],DB,DB).
|
||||
|
||||
geometry(X,DB):-
|
||||
make_vars(X,[],V),
|
||||
make_db(V,[],DB),
|
||||
make_constraints(X,V).
|
||||
|
||||
go:- geometry(
|
||||
[
|
||||
p(1,xy(10,10)),
|
||||
p(2,xy(10,20)),
|
||||
p(3,xy(20,10)),
|
||||
p(4,xy(20,20)),
|
||||
l(1,p(1),p(4)),
|
||||
l(2,p(2),p(3)),
|
||||
p(5,l(1),l(2))
|
||||
],
|
||||
DB
|
||||
),
|
||||
path(
|
||||
[
|
||||
p(1),
|
||||
p(2),
|
||||
p(5),
|
||||
p(1)
|
||||
],
|
||||
DB
|
||||
).
|
||||
|
||||
% Output:
|
||||
% G00 X10.000 Y10.000
|
||||
% G01 X10.000 Y20.000
|
||||
% G01 X15.000 Y15.000
|
||||
% G01 X10.000 Y10.000
|
||||
|
||||
?- printf("\n>>> Sample goal: go/0\n", []).
|
@ -1,62 +0,0 @@
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* CLP(R) Version 2.0 (Example Programs Release)
|
||||
* (C) Copyright, March 1986, Monash University
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
%
|
||||
% A program to solve the Zebra Puzzle.
|
||||
%
|
||||
|
||||
zebra(Zebraowner,Drinkswater) :-
|
||||
houses(s(s(s(s(s(zero))))), List),
|
||||
member(house( red, englishman, _, _, _) ,List),
|
||||
member(house( _, spaniard, dog, _, _) ,List),
|
||||
member(house(green, _, _, coffee, _) ,List),
|
||||
member(house( _, ukrainian, _, tea, _) ,List),
|
||||
sublist([house(ivory, _, _, _, _) ,
|
||||
house(green, _, _, _, _)],List),
|
||||
member(house( _, _,snail, _,old_gold),List),
|
||||
member(house(yellow, _, _, _, kools),List),
|
||||
eq([H1,H2,house( _, _, _, milk, _),H4,H5], List),
|
||||
eq([house( _, norwegian, _, _, _)|Hrest], List),
|
||||
nextto(house( _, _, _, _,chesterfield),
|
||||
house( _, _, fox, _, _),List),
|
||||
nextto(house( _, _, _, _, kools),
|
||||
house( _, _,horse, _, _),List),
|
||||
member(house( _, _, _, orange,lucky_strike),List),
|
||||
member(house( _, japanese, _, _,parliaments),List),
|
||||
nextto(house( _, norwegian, _, _, _),
|
||||
house( blue, _, _, _, _),List),
|
||||
member(house( _, Drinkswater, _, water, _),List),
|
||||
member(house( _, Zebraowner,zebra, _, _),List).
|
||||
|
||||
eq(X, X).
|
||||
|
||||
houses(zero, []).
|
||||
houses(s(N), [house(Color,Nat,Pet,Drink,Cig)|List]) :- houses(N, List).
|
||||
|
||||
member(X, [X|R]).
|
||||
member(X, [Y|R]) :- member(X, R).
|
||||
|
||||
sublist(S, L) :- append(S, S2, L).
|
||||
sublist(S, [H|T]) :- sublist(S, T).
|
||||
|
||||
append([], L, L).
|
||||
append([X|R], Y, [X|T]) :- append(R, Y, T).
|
||||
|
||||
nextto(H1, H2, L) :- sublist([H1, H2], L).
|
||||
nextto(H1, H2, L) :- sublist([H2, H1], L).
|
||||
|
||||
go :-
|
||||
zebra(Zebraowner, Drinkwater),
|
||||
printf("Zebraowner = %, Drinkwater = %\n", [Zebraowner, Drinkwater]).
|
||||
|
||||
% Answer:
|
||||
% Zebraowner = japanese, Drinkwater = norwegian
|
||||
|
||||
?- printf("\n>>> Sample goal: go/0\n", []).
|
@ -1,106 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.2 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: root.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%
|
||||
% perform N iterations of the sqrt(2) newton approx.
|
||||
%
|
||||
root( N, R) :-
|
||||
root( N, 1, R).
|
||||
|
||||
root( 0, S, R) :- !, S=R.
|
||||
root( N, S, R) :-
|
||||
N1 is N-1,
|
||||
{ S1 = S/2 + 1/S },
|
||||
root( N1, S1, R).
|
||||
|
||||
%
|
||||
% print e with a precision of at least N digits after 2.
|
||||
%
|
||||
e( N) :-
|
||||
e( N, E),
|
||||
print_decimal( E, N).
|
||||
|
||||
e( N, E) :-
|
||||
{ Err =:= exp(10,-(N+2)), Half =:= 1/2 },
|
||||
inv_e_series( Half, Half, 3, Err, Inv_E),
|
||||
{ E =:= 1/Inv_E }.
|
||||
|
||||
inv_e_series( Term, S0, _, Err, Sum) :-
|
||||
{ abs(Term) =< Err },
|
||||
!,
|
||||
S0 = Sum.
|
||||
inv_e_series( Term, S0, N, Err, Sum) :-
|
||||
N1 is N+1,
|
||||
{ Term1 =:= -Term/N, S1 =:= Term1+S0 },
|
||||
inv_e_series( Term1, S1, N1, Err, Sum).
|
||||
|
||||
%
|
||||
% print Rat with a precision of N places after the decimal point
|
||||
%
|
||||
print_decimal( Rat, N) :-
|
||||
clpq:arith_eval( truncate( Rat), Int), Int=rat(I,1),
|
||||
clpq:arith_eval( Rat-Int, Rest),
|
||||
clpq:arith_eval( numer( Rest), rat(Num,1)),
|
||||
clpq:arith_eval( denom( Rest), rat(Den,1)),
|
||||
format( "~d.", [I]),
|
||||
wdig( 0, N, Num, Den),
|
||||
nl.
|
||||
|
||||
wdig( N, M, _, _) :- N>=M, !.
|
||||
wdig( _, _, 0, _) :- !. % finite decimal expansion
|
||||
wdig( I, N, A, B) :-
|
||||
I1 is I+1,
|
||||
D is (10*A) // B,
|
||||
A1 is (10*A) mod B,
|
||||
( I mod 10 =:= 0 -> put(" ") ; true ),
|
||||
( I mod 70 =:= 0 -> nl, tab(2) ; true),
|
||||
write( D),
|
||||
wdig( I1, N, A1, B).
|
||||
|
||||
%
|
||||
% Collect n digits of the decimal expansion of a/b
|
||||
% where a//b = 0
|
||||
%
|
||||
dig( 0, _, _, []) :- !.
|
||||
dig( _, 0, _, []) :- !. % finite decimal expansion
|
||||
dig( I, A, B, [D|Ds]) :-
|
||||
I1 is I-1,
|
||||
A10 is 10*A,
|
||||
D is A10 // B,
|
||||
A1 is A10 mod B,
|
||||
dig( I1, A1, B, Ds).
|
||||
|
||||
/*
|
||||
| ?- time(expo(1000)).
|
||||
2.
|
||||
7182818284 5904523536 0287471352 6624977572 4709369995 9574966967 6277240766
|
||||
3035354759 4571382178 5251664274 2746639193 2003059921 8174135966 2904357290
|
||||
0334295260 5956307381 3232862794 3490763233 8298807531 9525101901 1573834187
|
||||
9307021540 8914993488 4167509244 7614606680 8226480016 8477411853 7423454424
|
||||
3710753907 7744992069 5517027618 3860626133 1384583000 7520449338 2656029760
|
||||
6737113200 7093287091 2744374704 7230696977 2093101416 9283681902 5515108657
|
||||
4637721112 5238978442 5056953696 7707854499 6996794686 4454905987 9316368892
|
||||
3009879312 7736178215 4249992295 7635148220 8269895193 6680331825 2886939849
|
||||
6465105820 9392398294 8879332036 2509443117 3012381970 6841614039 7019837679
|
||||
3206832823 7646480429 5311802328 7825098194 5581530175 6717361332 0698112509
|
||||
9618188159 3041690351 5988885193 4580727386 6738589422 8792284998 9208680582
|
||||
5749279610 4841984443 6346324496 8487560233 6248270419 7862320900 2160990235
|
||||
3043699418 4914631409 3431738143 6405462531 5209618369 0888707016 7683964243
|
||||
7814059271 4563549061 3031072085 1038375051 0115747704 1718986106 8739696552
|
||||
1267154688 9570350354
|
||||
%%% Timing 00:01:29.150 89.150
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
@ -1,337 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.2 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: simplex.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
% b152 p.32 40/160/17200
|
||||
example( 1, [X1,X2], Z) :-
|
||||
{
|
||||
X1=<50,
|
||||
X2=<200,
|
||||
X1+0.2*X2=<72,
|
||||
150*X1+25*X2=<10000,
|
||||
Z = 250*X1+45*X2
|
||||
},
|
||||
maximize(Z).
|
||||
|
||||
% p.33 1/0/1.5/7
|
||||
example( 2,[X1,X2,X3], Z) :-
|
||||
{
|
||||
X1=<2,
|
||||
X1+X2+2*X3=<4,
|
||||
3*X2+4*X3=<6,
|
||||
X1>=0,
|
||||
X2>=0,
|
||||
X3>=0,
|
||||
Z = X1+2*X2+4*X3
|
||||
},
|
||||
maximize(Z).
|
||||
|
||||
% p.38 38/170/18850
|
||||
example( 3, [X1,X2], Z) :-
|
||||
{
|
||||
X1=<50,
|
||||
X2=<200,
|
||||
X1+0.2*X2=<72,
|
||||
150*X1+25*X2=<10000,
|
||||
10*X1+X2>=550,
|
||||
Z = 250*X1+55*X2
|
||||
},
|
||||
maximize(Z).
|
||||
|
||||
% 7/2/310
|
||||
example( 4, [X,Y], Z) :-
|
||||
{
|
||||
2*X+Y =< 16,
|
||||
X+2*Y =< 11,
|
||||
X+3*Y =< 15,
|
||||
Z = 30*X+50*Y
|
||||
},
|
||||
maximize(Z).
|
||||
|
||||
% b30313 p.315 0/0/2.5/5
|
||||
example( 5, [X,Y,Z], Min) :-
|
||||
{
|
||||
X+3*Y+2*Z >= 5,
|
||||
2*X+2*Y+Z >= 2,
|
||||
4*X-2*Y+3*Z >= -1,
|
||||
X >= 0,
|
||||
Y >= 0,
|
||||
Z >= 0,
|
||||
Min = 6*X+5*Y+2*Z
|
||||
},
|
||||
minimize(Min).
|
||||
|
||||
% -7
|
||||
example( 6, [X1,X2,X3], Min) :-
|
||||
{
|
||||
X1=<2,
|
||||
X1+X2+2*X3=<4,
|
||||
3*X2+4*X3=<6,
|
||||
X1>=0,
|
||||
X2>=0,
|
||||
X3>=0,
|
||||
Min = -X1-2*X2-4*X3
|
||||
},
|
||||
minimize( Min).
|
||||
|
||||
% -70
|
||||
example( 7, [X1,X2,X3,X4,X5,X6,X7], Min) :-
|
||||
{
|
||||
X1 + X3 - X4 + X5 + 2*X6 + X7 =< 6,
|
||||
X2 + X4 - 2*X5 + X6 - 2*X7 =< 4,
|
||||
X3 - X4 + 2*X6 + X7 =< 1,
|
||||
|
||||
0 =< X1, X1 =< 6,
|
||||
0 =< X2, X2 =< 6,
|
||||
0 =< X3,
|
||||
0 =< X4, X4 =< 4,
|
||||
0 =< X5, X5 =< 2,
|
||||
0 =< X6, X6 =< 10,
|
||||
0 =< X7,
|
||||
Min = -3*X1 + 4*X2 + 2*X3 - 2*X4 - 14*X5 + 11*X6 - 5*X7
|
||||
},
|
||||
minimize( Min).
|
||||
|
||||
% -39/2
|
||||
example( 8, [X1,X2,X3,X4,X5,X6,X7], Min) :-
|
||||
{
|
||||
X1 + X3 - X4 + X5 + 2*X6 + X7 =< 6,
|
||||
X2 + X4 - 2*X5 + X6 - 2*X7 =< 4,
|
||||
X3 - X4 + 2*X6 + X7 =< 1,
|
||||
|
||||
0 =< X1, X1 =< 6,
|
||||
0 =< X2, X2 =< 6,
|
||||
0 =< X3,
|
||||
0 =< X4, X4 =< 4,
|
||||
0 =< X5, X5 =< 2,
|
||||
0 =< X6, X6 =< 10,
|
||||
0 =< X7,
|
||||
Min = 3*X1 - 4*X2 - 2*X3 + 2*X4 + 14*X5 - 11*X6 + 5*X7
|
||||
},
|
||||
minimize( Min).
|
||||
|
||||
%
|
||||
% min = 11429082625/9792 = 1167185.7255923203
|
||||
%
|
||||
example( 9, Vs, Obj) :-
|
||||
|
||||
Vs = [ Anm1,Anm2,Anm3,Anm4,Anm5,Anm6,
|
||||
Stm1,Stm2,Stm3,Stm4,Stm5,Stm6,
|
||||
UE1,UE2,UE3,UE4,UE5,UE6
|
||||
],
|
||||
|
||||
allpos( Vs),
|
||||
{
|
||||
+1*Stm1 = 60,
|
||||
+0.9*Stm1 +1*Anm1 -1*Stm2 = 0,
|
||||
+0.9*Stm2 +1*Anm2 -1*Stm3 = 0,
|
||||
+0.9*Stm3 +1*Anm3 -1*Stm4 = 0,
|
||||
+0.9*Stm4 +1*Anm4 -1*Stm5 = 0,
|
||||
+0.9*Stm5 +1*Anm5 -1*Stm6 = 0,
|
||||
+150*Stm1 -100*Anm1 +1*UE1 >= 8000,
|
||||
+150*Stm2 -100*Anm2 +1*UE2 >= 9000,
|
||||
+150*Stm3 -100*Anm3 +1*UE3 >= 8000,
|
||||
+150*Stm4 -100*Anm4 +1*UE4 >= 10000,
|
||||
+150*Stm5 -100*Anm5 +1*UE5 >= 9000,
|
||||
+150*Stm6 -100*Anm6 +1*UE6 >= 12000,
|
||||
-20*Stm1 +1*UE1 =< 0,
|
||||
-20*Stm2 +1*UE2 =< 0,
|
||||
-20*Stm3 +1*UE3 =< 0,
|
||||
-20*Stm4 +1*UE4 =< 0,
|
||||
-20*Stm5 +1*UE5 =< 0,
|
||||
-20*Stm6 +1*UE6 =< 0,
|
||||
Anm1 =< 18,
|
||||
57 =< Stm2,
|
||||
Stm2 =< 75,
|
||||
Anm2 =< 18,
|
||||
57 =< Stm3,
|
||||
Stm3 =< 75,
|
||||
Anm3 =< 18,
|
||||
57 =< Stm4,
|
||||
Stm4 =< 75,
|
||||
Anm4 =< 18,
|
||||
57 =< Stm5,
|
||||
Stm5 =< 75,
|
||||
Anm5 =< 18,
|
||||
57 =< Stm6,
|
||||
Stm6 =< 75,
|
||||
Anm6 =< 18,
|
||||
|
||||
Obj = +2700*Stm1 +1500*Anm1 +30*UE1
|
||||
+2700*Stm2 +1500*Anm2 +30*UE2
|
||||
+2700*Stm3 +1500*Anm3 +30*UE3
|
||||
+2700*Stm4 +1500*Anm4 +30*UE4
|
||||
+2700*Stm5 +1500*Anm5 +30*UE5
|
||||
+2700*Stm6 +1500*Anm6 +30*UE6
|
||||
},
|
||||
minimize( Obj).
|
||||
|
||||
|
||||
% b20011, p144
|
||||
%
|
||||
example( utility, Vs, Min) :-
|
||||
|
||||
Vs = [ X11, X12, X13, X14, X15,
|
||||
X21, X22, X23, X24, X25,
|
||||
Y11, Y12, Y13, Y14,
|
||||
Y21, Y22, Y23, Y24, Y25,
|
||||
Z11, Z12, Z13, Z14,
|
||||
Z21, Z22, Z23, Z24, Z25],
|
||||
{
|
||||
X11 + X12 + X13 + X14 + X15 = 1000,
|
||||
X21 + X22 + X23 + X24 + X25 = 1000,
|
||||
|
||||
3*X11 + 2*X21 - Y11 - Y14 - Z11 - Z14 =< 0,
|
||||
-3*X12 - 2*X22 + Y11 - Y12 + Z11 - Z12 = 0,
|
||||
-3*X13 - 2*X23 - Y13 + Y14 - Z13 + Z14 = 0,
|
||||
-3*X14 - 2*X24 + Y12 + Z12 = 0,
|
||||
-3*X15 - 2*X25 + Y13 + Z13 = 0,
|
||||
|
||||
4*X11 + 5*X21 - Y21 - Z21 =< 0,
|
||||
-4*X12 - 5*X22 + Y22 + Z22 = 0,
|
||||
-4*X13 - 5*X23 + Y24 - Y25 + Z24 - Z25 = 0,
|
||||
-4*X14 - 5*X24 + Y21 - Y22 - Y23 + Y25
|
||||
+ Z21 - Z22 - Z23 + Z25 = 0,
|
||||
-4*X15 - 5*X25 + Y23 - Y24 + Z23 - Z24 = 0,
|
||||
|
||||
7*X11 + 9*X21 >= 0,
|
||||
7*X12 + 9*X22 =< 3000,
|
||||
7*X13 + 9*X23 =< 200,
|
||||
7*X14 + 9*X24 =< 10000,
|
||||
7*X15 + 9*X25 =< 7000,
|
||||
|
||||
Z11 =< 1000,
|
||||
Z12 =< 500,
|
||||
Z13 =< 2000,
|
||||
Z14 =< 100,
|
||||
Z21 =< 5000,
|
||||
Z22 =< 250,
|
||||
Z23 =< 600,
|
||||
Z24 =< 7000,
|
||||
Z25 =< 4000,
|
||||
|
||||
X11 >= 0, X12 >= 0, X13 >= 0, X14 >= 0, X15 >= 0,
|
||||
X21 >= 0, X22 >= 0, X23 >= 0, X24 >= 0, X25 >= 0,
|
||||
|
||||
Y11 >= 0, Y12 >= 0, Y13 >= 0, Y14 >= 0,
|
||||
Y21 >= 0, Y22 >= 0, Y23 >= 0, Y24 >= 0, Y25 >= 0,
|
||||
|
||||
Z11 >= 0, Z12 >= 0, Z13 >= 0, Z14 >= 0,
|
||||
Z21 >= 0, Z22 >= 0, Z23 >= 0, Z24 >= 0, Z25 >= 0,
|
||||
|
||||
M = 99999,
|
||||
Min = M*X11 + M*X21 + 3*Y11 + 7*Y12 + 9*Y13 + Y14 + 4*Y21 + 7*Y22 + 3*Y23 +
|
||||
8*Y24 + 5*Y25
|
||||
},
|
||||
minimize(Min).
|
||||
|
||||
example( electricity, Vs, Min) :-
|
||||
|
||||
Vs = [ X11, X12, X13, X14, X15,
|
||||
X21, X22, X23, X24, X25,
|
||||
Y11, Y12, Y13, Y14,
|
||||
Z11, Z12, Z13, Z14],
|
||||
{
|
||||
X11 + X12 + X13 + X14 + X15 = 1000,
|
||||
X21 + X22 + X23 + X24 + X25 = 1000,
|
||||
|
||||
3*X11 + 2*X21 - Y11 - Y14 - Z11 - Z14 =< 0,
|
||||
-3*X12 - 2*X22 + Y11 - Y12 + Z11 - Z12 = 0,
|
||||
-3*X13 - 2*X23 - Y13 + Y14 - Z13 + Z14 = 0,
|
||||
-3*X14 - 2*X24 + Y12 + Z12 = 0,
|
||||
-3*X15 - 2*X25 + Y13 + Z13 = 0,
|
||||
|
||||
7*X11 + 9*X21 >= 0,
|
||||
7*X12 + 9*X22 =< 3000,
|
||||
7*X13 + 9*X23 =< 200,
|
||||
7*X14 + 9*X24 =< 10000,
|
||||
7*X15 + 9*X25 =< 7000,
|
||||
|
||||
Z11 =< 1000,
|
||||
Z12 =< 500,
|
||||
Z13 =< 2000,
|
||||
Z14 =< 100,
|
||||
|
||||
X11 >= 0, X12 >= 0, X13 >= 0, X14 >= 0, X15 >= 0,
|
||||
X21 >= 0, X22 >= 0, X23 >= 0, X24 >= 0, X25 >= 0,
|
||||
Y11 >= 0, Y12 >= 0, Y13 >= 0, Y14 >= 0,
|
||||
Z11 >= 0, Z12 >= 0, Z13 >= 0, Z14 >= 0,
|
||||
|
||||
M = 99999,
|
||||
Min = M*X11 + M*X21 + 3*Y11 + 7*Y12 + 9*Y13 + Y14
|
||||
},
|
||||
minimize(Min).
|
||||
|
||||
example( water, Vs, Min) :-
|
||||
|
||||
Vs = [ X11, X12, X13, X14, X15,
|
||||
X21, X22, X23, X24, X25,
|
||||
Y21, Y22, Y23, Y24, Y25,
|
||||
Z21, Z22, Z23, Z24, Z25],
|
||||
{
|
||||
X11 + X12 + X13 + X14 + X15 = 1000,
|
||||
X21 + X22 + X23 + X24 + X25 = 1000,
|
||||
|
||||
4*X11 + 5*X21 - Y21 - Z21 =< 0,
|
||||
-4*X12 - 5*X22 + Y22 + Z22 = 0,
|
||||
-4*X13 - 5*X23 + Y24 - Y25 + Z24 - Z25 = 0,
|
||||
-4*X14 - 5*X24 + Y21 - Y22 - Y23 + Y25
|
||||
+ Z21 - Z22 - Z23 + Z25 = 0,
|
||||
-4*X15 - 5*X25 + Y23 - Y24 + Z23 - Z24 = 0,
|
||||
|
||||
7*X11 + 9*X21 >= 0,
|
||||
7*X12 + 9*X22 =< 3000,
|
||||
7*X13 + 9*X23 =< 200,
|
||||
7*X14 + 9*X24 =< 10000,
|
||||
7*X15 + 9*X25 =< 7000,
|
||||
|
||||
Z21 =< 5000,
|
||||
Z22 =< 250,
|
||||
Z23 =< 600,
|
||||
Z24 =< 7000,
|
||||
Z25 =< 4000,
|
||||
|
||||
X11 >= 0, X12 >= 0, X13 >= 0, X14 >= 0, X15 >= 0,
|
||||
X21 >= 0, X22 >= 0, X23 >= 0, X24 >= 0, X25 >= 0,
|
||||
|
||||
Y21 >= 0, Y22 >= 0, Y23 >= 0, Y24 >= 0, Y25 >= 0,
|
||||
|
||||
Z21 >= 0, Z22 >= 0, Z23 >= 0, Z24 >= 0, Z25 >= 0,
|
||||
|
||||
M = 99999,
|
||||
Min = M*X11 + M*X21 + 4*Y21 + 7*Y22 + 3*Y23 + 8*Y24 + 5*Y25
|
||||
},
|
||||
minimize(Min).
|
||||
|
||||
allpos( []).
|
||||
allpos( [V|Vs]) :-
|
||||
{ V >= 0 },
|
||||
allpos( Vs).
|
||||
|
||||
% --------------------------------------------------------------------------
|
||||
|
||||
test(0) :- { A=<2,B=<3,C=<4,A+B+C=10 }. % must fail
|
||||
|
||||
test(5) :-
|
||||
{
|
||||
2*X1 + 4*X2 + 3*X3 - 4*W1 - 10*W2 = 0,
|
||||
2*X1 + X2 + X3 = 4,
|
||||
5*X1 + 3*X2 + 2*X3 = 10,
|
||||
2*W1 + 5*W2 =< 2,
|
||||
W1 + 3*W2 =< 4,
|
||||
W1 + 2*W2 =< 3,
|
||||
X1 >= 0,
|
||||
X2 >= 0,
|
||||
X3 >= 0
|
||||
}.
|
||||
|
||||
|
@ -1,108 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.2 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: squares.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
/*
|
||||
This beautiful example of disequations at work is due
|
||||
to [Colmerauer 90]. It addresses the task of tiling a rectangle
|
||||
with squares of all-different, a priori unknown sizes. Here is a
|
||||
translation of the original Prolog-III program to clp(q,r)
|
||||
|
||||
[Colmerauer 90]
|
||||
Colmerauer A.: An Introduction to Prolog III,
|
||||
Communications of the ACM, 33(7), 69-90, 1990.
|
||||
|
||||
|
||||
|
||||
|
||||
| ?- length(L,9),filled_rectangle(A,L).
|
||||
|
||||
A = 33/32,
|
||||
L = [15/32,9/16,1/4,7/32,1/8,7/16,1/32,5/16,9/32] ? ;
|
||||
|
||||
A = 69/61,
|
||||
L = [33/61,36/61,28/61,5/61,2/61,9/61,25/61,7/61,16/61] ?
|
||||
*/
|
||||
|
||||
|
||||
rectangle( A, Rs) :-
|
||||
Rs = [X1,X2,X3,X4,X5,X6,X7,X8,X9],
|
||||
filled_rectangle( A, Rs).
|
||||
|
||||
filled_rectangle( A, C) :-
|
||||
{ A >= 1 },
|
||||
distinct_squares( C), % also acts as generator [], [_], [_,_], ...
|
||||
filled_zone( [-1,A,1], _, C, []).
|
||||
|
||||
distinct_squares( []).
|
||||
distinct_squares( [B|C]) :-
|
||||
{ B > 0 },
|
||||
outof( C, B),
|
||||
distinct_squares( C).
|
||||
|
||||
outof( [], _).
|
||||
outof( [B1|C], B) :-
|
||||
{ B =\= B1 },
|
||||
outof( C, B).
|
||||
|
||||
filled_zone( [V|L], [V|L], C0, C0) :-
|
||||
{ V >= 0 }.
|
||||
filled_zone( [V|L], L3, [B|C], C2) :-
|
||||
{ V < 0 },
|
||||
placed_square( B, L, L1),
|
||||
filled_zone( L1, L2, C, C1),
|
||||
{ Vb=V+B },
|
||||
filled_zone( [Vb,B|L2], L3, C1, C2).
|
||||
|
||||
placed_square( B, [H,H0,H1|L], L1) :-
|
||||
{ B > H, H0=0, H2=H+H1 },
|
||||
placed_square( B, [H2|L], L1).
|
||||
placed_square( B, [B,V|L], [X|L]) :-
|
||||
{ X=V-B }.
|
||||
placed_square( B, [H|L], [X,Y|L]) :-
|
||||
{ B < H, X= -B, Y=H-B }.
|
||||
|
||||
%
|
||||
% first nontrivial solution has 21 squares ...
|
||||
%
|
||||
perfect( S) :-
|
||||
{ A = 1 },
|
||||
distinct_squares( S),
|
||||
length( S, Len), Len > 1,
|
||||
print( try(Len)), nl,
|
||||
flush_output,
|
||||
time( filled_zone( [-1,A,1], _, S, [])).
|
||||
|
||||
/*
|
||||
try(2)
|
||||
%%% Timing 00:00:00.030 0.030
|
||||
try(3)
|
||||
%%% Timing 00:00:00.070 0.070
|
||||
try(4)
|
||||
%%% Timing 00:00:00.270 0.270
|
||||
try(5)
|
||||
%%% Timing 00:00:01.060 1.060
|
||||
try(6)
|
||||
%%% Timing 00:00:04.470 4.470
|
||||
try(7)
|
||||
%%% Timing 00:00:19.960 19.960
|
||||
try(8)
|
||||
%%% Timing 00:01:33.380 93.380
|
||||
try(9)
|
||||
%%% Timing 00:07:27.380 447.380
|
||||
try(10)
|
||||
%%% Timing 00:37:03.770 2223.770
|
||||
try(11)
|
||||
%%% Timing 03:11:38.380 11498.380
|
||||
try(12)
|
||||
%%% Timing 16:18:43.110 58723.110
|
||||
*/
|
@ -1,196 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.2 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: expand.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%
|
||||
% Perform theory-purification in the presence of
|
||||
% interpreted terms.
|
||||
%
|
||||
|
||||
:- module( expand, [expand/0, noexpand/0]).
|
||||
:- dynamic expanding/0.
|
||||
|
||||
:- multifile
|
||||
user:term_expansion/2,
|
||||
user:goal_expansion/3.
|
||||
|
||||
:- dynamic
|
||||
user:term_expansion/2,
|
||||
user:goal_expansion/3.
|
||||
|
||||
user:term_expansion(A,B) :- % expands heads
|
||||
expanding,
|
||||
purify_head(A,B).
|
||||
|
||||
user:goal_expansion(G,M,E):- % expands bodies
|
||||
M \== prolog, % quite common due to internal call_cleanups etc.
|
||||
M \== expand, % this file may get loaded more than once
|
||||
expanding,
|
||||
purify(G,M,E).
|
||||
|
||||
noexpand :-
|
||||
retractall(expanding).
|
||||
|
||||
expand :-
|
||||
assert(expanding).
|
||||
|
||||
|
||||
purify( Goal, Module, _) :- quoted( Goal, Module), !, fail.
|
||||
purify( Goal, _, Expansion) :-
|
||||
interpreted_relation( Goal, _Module),
|
||||
!,
|
||||
Expansion = {Goal}.
|
||||
purify( X=Y, _Module, Expansion) :- !, % shortcut for =/2
|
||||
( ( var(X) ; interpreted_term( X, Th) ),
|
||||
( var(Y) ; interpreted_term( Y, Th) ),
|
||||
nonvar( Th) ->
|
||||
Expansion = {X=Y}
|
||||
;
|
||||
ra( X=Y, user, Pure, ThL, ThLTail),
|
||||
ThL \== ThLTail,
|
||||
ThLTail = [Pure],
|
||||
l2conj( ThL, Expansion)
|
||||
).
|
||||
purify( Goal, _Module, Expansion) :-
|
||||
nobuiltin( Goal),
|
||||
ra( Goal, user, Pure, ThL, ThLTail),
|
||||
ThL \== ThLTail, % ifunctors present ?
|
||||
ThLTail = [Pure],
|
||||
l2conj( ThL, Expansion).
|
||||
|
||||
nobuiltin( Goal) :-
|
||||
predicate_property( Goal, built_in),
|
||||
!,
|
||||
fail.
|
||||
nobuiltin( _).
|
||||
|
||||
quoted( {_}, _).
|
||||
quoted( run(_,_), geler). % late goal of verify_attributes/3
|
||||
quoted( resubmit_eq(_), nf). % some (all?) of its clients
|
||||
quoted( resubmit_lt(_), nf).
|
||||
quoted( resubmit_le(_), nf).
|
||||
quoted( resubmit_ne(_), nf).
|
||||
quoted( wait_linear_retry(_,_,_), nf).
|
||||
quoted( fm_cp_filter(_,_,_), linear). % generator in findall/3
|
||||
%
|
||||
quoted( printf(_), _).
|
||||
quoted( printf(_,_), _).
|
||||
quoted( user_tout(_,_,_,_), _). % undef pred
|
||||
|
||||
%
|
||||
% Identify the theory (module) involved.
|
||||
%
|
||||
interpreted_term( X, _) :- var(X), !, fail.
|
||||
interpreted_term( X, linear) :- number(X).
|
||||
interpreted_term( rat(_,_), linear). % rational constant
|
||||
%
|
||||
interpreted_term( #(_), linear). % Monash
|
||||
interpreted_term( -(_), linear). % unary minus
|
||||
interpreted_term( +(_), linear). % plus
|
||||
interpreted_term( +(_,_), linear). % binary
|
||||
interpreted_term( -(_,_), linear).
|
||||
interpreted_term( *(_,_), linear).
|
||||
interpreted_term( /(_,_), linear).
|
||||
interpreted_term( pow(_,_), linear).
|
||||
interpreted_term( exp(_,_), linear).
|
||||
interpreted_term( ^(_,_), linear).
|
||||
interpreted_term( sin(_), linear).
|
||||
interpreted_term( cos(_), linear).
|
||||
interpreted_term( tan(_), linear).
|
||||
interpreted_term( min(_,_), linear).
|
||||
interpreted_term( max(_,_), linear).
|
||||
interpreted_term( abs(_), linear).
|
||||
|
||||
interpreted_relation( G, _) :- var(G), !, fail.
|
||||
interpreted_relation( <(_,_), linear).
|
||||
interpreted_relation( =<(_,_), linear).
|
||||
interpreted_relation( <=(_,_), linear). % Monash
|
||||
interpreted_relation( >(_,_), linear).
|
||||
interpreted_relation( >=(_,_), linear).
|
||||
interpreted_relation( =\=(_,_), linear).
|
||||
interpreted_relation( =:=(_,_), linear).
|
||||
|
||||
% ----------------------------------------------------------------
|
||||
|
||||
%
|
||||
% replace alien subterms by variables
|
||||
% Special treatment for quote/1
|
||||
%
|
||||
%
|
||||
%
|
||||
ra( Term, _, Pure) --> {var(Term), !, Term = Pure}.
|
||||
ra( Term, Th, Pure) -->
|
||||
{
|
||||
functor( Term, N, A),
|
||||
functor( Pure, N, A)
|
||||
},
|
||||
ra( A, Term, Th, Pure).
|
||||
|
||||
ra( 0, _, _, _) --> !.
|
||||
ra( N, Term, Th, Pure) -->
|
||||
{
|
||||
N1 is N-1,
|
||||
arg( N, Term, Ta),
|
||||
arg( N, Pure, Pa)
|
||||
},
|
||||
ra_one( Ta, Th, Pa),
|
||||
ra( N1, Term, Th, Pure).
|
||||
|
||||
ra_one( Term, _, Pure) --> {var( Term), !, Pure=Term}.
|
||||
ra_one( quote(Term), _, Pure) --> {!, Pure=Term}.
|
||||
ra_one( Term, ParentTheory, Pure) -->
|
||||
{
|
||||
( interpreted_term( Term, Theory) ->
|
||||
true
|
||||
;
|
||||
Theory=user
|
||||
)
|
||||
},
|
||||
( { ParentTheory=Theory } ->
|
||||
ra( Term, Theory, Pure)
|
||||
;
|
||||
ra_equate( Theory, Pure, ThPure),
|
||||
ra( Term, Theory, ThPure)
|
||||
).
|
||||
|
||||
ra_equate( user, A, B) --> !, { A=B }. % now
|
||||
ra_equate( _Theory, A, B) --> [ {A=B} ]. % later
|
||||
|
||||
% ---------------------------------------------------------------------------
|
||||
|
||||
purify_head( Term, NewTerm) :-
|
||||
( prolog:dcg_expansion( Term, []/*undef layout*/, Exp, _) ->
|
||||
true
|
||||
;
|
||||
Term = Exp
|
||||
),
|
||||
( Exp = ?-(_) -> % don't touch these
|
||||
fail
|
||||
; Exp = :-(_) -> % expanded via goal_expansion
|
||||
fail
|
||||
; Exp = (H:-B) ->
|
||||
ra( H, user, NewHead, Cl, []),
|
||||
Cl = [_|_], % ifunctors in head ?
|
||||
l2conj( Cl, Thc),
|
||||
NewTerm = (NewHead:-Thc,B)
|
||||
; % facts
|
||||
ra( Exp, user, H, Cl, []),
|
||||
Cl = [_|_], % ifunctors in head ?
|
||||
l2conj( Cl, B),
|
||||
NewTerm = (H:-B)
|
||||
).
|
||||
|
||||
l2conj( [], true).
|
||||
l2conj( [X|Xs], Conj) :-
|
||||
( Xs = [], Conj = X
|
||||
; Xs = [_|_], Conj = (X,Xc), l2conj( Xs, Xc)
|
||||
).
|
@ -1,199 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.2 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: expand.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%
|
||||
% Perform theory-purification in the presence of
|
||||
% interpreted terms.
|
||||
%
|
||||
|
||||
:- module( expand, [expand/0, noexpand/0]).
|
||||
:- dynamic expanding/0.
|
||||
|
||||
:- multifile
|
||||
user:term_expansion/2,
|
||||
user:goal_expansion/3.
|
||||
|
||||
:- dynamic
|
||||
user:term_expansion/2,
|
||||
user:goal_expansion/3.
|
||||
|
||||
user:term_expansion(A,B) :- % expands heads
|
||||
expanding,
|
||||
purify_head(A,B).
|
||||
|
||||
user:goal_expansion(G,M,E):- % expands bodies
|
||||
M \== prolog, % quite common due to internal call_cleanups etc.
|
||||
M \== expand, % this file may get loaded more than once
|
||||
expanding,
|
||||
purify(G,M,E).
|
||||
|
||||
noexpand :-
|
||||
retractall(expanding).
|
||||
|
||||
expand :-
|
||||
assert(expanding).
|
||||
|
||||
|
||||
purify( Goal, Module, _) :- quoted( Goal, Module), !, fail.
|
||||
purify( Goal, _, Expansion) :-
|
||||
interpreted_relation( Goal, _Module),
|
||||
!,
|
||||
Expansion = {Goal}.
|
||||
purify( X=Y, _Module, Expansion) :- !, % shortcut for =/2
|
||||
( ( var(X) ; interpreted_term( X, Th) ),
|
||||
( var(Y) ; interpreted_term( Y, Th) ),
|
||||
nonvar( Th) ->
|
||||
Expansion = {X=Y}
|
||||
;
|
||||
ra( X=Y, user, Pure, ThL, ThLTail),
|
||||
ThL \== ThLTail,
|
||||
ThLTail = [Pure],
|
||||
l2conj( ThL, Expansion)
|
||||
).
|
||||
purify( Goal, _Module, Expansion) :-
|
||||
nobuiltin( Goal),
|
||||
ra( Goal, user, Pure, ThL, ThLTail),
|
||||
ThL \== ThLTail, % ifunctors present ?
|
||||
ThLTail = [Pure],
|
||||
l2conj( ThL, Expansion).
|
||||
|
||||
nobuiltin( Goal) :-
|
||||
predicate_property( Goal, built_in),
|
||||
!,
|
||||
fail.
|
||||
nobuiltin( _).
|
||||
|
||||
quoted( {_}, _).
|
||||
quoted( run(_,_), geler). % late goal of verify_attributes/3
|
||||
quoted( resubmit_eq(_), nf). % some (all?) of its clients
|
||||
quoted( resubmit_lt(_), nf).
|
||||
quoted( resubmit_le(_), nf).
|
||||
quoted( resubmit_ne(_), nf).
|
||||
quoted( wait_linear_retry(_,_,_), nf).
|
||||
quoted( fm_cp_filter(_,_,_), linear). % generator in findall/3
|
||||
%
|
||||
quoted( printf(_), _).
|
||||
quoted( printf(_,_), _).
|
||||
quoted( user_tout(_,_,_,_), _). % undef pred
|
||||
|
||||
%
|
||||
% Identify the theory (module) involved.
|
||||
%
|
||||
interpreted_term( X, _) :- var(X), !, fail.
|
||||
interpreted_term( X, linear) :- number(X).
|
||||
interpreted_term( rat(_,_), linear). % rational constant
|
||||
%
|
||||
interpreted_term( #(_), linear). % Monash
|
||||
interpreted_term( -(_), linear). % unary minus
|
||||
interpreted_term( +(_), linear). % plus
|
||||
interpreted_term( +(_,_), linear). % binary
|
||||
interpreted_term( -(_,_), linear).
|
||||
interpreted_term( *(_,_), linear).
|
||||
interpreted_term( /(_,_), linear).
|
||||
interpreted_term( pow(_,_), linear).
|
||||
interpreted_term( exp(_,_), linear).
|
||||
interpreted_term( ^(_,_), linear).
|
||||
interpreted_term( sin(_), linear).
|
||||
interpreted_term( cos(_), linear).
|
||||
interpreted_term( tan(_), linear).
|
||||
interpreted_term( min(_,_), linear).
|
||||
interpreted_term( max(_,_), linear).
|
||||
interpreted_term( abs(_), linear).
|
||||
|
||||
interpreted_relation( G, _) :- var(G), !, fail.
|
||||
interpreted_relation( <(_,_), linear).
|
||||
interpreted_relation( =<(_,_), linear).
|
||||
interpreted_relation( <=(_,_), linear). % Monash
|
||||
interpreted_relation( >(_,_), linear).
|
||||
interpreted_relation( >=(_,_), linear).
|
||||
interpreted_relation( =\=(_,_), linear).
|
||||
interpreted_relation( =:=(_,_), linear).
|
||||
|
||||
% ----------------------------------------------------------------
|
||||
|
||||
%
|
||||
% replace alien subterms by variables
|
||||
% Special treatment for quote/1
|
||||
%
|
||||
%
|
||||
%
|
||||
ra( Term, _, Pure) --> {var(Term), !, Term = Pure}.
|
||||
ra( Term, Th, Pure) -->
|
||||
{
|
||||
functor( Term, N, A),
|
||||
functor( Pure, N, A)
|
||||
},
|
||||
ra( A, Term, Th, Pure).
|
||||
|
||||
ra( 0, _, _, _) --> !.
|
||||
ra( N, Term, Th, Pure) -->
|
||||
{
|
||||
N1 is N-1,
|
||||
arg( N, Term, Ta),
|
||||
arg( N, Pure, Pa)
|
||||
},
|
||||
ra_one( Ta, Th, Pa),
|
||||
ra( N1, Term, Th, Pure).
|
||||
|
||||
ra_one( Term, _, Pure) --> {var( Term), !, Pure=Term}.
|
||||
ra_one( quote(Term), _, Pure) --> {!, Pure=Term}.
|
||||
ra_one( Term, ParentTheory, Pure) -->
|
||||
{
|
||||
( interpreted_term( Term, Theory) ->
|
||||
true
|
||||
;
|
||||
Theory=user
|
||||
)
|
||||
},
|
||||
( { ParentTheory=Theory } ->
|
||||
ra( Term, Theory, Pure)
|
||||
;
|
||||
ra_equate( Theory, Pure, ThPure),
|
||||
ra( Term, Theory, ThPure)
|
||||
).
|
||||
|
||||
ra_equate( user, A, B) --> !, { A=B }. % now
|
||||
ra_equate( _Theory, A, B) --> [ {A=B} ]. % later
|
||||
|
||||
% ---------------------------------------------------------------------------
|
||||
|
||||
purify_head( Term, NewTerm) :-
|
||||
% vsc: doesn't really exist in YAP, ignore it for now.
|
||||
% ( prolog:dcg_expansion( Term, []/*undef layout*/, Exp, _) ->
|
||||
% true
|
||||
% ;
|
||||
% Term = Exp
|
||||
% ),
|
||||
Term = Exp,
|
||||
( Exp = ?-(_) -> % don't touch these
|
||||
fail
|
||||
; Exp = :-(_) -> % expanded via goal_expansion
|
||||
fail
|
||||
; Exp = (H:-B) ->
|
||||
ra( H, user, NewHead, Cl, []),
|
||||
Cl = [_|_], % ifunctors in head ?
|
||||
l2conj( Cl, Thc),
|
||||
NewTerm = (NewHead:-Thc,B)
|
||||
; % facts
|
||||
ra( Exp, user, H, Cl, []),
|
||||
Cl = [_|_], % ifunctors in head ?
|
||||
l2conj( Cl, B),
|
||||
NewTerm = (H:-B)
|
||||
).
|
||||
|
||||
l2conj( [], true).
|
||||
l2conj( [X|Xs], Conj) :-
|
||||
( Xs = [], Conj = X
|
||||
; Xs = [_|_], Conj = (X,Xc), l2conj( Xs, Xc)
|
||||
).
|
||||
|
@ -1,294 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.2 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: fourmotz.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%
|
||||
% TODO -) remove syntactic redundancy first ?!!
|
||||
% -) avoid the construction of the crossproduct list
|
||||
% +) consider strictness in crossproduct generation !!!
|
||||
%
|
||||
|
||||
fm_elim( Vs, Target, Pivots) :-
|
||||
prefilter( Vs, Vsf),
|
||||
fm_elim_int( Vsf, Target, Pivots).
|
||||
|
||||
prefilter( [], []).
|
||||
prefilter( [V|Vs], Res) :-
|
||||
( get_atts( V, -target),
|
||||
occurs( V) ->
|
||||
Res = [V|Tail],
|
||||
put_atts( V, keep_indep),
|
||||
prefilter( Vs, Tail)
|
||||
;
|
||||
prefilter( Vs, Res)
|
||||
).
|
||||
|
||||
%
|
||||
% the target variables are marked with an attribute, and we get a list
|
||||
% of them as an argument too
|
||||
%
|
||||
fm_elim_int( [], _, Pivots) :- % done
|
||||
unkeep( Pivots).
|
||||
fm_elim_int( Vs, Target, Pivots) :-
|
||||
Vs = [_|_],
|
||||
( best( Vs, Best, Rest) ->
|
||||
occurences( Best, Occ),
|
||||
elim_min( Best, Occ, Target, Pivots, NewPivots)
|
||||
; % give up
|
||||
NewPivots=Pivots, Rest = []
|
||||
),
|
||||
fm_elim_int( Rest, Target, NewPivots).
|
||||
|
||||
%
|
||||
% Find the variable with the smallest netto increase on the
|
||||
% size of the ineq. system after its elimination
|
||||
%
|
||||
best( Vs, Best, Rest) :-
|
||||
findall( Delta-N, fm_cp_filter( Vs, Delta, N), Deltas),
|
||||
keysort( Deltas, [_-N|_]),
|
||||
select_nth( Vs, N, Best, Rest).
|
||||
|
||||
fm_cp_filter( Vs, Delta, N) :-
|
||||
length( Vs, Len),
|
||||
mem( Vs,X,Vst),
|
||||
get_atts( X, [-target,lin(Lin)]),
|
||||
indep( Lin, X),
|
||||
occurences( X, Occ),
|
||||
Occ = [_|_],
|
||||
% crossproduct( Occ, New, []),
|
||||
% length( New, CpLnew),
|
||||
cp_card( Occ, 0,Lnew),
|
||||
length( Occ, Locc),
|
||||
Delta is Lnew-Locc,
|
||||
length( Vst, Vstl),
|
||||
N is Len-Vstl.
|
||||
|
||||
mem( [X|Xs], X, Xs).
|
||||
mem( [_|Ys], X, Xs) :- mem( Ys, X, Xs).
|
||||
|
||||
select_nth( List, N, Nth, Others) :-
|
||||
select_nth( List, 1,N, Nth, Others).
|
||||
|
||||
select_nth( [X|Xs], N,N, X, Xs) :- !.
|
||||
select_nth( [Y|Ys], M,N, X, [Y|Xs]) :-
|
||||
M1 is M+1,
|
||||
select_nth( Ys, M1,N, X, Xs).
|
||||
|
||||
%
|
||||
% fm_detach + reverse_pivot introduce indep t_none, which
|
||||
% invalidates the invariants
|
||||
%
|
||||
elim_min( V, Occ, Target, Pivots, NewPivots) :-
|
||||
crossproduct( Occ, New, []),
|
||||
activate_crossproduct( New),
|
||||
reverse_pivot( Pivots),
|
||||
fm_detach( Occ),
|
||||
% length( Occ, Locc), length( New, Lnew), print( fm(-Locc,+Lnew)), nl,
|
||||
allvars( V, All),
|
||||
redundancy_vars( All), % only for New \== []
|
||||
make_target_indep( Target, NewPivots),
|
||||
drop_dep( All).
|
||||
|
||||
%
|
||||
% restore NF by reverse pivoting
|
||||
%
|
||||
reverse_pivot( []).
|
||||
reverse_pivot( [I:D|Ps]) :-
|
||||
get_atts( D, type(Dt)),
|
||||
put_atts( D, -keep), % no longer
|
||||
pivot( D, I, Dt),
|
||||
reverse_pivot( Ps).
|
||||
|
||||
unkeep( []).
|
||||
unkeep( [_:D|Ps]) :-
|
||||
put_atts( D, -keep),
|
||||
drop_dep_one( D),
|
||||
unkeep( Ps).
|
||||
|
||||
|
||||
%
|
||||
% All we drop are bounds
|
||||
%
|
||||
fm_detach( []).
|
||||
fm_detach( [V:_|Vs]) :-
|
||||
detach_bounds( V),
|
||||
fm_detach( Vs).
|
||||
|
||||
%
|
||||
% Todo: maybe bulk_basis_add
|
||||
%
|
||||
activate_crossproduct( []).
|
||||
activate_crossproduct( [lez(Strict,Lin)|News]) :-
|
||||
arith_eval( 0, Z),
|
||||
var_with_def_intern( t_u(Z), Var, Lin, Strict),
|
||||
basis_add( Var, _),
|
||||
activate_crossproduct( News).
|
||||
|
||||
% ------------------------------------------------------------------------------
|
||||
|
||||
crossproduct( []) --> [].
|
||||
crossproduct( [A|As]) -->
|
||||
crossproduct( As, A),
|
||||
crossproduct( As).
|
||||
|
||||
crossproduct( [], _) --> [].
|
||||
crossproduct( [B:Kb|Bs], A:Ka) -->
|
||||
{
|
||||
get_atts( A, [type(Ta),lin(LinA),strictness(Sa)]),
|
||||
get_atts( B, [type(Tb),lin(LinB),strictness(Sb)]),
|
||||
arith_eval( -Kb/Ka, K),
|
||||
add_linear_f1( LinA, K, LinB, Lin)
|
||||
},
|
||||
( { arith_eval( K > 0) } -> % signs were opposite
|
||||
{ Strict is Sa \/ Sb },
|
||||
cross_lower( Ta, Tb, K, Lin, Strict),
|
||||
cross_upper( Ta, Tb, K, Lin, Strict)
|
||||
; % La =< A =< Ua -> -Ua =< -A =< -La
|
||||
{
|
||||
flip( Ta, Taf),
|
||||
flip_strict( Sa, Saf),
|
||||
Strict is Saf \/ Sb
|
||||
},
|
||||
cross_lower( Taf, Tb, K, Lin, Strict),
|
||||
cross_upper( Taf, Tb, K, Lin, Strict)
|
||||
),
|
||||
crossproduct( Bs, A:Ka).
|
||||
|
||||
cross_lower( Ta, Tb, K, Lin, Strict) -->
|
||||
{
|
||||
lower( Ta, La),
|
||||
lower( Tb, Lb),
|
||||
!,
|
||||
arith_eval(K*La+Lb,L),
|
||||
normalize_scalar( L, Ln),
|
||||
arith_eval( -1, Mone),
|
||||
add_linear_f1( Lin, Mone, Ln, Lhs),
|
||||
Sl is Strict >> 1 % normalize to upper bound
|
||||
},
|
||||
[ lez(Sl,Lhs) ].
|
||||
cross_lower( _, _, _, _, _) --> [].
|
||||
|
||||
cross_upper( Ta, Tb, K, Lin, Strict) -->
|
||||
{
|
||||
upper( Ta, Ua),
|
||||
upper( Tb, Ub),
|
||||
!,
|
||||
arith_eval(-(K*Ua+Ub),U),
|
||||
normalize_scalar( U, Un),
|
||||
add_linear_11( Un, Lin, Lhs),
|
||||
Su is Strict /\ 2'01 % normalize to upper bound
|
||||
},
|
||||
[ lez(Su,Lhs) ].
|
||||
cross_upper( _, _, _, _, _) --> [].
|
||||
|
||||
lower( t_l(L), L).
|
||||
lower( t_lu(L,_), L).
|
||||
lower( t_L(L), L).
|
||||
lower( t_Lu(L,_), L).
|
||||
lower( t_lU(L,_), L).
|
||||
|
||||
upper( t_u(U), U).
|
||||
upper( t_lu(_,U), U).
|
||||
upper( t_U(U), U).
|
||||
upper( t_Lu(_,U), U).
|
||||
upper( t_lU(_,U), U).
|
||||
|
||||
flip( t_l(X), t_u(X)).
|
||||
flip( t_u(X), t_l(X)).
|
||||
flip( t_lu(X,Y),t_lu(Y,X)).
|
||||
flip( t_L(X), t_u(X)).
|
||||
flip( t_U(X), t_l(X)).
|
||||
flip( t_lU(X,Y),t_lu(Y,X)).
|
||||
flip( t_Lu(X,Y),t_lu(Y,X)).
|
||||
|
||||
flip_strict( 2'00, 2'00).
|
||||
flip_strict( 2'01, 2'10).
|
||||
flip_strict( 2'10, 2'01).
|
||||
flip_strict( 2'11, 2'11).
|
||||
|
||||
cp_card( [], Ci,Ci).
|
||||
cp_card( [A|As], Ci,Co) :-
|
||||
cp_card( As, A, Ci,Cii),
|
||||
cp_card( As, Cii,Co).
|
||||
|
||||
cp_card( [], _, Ci,Ci).
|
||||
cp_card( [B:Kb|Bs], A:Ka, Ci,Co) :-
|
||||
get_atts( A, type(Ta)),
|
||||
get_atts( B, type(Tb)),
|
||||
arith_eval( -Kb/Ka, K),
|
||||
( arith_eval( K > 0) -> % signs were opposite
|
||||
cp_card_lower( Ta, Tb, Ci,Cii),
|
||||
cp_card_upper( Ta, Tb, Cii,Ciii)
|
||||
;
|
||||
flip( Ta, Taf),
|
||||
cp_card_lower( Taf, Tb, Ci,Cii),
|
||||
cp_card_upper( Taf, Tb, Cii,Ciii)
|
||||
),
|
||||
cp_card( Bs, A:Ka, Ciii,Co).
|
||||
|
||||
cp_card_lower( Ta, Tb, Si,So) :-
|
||||
lower( Ta, _),
|
||||
lower( Tb, _),
|
||||
!,
|
||||
So is Si+1.
|
||||
cp_card_lower( _, _, Si,Si).
|
||||
|
||||
cp_card_upper( Ta, Tb, Si,So) :-
|
||||
upper( Ta, _),
|
||||
upper( Tb, _),
|
||||
!,
|
||||
So is Si+1.
|
||||
cp_card_upper( _, _, Si,Si).
|
||||
|
||||
% ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
occurences( V, Occ) :-
|
||||
allvars( V, All),
|
||||
occurences( All, V, Occ).
|
||||
|
||||
occurences( De, _, []) :- var( De), !.
|
||||
occurences( [D|De], V, Occ) :-
|
||||
( get_atts( D, [lin(Lin),type(Type)]),
|
||||
occ_type_filter( Type),
|
||||
nf_coeff_of( Lin, V, K) ->
|
||||
Occ = [D:K|Occt],
|
||||
occurences( De, V, Occt)
|
||||
;
|
||||
occurences( De, V, Occ)
|
||||
).
|
||||
|
||||
occ_type_filter( t_l(_)).
|
||||
occ_type_filter( t_u(_)).
|
||||
occ_type_filter( t_lu(_,_)).
|
||||
occ_type_filter( t_L(_)).
|
||||
occ_type_filter( t_U(_)).
|
||||
occ_type_filter( t_lU(_,_)).
|
||||
occ_type_filter( t_Lu(_,_)).
|
||||
|
||||
%
|
||||
% occurs( V) :- occurences( V, Occ), Occ = [_|_].
|
||||
%
|
||||
occurs( V) :-
|
||||
allvars( V, All),
|
||||
occurs( All, V).
|
||||
|
||||
occurs( De, _) :- var( De), !, fail.
|
||||
occurs( [D|De], V) :-
|
||||
( get_atts( D, [lin(Lin),type(Type)]),
|
||||
occ_type_filter( Type),
|
||||
nf_coeff_of( Lin, V, _) ->
|
||||
true
|
||||
;
|
||||
occurs( De, V)
|
||||
).
|
@ -1,984 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.2 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: ineq.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%
|
||||
% Lin (=)< 0
|
||||
%
|
||||
ineq( [], I, _, Strictness) :- ineq_ground( Strictness, I).
|
||||
ineq( [v(K,[X^1])|Tail], I, Lin, Strictness) :-
|
||||
ineq_cases( Tail, I, Lin, Strictness, X, K).
|
||||
|
||||
ineq_cases( [], I, _, Strictness, X, K) :-
|
||||
ineq_one( Strictness, X, K, I).
|
||||
ineq_cases( [_|_], _, Lin, Strictness, _, _) :-
|
||||
deref( Lin, Lind), % Id+Hd =< 0
|
||||
decompose( Lind, Hom, _, Inhom),
|
||||
ineq_more( Hom, Inhom, Lind, Strictness).
|
||||
|
||||
ineq_ground( strict, I) :- arith_eval( I < 0).
|
||||
ineq_ground( nonstrict, I) :- arith_eval( I =< 0).
|
||||
|
||||
%
|
||||
% Special cases: k={+-}1,i=0
|
||||
%
|
||||
ineq_one( strict, X, K, I) :-
|
||||
( arith_eval(K>0) ->
|
||||
( arith_eval(I=:=0) ->
|
||||
ineq_one_s_p_0( X)
|
||||
;
|
||||
arith_eval( I/K, Inhom),
|
||||
ineq_one_s_p_i( X, Inhom)
|
||||
)
|
||||
;
|
||||
( arith_eval(I=:=0) ->
|
||||
ineq_one_s_n_0( X)
|
||||
;
|
||||
arith_eval( -I/K, Inhom),
|
||||
ineq_one_s_n_i( X, Inhom)
|
||||
)
|
||||
).
|
||||
ineq_one( nonstrict, X, K, I) :-
|
||||
( arith_eval(K>0) ->
|
||||
( arith_eval(I=:=0) ->
|
||||
ineq_one_n_p_0( X)
|
||||
;
|
||||
arith_eval( I/K, Inhom),
|
||||
ineq_one_n_p_i( X, Inhom)
|
||||
)
|
||||
;
|
||||
( arith_eval(I=:=0) ->
|
||||
ineq_one_n_n_0( X)
|
||||
;
|
||||
arith_eval( -I/K, Inhom),
|
||||
ineq_one_n_n_i( X, Inhom)
|
||||
)
|
||||
).
|
||||
|
||||
/*
|
||||
ineq_one( Strictness, X, K, I) :-
|
||||
get_atts( X, lin(LinX)),
|
||||
!, % old variable, this is deref
|
||||
decompose( LinX, OrdX, _, Ix),
|
||||
ineq_one_old( OrdX, K, I, Strictness, X, Ix).
|
||||
ineq_one( Strictness, X, K, I) :- % new variable, nothing depends on it
|
||||
arith_eval( -I/K, Bound),
|
||||
ineq_one_new( Strictness, X, K, Bound).
|
||||
|
||||
ineq_one_new( strict, X, K, Bound) :-
|
||||
arith_eval( 1, One),
|
||||
( arith_eval( K < 0) ->
|
||||
var_intern( t_l(Bound), X, 2'10)
|
||||
;
|
||||
var_intern( t_u(Bound), X, 2'01)
|
||||
).
|
||||
ineq_one_new( nonstrict, X, K, Bound) :-
|
||||
arith_eval( 1, One),
|
||||
( arith_eval( K < 0) ->
|
||||
var_intern( t_l(Bound), X, 2'00)
|
||||
;
|
||||
var_intern( t_u(Bound), X, 2'00)
|
||||
).
|
||||
|
||||
|
||||
ineq_one_old( [], K, I, Strictness, _X, Ix) :-
|
||||
arith_eval( K*Ix+I, Inhom),
|
||||
ineq_ground( Strictness, Inhom).
|
||||
%
|
||||
% here we would have the choice to bound X or Y
|
||||
%
|
||||
ineq_one_old( [Y*Ky|Tail], K, I, Strictness, X, Ix) :-
|
||||
( Tail = [],
|
||||
arith_eval( K*Ky, Coeff),
|
||||
arith_eval( -(K*Ix+I)/Coeff, Bound),
|
||||
update_indep( Strictness, Y, Coeff, Bound)
|
||||
; Tail = [_|_],
|
||||
arith_eval( -I/K, Bound),
|
||||
update_dep( Strictness, X, K, Bound)
|
||||
).
|
||||
|
||||
update_dep( strict, X, K, Bound) :-
|
||||
get_atts( X, [lin(Lin),type(Type),strictness(Old)]),
|
||||
( arith_eval( K < 0) ->
|
||||
udls( Type, X, Lin, Bound, Old)
|
||||
;
|
||||
udus( Type, X, Lin, Bound, Old)
|
||||
).
|
||||
update_dep( nonstrict, X, K, Bound) :-
|
||||
get_atts( X, [lin(Lin),type(Type),strictness(Old)]),
|
||||
( arith_eval( K < 0) ->
|
||||
udl( Type, X, Lin, Bound, Old)
|
||||
;
|
||||
udu( Type, X, Lin, Bound, Old)
|
||||
).
|
||||
*/
|
||||
|
||||
% --------------------------- strict ----------------------------
|
||||
|
||||
ineq_one_s_p_0( X) :-
|
||||
get_atts( X, lin(LinX)),
|
||||
!, % old variable, this is deref
|
||||
decompose( LinX, OrdX, _, Ix),
|
||||
ineq_one_old_s_p_0( OrdX, X, Ix).
|
||||
ineq_one_s_p_0( X) :- % new variable, nothing depends on it
|
||||
arith_eval( 0, Zero),
|
||||
var_intern( t_u(Zero), X, 2'01).
|
||||
|
||||
ineq_one_s_n_0( X) :-
|
||||
get_atts( X, lin(LinX)),
|
||||
!,
|
||||
decompose( LinX, OrdX, _, Ix),
|
||||
ineq_one_old_s_n_0( OrdX, X, Ix).
|
||||
ineq_one_s_n_0( X) :-
|
||||
arith_eval( 0, Zero),
|
||||
var_intern( t_l(Zero), X, 2'10).
|
||||
|
||||
ineq_one_s_p_i( X, I) :-
|
||||
get_atts( X, lin(LinX)),
|
||||
!,
|
||||
decompose( LinX, OrdX, _, Ix),
|
||||
ineq_one_old_s_p_i( OrdX, I, X, Ix).
|
||||
ineq_one_s_p_i( X, I) :-
|
||||
arith_eval( -I, Bound),
|
||||
var_intern( t_u(Bound), X, 2'01).
|
||||
|
||||
ineq_one_s_n_i( X, I) :-
|
||||
get_atts( X, lin(LinX)),
|
||||
!,
|
||||
decompose( LinX, OrdX, _, Ix),
|
||||
ineq_one_old_s_n_i( OrdX, I, X, Ix).
|
||||
ineq_one_s_n_i( X, I) :-
|
||||
var_intern( t_l(I), X, 2'10).
|
||||
|
||||
ineq_one_old_s_p_0( [], _, Ix) :-
|
||||
arith_eval( Ix < 0).
|
||||
ineq_one_old_s_p_0( [Y*Ky|Tail], X, Ix) :-
|
||||
( Tail = [],
|
||||
arith_eval( -Ix/Ky, Bound),
|
||||
update_indep( strict, Y, Ky, Bound)
|
||||
; Tail = [_|_],
|
||||
arith_eval( 0, Zero),
|
||||
get_atts( X, [lin(Lin),type(Type),strictness(Old)]),
|
||||
udus( Type, X, Lin, Zero, Old)
|
||||
).
|
||||
|
||||
ineq_one_old_s_n_0( [], _, Ix) :-
|
||||
arith_eval( Ix > 0).
|
||||
ineq_one_old_s_n_0( [Y*Ky|Tail], X, Ix) :-
|
||||
( Tail = [],
|
||||
arith_eval( -Ky, Coeff),
|
||||
arith_eval( Ix/Coeff, Bound),
|
||||
update_indep( strict, Y, Coeff, Bound)
|
||||
; Tail = [_|_],
|
||||
arith_eval( 0, Zero),
|
||||
get_atts( X, [lin(Lin),type(Type),strictness(Old)]),
|
||||
udls( Type, X, Lin, Zero, Old)
|
||||
).
|
||||
|
||||
ineq_one_old_s_p_i( [], I, _, Ix) :-
|
||||
arith_eval( Ix+I < 0).
|
||||
ineq_one_old_s_p_i( [Y*Ky|Tail], I, X, Ix) :-
|
||||
( Tail = [],
|
||||
arith_eval( -(Ix+I)/Ky, Bound),
|
||||
update_indep( strict, Y, Ky, Bound)
|
||||
; Tail = [_|_],
|
||||
arith_eval( -I, Bound),
|
||||
get_atts( X, [lin(Lin),type(Type),strictness(Old)]),
|
||||
udus( Type, X, Lin, Bound, Old)
|
||||
).
|
||||
|
||||
ineq_one_old_s_n_i( [], I, _, Ix) :-
|
||||
arith_eval( -Ix+I < 0).
|
||||
ineq_one_old_s_n_i( [Y*Ky|Tail], I, X, Ix) :-
|
||||
( Tail = [],
|
||||
arith_eval( -Ky, Coeff),
|
||||
arith_eval( (Ix-I)/Coeff, Bound),
|
||||
update_indep( strict, Y, Coeff, Bound)
|
||||
; Tail = [_|_],
|
||||
get_atts( X, [lin(Lin),type(Type),strictness(Old)]),
|
||||
udls( Type, X, Lin, I, Old)
|
||||
).
|
||||
|
||||
% -------------------------- nonstrict --------------------------
|
||||
|
||||
ineq_one_n_p_0( X) :-
|
||||
get_atts( X, lin(LinX)),
|
||||
!, % old variable, this is deref
|
||||
decompose( LinX, OrdX, _, Ix),
|
||||
ineq_one_old_n_p_0( OrdX, X, Ix).
|
||||
ineq_one_n_p_0( X) :- % new variable, nothing depends on it
|
||||
arith_eval( 0, Zero),
|
||||
var_intern( t_u(Zero), X, 2'00).
|
||||
|
||||
ineq_one_n_n_0( X) :-
|
||||
get_atts( X, lin(LinX)),
|
||||
!,
|
||||
decompose( LinX, OrdX, _, Ix),
|
||||
ineq_one_old_n_n_0( OrdX, X, Ix).
|
||||
ineq_one_n_n_0( X) :-
|
||||
arith_eval( 0, Zero),
|
||||
var_intern( t_l(Zero), X, 2'00).
|
||||
|
||||
ineq_one_n_p_i( X, I) :-
|
||||
get_atts( X, lin(LinX)),
|
||||
!,
|
||||
decompose( LinX, OrdX, _, Ix),
|
||||
ineq_one_old_n_p_i( OrdX, I, X, Ix).
|
||||
ineq_one_n_p_i( X, I) :-
|
||||
arith_eval( -I, Bound),
|
||||
var_intern( t_u(Bound), X, 2'00).
|
||||
|
||||
ineq_one_n_n_i( X, I) :-
|
||||
get_atts( X, lin(LinX)),
|
||||
!,
|
||||
decompose( LinX, OrdX, _, Ix),
|
||||
ineq_one_old_n_n_i( OrdX, I, X, Ix).
|
||||
ineq_one_n_n_i( X, I) :-
|
||||
var_intern( t_l(I), X, 2'00).
|
||||
|
||||
ineq_one_old_n_p_0( [], _, Ix) :-
|
||||
arith_eval( Ix =< 0).
|
||||
ineq_one_old_n_p_0( [Y*Ky|Tail], X, Ix) :-
|
||||
( Tail = [],
|
||||
arith_eval( -Ix/Ky, Bound),
|
||||
update_indep( nonstrict, Y, Ky, Bound)
|
||||
; Tail = [_|_],
|
||||
arith_eval( 0, Zero),
|
||||
get_atts( X, [lin(Lin),type(Type),strictness(Old)]),
|
||||
udu( Type, X, Lin, Zero, Old)
|
||||
).
|
||||
|
||||
ineq_one_old_n_n_0( [], _, Ix) :-
|
||||
arith_eval( Ix >= 0).
|
||||
ineq_one_old_n_n_0( [Y*Ky|Tail], X, Ix) :-
|
||||
( Tail = [],
|
||||
arith_eval( -Ky, Coeff),
|
||||
arith_eval( Ix/Coeff, Bound),
|
||||
update_indep( nonstrict, Y, Coeff, Bound)
|
||||
; Tail = [_|_],
|
||||
arith_eval( 0, Zero),
|
||||
get_atts( X, [lin(Lin),type(Type),strictness(Old)]),
|
||||
udl( Type, X, Lin, Zero, Old)
|
||||
).
|
||||
|
||||
ineq_one_old_n_p_i( [], I, _, Ix) :-
|
||||
arith_eval( Ix+I =< 0).
|
||||
ineq_one_old_n_p_i( [Y*Ky|Tail], I, X, Ix) :-
|
||||
( Tail = [],
|
||||
arith_eval( -(Ix+I)/Ky, Bound),
|
||||
update_indep( nonstrict, Y, Ky, Bound)
|
||||
; Tail = [_|_],
|
||||
arith_eval( -I, Bound),
|
||||
get_atts( X, [lin(Lin),type(Type),strictness(Old)]),
|
||||
udu( Type, X, Lin, Bound, Old)
|
||||
).
|
||||
|
||||
ineq_one_old_n_n_i( [], I, _, Ix) :-
|
||||
arith_eval( -Ix+I =< 0).
|
||||
ineq_one_old_n_n_i( [Y*Ky|Tail], I, X, Ix) :-
|
||||
( Tail = [],
|
||||
arith_eval( -Ky, Coeff),
|
||||
arith_eval( (Ix-I)/Coeff, Bound),
|
||||
update_indep( nonstrict, Y, Coeff, Bound)
|
||||
; Tail = [_|_],
|
||||
get_atts( X, [lin(Lin),type(Type),strictness(Old)]),
|
||||
udl( Type, X, Lin, I, Old)
|
||||
).
|
||||
|
||||
% ---------------------------------------------------------------
|
||||
|
||||
|
||||
ineq_more( [], I, _, Strictness) :- ineq_ground( Strictness, I).
|
||||
ineq_more( [X*K|Tail], Id, Lind, Strictness) :-
|
||||
( Tail = [], % one var: update bound instead of slack introduction
|
||||
get_or_add_class( X, _),
|
||||
arith_eval( -Id/K, Bound),
|
||||
update_indep( Strictness, X, K, Bound)
|
||||
; Tail = [_|_],
|
||||
ineq_more( Strictness, Lind)
|
||||
).
|
||||
|
||||
ineq_more( strict, Lind) :-
|
||||
( unconstrained( Lind, U,K, Rest) -> % never fails, no implied value
|
||||
arith_eval( 0, Z),
|
||||
arith_eval( 1, One),
|
||||
var_intern( t_l(Z), S, 2'10),
|
||||
arith_eval( -1/K, Ki),
|
||||
add_linear_ff( Rest, Ki, [Z,Z,S*One], Ki, LinU),
|
||||
decompose( LinU, Hu, _, _),
|
||||
get_or_add_class( U, Class),
|
||||
same_class( Hu, Class),
|
||||
backsubst( U, LinU)
|
||||
;
|
||||
arith_eval( 0, Z),
|
||||
var_with_def_intern( t_u(Z), S, Lind, 2'01),
|
||||
basis_add( S, _),
|
||||
determine_active_dec( Lind),
|
||||
reconsider( S)
|
||||
).
|
||||
ineq_more( nonstrict, Lind) :-
|
||||
( unconstrained( Lind, U,K, Rest) -> % never fails, no implied value
|
||||
arith_eval( 0, Z),
|
||||
arith_eval( 1, One),
|
||||
var_intern( t_l(Z), S, 2'00),
|
||||
arith_eval( -1/K, Ki),
|
||||
add_linear_ff( Rest, Ki, [Z,Z,S*One], Ki, LinU),
|
||||
decompose( LinU, Hu, _, _),
|
||||
get_or_add_class( U, Class),
|
||||
same_class( Hu, Class),
|
||||
backsubst( U, LinU)
|
||||
;
|
||||
arith_eval( 0, Z),
|
||||
var_with_def_intern( t_u(Z), S, Lind, 2'00),
|
||||
basis_add( S, _),
|
||||
determine_active_dec( Lind),
|
||||
reconsider( S)
|
||||
).
|
||||
|
||||
update_indep( strict, X, K, Bound) :-
|
||||
get_atts( X, [lin(Lin),type(Type),strictness(Old)]),
|
||||
( arith_eval( K < 0) ->
|
||||
uils( Type, X, Lin, Bound, Old)
|
||||
;
|
||||
uius( Type, X, Lin, Bound, Old)
|
||||
).
|
||||
update_indep( nonstrict, X, K, Bound) :-
|
||||
get_atts( X, [lin(Lin),type(Type),strictness(Old)]),
|
||||
( arith_eval( K < 0) ->
|
||||
uil( Type, X, Lin, Bound, Old)
|
||||
;
|
||||
uiu( Type, X, Lin, Bound, Old)
|
||||
).
|
||||
|
||||
|
||||
% ---------------------------------------------------------------------------------------
|
||||
|
||||
%
|
||||
% Update a bound on a var xi
|
||||
%
|
||||
% a) independent variable
|
||||
%
|
||||
% a1) update inactive bound: done
|
||||
%
|
||||
% a2) update active bound:
|
||||
% Determine [lu]b including most constraining row R
|
||||
% If we are within: done
|
||||
% else pivot(R,xi) and introduce bound via (b)
|
||||
%
|
||||
% a3) introduce a bound on an unconstrained var:
|
||||
% All vars that depend on xi are unconstrained (invariant) ->
|
||||
% the bound cannot invalidate any Lhs
|
||||
%
|
||||
% b) dependent variable
|
||||
%
|
||||
% repair upper or lower (maybe just swap with an unconstrained var from Rhs)
|
||||
%
|
||||
|
||||
%
|
||||
% Sign = 1,0,-1 means inside,at,outside
|
||||
%
|
||||
|
||||
udl( t_none, X, Lin, Bound, _Sold) :-
|
||||
put_atts( X, [type(t_l(Bound)),strictness(2'00)]),
|
||||
( unconstrained( Lin, Uc,Kuc, Rest) ->
|
||||
arith_eval( -1/Kuc, Ki),
|
||||
arith_eval( 0, Z),
|
||||
arith_eval( -1, Mone),
|
||||
add_linear_ff( Rest, Ki, [Z,Z,X*Mone], Ki, LinU),
|
||||
backsubst( Uc, LinU)
|
||||
;
|
||||
basis_add( X, _),
|
||||
determine_active_inc( Lin),
|
||||
reconsider( X)
|
||||
).
|
||||
udl( t_l(L), X, Lin, Bound, Sold) :-
|
||||
case_signum( Bound-L,
|
||||
true,
|
||||
true,
|
||||
(
|
||||
Strict is Sold /\ 2'01,
|
||||
put_atts( X, [type(t_l(Bound)),strictness(Strict)]),
|
||||
reconsider_lower( X, Lin, Bound)
|
||||
)).
|
||||
udl( t_u(U), X, Lin, Bound, _Sold) :-
|
||||
case_signum( U-Bound,
|
||||
fail,
|
||||
solve_bound( Lin, Bound),
|
||||
(
|
||||
put_atts( X, type(t_lu(Bound,U))),
|
||||
reconsider_lower( X, Lin, Bound)
|
||||
)).
|
||||
udl( t_lu(L,U), X, Lin, Bound, Sold) :-
|
||||
case_signum( Bound-L,
|
||||
true,
|
||||
true,
|
||||
(
|
||||
case_signum( U-Bound,
|
||||
fail,
|
||||
(
|
||||
Sold /\ 2'01 =:= 0,
|
||||
solve_bound( Lin, Bound)
|
||||
),
|
||||
(
|
||||
Strict is Sold /\ 2'01,
|
||||
put_atts( X, [type(t_lu(Bound,U)),strictness(Strict)]),
|
||||
reconsider_lower( X, Lin, Bound)
|
||||
))
|
||||
)).
|
||||
|
||||
udls( t_none, X, Lin, Bound, _Sold) :-
|
||||
put_atts( X, [type(t_l(Bound)),strictness(2'10)]),
|
||||
( unconstrained( Lin, Uc,Kuc, Rest) ->
|
||||
arith_eval( -1/Kuc, Ki),
|
||||
arith_eval( -1, Mone),
|
||||
arith_eval( 0, Z),
|
||||
add_linear_ff( Rest, Ki, [Z,Z,X*Mone], Ki, LinU),
|
||||
backsubst( Uc, LinU)
|
||||
;
|
||||
basis_add( X, _),
|
||||
determine_active_inc( Lin),
|
||||
reconsider( X)
|
||||
).
|
||||
udls( t_l(L), X, Lin, Bound, Sold) :-
|
||||
case_signum( Bound-L,
|
||||
true,
|
||||
(
|
||||
Strict is Sold \/ 2'10,
|
||||
put_atts( X, strictness(Strict))
|
||||
),
|
||||
(
|
||||
Strict is Sold \/ 2'10,
|
||||
put_atts( X, [type(t_l(Bound)),strictness(Strict)]),
|
||||
reconsider_lower( X, Lin, Bound)
|
||||
)).
|
||||
udls( t_u(U), X, Lin, Bound, Sold) :-
|
||||
arith_eval( U>Bound),
|
||||
Strict is Sold \/ 2'10,
|
||||
put_atts( X, [type(t_lu(Bound,U)),strictness(Strict)]),
|
||||
reconsider_lower( X, Lin, Bound).
|
||||
udls( t_lu(L,U), X, Lin, Bound, Sold) :-
|
||||
case_signum( Bound-L,
|
||||
true,
|
||||
(
|
||||
Strict is Sold \/ 2'10,
|
||||
put_atts( X, strictness(Strict))
|
||||
),
|
||||
(
|
||||
arith_eval( U>Bound),
|
||||
Strict is Sold \/ 2'10,
|
||||
put_atts( X, [type(t_lu(Bound,U)),strictness(Strict)]),
|
||||
reconsider_lower( X, Lin, Bound)
|
||||
)).
|
||||
|
||||
|
||||
udu( t_none, X, Lin, Bound, _Sold) :-
|
||||
put_atts( X, [type(t_u(Bound)),strictness(2'00)]),
|
||||
( unconstrained( Lin, Uc,Kuc, Rest) ->
|
||||
arith_eval( -1/Kuc, Ki),
|
||||
arith_eval( -1, Mone),
|
||||
arith_eval( 0, Z),
|
||||
add_linear_ff( Rest, Ki, [Z,Z,X*Mone], Ki, LinU),
|
||||
backsubst( Uc, LinU)
|
||||
;
|
||||
basis_add( X, _),
|
||||
determine_active_dec( Lin),
|
||||
reconsider( X)
|
||||
).
|
||||
udu( t_u(U), X, Lin, Bound, Sold) :-
|
||||
case_signum( U-Bound,
|
||||
true,
|
||||
true,
|
||||
(
|
||||
Strict is Sold /\ 2'10,
|
||||
put_atts( X, [type(t_u(Bound)),strictness(Strict)]),
|
||||
reconsider_upper( X, Lin, Bound)
|
||||
)).
|
||||
udu( t_l(L), X, Lin, Bound, _Sold) :-
|
||||
case_signum( Bound-L,
|
||||
fail,
|
||||
solve_bound( Lin, Bound),
|
||||
(
|
||||
put_atts( X, type(t_lu(L,Bound))),
|
||||
reconsider_upper( X, Lin, Bound)
|
||||
)).
|
||||
udu( t_lu(L,U), X, Lin, Bound, Sold) :-
|
||||
case_signum( U-Bound,
|
||||
true,
|
||||
true,
|
||||
(
|
||||
case_signum( Bound-L,
|
||||
fail,
|
||||
(
|
||||
Sold /\ 2'10 =:= 0,
|
||||
solve_bound( Lin, Bound)
|
||||
),
|
||||
(
|
||||
Strict is Sold /\ 2'10,
|
||||
put_atts( X, [type(t_lu(L,Bound)),strictness(Strict)]),
|
||||
reconsider_upper( X, Lin, Bound)
|
||||
))
|
||||
)).
|
||||
|
||||
udus( t_none, X, Lin, Bound, _Sold) :-
|
||||
put_atts( X, [type(t_u(Bound)),strictness(2'01)]),
|
||||
( unconstrained( Lin, Uc,Kuc, Rest) ->
|
||||
arith_eval( -1/Kuc, Ki),
|
||||
arith_eval( -1, Mone),
|
||||
arith_eval( 0, Z),
|
||||
add_linear_ff( Rest, Ki, [Z,Z,X*Mone], Ki, LinU),
|
||||
backsubst( Uc, LinU)
|
||||
;
|
||||
basis_add( X, _),
|
||||
determine_active_dec( Lin),
|
||||
reconsider( X)
|
||||
).
|
||||
udus( t_u(U), X, Lin, Bound, Sold) :-
|
||||
case_signum( U-Bound,
|
||||
true,
|
||||
(
|
||||
Strict is Sold \/ 2'01,
|
||||
put_atts( X, strictness(Strict))
|
||||
),
|
||||
(
|
||||
Strict is Sold \/ 2'01,
|
||||
put_atts( X, [type(t_u(Bound)),strictness(Strict)]),
|
||||
reconsider_upper( X, Lin, Bound)
|
||||
)).
|
||||
udus( t_l(L), X, Lin, Bound, Sold) :-
|
||||
arith_eval( Bound>L),
|
||||
Strict is Sold \/ 2'01,
|
||||
put_atts( X, [type(t_lu(L,Bound)),strictness(Strict)]),
|
||||
reconsider_upper( X, Lin, Bound).
|
||||
udus( t_lu(L,U), X, Lin, Bound, Sold) :-
|
||||
case_signum( U-Bound,
|
||||
true,
|
||||
(
|
||||
Strict is Sold \/ 2'01,
|
||||
put_atts( X, strictness(Strict))
|
||||
),
|
||||
(
|
||||
arith_eval( Bound>L),
|
||||
Strict is Sold \/ 2'01,
|
||||
put_atts( X, [type(t_lu(L,Bound)),strictness(Strict)]),
|
||||
reconsider_upper( X, Lin, Bound)
|
||||
)).
|
||||
|
||||
uiu( t_none, X, _Lin, Bound, _) :-
|
||||
put_atts( X, [type(t_u(Bound)),strictness(2'00)]).
|
||||
uiu( t_u(U), X, _Lin, Bound, Sold) :-
|
||||
case_signum( U-Bound,
|
||||
true,
|
||||
true,
|
||||
(
|
||||
Strict is Sold /\ 2'10,
|
||||
put_atts( X, [type(t_u(Bound)),strictness(Strict)])
|
||||
)).
|
||||
uiu( t_l(L), X, Lin, Bound, _Sold) :-
|
||||
case_signum( Bound-L,
|
||||
fail,
|
||||
solve_bound( Lin, Bound),
|
||||
put_atts( X, type(t_lu(L,Bound)))).
|
||||
uiu( t_L(L), X, Lin, Bound, _Sold) :-
|
||||
case_signum( Bound-L,
|
||||
fail,
|
||||
solve_bound( Lin, Bound),
|
||||
put_atts( X, type(t_Lu(L,Bound)))).
|
||||
uiu( t_lu(L,U), X, Lin, Bound, Sold) :-
|
||||
case_signum( U-Bound,
|
||||
true,
|
||||
true,
|
||||
(
|
||||
case_signum( Bound-L,
|
||||
fail,
|
||||
(
|
||||
Sold /\ 2'10 =:= 0,
|
||||
solve_bound( Lin, Bound)
|
||||
),
|
||||
(
|
||||
Strict is Sold /\ 2'10,
|
||||
put_atts( X, [type(t_lu(L,Bound)),strictness(Strict)])
|
||||
))
|
||||
)).
|
||||
uiu( t_Lu(L,U), X, Lin, Bound, Sold) :-
|
||||
case_signum( U-Bound,
|
||||
true,
|
||||
true,
|
||||
(
|
||||
case_signum( Bound-L,
|
||||
fail,
|
||||
(
|
||||
Sold /\ 2'10 =:= 0,
|
||||
solve_bound( Lin, Bound)
|
||||
),
|
||||
(
|
||||
Strict is Sold /\ 2'10,
|
||||
put_atts( X, [type(t_Lu(L,Bound)),strictness(Strict)])
|
||||
))
|
||||
)).
|
||||
%
|
||||
% update active:
|
||||
%
|
||||
uiu( t_U(U), X, _Lin, Bound, Sold) :-
|
||||
case_signum( U-Bound,
|
||||
true,
|
||||
true,
|
||||
(
|
||||
Strict is Sold /\ 2'10,
|
||||
( lb( X, Vlb-Vb-Lb),
|
||||
arith_eval( Bound =< Lb+U) ->
|
||||
put_atts( X, [type(t_U(Bound)),strictness(Strict)]),
|
||||
pivot_a( Vlb, X, Vb, t_u(Bound)),
|
||||
reconsider( X)
|
||||
;
|
||||
put_atts( X, [type(t_U(Bound)),strictness(Strict)]),
|
||||
arith_eval( Bound-U, Delta),
|
||||
backsubst_delta( X, Delta)
|
||||
)
|
||||
)).
|
||||
uiu( t_lU(L,U), X, Lin, Bound, Sold) :-
|
||||
case_signum( U-Bound,
|
||||
true,
|
||||
true,
|
||||
(
|
||||
case_signum( Bound-L,
|
||||
fail,
|
||||
(
|
||||
Sold /\ 2'10 =:= 0,
|
||||
solve_bound( Lin, Bound)
|
||||
),
|
||||
(
|
||||
Strict is Sold /\ 2'10,
|
||||
( lb( X, Vlb-Vb-Lb),
|
||||
arith_eval( Bound =< Lb+U) ->
|
||||
put_atts( X, [type(t_lU(L,Bound)),strictness(Strict)]),
|
||||
pivot_a( Vlb, X, Vb, t_lu(L,Bound)),
|
||||
reconsider( X)
|
||||
;
|
||||
put_atts( X, [type(t_lU(L,Bound)),strictness(Strict)]),
|
||||
arith_eval( Bound-U, Delta),
|
||||
backsubst_delta( X, Delta)
|
||||
)
|
||||
))
|
||||
)).
|
||||
|
||||
|
||||
uius( t_none, X, _Lin, Bound, _Sold) :-
|
||||
put_atts( X, [type(t_u(Bound)),strictness(2'01)]).
|
||||
uius( t_u(U), X, _Lin, Bound, Sold) :-
|
||||
case_signum( U-Bound,
|
||||
true,
|
||||
(
|
||||
Strict is Sold \/ 2'01,
|
||||
put_atts( X, strictness(Strict))
|
||||
),
|
||||
(
|
||||
Strict is Sold \/ 2'01,
|
||||
put_atts( X, [type(t_u(Bound)),strictness(Strict)])
|
||||
)).
|
||||
uius( t_l(L), X, _Lin, Bound, Sold) :-
|
||||
arith_eval( Bound>L),
|
||||
Strict is Sold \/ 2'01,
|
||||
put_atts( X, [type(t_lu(L,Bound)),strictness(Strict)]).
|
||||
uius( t_L(L), X, _Lin, Bound, Sold) :-
|
||||
arith_eval( Bound>L),
|
||||
Strict is Sold \/ 2'01,
|
||||
put_atts( X, [type(t_Lu(L,Bound)),strictness(Strict)]).
|
||||
uius( t_lu(L,U), X, _Lin, Bound, Sold) :-
|
||||
case_signum( U-Bound,
|
||||
true,
|
||||
(
|
||||
Strict is Sold \/ 2'01,
|
||||
put_atts( X, strictness(Strict))
|
||||
),
|
||||
(
|
||||
arith_eval( Bound>L),
|
||||
Strict is Sold \/ 2'01,
|
||||
put_atts( X, [type(t_lu(L,Bound)),strictness(Strict)])
|
||||
)).
|
||||
uius( t_Lu(L,U), X, _Lin, Bound, Sold) :-
|
||||
case_signum( U-Bound,
|
||||
true,
|
||||
(
|
||||
Strict is Sold \/ 2'01,
|
||||
put_atts( X, strictness(Strict))
|
||||
),
|
||||
(
|
||||
arith_eval( Bound>L),
|
||||
Strict is Sold \/ 2'01,
|
||||
put_atts( X, [type(t_Lu(L,Bound)),strictness(Strict)])
|
||||
)).
|
||||
%
|
||||
% update active:
|
||||
%
|
||||
uius( t_U(U), X, _Lin, Bound, Sold) :-
|
||||
case_signum( U-Bound,
|
||||
true,
|
||||
(
|
||||
Strict is Sold \/ 2'01,
|
||||
put_atts( X, strictness(Strict))
|
||||
),
|
||||
(
|
||||
Strict is Sold \/ 2'01,
|
||||
( lb( X, Vlb-Vb-Lb),
|
||||
arith_eval( Bound =< Lb+U) ->
|
||||
put_atts( X, [type(t_U(Bound)),strictness(Strict)]),
|
||||
pivot_a( Vlb, X, Vb, t_u(Bound)),
|
||||
reconsider( X)
|
||||
;
|
||||
put_atts( X, [type(t_U(Bound)),strictness(Strict)]),
|
||||
arith_eval( Bound-U, Delta),
|
||||
backsubst_delta( X, Delta)
|
||||
)
|
||||
)).
|
||||
uius( t_lU(L,U), X, _Lin, Bound, Sold) :-
|
||||
case_signum( U-Bound,
|
||||
true,
|
||||
(
|
||||
Strict is Sold \/ 2'01,
|
||||
put_atts( X, strictness(Strict))
|
||||
),
|
||||
(
|
||||
arith_eval( Bound>L),
|
||||
Strict is Sold \/ 2'01,
|
||||
( lb( X, Vlb-Vb-Lb),
|
||||
arith_eval( Bound =< Lb+U) ->
|
||||
put_atts( X, [type(t_lU(L,Bound)),strictness(Strict)]),
|
||||
pivot_a( Vlb, X, Vb, t_lu(L,Bound)),
|
||||
reconsider( X)
|
||||
;
|
||||
put_atts( X, [type(t_lU(L,Bound)),strictness(Strict)]),
|
||||
arith_eval( Bound-U, Delta),
|
||||
backsubst_delta( X, Delta)
|
||||
)
|
||||
)).
|
||||
|
||||
|
||||
uil( t_none, X, _Lin, Bound, _Sold) :-
|
||||
put_atts( X, [type(t_l(Bound)),strictness(2'00)]).
|
||||
uil( t_l(L), X, _Lin, Bound, Sold) :-
|
||||
case_signum( Bound-L,
|
||||
true,
|
||||
true,
|
||||
(
|
||||
Strict is Sold /\ 2'01,
|
||||
put_atts( X, [type(t_l(Bound)),strictness(Strict)])
|
||||
)).
|
||||
uil( t_u(U), X, Lin, Bound, _Sold) :-
|
||||
case_signum( U-Bound,
|
||||
fail,
|
||||
solve_bound( Lin, Bound),
|
||||
put_atts( X, type(t_lu(Bound,U)))).
|
||||
uil( t_U(U), X, Lin, Bound, _Sold) :-
|
||||
case_signum( U-Bound,
|
||||
fail,
|
||||
solve_bound( Lin, Bound),
|
||||
put_atts( X, type(t_lU(Bound,U)))).
|
||||
uil( t_lu(L,U), X, Lin, Bound, Sold) :-
|
||||
case_signum( Bound-L,
|
||||
true,
|
||||
true,
|
||||
(
|
||||
case_signum( U-Bound,
|
||||
fail,
|
||||
(
|
||||
Sold /\ 2'01 =:= 0,
|
||||
solve_bound( Lin, Bound)
|
||||
),
|
||||
(
|
||||
Strict is Sold /\ 2'01,
|
||||
put_atts( X, [type(t_lu(Bound,U)),strictness(Strict)])
|
||||
))
|
||||
)).
|
||||
uil( t_lU(L,U), X, Lin, Bound, Sold) :-
|
||||
case_signum( Bound-L,
|
||||
true,
|
||||
true,
|
||||
(
|
||||
case_signum( U-Bound,
|
||||
fail,
|
||||
(
|
||||
Sold /\ 2'01 =:= 0,
|
||||
solve_bound( Lin, Bound)
|
||||
),
|
||||
(
|
||||
Strict is Sold /\ 2'01,
|
||||
put_atts( X, [type(t_lU(Bound,U)),strictness(Strict)])
|
||||
))
|
||||
)).
|
||||
%
|
||||
% update active bound: % { a>=100,d=<5000,c>=10,-2*a+d-c=10,a>=2490 }.
|
||||
%
|
||||
uil( t_L(L), X, _Lin, Bound, Sold) :-
|
||||
case_signum( Bound-L,
|
||||
true,
|
||||
true,
|
||||
(
|
||||
Strict is Sold /\ 2'01,
|
||||
( ub( X, Vub-Vb-Ub),
|
||||
arith_eval( Bound >= Ub+L) ->
|
||||
put_atts( X, [type(t_L(Bound)),strictness(Strict)]),
|
||||
pivot_a( Vub, X, Vb, t_l(Bound)),
|
||||
reconsider( X)
|
||||
; %
|
||||
% max(X) >= Ub, no implied value missed
|
||||
%
|
||||
put_atts( X, [type(t_L(Bound)),strictness(Strict)]),
|
||||
arith_eval( Bound-L, Delta),
|
||||
backsubst_delta( X, Delta)
|
||||
)
|
||||
)).
|
||||
uil( t_Lu(L,U), X, Lin, Bound, Sold) :-
|
||||
case_signum( Bound-L,
|
||||
true,
|
||||
true,
|
||||
(
|
||||
case_signum( U-Bound,
|
||||
fail,
|
||||
(
|
||||
Sold /\ 2'01 =:= 0,
|
||||
solve_bound( Lin, Bound)
|
||||
),
|
||||
(
|
||||
Strict is Sold /\ 2'01,
|
||||
( ub( X, Vub-Vb-Ub),
|
||||
arith_eval( Bound >= Ub+L) ->
|
||||
put_atts( X, [type(t_Lu(Bound,U)),strictness(Strict)]),
|
||||
pivot_a( Vub, X, Vb, t_lu(Bound,U)),
|
||||
reconsider( X)
|
||||
;
|
||||
put_atts( X, [type(t_Lu(Bound,U)),strictness(Strict)]),
|
||||
arith_eval( Bound-L, Delta),
|
||||
backsubst_delta( X, Delta)
|
||||
)
|
||||
)))).
|
||||
|
||||
|
||||
uils( t_none, X, _Lin, Bound, _Sold) :-
|
||||
put_atts( X, [type(t_l(Bound)),strictness(2'10)]).
|
||||
uils( t_l(L), X, _Lin, Bound, Sold) :-
|
||||
case_signum( Bound-L,
|
||||
true,
|
||||
(
|
||||
Strict is Sold \/ 2'10,
|
||||
put_atts( X, strictness(Strict))
|
||||
),
|
||||
(
|
||||
Strict is Sold \/ 2'10,
|
||||
put_atts( X, [type(t_l(Bound)),strictness(Strict)])
|
||||
)).
|
||||
uils( t_u(U), X, _Lin, Bound, Sold) :-
|
||||
arith_eval( U>Bound),
|
||||
Strict is Sold \/ 2'10,
|
||||
put_atts( X, [type(t_lu(Bound,U)),strictness(Strict)]).
|
||||
uils( t_U(U), X, _Lin, Bound, Sold) :-
|
||||
arith_eval( U>Bound),
|
||||
Strict is Sold \/ 2'10,
|
||||
put_atts( X, [type(t_lU(Bound,U)),strictness(Strict)]).
|
||||
uils( t_lu(L,U), X, _Lin, Bound, Sold) :-
|
||||
case_signum( Bound-L,
|
||||
true,
|
||||
(
|
||||
Strict is Sold \/ 2'10,
|
||||
put_atts( X, strictness(Strict))
|
||||
),
|
||||
(
|
||||
arith_eval( U>Bound),
|
||||
Strict is Sold \/ 2'10,
|
||||
put_atts( X, [type(t_lu(Bound,U)),strictness(Strict)])
|
||||
)).
|
||||
uils( t_lU(L,U), X, _Lin, Bound, Sold) :-
|
||||
case_signum( Bound-L,
|
||||
true,
|
||||
(
|
||||
Strict is Sold \/ 2'10,
|
||||
put_atts( X, strictness(Strict))
|
||||
),
|
||||
(
|
||||
arith_eval( U>Bound),
|
||||
Strict is Sold \/ 2'10,
|
||||
put_atts( X, [type(t_lU(Bound,U)),strictness(Strict)])
|
||||
)).
|
||||
%
|
||||
% update active bound:
|
||||
%
|
||||
uils( t_L(L), X, _Lin, Bound, Sold) :-
|
||||
case_signum( Bound-L,
|
||||
true,
|
||||
(
|
||||
Strict is Sold \/ 2'10,
|
||||
put_atts( X, strictness(Strict))
|
||||
),
|
||||
(
|
||||
Strict is Sold \/ 2'10,
|
||||
( ub( X, Vub-Vb-Ub),
|
||||
arith_eval( Bound >= Ub+L) ->
|
||||
put_atts( X, [type(t_L(Bound)),strictness(Strict)]),
|
||||
pivot_a( Vub, X, Vb, t_l(Bound)),
|
||||
reconsider( X)
|
||||
; %
|
||||
% max(X) >= Ub, no implied value missed
|
||||
%
|
||||
put_atts( X, [type(t_L(Bound)),strictness(Strict)]),
|
||||
arith_eval( Bound-L, Delta),
|
||||
backsubst_delta( X, Delta)
|
||||
))).
|
||||
uils( t_Lu(L,U), X, _Lin, Bound, Sold) :-
|
||||
case_signum( Bound-L,
|
||||
true,
|
||||
(
|
||||
Strict is Sold \/ 2'10,
|
||||
put_atts( X, strictness(Strict))
|
||||
),
|
||||
(
|
||||
arith_eval( U>Bound),
|
||||
Strict is Sold \/ 2'10,
|
||||
( ub( X, Vub-Vb-Ub),
|
||||
arith_eval( Bound >= Ub+L) ->
|
||||
put_atts( X, [type(t_Lu(Bound,U)),strictness(Strict)]),
|
||||
pivot_a( Vub, X, Vb, t_lu(Bound,U)),
|
||||
reconsider( X)
|
||||
;
|
||||
put_atts( X, [type(t_Lu(Bound,U)),strictness(Strict)]),
|
||||
arith_eval( Bound-L, Delta),
|
||||
backsubst_delta( X, Delta)
|
||||
))).
|
||||
|
||||
reconsider_upper( X, Lin, U) :-
|
||||
decompose( Lin, H, R, I),
|
||||
arith_eval( R+I >= U),
|
||||
!,
|
||||
dec_step( H, Status),
|
||||
rcbl_status( Status, X, [], Binds,[], u(U)),
|
||||
export_binding( Binds).
|
||||
reconsider_upper( _, _, _).
|
||||
|
||||
reconsider_lower( X, Lin, L) :-
|
||||
decompose( Lin, H, R, I),
|
||||
arith_eval( R+I =< L),
|
||||
!,
|
||||
inc_step( H, Status),
|
||||
rcbl_status( Status, X, [], Binds,[], l(L)),
|
||||
export_binding( Binds).
|
||||
reconsider_lower( _, _, _).
|
||||
|
||||
%
|
||||
% lin is dereferenced
|
||||
%
|
||||
solve_bound( Lin, Bound) :-
|
||||
arith_eval( Bound =:= 0),
|
||||
!,
|
||||
solve( Lin).
|
||||
solve_bound( Lin, Bound) :-
|
||||
arith_eval( -Bound, Nb),
|
||||
normalize_scalar( Nb, Nbs),
|
||||
add_linear_11( Nbs, Lin, Eq),
|
||||
solve( Eq).
|
@ -1,993 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.2 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: ineq.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%
|
||||
% Lin (=)< 0
|
||||
%
|
||||
ineq( [], I, _, Strictness) :- ineq_ground( Strictness, I).
|
||||
ineq( [v(K,[X^1])|Tail], I, Lin, Strictness) :-
|
||||
ineq_cases( Tail, I, Lin, Strictness, X, K).
|
||||
|
||||
ineq_cases( [], I, _, Strictness, X, K) :-
|
||||
ineq_one( Strictness, X, K, I).
|
||||
ineq_cases( [_|_], _, Lin, Strictness, _, _) :-
|
||||
deref( Lin, Lind), % Id+Hd =< 0
|
||||
decompose( Lind, Hom, _, Inhom),
|
||||
ineq_more( Hom, Inhom, Lind, Strictness).
|
||||
|
||||
ineq_ground( strict, I) :- arith_eval( I < 0).
|
||||
ineq_ground( nonstrict, I) :- arith_eval( I =< 0).
|
||||
|
||||
%
|
||||
% Special cases: k={+-}1,i=0
|
||||
%
|
||||
ineq_one( strict, X, K, I) :-
|
||||
( arith_eval(K>0) ->
|
||||
( arith_eval(I=:=0) ->
|
||||
ineq_one_s_p_0( X)
|
||||
;
|
||||
arith_eval( I/K, Inhom),
|
||||
ineq_one_s_p_i( X, Inhom)
|
||||
)
|
||||
;
|
||||
( arith_eval(I=:=0) ->
|
||||
ineq_one_s_n_0( X)
|
||||
;
|
||||
arith_eval( -I/K, Inhom),
|
||||
ineq_one_s_n_i( X, Inhom)
|
||||
)
|
||||
).
|
||||
ineq_one( nonstrict, X, K, I) :-
|
||||
( arith_eval(K>0) ->
|
||||
( arith_eval(I=:=0) ->
|
||||
ineq_one_n_p_0( X)
|
||||
;
|
||||
arith_eval( I/K, Inhom),
|
||||
ineq_one_n_p_i( X, Inhom)
|
||||
)
|
||||
;
|
||||
( arith_eval(I=:=0) ->
|
||||
ineq_one_n_n_0( X)
|
||||
;
|
||||
arith_eval( -I/K, Inhom),
|
||||
ineq_one_n_n_i( X, Inhom)
|
||||
)
|
||||
).
|
||||
|
||||
/*
|
||||
ineq_one( Strictness, X, K, I) :-
|
||||
get_atts( X, lin(LinX)),
|
||||
!, % old variable, this is deref
|
||||
decompose( LinX, OrdX, _, Ix),
|
||||
ineq_one_old( OrdX, K, I, Strictness, X, Ix).
|
||||
ineq_one( Strictness, X, K, I) :- % new variable, nothing depends on it
|
||||
arith_eval( -I/K, Bound),
|
||||
ineq_one_new( Strictness, X, K, Bound).
|
||||
|
||||
ineq_one_new( strict, X, K, Bound) :-
|
||||
arith_eval( 1, One),
|
||||
( arith_eval( K < 0) ->
|
||||
var_intern( t_l(Bound), X, 2'10)
|
||||
;
|
||||
var_intern( t_u(Bound), X, 2'01)
|
||||
).
|
||||
ineq_one_new( nonstrict, X, K, Bound) :-
|
||||
arith_eval( 1, One),
|
||||
( arith_eval( K < 0) ->
|
||||
var_intern( t_l(Bound), X, 2'00)
|
||||
;
|
||||
var_intern( t_u(Bound), X, 2'00)
|
||||
).
|
||||
|
||||
|
||||
ineq_one_old( [], K, I, Strictness, _X, Ix) :-
|
||||
arith_eval( K*Ix+I, Inhom),
|
||||
ineq_ground( Strictness, Inhom).
|
||||
%
|
||||
% here we would have the choice to bound X or Y
|
||||
%
|
||||
ineq_one_old( [Y*Ky|Tail], K, I, Strictness, X, Ix) :-
|
||||
( Tail = [],
|
||||
arith_eval( K*Ky, Coeff),
|
||||
arith_eval( -(K*Ix+I)/Coeff, Bound),
|
||||
update_indep( Strictness, Y, Coeff, Bound)
|
||||
; Tail = [_|_],
|
||||
arith_eval( -I/K, Bound),
|
||||
update_dep( Strictness, X, K, Bound)
|
||||
).
|
||||
|
||||
update_dep( strict, X, K, Bound) :-
|
||||
get_atts( X, [lin(Lin),type(Type),strictness(Old)]),
|
||||
( arith_eval( K < 0) ->
|
||||
udls( Type, X, Lin, Bound, Old)
|
||||
;
|
||||
udus( Type, X, Lin, Bound, Old)
|
||||
).
|
||||
update_dep( nonstrict, X, K, Bound) :-
|
||||
get_atts( X, [lin(Lin),type(Type),strictness(Old)]),
|
||||
( arith_eval( K < 0) ->
|
||||
udl( Type, X, Lin, Bound, Old)
|
||||
;
|
||||
udu( Type, X, Lin, Bound, Old)
|
||||
).
|
||||
*/
|
||||
|
||||
% --------------------------- strict ----------------------------
|
||||
|
||||
ineq_one_s_p_0( X) :-
|
||||
get_atts( X, lin(LinX)),
|
||||
!, % old variable, this is deref
|
||||
decompose( LinX, OrdX, _, Ix),
|
||||
ineq_one_old_s_p_0( OrdX, X, Ix).
|
||||
ineq_one_s_p_0( X) :- % new variable, nothing depends on it
|
||||
arith_eval( 0, Zero),
|
||||
var_intern( t_u(Zero), X, 2'01).
|
||||
|
||||
ineq_one_s_n_0( X) :-
|
||||
get_atts( X, lin(LinX)),
|
||||
!,
|
||||
decompose( LinX, OrdX, _, Ix),
|
||||
ineq_one_old_s_n_0( OrdX, X, Ix).
|
||||
ineq_one_s_n_0( X) :-
|
||||
arith_eval( 0, Zero),
|
||||
var_intern( t_l(Zero), X, 2'10).
|
||||
|
||||
ineq_one_s_p_i( X, I) :-
|
||||
get_atts( X, lin(LinX)),
|
||||
!,
|
||||
decompose( LinX, OrdX, _, Ix),
|
||||
ineq_one_old_s_p_i( OrdX, I, X, Ix).
|
||||
ineq_one_s_p_i( X, I) :-
|
||||
arith_eval( -I, Bound),
|
||||
var_intern( t_u(Bound), X, 2'01).
|
||||
|
||||
ineq_one_s_n_i( X, I) :-
|
||||
get_atts( X, lin(LinX)),
|
||||
!,
|
||||
decompose( LinX, OrdX, _, Ix),
|
||||
ineq_one_old_s_n_i( OrdX, I, X, Ix).
|
||||
ineq_one_s_n_i( X, I) :-
|
||||
var_intern( t_l(I), X, 2'10).
|
||||
|
||||
ineq_one_old_s_p_0( [], _, Ix) :-
|
||||
arith_eval( Ix < 0).
|
||||
ineq_one_old_s_p_0( [Y*Ky|Tail], X, Ix) :-
|
||||
%vsc: added -> (01/06/06)
|
||||
( Tail = [] ->
|
||||
arith_eval( -Ix/Ky, Bound),
|
||||
update_indep( strict, Y, Ky, Bound)
|
||||
; Tail = [_|_] ->
|
||||
arith_eval( 0, Zero),
|
||||
get_atts( X, [lin(Lin),type(Type),strictness(Old)]),
|
||||
udus( Type, X, Lin, Zero, Old)
|
||||
).
|
||||
|
||||
ineq_one_old_s_n_0( [], _, Ix) :-
|
||||
arith_eval( Ix > 0).
|
||||
ineq_one_old_s_n_0( [Y*Ky|Tail], X, Ix) :-
|
||||
%vsc: added -> (01/06/06)
|
||||
( Tail = [] ->
|
||||
arith_eval( -Ky, Coeff),
|
||||
arith_eval( Ix/Coeff, Bound),
|
||||
update_indep( strict, Y, Coeff, Bound)
|
||||
; Tail = [_|_] ->
|
||||
arith_eval( 0, Zero),
|
||||
get_atts( X, [lin(Lin),type(Type),strictness(Old)]),
|
||||
udls( Type, X, Lin, Zero, Old)
|
||||
).
|
||||
|
||||
ineq_one_old_s_p_i( [], I, _, Ix) :-
|
||||
arith_eval( Ix+I < 0).
|
||||
ineq_one_old_s_p_i( [Y*Ky|Tail], I, X, Ix) :-
|
||||
%vsc: added -> (01/06/06)
|
||||
( Tail = [] ->
|
||||
arith_eval( -(Ix+I)/Ky, Bound),
|
||||
update_indep( strict, Y, Ky, Bound)
|
||||
; Tail = [_|_] ->
|
||||
arith_eval( -I, Bound),
|
||||
get_atts( X, [lin(Lin),type(Type),strictness(Old)]),
|
||||
udus( Type, X, Lin, Bound, Old)
|
||||
).
|
||||
|
||||
ineq_one_old_s_n_i( [], I, _, Ix) :-
|
||||
arith_eval( -Ix+I < 0).
|
||||
ineq_one_old_s_n_i( [Y*Ky|Tail], I, X, Ix) :-
|
||||
%vsc: added -> (01/06/06)
|
||||
( Tail = [] ->
|
||||
arith_eval( -Ky, Coeff),
|
||||
arith_eval( (Ix-I)/Coeff, Bound),
|
||||
update_indep( strict, Y, Coeff, Bound)
|
||||
; Tail = [_|_] ->
|
||||
get_atts( X, [lin(Lin),type(Type),strictness(Old)]),
|
||||
udls( Type, X, Lin, I, Old)
|
||||
).
|
||||
|
||||
% -------------------------- nonstrict --------------------------
|
||||
|
||||
ineq_one_n_p_0( X) :-
|
||||
get_atts( X, lin(LinX)),
|
||||
!, % old variable, this is deref
|
||||
decompose( LinX, OrdX, _, Ix),
|
||||
ineq_one_old_n_p_0( OrdX, X, Ix).
|
||||
ineq_one_n_p_0( X) :- % new variable, nothing depends on it
|
||||
arith_eval( 0, Zero),
|
||||
var_intern( t_u(Zero), X, 2'00).
|
||||
|
||||
ineq_one_n_n_0( X) :-
|
||||
get_atts( X, lin(LinX)),
|
||||
!,
|
||||
decompose( LinX, OrdX, _, Ix),
|
||||
ineq_one_old_n_n_0( OrdX, X, Ix).
|
||||
ineq_one_n_n_0( X) :-
|
||||
arith_eval( 0, Zero),
|
||||
var_intern( t_l(Zero), X, 2'00).
|
||||
|
||||
ineq_one_n_p_i( X, I) :-
|
||||
get_atts( X, lin(LinX)),
|
||||
!,
|
||||
decompose( LinX, OrdX, _, Ix),
|
||||
ineq_one_old_n_p_i( OrdX, I, X, Ix).
|
||||
ineq_one_n_p_i( X, I) :-
|
||||
arith_eval( -I, Bound),
|
||||
var_intern( t_u(Bound), X, 2'00).
|
||||
|
||||
ineq_one_n_n_i( X, I) :-
|
||||
get_atts( X, lin(LinX)),
|
||||
!,
|
||||
decompose( LinX, OrdX, _, Ix),
|
||||
ineq_one_old_n_n_i( OrdX, I, X, Ix).
|
||||
ineq_one_n_n_i( X, I) :-
|
||||
var_intern( t_l(I), X, 2'00).
|
||||
|
||||
ineq_one_old_n_p_0( [], _, Ix) :-
|
||||
arith_eval( Ix =< 0).
|
||||
ineq_one_old_n_p_0( [Y*Ky|Tail], X, Ix) :-
|
||||
%vsc: added -> (01/06/06)
|
||||
( Tail = [] ->
|
||||
arith_eval( -Ix/Ky, Bound),
|
||||
update_indep( nonstrict, Y, Ky, Bound)
|
||||
; Tail = [_|_] ->
|
||||
arith_eval( 0, Zero),
|
||||
get_atts( X, [lin(Lin),type(Type),strictness(Old)]),
|
||||
udu( Type, X, Lin, Zero, Old)
|
||||
).
|
||||
|
||||
ineq_one_old_n_n_0( [], _, Ix) :-
|
||||
arith_eval( Ix >= 0).
|
||||
ineq_one_old_n_n_0( [Y*Ky|Tail], X, Ix) :-
|
||||
%vsc: added -> (01/06/06)
|
||||
( Tail = [] ->
|
||||
arith_eval( -Ky, Coeff),
|
||||
arith_eval( Ix/Coeff, Bound),
|
||||
update_indep( nonstrict, Y, Coeff, Bound)
|
||||
; Tail = [_|_] ->
|
||||
arith_eval( 0, Zero),
|
||||
get_atts( X, [lin(Lin),type(Type),strictness(Old)]),
|
||||
udl( Type, X, Lin, Zero, Old)
|
||||
).
|
||||
|
||||
ineq_one_old_n_p_i( [], I, _, Ix) :-
|
||||
arith_eval( Ix+I =< 0).
|
||||
ineq_one_old_n_p_i( [Y*Ky|Tail], I, X, Ix) :-
|
||||
%vsc: added -> (01/06/06)
|
||||
( Tail = [] ->
|
||||
arith_eval( -(Ix+I)/Ky, Bound),
|
||||
update_indep( nonstrict, Y, Ky, Bound)
|
||||
; Tail = [_|_] ->
|
||||
arith_eval( -I, Bound),
|
||||
get_atts( X, [lin(Lin),type(Type),strictness(Old)]),
|
||||
udu( Type, X, Lin, Bound, Old)
|
||||
).
|
||||
|
||||
ineq_one_old_n_n_i( [], I, _, Ix) :-
|
||||
arith_eval( -Ix+I =< 0).
|
||||
ineq_one_old_n_n_i( [Y*Ky|Tail], I, X, Ix) :-
|
||||
%vsc: added -> (01/06/06)
|
||||
( Tail = [] ->
|
||||
arith_eval( -Ky, Coeff),
|
||||
arith_eval( (Ix-I)/Coeff, Bound),
|
||||
update_indep( nonstrict, Y, Coeff, Bound)
|
||||
; Tail = [_|_] ->
|
||||
get_atts( X, [lin(Lin),type(Type),strictness(Old)]),
|
||||
udl( Type, X, Lin, I, Old)
|
||||
).
|
||||
|
||||
% ---------------------------------------------------------------
|
||||
|
||||
|
||||
ineq_more( [], I, _, Strictness) :- ineq_ground( Strictness, I).
|
||||
ineq_more( [X*K|Tail], Id, Lind, Strictness) :-
|
||||
%vsc: added -> (01/06/06)
|
||||
( Tail = [] -> % one var: update bound instead of slack introduction
|
||||
get_or_add_class( X, _),
|
||||
arith_eval( -Id/K, Bound),
|
||||
update_indep( Strictness, X, K, Bound)
|
||||
; Tail = [_|_] ->
|
||||
ineq_more( Strictness, Lind)
|
||||
).
|
||||
|
||||
ineq_more( strict, Lind) :-
|
||||
( unconstrained( Lind, U,K, Rest) -> % never fails, no implied value
|
||||
arith_eval( 0, Z),
|
||||
arith_eval( 1, One),
|
||||
var_intern( t_l(Z), S, 2'10),
|
||||
arith_eval( -1/K, Ki),
|
||||
add_linear_ff( Rest, Ki, [Z,Z,S*One], Ki, LinU),
|
||||
decompose( LinU, Hu, _, _),
|
||||
get_or_add_class( U, Class),
|
||||
same_class( Hu, Class),
|
||||
backsubst( U, LinU)
|
||||
;
|
||||
arith_eval( 0, Z),
|
||||
var_with_def_intern( t_u(Z), S, Lind, 2'01),
|
||||
basis_add( S, _),
|
||||
determine_active_dec( Lind),
|
||||
reconsider( S)
|
||||
).
|
||||
ineq_more( nonstrict, Lind) :-
|
||||
( unconstrained( Lind, U,K, Rest) -> % never fails, no implied value
|
||||
arith_eval( 0, Z),
|
||||
arith_eval( 1, One),
|
||||
var_intern( t_l(Z), S, 2'00),
|
||||
arith_eval( -1/K, Ki),
|
||||
add_linear_ff( Rest, Ki, [Z,Z,S*One], Ki, LinU),
|
||||
decompose( LinU, Hu, _, _),
|
||||
get_or_add_class( U, Class),
|
||||
same_class( Hu, Class),
|
||||
backsubst( U, LinU)
|
||||
;
|
||||
arith_eval( 0, Z),
|
||||
var_with_def_intern( t_u(Z), S, Lind, 2'00),
|
||||
basis_add( S, _),
|
||||
determine_active_dec( Lind),
|
||||
reconsider( S)
|
||||
).
|
||||
|
||||
update_indep( strict, X, K, Bound) :-
|
||||
get_atts( X, [lin(Lin),type(Type),strictness(Old)]),
|
||||
( arith_eval( K < 0) ->
|
||||
uils( Type, X, Lin, Bound, Old)
|
||||
;
|
||||
uius( Type, X, Lin, Bound, Old)
|
||||
).
|
||||
update_indep( nonstrict, X, K, Bound) :-
|
||||
get_atts( X, [lin(Lin),type(Type),strictness(Old)]),
|
||||
( arith_eval( K < 0) ->
|
||||
uil( Type, X, Lin, Bound, Old)
|
||||
;
|
||||
uiu( Type, X, Lin, Bound, Old)
|
||||
).
|
||||
|
||||
|
||||
% ---------------------------------------------------------------------------------------
|
||||
|
||||
%
|
||||
% Update a bound on a var xi
|
||||
%
|
||||
% a) independent variable
|
||||
%
|
||||
% a1) update inactive bound: done
|
||||
%
|
||||
% a2) update active bound:
|
||||
% Determine [lu]b including most constraining row R
|
||||
% If we are within: done
|
||||
% else pivot(R,xi) and introduce bound via (b)
|
||||
%
|
||||
% a3) introduce a bound on an unconstrained var:
|
||||
% All vars that depend on xi are unconstrained (invariant) ->
|
||||
% the bound cannot invalidate any Lhs
|
||||
%
|
||||
% b) dependent variable
|
||||
%
|
||||
% repair upper or lower (maybe just swap with an unconstrained var from Rhs)
|
||||
%
|
||||
|
||||
%
|
||||
% Sign = 1,0,-1 means inside,at,outside
|
||||
%
|
||||
|
||||
udl( t_none, X, Lin, Bound, _Sold) :-
|
||||
put_atts( X, [type(t_l(Bound)),strictness(2'00)]),
|
||||
( unconstrained( Lin, Uc,Kuc, Rest) ->
|
||||
arith_eval( -1/Kuc, Ki),
|
||||
arith_eval( 0, Z),
|
||||
arith_eval( -1, Mone),
|
||||
add_linear_ff( Rest, Ki, [Z,Z,X*Mone], Ki, LinU),
|
||||
backsubst( Uc, LinU)
|
||||
;
|
||||
basis_add( X, _),
|
||||
determine_active_inc( Lin),
|
||||
reconsider( X)
|
||||
).
|
||||
udl( t_l(L), X, Lin, Bound, Sold) :-
|
||||
case_signum( Bound-L,
|
||||
true,
|
||||
true,
|
||||
(
|
||||
Strict is Sold /\ 2'01,
|
||||
put_atts( X, [type(t_l(Bound)),strictness(Strict)]),
|
||||
reconsider_lower( X, Lin, Bound)
|
||||
)).
|
||||
udl( t_u(U), X, Lin, Bound, _Sold) :-
|
||||
case_signum( U-Bound,
|
||||
fail,
|
||||
solve_bound( Lin, Bound),
|
||||
(
|
||||
put_atts( X, type(t_lu(Bound,U))),
|
||||
reconsider_lower( X, Lin, Bound)
|
||||
)).
|
||||
udl( t_lu(L,U), X, Lin, Bound, Sold) :-
|
||||
case_signum( Bound-L,
|
||||
true,
|
||||
true,
|
||||
(
|
||||
case_signum( U-Bound,
|
||||
fail,
|
||||
(
|
||||
Sold /\ 2'01 =:= 0,
|
||||
solve_bound( Lin, Bound)
|
||||
),
|
||||
(
|
||||
Strict is Sold /\ 2'01,
|
||||
put_atts( X, [type(t_lu(Bound,U)),strictness(Strict)]),
|
||||
reconsider_lower( X, Lin, Bound)
|
||||
))
|
||||
)).
|
||||
|
||||
udls( t_none, X, Lin, Bound, _Sold) :-
|
||||
put_atts( X, [type(t_l(Bound)),strictness(2'10)]),
|
||||
( unconstrained( Lin, Uc,Kuc, Rest) ->
|
||||
arith_eval( -1/Kuc, Ki),
|
||||
arith_eval( -1, Mone),
|
||||
arith_eval( 0, Z),
|
||||
add_linear_ff( Rest, Ki, [Z,Z,X*Mone], Ki, LinU),
|
||||
backsubst( Uc, LinU)
|
||||
;
|
||||
basis_add( X, _),
|
||||
determine_active_inc( Lin),
|
||||
reconsider( X)
|
||||
).
|
||||
udls( t_l(L), X, Lin, Bound, Sold) :-
|
||||
case_signum( Bound-L,
|
||||
true,
|
||||
(
|
||||
Strict is Sold \/ 2'10,
|
||||
put_atts( X, strictness(Strict))
|
||||
),
|
||||
(
|
||||
Strict is Sold \/ 2'10,
|
||||
put_atts( X, [type(t_l(Bound)),strictness(Strict)]),
|
||||
reconsider_lower( X, Lin, Bound)
|
||||
)).
|
||||
udls( t_u(U), X, Lin, Bound, Sold) :-
|
||||
arith_eval( U>Bound),
|
||||
Strict is Sold \/ 2'10,
|
||||
put_atts( X, [type(t_lu(Bound,U)),strictness(Strict)]),
|
||||
reconsider_lower( X, Lin, Bound).
|
||||
udls( t_lu(L,U), X, Lin, Bound, Sold) :-
|
||||
case_signum( Bound-L,
|
||||
true,
|
||||
(
|
||||
Strict is Sold \/ 2'10,
|
||||
put_atts( X, strictness(Strict))
|
||||
),
|
||||
(
|
||||
arith_eval( U>Bound),
|
||||
Strict is Sold \/ 2'10,
|
||||
put_atts( X, [type(t_lu(Bound,U)),strictness(Strict)]),
|
||||
reconsider_lower( X, Lin, Bound)
|
||||
)).
|
||||
|
||||
|
||||
udu( t_none, X, Lin, Bound, _Sold) :-
|
||||
put_atts( X, [type(t_u(Bound)),strictness(2'00)]),
|
||||
( unconstrained( Lin, Uc,Kuc, Rest) ->
|
||||
arith_eval( -1/Kuc, Ki),
|
||||
arith_eval( -1, Mone),
|
||||
arith_eval( 0, Z),
|
||||
add_linear_ff( Rest, Ki, [Z,Z,X*Mone], Ki, LinU),
|
||||
backsubst( Uc, LinU)
|
||||
;
|
||||
basis_add( X, _),
|
||||
determine_active_dec( Lin),
|
||||
reconsider( X)
|
||||
).
|
||||
udu( t_u(U), X, Lin, Bound, Sold) :-
|
||||
case_signum( U-Bound,
|
||||
true,
|
||||
true,
|
||||
(
|
||||
Strict is Sold /\ 2'10,
|
||||
put_atts( X, [type(t_u(Bound)),strictness(Strict)]),
|
||||
reconsider_upper( X, Lin, Bound)
|
||||
)).
|
||||
udu( t_l(L), X, Lin, Bound, _Sold) :-
|
||||
case_signum( Bound-L,
|
||||
fail,
|
||||
solve_bound( Lin, Bound),
|
||||
(
|
||||
put_atts( X, type(t_lu(L,Bound))),
|
||||
reconsider_upper( X, Lin, Bound)
|
||||
)).
|
||||
udu( t_lu(L,U), X, Lin, Bound, Sold) :-
|
||||
case_signum( U-Bound,
|
||||
true,
|
||||
true,
|
||||
(
|
||||
case_signum( Bound-L,
|
||||
fail,
|
||||
(
|
||||
Sold /\ 2'10 =:= 0,
|
||||
solve_bound( Lin, Bound)
|
||||
),
|
||||
(
|
||||
Strict is Sold /\ 2'10,
|
||||
put_atts( X, [type(t_lu(L,Bound)),strictness(Strict)]),
|
||||
reconsider_upper( X, Lin, Bound)
|
||||
))
|
||||
)).
|
||||
|
||||
udus( t_none, X, Lin, Bound, _Sold) :-
|
||||
put_atts( X, [type(t_u(Bound)),strictness(2'01)]),
|
||||
( unconstrained( Lin, Uc,Kuc, Rest) ->
|
||||
arith_eval( -1/Kuc, Ki),
|
||||
arith_eval( -1, Mone),
|
||||
arith_eval( 0, Z),
|
||||
add_linear_ff( Rest, Ki, [Z,Z,X*Mone], Ki, LinU),
|
||||
backsubst( Uc, LinU)
|
||||
;
|
||||
basis_add( X, _),
|
||||
determine_active_dec( Lin),
|
||||
reconsider( X)
|
||||
).
|
||||
udus( t_u(U), X, Lin, Bound, Sold) :-
|
||||
case_signum( U-Bound,
|
||||
true,
|
||||
(
|
||||
Strict is Sold \/ 2'01,
|
||||
put_atts( X, strictness(Strict))
|
||||
),
|
||||
(
|
||||
Strict is Sold \/ 2'01,
|
||||
put_atts( X, [type(t_u(Bound)),strictness(Strict)]),
|
||||
reconsider_upper( X, Lin, Bound)
|
||||
)).
|
||||
udus( t_l(L), X, Lin, Bound, Sold) :-
|
||||
arith_eval( Bound>L),
|
||||
Strict is Sold \/ 2'01,
|
||||
put_atts( X, [type(t_lu(L,Bound)),strictness(Strict)]),
|
||||
reconsider_upper( X, Lin, Bound).
|
||||
udus( t_lu(L,U), X, Lin, Bound, Sold) :-
|
||||
case_signum( U-Bound,
|
||||
true,
|
||||
(
|
||||
Strict is Sold \/ 2'01,
|
||||
put_atts( X, strictness(Strict))
|
||||
),
|
||||
(
|
||||
arith_eval( Bound>L),
|
||||
Strict is Sold \/ 2'01,
|
||||
put_atts( X, [type(t_lu(L,Bound)),strictness(Strict)]),
|
||||
reconsider_upper( X, Lin, Bound)
|
||||
)).
|
||||
|
||||
uiu( t_none, X, _Lin, Bound, _) :-
|
||||
put_atts( X, [type(t_u(Bound)),strictness(2'00)]).
|
||||
uiu( t_u(U), X, _Lin, Bound, Sold) :-
|
||||
case_signum( U-Bound,
|
||||
true,
|
||||
true,
|
||||
(
|
||||
Strict is Sold /\ 2'10,
|
||||
put_atts( X, [type(t_u(Bound)),strictness(Strict)])
|
||||
)).
|
||||
uiu( t_l(L), X, Lin, Bound, _Sold) :-
|
||||
case_signum( Bound-L,
|
||||
fail,
|
||||
solve_bound( Lin, Bound),
|
||||
put_atts( X, type(t_lu(L,Bound)))).
|
||||
uiu( t_L(L), X, Lin, Bound, _Sold) :-
|
||||
case_signum( Bound-L,
|
||||
fail,
|
||||
solve_bound( Lin, Bound),
|
||||
put_atts( X, type(t_Lu(L,Bound)))).
|
||||
uiu( t_lu(L,U), X, Lin, Bound, Sold) :-
|
||||
case_signum( U-Bound,
|
||||
true,
|
||||
true,
|
||||
(
|
||||
case_signum( Bound-L,
|
||||
fail,
|
||||
(
|
||||
Sold /\ 2'10 =:= 0,
|
||||
solve_bound( Lin, Bound)
|
||||
),
|
||||
(
|
||||
Strict is Sold /\ 2'10,
|
||||
put_atts( X, [type(t_lu(L,Bound)),strictness(Strict)])
|
||||
))
|
||||
)).
|
||||
uiu( t_Lu(L,U), X, Lin, Bound, Sold) :-
|
||||
case_signum( U-Bound,
|
||||
true,
|
||||
true,
|
||||
(
|
||||
case_signum( Bound-L,
|
||||
fail,
|
||||
(
|
||||
Sold /\ 2'10 =:= 0,
|
||||
solve_bound( Lin, Bound)
|
||||
),
|
||||
(
|
||||
Strict is Sold /\ 2'10,
|
||||
put_atts( X, [type(t_Lu(L,Bound)),strictness(Strict)])
|
||||
))
|
||||
)).
|
||||
%
|
||||
% update active:
|
||||
%
|
||||
uiu( t_U(U), X, _Lin, Bound, Sold) :-
|
||||
case_signum( U-Bound,
|
||||
true,
|
||||
true,
|
||||
(
|
||||
Strict is Sold /\ 2'10,
|
||||
( lb( X, Vlb-Vb-Lb),
|
||||
arith_eval( Bound =< Lb+U) ->
|
||||
put_atts( X, [type(t_U(Bound)),strictness(Strict)]),
|
||||
pivot_a( Vlb, X, Vb, t_u(Bound)),
|
||||
reconsider( X)
|
||||
;
|
||||
put_atts( X, [type(t_U(Bound)),strictness(Strict)]),
|
||||
arith_eval( Bound-U, Delta),
|
||||
backsubst_delta( X, Delta)
|
||||
)
|
||||
)).
|
||||
uiu( t_lU(L,U), X, Lin, Bound, Sold) :-
|
||||
case_signum( U-Bound,
|
||||
true,
|
||||
true,
|
||||
(
|
||||
case_signum( Bound-L,
|
||||
fail,
|
||||
(
|
||||
Sold /\ 2'10 =:= 0,
|
||||
solve_bound( Lin, Bound)
|
||||
),
|
||||
(
|
||||
Strict is Sold /\ 2'10,
|
||||
( lb( X, Vlb-Vb-Lb),
|
||||
arith_eval( Bound =< Lb+U) ->
|
||||
put_atts( X, [type(t_lU(L,Bound)),strictness(Strict)]),
|
||||
pivot_a( Vlb, X, Vb, t_lu(L,Bound)),
|
||||
reconsider( X)
|
||||
;
|
||||
put_atts( X, [type(t_lU(L,Bound)),strictness(Strict)]),
|
||||
arith_eval( Bound-U, Delta),
|
||||
backsubst_delta( X, Delta)
|
||||
)
|
||||
))
|
||||
)).
|
||||
|
||||
|
||||
uius( t_none, X, _Lin, Bound, _Sold) :-
|
||||
put_atts( X, [type(t_u(Bound)),strictness(2'01)]).
|
||||
uius( t_u(U), X, _Lin, Bound, Sold) :-
|
||||
case_signum( U-Bound,
|
||||
true,
|
||||
(
|
||||
Strict is Sold \/ 2'01,
|
||||
put_atts( X, strictness(Strict))
|
||||
),
|
||||
(
|
||||
Strict is Sold \/ 2'01,
|
||||
put_atts( X, [type(t_u(Bound)),strictness(Strict)])
|
||||
)).
|
||||
uius( t_l(L), X, _Lin, Bound, Sold) :-
|
||||
arith_eval( Bound>L),
|
||||
Strict is Sold \/ 2'01,
|
||||
put_atts( X, [type(t_lu(L,Bound)),strictness(Strict)]).
|
||||
uius( t_L(L), X, _Lin, Bound, Sold) :-
|
||||
arith_eval( Bound>L),
|
||||
Strict is Sold \/ 2'01,
|
||||
put_atts( X, [type(t_Lu(L,Bound)),strictness(Strict)]).
|
||||
uius( t_lu(L,U), X, _Lin, Bound, Sold) :-
|
||||
case_signum( U-Bound,
|
||||
true,
|
||||
(
|
||||
Strict is Sold \/ 2'01,
|
||||
put_atts( X, strictness(Strict))
|
||||
),
|
||||
(
|
||||
arith_eval( Bound>L),
|
||||
Strict is Sold \/ 2'01,
|
||||
put_atts( X, [type(t_lu(L,Bound)),strictness(Strict)])
|
||||
)).
|
||||
uius( t_Lu(L,U), X, _Lin, Bound, Sold) :-
|
||||
case_signum( U-Bound,
|
||||
true,
|
||||
(
|
||||
Strict is Sold \/ 2'01,
|
||||
put_atts( X, strictness(Strict))
|
||||
),
|
||||
(
|
||||
arith_eval( Bound>L),
|
||||
Strict is Sold \/ 2'01,
|
||||
put_atts( X, [type(t_Lu(L,Bound)),strictness(Strict)])
|
||||
)).
|
||||
%
|
||||
% update active:
|
||||
%
|
||||
uius( t_U(U), X, _Lin, Bound, Sold) :-
|
||||
case_signum( U-Bound,
|
||||
true,
|
||||
(
|
||||
Strict is Sold \/ 2'01,
|
||||
put_atts( X, strictness(Strict))
|
||||
),
|
||||
(
|
||||
Strict is Sold \/ 2'01,
|
||||
( lb( X, Vlb-Vb-Lb),
|
||||
arith_eval( Bound =< Lb+U) ->
|
||||
put_atts( X, [type(t_U(Bound)),strictness(Strict)]),
|
||||
pivot_a( Vlb, X, Vb, t_u(Bound)),
|
||||
reconsider( X)
|
||||
;
|
||||
put_atts( X, [type(t_U(Bound)),strictness(Strict)]),
|
||||
arith_eval( Bound-U, Delta),
|
||||
backsubst_delta( X, Delta)
|
||||
)
|
||||
)).
|
||||
uius( t_lU(L,U), X, _Lin, Bound, Sold) :-
|
||||
case_signum( U-Bound,
|
||||
true,
|
||||
(
|
||||
Strict is Sold \/ 2'01,
|
||||
put_atts( X, strictness(Strict))
|
||||
),
|
||||
(
|
||||
arith_eval( Bound>L),
|
||||
Strict is Sold \/ 2'01,
|
||||
( lb( X, Vlb-Vb-Lb),
|
||||
arith_eval( Bound =< Lb+U) ->
|
||||
put_atts( X, [type(t_lU(L,Bound)),strictness(Strict)]),
|
||||
pivot_a( Vlb, X, Vb, t_lu(L,Bound)),
|
||||
reconsider( X)
|
||||
;
|
||||
put_atts( X, [type(t_lU(L,Bound)),strictness(Strict)]),
|
||||
arith_eval( Bound-U, Delta),
|
||||
backsubst_delta( X, Delta)
|
||||
)
|
||||
)).
|
||||
|
||||
|
||||
uil( t_none, X, _Lin, Bound, _Sold) :-
|
||||
put_atts( X, [type(t_l(Bound)),strictness(2'00)]).
|
||||
uil( t_l(L), X, _Lin, Bound, Sold) :-
|
||||
case_signum( Bound-L,
|
||||
true,
|
||||
true,
|
||||
(
|
||||
Strict is Sold /\ 2'01,
|
||||
put_atts( X, [type(t_l(Bound)),strictness(Strict)])
|
||||
)).
|
||||
uil( t_u(U), X, Lin, Bound, _Sold) :-
|
||||
case_signum( U-Bound,
|
||||
fail,
|
||||
solve_bound( Lin, Bound),
|
||||
put_atts( X, type(t_lu(Bound,U)))).
|
||||
uil( t_U(U), X, Lin, Bound, _Sold) :-
|
||||
case_signum( U-Bound,
|
||||
fail,
|
||||
solve_bound( Lin, Bound),
|
||||
put_atts( X, type(t_lU(Bound,U)))).
|
||||
uil( t_lu(L,U), X, Lin, Bound, Sold) :-
|
||||
case_signum( Bound-L,
|
||||
true,
|
||||
true,
|
||||
(
|
||||
case_signum( U-Bound,
|
||||
fail,
|
||||
(
|
||||
Sold /\ 2'01 =:= 0,
|
||||
solve_bound( Lin, Bound)
|
||||
),
|
||||
(
|
||||
Strict is Sold /\ 2'01,
|
||||
put_atts( X, [type(t_lu(Bound,U)),strictness(Strict)])
|
||||
))
|
||||
)).
|
||||
uil( t_lU(L,U), X, Lin, Bound, Sold) :-
|
||||
case_signum( Bound-L,
|
||||
true,
|
||||
true,
|
||||
(
|
||||
case_signum( U-Bound,
|
||||
fail,
|
||||
(
|
||||
Sold /\ 2'01 =:= 0,
|
||||
solve_bound( Lin, Bound)
|
||||
),
|
||||
(
|
||||
Strict is Sold /\ 2'01,
|
||||
put_atts( X, [type(t_lU(Bound,U)),strictness(Strict)])
|
||||
))
|
||||
)).
|
||||
%
|
||||
% update active bound: % { a>=100,d=<5000,c>=10,-2*a+d-c=10,a>=2490 }.
|
||||
%
|
||||
uil( t_L(L), X, _Lin, Bound, Sold) :-
|
||||
case_signum( Bound-L,
|
||||
true,
|
||||
true,
|
||||
(
|
||||
Strict is Sold /\ 2'01,
|
||||
( ub( X, Vub-Vb-Ub),
|
||||
arith_eval( Bound >= Ub+L) ->
|
||||
put_atts( X, [type(t_L(Bound)),strictness(Strict)]),
|
||||
pivot_a( Vub, X, Vb, t_l(Bound)),
|
||||
reconsider( X)
|
||||
; %
|
||||
% max(X) >= Ub, no implied value missed
|
||||
%
|
||||
put_atts( X, [type(t_L(Bound)),strictness(Strict)]),
|
||||
arith_eval( Bound-L, Delta),
|
||||
backsubst_delta( X, Delta)
|
||||
)
|
||||
)).
|
||||
uil( t_Lu(L,U), X, Lin, Bound, Sold) :-
|
||||
case_signum( Bound-L,
|
||||
true,
|
||||
true,
|
||||
(
|
||||
case_signum( U-Bound,
|
||||
fail,
|
||||
(
|
||||
Sold /\ 2'01 =:= 0,
|
||||
solve_bound( Lin, Bound)
|
||||
),
|
||||
(
|
||||
Strict is Sold /\ 2'01,
|
||||
( ub( X, Vub-Vb-Ub),
|
||||
arith_eval( Bound >= Ub+L) ->
|
||||
put_atts( X, [type(t_Lu(Bound,U)),strictness(Strict)]),
|
||||
pivot_a( Vub, X, Vb, t_lu(Bound,U)),
|
||||
reconsider( X)
|
||||
;
|
||||
put_atts( X, [type(t_Lu(Bound,U)),strictness(Strict)]),
|
||||
arith_eval( Bound-L, Delta),
|
||||
backsubst_delta( X, Delta)
|
||||
)
|
||||
)))).
|
||||
|
||||
|
||||
uils( t_none, X, _Lin, Bound, _Sold) :-
|
||||
put_atts( X, [type(t_l(Bound)),strictness(2'10)]).
|
||||
uils( t_l(L), X, _Lin, Bound, Sold) :-
|
||||
case_signum( Bound-L,
|
||||
true,
|
||||
(
|
||||
Strict is Sold \/ 2'10,
|
||||
put_atts( X, strictness(Strict))
|
||||
),
|
||||
(
|
||||
Strict is Sold \/ 2'10,
|
||||
put_atts( X, [type(t_l(Bound)),strictness(Strict)])
|
||||
)).
|
||||
uils( t_u(U), X, _Lin, Bound, Sold) :-
|
||||
arith_eval( U>Bound),
|
||||
Strict is Sold \/ 2'10,
|
||||
put_atts( X, [type(t_lu(Bound,U)),strictness(Strict)]).
|
||||
uils( t_U(U), X, _Lin, Bound, Sold) :-
|
||||
arith_eval( U>Bound),
|
||||
Strict is Sold \/ 2'10,
|
||||
put_atts( X, [type(t_lU(Bound,U)),strictness(Strict)]).
|
||||
uils( t_lu(L,U), X, _Lin, Bound, Sold) :-
|
||||
case_signum( Bound-L,
|
||||
true,
|
||||
(
|
||||
Strict is Sold \/ 2'10,
|
||||
put_atts( X, strictness(Strict))
|
||||
),
|
||||
(
|
||||
arith_eval( U>Bound),
|
||||
Strict is Sold \/ 2'10,
|
||||
put_atts( X, [type(t_lu(Bound,U)),strictness(Strict)])
|
||||
)).
|
||||
uils( t_lU(L,U), X, _Lin, Bound, Sold) :-
|
||||
case_signum( Bound-L,
|
||||
true,
|
||||
(
|
||||
Strict is Sold \/ 2'10,
|
||||
put_atts( X, strictness(Strict))
|
||||
),
|
||||
(
|
||||
arith_eval( U>Bound),
|
||||
Strict is Sold \/ 2'10,
|
||||
put_atts( X, [type(t_lU(Bound,U)),strictness(Strict)])
|
||||
)).
|
||||
%
|
||||
% update active bound:
|
||||
%
|
||||
uils( t_L(L), X, _Lin, Bound, Sold) :-
|
||||
case_signum( Bound-L,
|
||||
true,
|
||||
(
|
||||
Strict is Sold \/ 2'10,
|
||||
put_atts( X, strictness(Strict))
|
||||
),
|
||||
(
|
||||
Strict is Sold \/ 2'10,
|
||||
( ub( X, Vub-Vb-Ub),
|
||||
arith_eval( Bound >= Ub+L) ->
|
||||
put_atts( X, [type(t_L(Bound)),strictness(Strict)]),
|
||||
pivot_a( Vub, X, Vb, t_l(Bound)),
|
||||
reconsider( X)
|
||||
; %
|
||||
% max(X) >= Ub, no implied value missed
|
||||
%
|
||||
put_atts( X, [type(t_L(Bound)),strictness(Strict)]),
|
||||
arith_eval( Bound-L, Delta),
|
||||
backsubst_delta( X, Delta)
|
||||
))).
|
||||
uils( t_Lu(L,U), X, _Lin, Bound, Sold) :-
|
||||
case_signum( Bound-L,
|
||||
true,
|
||||
(
|
||||
Strict is Sold \/ 2'10,
|
||||
put_atts( X, strictness(Strict))
|
||||
),
|
||||
(
|
||||
arith_eval( U>Bound),
|
||||
Strict is Sold \/ 2'10,
|
||||
( ub( X, Vub-Vb-Ub),
|
||||
arith_eval( Bound >= Ub+L) ->
|
||||
put_atts( X, [type(t_Lu(Bound,U)),strictness(Strict)]),
|
||||
pivot_a( Vub, X, Vb, t_lu(Bound,U)),
|
||||
reconsider( X)
|
||||
;
|
||||
put_atts( X, [type(t_Lu(Bound,U)),strictness(Strict)]),
|
||||
arith_eval( Bound-L, Delta),
|
||||
backsubst_delta( X, Delta)
|
||||
))).
|
||||
|
||||
reconsider_upper( X, Lin, U) :-
|
||||
decompose( Lin, H, R, I),
|
||||
arith_eval( R+I >= U),
|
||||
!,
|
||||
dec_step( H, Status),
|
||||
rcbl_status( Status, X, [], Binds,[], u(U)),
|
||||
export_binding( Binds).
|
||||
reconsider_upper( _, _, _).
|
||||
|
||||
reconsider_lower( X, Lin, L) :-
|
||||
decompose( Lin, H, R, I),
|
||||
arith_eval( R+I =< L),
|
||||
!,
|
||||
inc_step( H, Status),
|
||||
rcbl_status( Status, X, [], Binds,[], l(L)),
|
||||
export_binding( Binds).
|
||||
reconsider_lower( _, _, _).
|
||||
|
||||
%
|
||||
% lin is dereferenced
|
||||
%
|
||||
solve_bound( Lin, Bound) :-
|
||||
arith_eval( Bound =:= 0),
|
||||
!,
|
||||
solve( Lin).
|
||||
solve_bound( Lin, Bound) :-
|
||||
arith_eval( -Bound, Nb),
|
||||
normalize_scalar( Nb, Nbs),
|
||||
add_linear_11( Nbs, Lin, Eq),
|
||||
solve( Eq).
|
@ -1,273 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.3 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: itf3.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%
|
||||
% interface to attribute encoding and hooks
|
||||
%
|
||||
|
||||
:- use_module( library(atts)).
|
||||
|
||||
:- attribute class/1, order/1, lin/1, forward/1,
|
||||
type/1, strictness/1, nonzero/0,
|
||||
target/0, keep_indep/0, keep/0. % project.pl
|
||||
|
||||
/* Moved here from store.pl to break cyclic dependencies. --Mats C. */
|
||||
%
|
||||
% critical impact on the backsubstitution effort
|
||||
% AND precision in clp(r)
|
||||
%
|
||||
% nf_ordering( A, B, Rel) :-
|
||||
% get_atts( A, order( Oa)),
|
||||
% get_atts( B, order( Ob)),
|
||||
% compare( Rel, Oa, Ob).
|
||||
|
||||
:- multifile
|
||||
user:goal_expansion/3.
|
||||
|
||||
:- dynamic
|
||||
user:goal_expansion/3.
|
||||
%
|
||||
user:goal_expansion( nf_ordering(A,B,Rel), Module, Exp) :-
|
||||
clpqr( Module),
|
||||
Exp = (
|
||||
get_atts( A, order(Oa)),
|
||||
get_atts( B, order(Ob)),
|
||||
compare( Rel, Oa, Ob)
|
||||
).
|
||||
|
||||
user:goal_expansion( decompose(Lin,H,R,I), Module, Lin=[I,R|H]) :-
|
||||
clpqr( Module).
|
||||
|
||||
clpqr( clpq).
|
||||
clpqr( clpr).
|
||||
/* End of code from store.pl */
|
||||
|
||||
%
|
||||
% Parametrize the answer presentation mechanism
|
||||
% (toplevel,compiler/debugger ...)
|
||||
%
|
||||
:- dynamic presentation_context/1.
|
||||
|
||||
presentation_context( Old, New) :-
|
||||
clause( presentation_context(Current), _),
|
||||
!,
|
||||
Current = Old,
|
||||
retractall( presentation_context(_)),
|
||||
assert( presentation_context( New)).
|
||||
presentation_context( toplevel, New) :- % default
|
||||
assert( presentation_context( New)).
|
||||
|
||||
%
|
||||
% attribute_goal( V, V:Atts) :- get_atts( V, Atts).
|
||||
%
|
||||
attribute_goal( V, Goal) :-
|
||||
presentation_context( Cont, Cont),
|
||||
dump_linear( V, Cont, Goals, Gtail),
|
||||
dump_nonzero( V, Cont, Gtail, []),
|
||||
l2wrapped( Goals, Goal).
|
||||
|
||||
l2wrapped( [], true).
|
||||
l2wrapped( [X|Xs], Conj) :-
|
||||
( Xs = [], wrap( X, Conj)
|
||||
; Xs = [_|_], wrap( X, Xw),
|
||||
Conj = (Xw,Xc),
|
||||
l2wrapped( Xs, Xc)
|
||||
).
|
||||
|
||||
%
|
||||
% Tests should be pulled out of the loop ...
|
||||
%
|
||||
wrap( C, W) :-
|
||||
prolog_flag(typein_module, Module),
|
||||
this_linear_solver( Solver),
|
||||
( Module == Solver ->
|
||||
W = {C}
|
||||
; predicate_property( Module:{_}, imported_from(Solver)) ->
|
||||
W = {C}
|
||||
;
|
||||
W = Solver:{C}
|
||||
).
|
||||
|
||||
dump_linear( V, Context) -->
|
||||
{
|
||||
get_atts( V, [lin(Lin),type(Type)]),
|
||||
!,
|
||||
decompose( Lin, H, _, I)
|
||||
},
|
||||
%
|
||||
% This happens if not all target variables can be made independend
|
||||
% Example: examples/option.pl:
|
||||
% | ?- go2(S,W).
|
||||
%
|
||||
% W = 21/4,
|
||||
% S>=0,
|
||||
% S<50 ? ;
|
||||
%
|
||||
% W>5,
|
||||
% S=221/4-W, this line would be missing !!!
|
||||
% W=<21/4
|
||||
%
|
||||
( { Type=t_none ; get_atts( V, -target) } -> [] ; dump_v( Context, t_none, V, I, H) ),
|
||||
%
|
||||
( {Type=t_none, get_atts( V, -target) } -> % nonzero produces such
|
||||
[]
|
||||
;
|
||||
dump_v( Context, Type, V, I, H)
|
||||
).
|
||||
dump_linear( _, _) --> [].
|
||||
|
||||
dump_v( toplevel, Type, V, I, H) --> dump_var( Type, V, I, H).
|
||||
dump_v( compiler, Type, V, I, H) --> compiler_dump_var( Type, V, I, H).
|
||||
|
||||
dump_nonzero( V, Cont) -->
|
||||
{
|
||||
get_atts( V, [nonzero,lin(Lin)]),
|
||||
!,
|
||||
decompose( Lin, H, _, I)
|
||||
},
|
||||
dump_nz( Cont, V, H, I).
|
||||
dump_nonzero( _, _) --> [].
|
||||
|
||||
dump_nz( toplevel, V, H, I) --> dump_nz( V, H, I).
|
||||
dump_nz( compiler, V, H, I) --> compiler_dump_nz( V, H, I).
|
||||
|
||||
numbers_only( Y, _) :- var(Y), !.
|
||||
numbers_only( Y, _) :- arith_normalize( Y, Y), !.
|
||||
numbers_only( Y, X) :-
|
||||
this_linear_solver( Solver),
|
||||
( Solver==clpr ->
|
||||
What = 'a real number'
|
||||
; Solver==clpq ->
|
||||
What = 'a rational number'
|
||||
),
|
||||
raise_exception( type_error(X=Y,2,What,Y)).
|
||||
|
||||
verify_attributes( X, _, []) :-
|
||||
get_atts(X, [-class(_),-order(_),-lin(_),-forward(_),-type(_),-strictness(_),
|
||||
-nonzero]),
|
||||
!.
|
||||
verify_attributes( X, Y, []) :-
|
||||
get_atts( X, forward(F)),
|
||||
!,
|
||||
fwd_deref( F, Y).
|
||||
verify_attributes( X, Y, Later) :-
|
||||
numbers_only( Y, X),
|
||||
put_atts( X, forward(Y)),
|
||||
verify_nonzero( X, Y),
|
||||
verify_type( X, Y, Later, []),
|
||||
verify_lin( X, Y).
|
||||
|
||||
fwd_deref( X, Y) :- nonvar(X), X=Y.
|
||||
fwd_deref( X, Y) :- var(X),
|
||||
( get_atts( X, forward(F)) ->
|
||||
fwd_deref( F, Y)
|
||||
;
|
||||
X = Y
|
||||
).
|
||||
|
||||
verify_nonzero( X, Y) :-
|
||||
get_atts( X, nonzero),
|
||||
!,
|
||||
( var(Y) ->
|
||||
put_atts( Y, nonzero)
|
||||
;
|
||||
arith_eval( Y =\= 0)
|
||||
).
|
||||
verify_nonzero( _, _).
|
||||
|
||||
verify_type( X, Y) -->
|
||||
{
|
||||
get_atts( X, [type(Type),strictness(Strict)])
|
||||
},
|
||||
!,
|
||||
verify_type( Y, Type, Strict).
|
||||
verify_type( _, _) --> [].
|
||||
|
||||
verify_type( Y, TypeX, StrictX) --> {var(Y)}, !,
|
||||
verify_type_var( TypeX, Y, StrictX).
|
||||
verify_type( Y, TypeX, StrictX) -->
|
||||
{
|
||||
verify_type_nonvar( TypeX, Y, StrictX)
|
||||
}.
|
||||
|
||||
verify_type_nonvar( t_none, _, _).
|
||||
verify_type_nonvar( t_l(L), Value, S) :- lb( S, L, Value).
|
||||
verify_type_nonvar( t_u(U), Value, S) :- ub( S, U, Value).
|
||||
verify_type_nonvar( t_lu(L,U), Value, S) :- lb( S, L, Value), ub( S, U, Value).
|
||||
verify_type_nonvar( t_L(L), Value, S) :- lb( S, L, Value).
|
||||
verify_type_nonvar( t_U(U), Value, S) :- ub( S, U, Value).
|
||||
verify_type_nonvar( t_Lu(L,U), Value, S) :- lb( S, L, Value), ub( S, U, Value).
|
||||
verify_type_nonvar( t_lU(L,U), Value, S) :- lb( S, L, Value), ub( S, U, Value).
|
||||
|
||||
lb( S, L, V) :- S /\ 2'10 =:= 0, !, arith_eval( L =< V).
|
||||
lb( _, L, V) :- arith_eval( L < V).
|
||||
|
||||
ub( S, U, V) :- S /\ 2'01 =:= 0, !, arith_eval( V =< U).
|
||||
ub( _, U, V) :- arith_eval( V < U).
|
||||
|
||||
|
||||
%
|
||||
% Running some goals after X=Y simplifies the coding. It should be possible
|
||||
% to run the goals here and taking care not to put_atts/2 on X ...
|
||||
%
|
||||
verify_type_var( t_none, _, _) --> [].
|
||||
verify_type_var( t_l(L), Y, S) --> llb( S, L, Y).
|
||||
verify_type_var( t_u(U), Y, S) --> lub( S, U, Y).
|
||||
verify_type_var( t_lu(L,U), Y, S) --> llb( S, L, Y), lub( S, U, Y).
|
||||
verify_type_var( t_L(L), Y, S) --> llb( S, L, Y).
|
||||
verify_type_var( t_U(U), Y, S) --> lub( S, U, Y).
|
||||
verify_type_var( t_Lu(L,U), Y, S) --> llb( S, L, Y), lub( S, U, Y).
|
||||
verify_type_var( t_lU(L,U), Y, S) --> llb( S, L, Y), lub( S, U, Y).
|
||||
|
||||
llb( S, L, V) --> {S /\ 2'10 =:= 0}, !, [ {L =< V} ].
|
||||
llb( _, L, V) --> [ {L < V} ].
|
||||
|
||||
lub( S, U, V) --> {S /\ 2'01 =:= 0}, !, [ {V =< U} ].
|
||||
lub( _, U, V) --> [ {V < U} ].
|
||||
|
||||
|
||||
%
|
||||
% We used to drop X from the class/basis to avoid trouble with subsequent
|
||||
% put_atts/2 on X. Now we could let these dead but harmless updates happen.
|
||||
% In R however, exported bindings might conflict, e.g. 0 \== 0.0
|
||||
%
|
||||
% If X is indep and we do _not_ solve for it, we are in deep shit
|
||||
% because the ordering is violated.
|
||||
%
|
||||
verify_lin( X, Y) :-
|
||||
get_atts( X, [class(Class),lin(LinX)]),
|
||||
!,
|
||||
( indep( LinX, X) ->
|
||||
detach_bounds( X), % if there were bounds, they are requeued already
|
||||
class_drop( Class, X),
|
||||
nf( X-Y, Lin),
|
||||
deref( Lin, Lind),
|
||||
( nf_coeff_of( Lind, X, _) ->
|
||||
solve_x( Lind, X)
|
||||
;
|
||||
solve( Lind)
|
||||
)
|
||||
;
|
||||
class_drop( Class, X),
|
||||
nf( X-Y, Lin),
|
||||
deref( Lin, Lind),
|
||||
solve( Lind)
|
||||
).
|
||||
verify_lin( _, _).
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,27 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.2 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: monash.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%
|
||||
% Monash compatibility
|
||||
%
|
||||
|
||||
:- op( 700, xfx, <=).
|
||||
:- op( 150, fx, #).
|
||||
|
||||
:- use_module( printf).
|
||||
:- use_module( expand).
|
||||
|
||||
:- prolog_flag( unknown, _, fail).
|
||||
|
||||
dump. % cheating
|
||||
dump( L) :- ordering( L).
|
@ -1,834 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.3 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: nf.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
:- use_module( library(terms), [term_variables/2]).
|
||||
:- use_module( geler).
|
||||
|
||||
% -------------------------------------------------------------------------
|
||||
|
||||
{ Rel } :- var( Rel), !, raise_exception(instantiation_error({Rel},1)).
|
||||
{ R,Rs } :- !, {R}, {Rs}.
|
||||
{ R;Rs } :- !, ({R} ; {Rs}). % for entailment checking
|
||||
{ L < R } :- !, nf( L-R, Nf), submit_lt( Nf).
|
||||
{ L > R } :- !, nf( R-L, Nf), submit_lt( Nf).
|
||||
{ L =< R } :- !, nf( L-R, Nf), submit_le( Nf).
|
||||
{ <=(L,R) } :- !, nf( L-R, Nf), submit_le( Nf).
|
||||
{ L >= R } :- !, nf( R-L, Nf), submit_le( Nf).
|
||||
{ L =\= R } :- !, nf( L-R, Nf), submit_ne( Nf).
|
||||
{ L =:= R } :- !, nf( L-R, Nf), submit_eq( Nf).
|
||||
{ L = R } :- !, nf( L-R, Nf), submit_eq( Nf).
|
||||
{ Rel } :- raise_exception( type_error({Rel},1,'a constraint',Rel)).
|
||||
|
||||
%
|
||||
% s -> c = ~s v c = ~(s /\ ~c)
|
||||
% where s is the store and c is the constraint for which
|
||||
% we want to know whether it is entailed.
|
||||
%
|
||||
entailed( C) :-
|
||||
negate( C, Cn),
|
||||
\+ { Cn }.
|
||||
|
||||
negate( Rel, _) :- var( Rel), !, raise_exception(instantiation_error(entailed(Rel),1)).
|
||||
negate( (A,B), (Na;Nb)) :- !, negate( A, Na), negate( B, Nb).
|
||||
negate( (A;B), (Na,Nb)) :- !, negate( A, Na), negate( B, Nb).
|
||||
negate( A<B, A>=B) :- !.
|
||||
negate( A>B, A=<B) :- !.
|
||||
negate( A=<B, A>B) :- !.
|
||||
negate( A>=B, A<B) :- !.
|
||||
negate( A=:=B, A=\=B) :- !.
|
||||
negate( A=B, A=\=B) :- !.
|
||||
negate( A=\=B, A=:=B) :- !.
|
||||
negate( Rel, _) :- raise_exception( type_error(entailed(Rel),1,'a constraint',Rel)).
|
||||
|
||||
/*
|
||||
Cases: a) Nf=[]
|
||||
b) Nf=[A]
|
||||
b1) A=k
|
||||
b2) invertible(A)
|
||||
b3) linear -> A=0
|
||||
b4) nonlinear -> geler
|
||||
c) Nf=[A,B|Rest]
|
||||
c1) A=k
|
||||
c11) B=X^+-1, Rest=[] -> B=
|
||||
c12) invertible(A,B)
|
||||
c13) linear(B|Rest)
|
||||
c14) geler
|
||||
c2) linear(Nf)
|
||||
c3) nonlinear -> geler
|
||||
*/
|
||||
submit_eq( []). % trivial success
|
||||
submit_eq( [T|Ts]) :-
|
||||
submit_eq( Ts, T).
|
||||
|
||||
submit_eq( [], A) :- submit_eq_b( A).
|
||||
submit_eq( [B|Bs], A) :- submit_eq_c( A, B, Bs).
|
||||
|
||||
submit_eq_b( v(_,[])) :- !, fail. % b1: trivial failure
|
||||
submit_eq_b( v(_,[X^P])) :- % b2,b3: n*x^p=0 -> x=0
|
||||
var( X),
|
||||
P > 0,
|
||||
!,
|
||||
arith_eval( 0, Z),
|
||||
export_binding( X, Z).
|
||||
submit_eq_b( v(_,[NL^1])) :- % b2
|
||||
nonvar( NL),
|
||||
arith_eval( 0, Z),
|
||||
nl_invertible( NL, X, Z, Inv),
|
||||
!,
|
||||
nf( -Inv, S),
|
||||
nf_add( X, S, New),
|
||||
submit_eq( New).
|
||||
submit_eq_b( Term) :- % b4
|
||||
term_variables( Term, Vs),
|
||||
geler( Vs, resubmit_eq([Term])).
|
||||
|
||||
submit_eq_c( v(I,[]), B, Rest) :- !,
|
||||
submit_eq_c1( Rest, B, I).
|
||||
submit_eq_c( A, B, Rest) :- % c2
|
||||
A=v(_,[X^1]), var(X),
|
||||
B=v(_,[Y^1]), var(Y),
|
||||
linear( Rest),
|
||||
!,
|
||||
Hom = [A,B|Rest],
|
||||
% 'solve_='( Hom).
|
||||
nf_length( Hom, 0, Len),
|
||||
log_deref( Len, Hom, [], HomD),
|
||||
solve( HomD).
|
||||
submit_eq_c( A, B, Rest) :- % c3
|
||||
Norm = [A,B|Rest],
|
||||
term_variables( Norm, Vs),
|
||||
geler( Vs, resubmit_eq(Norm)).
|
||||
|
||||
submit_eq_c1( [], v(K,[X^P]), I) :- % c11
|
||||
var( X),
|
||||
( P = 1, !, arith_eval( -I/K, Val), export_binding( X, Val)
|
||||
; P = -1, !, arith_eval( -K/I, Val), export_binding( X, Val)
|
||||
).
|
||||
submit_eq_c1( [], v(K,[NL^P]), I) :- % c12
|
||||
nonvar( NL),
|
||||
( P = 1, arith_eval( -I/K, Y)
|
||||
; P = -1, arith_eval( -K/I, Y)
|
||||
),
|
||||
nl_invertible( NL, X, Y, Inv),
|
||||
!,
|
||||
nf( -Inv, S),
|
||||
nf_add( X, S, New),
|
||||
submit_eq( New).
|
||||
submit_eq_c1( Rest, B, I) :- % c13
|
||||
B=v(_,[Y^1]), var(Y),
|
||||
linear( Rest),
|
||||
!,
|
||||
% 'solve_='( [v(I,[]),B|Rest]).
|
||||
Hom = [B|Rest],
|
||||
nf_length( Hom, 0, Len),
|
||||
normalize_scalar( I, Nonvar),
|
||||
log_deref( Len, Hom, [], HomD),
|
||||
add_linear_11( Nonvar, HomD, LinD),
|
||||
solve( LinD).
|
||||
submit_eq_c1( Rest, B, I) :- % c14
|
||||
Norm = [v(I,[]),B|Rest],
|
||||
term_variables( Norm, Vs),
|
||||
geler( Vs, resubmit_eq(Norm)).
|
||||
|
||||
% -----------------------------------------------------------------------
|
||||
|
||||
submit_lt( []) :- fail. % trivial failure
|
||||
submit_lt( [A|As]) :-
|
||||
submit_lt( As, A).
|
||||
|
||||
submit_lt( [], v(K,P)) :- submit_lt_b( P, K).
|
||||
submit_lt( [B|Bs], A) :- submit_lt_c( Bs, A, B).
|
||||
|
||||
submit_lt_b( [], I) :- !, arith_eval( I<0).
|
||||
submit_lt_b( [X^1], K) :-
|
||||
var(X),
|
||||
!,
|
||||
( arith_eval( K>0) ->
|
||||
ineq_one_s_p_0( X)
|
||||
;
|
||||
ineq_one_s_n_0( X)
|
||||
).
|
||||
submit_lt_b( P, K) :-
|
||||
term_variables( P, Vs),
|
||||
geler( Vs, resubmit_lt([v(K,P)])).
|
||||
|
||||
submit_lt_c( [], A, B) :-
|
||||
A=v(I,[]),
|
||||
B=v(K,[Y^1]), var(Y),
|
||||
!,
|
||||
ineq_one( strict, Y, K, I).
|
||||
submit_lt_c( Rest, A, B) :-
|
||||
Norm = [A,B|Rest],
|
||||
( linear(Norm) ->
|
||||
'solve_<'( Norm)
|
||||
;
|
||||
term_variables( Norm, Vs),
|
||||
geler( Vs, resubmit_lt(Norm))
|
||||
).
|
||||
|
||||
submit_le( []). % trivial success
|
||||
submit_le( [A|As]) :-
|
||||
submit_le( As, A).
|
||||
|
||||
submit_le( [], v(K,P)) :- submit_le_b( P, K).
|
||||
submit_le( [B|Bs], A) :- submit_le_c( Bs, A, B).
|
||||
|
||||
submit_le_b( [], I) :- !, arith_eval( I=<0).
|
||||
submit_le_b( [X^1], K) :-
|
||||
var(X),
|
||||
!,
|
||||
( arith_eval( K>0) ->
|
||||
ineq_one_n_p_0( X)
|
||||
;
|
||||
ineq_one_n_n_0( X)
|
||||
).
|
||||
submit_le_b( P, K) :-
|
||||
term_variables( P, Vs),
|
||||
geler( Vs, resubmit_le([v(K,P)])).
|
||||
|
||||
submit_le_c( [], A, B) :-
|
||||
A=v(I,[]),
|
||||
B=v(K,[Y^1]), var(Y),
|
||||
!,
|
||||
ineq_one( nonstrict, Y, K, I).
|
||||
submit_le_c( Rest, A, B) :-
|
||||
Norm = [A,B|Rest],
|
||||
( linear(Norm) ->
|
||||
'solve_=<'( Norm)
|
||||
;
|
||||
term_variables( Norm, Vs),
|
||||
geler( Vs, resubmit_le(Norm))
|
||||
).
|
||||
|
||||
submit_ne( Norm1) :-
|
||||
( nf_constant( Norm1, K) ->
|
||||
arith_eval( K=\=0)
|
||||
; linear( Norm1) ->
|
||||
'solve_=\='( Norm1)
|
||||
;
|
||||
term_variables( Norm1, Vs),
|
||||
geler( Vs, resubmit_ne(Norm1))
|
||||
).
|
||||
|
||||
|
||||
linear( []).
|
||||
linear( v(_,Ps)) :- linear_ps( Ps).
|
||||
linear( [A|As]) :-
|
||||
linear( A),
|
||||
linear( As).
|
||||
|
||||
linear_ps( []).
|
||||
linear_ps( [V^1]) :- var( V). % excludes sin(_), ...
|
||||
|
||||
%
|
||||
% Goal delays until Term gets linear.
|
||||
% At this time, Var will be bound to the normalform of Term.
|
||||
%
|
||||
:- meta_predicate wait_linear( ?, ?, :).
|
||||
%
|
||||
wait_linear( Term, Var, Goal) :-
|
||||
nf( Term, Nf),
|
||||
( linear( Nf) ->
|
||||
Var = Nf,
|
||||
call( Goal)
|
||||
;
|
||||
term_variables( Nf, Vars),
|
||||
geler( Vars, wait_linear_retry(Nf,Var,Goal))
|
||||
).
|
||||
|
||||
%
|
||||
% geler clients
|
||||
%
|
||||
resubmit_eq( N) :-
|
||||
repair( N, Norm),
|
||||
submit_eq( Norm).
|
||||
|
||||
resubmit_lt( N) :-
|
||||
repair( N, Norm),
|
||||
submit_lt( Norm).
|
||||
|
||||
resubmit_le( N) :-
|
||||
repair( N, Norm),
|
||||
submit_le( Norm).
|
||||
|
||||
resubmit_ne( N) :-
|
||||
repair( N, Norm),
|
||||
submit_ne( Norm).
|
||||
|
||||
wait_linear_retry( Nf0, Var, Goal) :-
|
||||
repair( Nf0, Nf),
|
||||
( linear( Nf) ->
|
||||
Var = Nf,
|
||||
call( Goal)
|
||||
;
|
||||
term_variables( Nf, Vars),
|
||||
geler( Vars, wait_linear_retry(Nf,Var,Goal))
|
||||
).
|
||||
|
||||
% -----------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
invertible( [v(Mone,[]),v(One,[X^Px,Y^Py])], Norm) :-
|
||||
Px+Py =:= 0,
|
||||
abs(Px) mod 2 =:= 1, % odd powers only ...
|
||||
arith_eval( 1, One),
|
||||
arith_eval( -1, Mone),
|
||||
!,
|
||||
( Px < 0 ->
|
||||
{X=\=0}
|
||||
;
|
||||
{Y=\=0}
|
||||
),
|
||||
nf( X-Y, Norm). % x=y
|
||||
*/
|
||||
|
||||
nl_invertible( sin(X), X, Y, Res) :- arith_eval( asin(Y), Res).
|
||||
nl_invertible( cos(X), X, Y, Res) :- arith_eval( acos(Y), Res).
|
||||
nl_invertible( tan(X), X, Y, Res) :- arith_eval( atan(Y), Res).
|
||||
nl_invertible( exp(B,C), X, A, Res) :-
|
||||
( nf_constant( B, Kb) ->
|
||||
arith_eval(A>0),
|
||||
arith_eval(Kb>0),
|
||||
arith_eval(Kb=\=1),
|
||||
X = C,
|
||||
arith_eval( log(A)/log(Kb), Res)
|
||||
; nf_constant( C, Kc),
|
||||
\+ (arith_eval(A=:=0),arith_eval(Kc=<0)),
|
||||
X = B,
|
||||
arith_eval( exp(A,1/Kc), Res)
|
||||
).
|
||||
|
||||
% -----------------------------------------------------------------------
|
||||
|
||||
nf( X, Norm) :- var(X), !,
|
||||
Norm = [v(One,[X^1])],
|
||||
arith_eval( 1, One).
|
||||
nf( X, Norm) :- number(X), !,
|
||||
nf_number( X, Norm).
|
||||
%
|
||||
nf( rat(N,D), Norm) :- !,
|
||||
nf_number( rat(N,D), Norm).
|
||||
%
|
||||
nf( #(Const), Norm) :-
|
||||
monash_constant( Const, Value),
|
||||
!,
|
||||
( arith_eval( 1, rat(1,1)) ->
|
||||
nf_number( Value, Norm) % swallows #(zero) ... ok in Q
|
||||
;
|
||||
arith_normalize( Value, N), % in R we want it
|
||||
Norm = [v(N,[])]
|
||||
).
|
||||
%
|
||||
nf( -A, Norm) :- !,
|
||||
nf( A, An),
|
||||
arith_eval( -1, K),
|
||||
nf_mul_factor( v(K,[]), An, Norm).
|
||||
nf( +A, Norm) :- !,
|
||||
nf( A, Norm).
|
||||
%
|
||||
nf( A+B, Norm) :- !,
|
||||
nf( A, An),
|
||||
nf( B, Bn),
|
||||
nf_add( An, Bn, Norm).
|
||||
nf( A-B, Norm) :- !,
|
||||
nf( A, An),
|
||||
nf( -B, Bn),
|
||||
nf_add( An, Bn, Norm).
|
||||
%
|
||||
nf( A*B, Norm) :- !,
|
||||
nf( A, An),
|
||||
nf( B, Bn),
|
||||
nf_mul( An, Bn, Norm).
|
||||
nf( A/B, Norm) :- !,
|
||||
nf( A, An),
|
||||
nf( B, Bn),
|
||||
nf_div( Bn, An, Norm).
|
||||
%
|
||||
nf( Term, Norm) :-
|
||||
nonlin_1( Term, Arg, Skel, Sa1),
|
||||
!,
|
||||
nf( Arg, An),
|
||||
nf_nonlin_1( Skel, An, Sa1, Norm).
|
||||
nf( Term, Norm) :-
|
||||
nonlin_2( Term, A1,A2, Skel, Sa1, Sa2),
|
||||
!,
|
||||
nf( A1, A1n),
|
||||
nf( A2, A2n),
|
||||
nf_nonlin_2( Skel, A1n, A2n, Sa1, Sa2, Norm).
|
||||
%
|
||||
nf( Term, _) :-
|
||||
raise_exception( type_error(nf(Term,_),1,'a numeric expression',Term)).
|
||||
|
||||
nf_number( N, Res) :-
|
||||
nf_number( N),
|
||||
arith_normalize( N, Normal),
|
||||
( arith_eval( Normal=:=0) ->
|
||||
Res = []
|
||||
;
|
||||
Res = [v(Normal,[])]
|
||||
).
|
||||
|
||||
nf_number( N) :- number( N),
|
||||
!. /* MC 980507 */
|
||||
nf_number( N) :- compound( N), N=rat(_,_). % sicstus
|
||||
|
||||
nonlin_1( abs(X), X, abs(Y), Y).
|
||||
nonlin_1( sin(X), X, sin(Y), Y).
|
||||
nonlin_1( cos(X), X, cos(Y), Y).
|
||||
nonlin_1( tan(X), X, tan(Y), Y).
|
||||
|
||||
nonlin_2( min(A,B), A,B, min(X,Y), X, Y).
|
||||
nonlin_2( max(A,B), A,B, max(X,Y), X, Y).
|
||||
nonlin_2( exp(A,B), A,B, exp(X,Y), X, Y).
|
||||
nonlin_2( pow(A,B), A,B, exp(X,Y), X, Y). % pow->exp
|
||||
nonlin_2( A^B, A,B, exp(X,Y), X, Y).
|
||||
|
||||
nf_nonlin_1( Skel, An, S1, Norm) :-
|
||||
( nf_constant( An, S1) ->
|
||||
nl_eval( Skel, Res),
|
||||
nf_number( Res, Norm)
|
||||
;
|
||||
S1 = An,
|
||||
arith_eval( 1, One),
|
||||
Norm = [v(One,[Skel^1])]
|
||||
).
|
||||
|
||||
nf_nonlin_2( Skel, A1n, A2n, S1, S2, Norm) :-
|
||||
( nf_constant( A1n, S1),
|
||||
nf_constant( A2n, S2) ->
|
||||
nl_eval( Skel, Res),
|
||||
nf_number( Res, Norm)
|
||||
; Skel=exp(_,_),
|
||||
nf_constant( A2n, Exp),
|
||||
integerp( Exp, I) ->
|
||||
nf_power( I, A1n, Norm)
|
||||
;
|
||||
S1 = A1n,
|
||||
S2 = A2n,
|
||||
arith_eval( 1, One),
|
||||
Norm = [v(One,[Skel^1])]
|
||||
).
|
||||
|
||||
|
||||
nl_eval( abs(X), R) :- arith_eval( abs(X), R).
|
||||
nl_eval( sin(X), R) :- arith_eval( sin(X), R).
|
||||
nl_eval( cos(X), R) :- arith_eval( cos(X), R).
|
||||
nl_eval( tan(X), R) :- arith_eval( tan(X), R).
|
||||
%
|
||||
nl_eval( min(X,Y), R) :- arith_eval( min(X,Y), R).
|
||||
nl_eval( max(X,Y), R) :- arith_eval( max(X,Y), R).
|
||||
nl_eval( exp(X,Y), R) :- arith_eval( exp(X,Y), R).
|
||||
|
||||
monash_constant( X, _) :- var(X), !, fail.
|
||||
monash_constant( p, 3.14259265).
|
||||
monash_constant( pi, 3.14259265).
|
||||
monash_constant( e, 2.71828182).
|
||||
monash_constant( zero, Eps) :- arith_eps( Eps).
|
||||
|
||||
%
|
||||
% check if a Nf consists of just a constant
|
||||
%
|
||||
nf_constant( [], Z) :- arith_eval( 0, Z).
|
||||
nf_constant( [v(K,[])], K).
|
||||
|
||||
%
|
||||
% this depends on the polynf ordering, i.e. [] < [X^1] ...
|
||||
%
|
||||
split( [], [], Z) :- arith_eval( 0, Z).
|
||||
split( [First|T], H, I) :-
|
||||
( First=v(I,[]) ->
|
||||
H=T
|
||||
;
|
||||
arith_eval( 0, I),
|
||||
H = [First|T]
|
||||
).
|
||||
|
||||
%
|
||||
% runtime predicate
|
||||
%
|
||||
:- mode nf_add( +, +, ?).
|
||||
%
|
||||
nf_add( [], Bs, Bs).
|
||||
nf_add( [A|As], Bs, Cs) :-
|
||||
nf_add( Bs, A, As, Cs).
|
||||
|
||||
:- mode nf_add( +, +, +, ?).
|
||||
%
|
||||
nf_add( [], A, As, Cs) :- Cs = [A|As].
|
||||
nf_add( [B|Bs], A, As, Cs) :-
|
||||
A = v(Ka,Pa),
|
||||
B = v(Kb,Pb),
|
||||
compare( Rel, Pa, Pb),
|
||||
nf_add_case( Rel, A, As, Cs, B, Bs, Ka, Kb, Pa).
|
||||
|
||||
:- mode nf_add_case( +, +, +, -, +, +, +, +, +).
|
||||
%
|
||||
nf_add_case( <, A, As, Cs, B, Bs, _, _, _) :-
|
||||
Cs=[A|Rest],
|
||||
nf_add( As, B, Bs, Rest).
|
||||
nf_add_case( >, A, As, Cs, B, Bs, _, _, _) :-
|
||||
Cs=[B|Rest],
|
||||
nf_add( Bs, A, As, Rest).
|
||||
nf_add_case( =, _, As, Cs, _, Bs, Ka, Kb, Pa) :-
|
||||
arith_eval( Ka+Kb, Kc),
|
||||
( arith_eval( Kc=:=0 ) ->
|
||||
nf_add( As, Bs, Cs)
|
||||
;
|
||||
Cs=[v(Kc,Pa)|Rest],
|
||||
nf_add( As, Bs, Rest)
|
||||
).
|
||||
|
||||
:- mode nf_mul( +, +, -).
|
||||
%
|
||||
nf_mul( A, B, Res) :-
|
||||
nf_length( A, 0, LenA),
|
||||
nf_length( B, 0, LenB),
|
||||
nf_mul_log( LenA, A, [], LenB, B, Res).
|
||||
|
||||
nf_mul_log( 0, As, As, _, _, []) :- !.
|
||||
nf_mul_log( 1, [A|As], As, Lb, B, R) :- !,
|
||||
nf_mul_factor_log( Lb, B, [], A, R).
|
||||
nf_mul_log( 2, [A1,A2|As], As, Lb, B, R) :- !,
|
||||
nf_mul_factor_log( Lb, B, [], A1, A1b),
|
||||
nf_mul_factor_log( Lb, B, [], A2, A2b),
|
||||
nf_add( A1b, A2b, R).
|
||||
nf_mul_log( N, A0, A2, Lb, B, R) :-
|
||||
P is N>>1,
|
||||
Q is N-P,
|
||||
nf_mul_log( P, A0, A1, Lb, B, Rp),
|
||||
nf_mul_log( Q, A1, A2, Lb, B, Rq),
|
||||
nf_add( Rp, Rq, R).
|
||||
|
||||
:- mode nf_add_2( +, +, -).
|
||||
%
|
||||
nf_add_2( Af, Bf, Res) :- % unfold: nf_add( [Af], [Bf], Res).
|
||||
Af = v(Ka,Pa),
|
||||
Bf = v(Kb,Pb),
|
||||
compare( Rel, Pa, Pb),
|
||||
nf_add_2_case( Rel, Af, Bf, Res, Ka, Kb, Pa).
|
||||
|
||||
:- mode nf_add_2_case( +, +, +, -, +, +, +).
|
||||
%
|
||||
nf_add_2_case( <, Af, Bf, [Af,Bf], _, _, _).
|
||||
nf_add_2_case( >, Af, Bf, [Bf,Af], _, _, _).
|
||||
nf_add_2_case( =, _, _, Res, Ka, Kb, Pa) :-
|
||||
arith_eval( Ka+Kb, Kc),
|
||||
( arith_eval( Kc=:=0 ) ->
|
||||
Res = []
|
||||
;
|
||||
Res=[v(Kc,Pa)]
|
||||
).
|
||||
|
||||
%
|
||||
% multiply with a scalar =\= 0
|
||||
%
|
||||
nf_mul_k( [], _, []).
|
||||
nf_mul_k( [v(I,P)|Vs], K, [v(Ki,P)|Vks]) :-
|
||||
arith_eval( K*I, Ki),
|
||||
nf_mul_k( Vs, K, Vks).
|
||||
|
||||
nf_mul_factor( v(K,[]), Sum, Res) :- !, nf_mul_k( Sum, K, Res).
|
||||
nf_mul_factor( F, Sum, Res) :-
|
||||
nf_length( Sum, 0, Len),
|
||||
nf_mul_factor_log( Len, Sum, [], F, Res).
|
||||
|
||||
nf_mul_factor_log( 0, As, As, _, []) :- !.
|
||||
nf_mul_factor_log( 1, [A|As], As, F, [R]) :- !,
|
||||
mult( A, F, R).
|
||||
nf_mul_factor_log( 2, [A,B|As], As, F, Res) :- !,
|
||||
mult( A, F, Af),
|
||||
mult( B, F, Bf),
|
||||
nf_add_2( Af, Bf, Res).
|
||||
nf_mul_factor_log( N, A0, A2, F, R) :-
|
||||
P is N>>1,
|
||||
Q is N-P,
|
||||
nf_mul_factor_log( P, A0, A1, F, Rp),
|
||||
nf_mul_factor_log( Q, A1, A2, F, Rq),
|
||||
nf_add( Rp, Rq, R).
|
||||
|
||||
mult( v(Ka,La), v(Kb,Lb), v(Kc,Lc)) :-
|
||||
arith_eval( Ka*Kb, Kc),
|
||||
pmerge( La, Lb, Lc).
|
||||
|
||||
pmerge( [], Bs, Bs).
|
||||
pmerge( [A|As], Bs, Cs) :-
|
||||
pmerge( Bs, A, As, Cs).
|
||||
|
||||
:- mode pmerge(+,+,+,-).
|
||||
%
|
||||
pmerge( [], A, As, Res) :- Res = [A|As].
|
||||
pmerge( [B|Bs], A, As, Res) :-
|
||||
A=Xa^Ka,
|
||||
B=Xb^Kb,
|
||||
compare( R, Xa, Xb),
|
||||
pmerge_case( R, A, As, Res, B, Bs, Ka, Kb, Xa).
|
||||
|
||||
:- mode pmerge_case( +, +, +, -, +, +, +, +, ?).
|
||||
%
|
||||
pmerge_case( <, A, As, Res, B, Bs, _, _, _) :-
|
||||
Res = [A|Tail],
|
||||
pmerge( As, B, Bs, Tail).
|
||||
pmerge_case( >, A, As, Res, B, Bs, _, _, _) :-
|
||||
Res = [B|Tail],
|
||||
pmerge( Bs, A, As, Tail).
|
||||
pmerge_case( =, _, As, Res, _, Bs, Ka, Kb, Xa) :-
|
||||
Kc is Ka+Kb,
|
||||
( Kc=:=0 ->
|
||||
pmerge( As, Bs, Res)
|
||||
;
|
||||
Res = [Xa^Kc|Tail],
|
||||
pmerge( As, Bs, Tail)
|
||||
).
|
||||
|
||||
nf_div( [], _, _) :- !, zero_division.
|
||||
nf_div( [v(K,P)], Sum, Res) :- !,
|
||||
arith_eval( 1/K, Ki),
|
||||
mult_exp( P, -1, Pi),
|
||||
nf_mul_factor( v(Ki,Pi), Sum, Res).
|
||||
nf_div( D, A, [v(One,[(A/D)^1])]) :-
|
||||
arith_eval( 1, One).
|
||||
|
||||
zero_division :- fail. % raise_exception(_) ?
|
||||
|
||||
mult_exp( [], _, []).
|
||||
mult_exp( [X^P|Xs], K, [X^I|Tail]) :-
|
||||
I is K*P,
|
||||
mult_exp( Xs, K, Tail).
|
||||
|
||||
%
|
||||
% raise to integer powers
|
||||
%
|
||||
% | ?- time({(1+X+Y+Z)^15=0}).
|
||||
% Timing 00:00:02.610 2.610 iterative
|
||||
% Timing 00:00:00.660 0.660 binomial
|
||||
nf_power( N, Sum, Norm) :-
|
||||
integer( N),
|
||||
compare( Rel, N, 0),
|
||||
( Rel = < ->
|
||||
Pn is -N,
|
||||
% nf_power_pos( Pn, Sum, Inorm),
|
||||
binom( Sum, Pn, Inorm),
|
||||
arith_eval( 1, One),
|
||||
nf_div( Inorm, [v(One,[])], Norm)
|
||||
; Rel = > ->
|
||||
% nf_power_pos( N, Sum, Norm)
|
||||
binom( Sum, N, Norm)
|
||||
; Rel = = -> % 0^0 is indeterminate but we say 1
|
||||
arith_eval( 1, One),
|
||||
Norm = [v(One,[])]
|
||||
).
|
||||
|
||||
|
||||
%
|
||||
% N>0
|
||||
%
|
||||
nf_power_pos( 1, Sum, Norm) :- !, Sum = Norm.
|
||||
nf_power_pos( N, Sum, Norm) :-
|
||||
N1 is N-1,
|
||||
nf_power_pos( N1, Sum, Pn1),
|
||||
nf_mul( Sum, Pn1, Norm).
|
||||
|
||||
%
|
||||
% N>0
|
||||
%
|
||||
binom( Sum, 1, Power) :- !, Power = Sum.
|
||||
binom( [], _, []).
|
||||
binom( [A|Bs], N, Power) :-
|
||||
( Bs=[] ->
|
||||
nf_power_factor( A, N, Ap),
|
||||
Power = [Ap]
|
||||
; Bs=[_|_] ->
|
||||
arith_eval( 1, One),
|
||||
factor_powers( N, A, v(One,[]), Pas),
|
||||
sum_powers( N, Bs, [v(One,[])], Pbs, []),
|
||||
combine_powers( Pas, Pbs, 0, N, 1, [], Power)
|
||||
).
|
||||
|
||||
combine_powers( [], [], _, _, _, Pi, Pi).
|
||||
combine_powers( [A|As], [B|Bs], L, R, C, Pi, Po) :-
|
||||
nf_mul( A, B, Ab),
|
||||
arith_normalize( C, Cn),
|
||||
nf_mul_k( Ab, Cn, Abc),
|
||||
nf_add( Abc, Pi, Pii),
|
||||
L1 is L+1,
|
||||
R1 is R-1,
|
||||
C1 is C*R//L1,
|
||||
combine_powers( As, Bs, L1, R1, C1, Pii, Po).
|
||||
|
||||
|
||||
nf_power_factor( v(K,P), N, v(Kn,Pn)) :-
|
||||
arith_normalize( N, Nn),
|
||||
arith_eval( exp(K,Nn), Kn),
|
||||
mult_exp( P, N, Pn).
|
||||
|
||||
factor_powers( 0, _, Prev, [[Prev]]) :- !.
|
||||
factor_powers( N, F, Prev, [[Prev]|Ps]) :-
|
||||
N1 is N-1,
|
||||
mult( Prev, F, Next),
|
||||
factor_powers( N1, F, Next, Ps).
|
||||
|
||||
sum_powers( 0, _, Prev, [Prev|Lt], Lt) :- !.
|
||||
sum_powers( N, S, Prev, L0, Lt) :-
|
||||
N1 is N-1,
|
||||
nf_mul( S, Prev, Next),
|
||||
sum_powers( N1, S, Next, L0, [Prev|Lt]).
|
||||
|
||||
% ------------------------------------------------------------------------------
|
||||
|
||||
repair( Sum, Norm) :-
|
||||
nf_length( Sum, 0, Len),
|
||||
repair_log( Len, Sum, [], Norm).
|
||||
|
||||
repair_log( 0, As, As, []) :- !.
|
||||
repair_log( 1, [v(Ka,Pa)|As], As, R) :- !,
|
||||
repair_term( Ka, Pa, R).
|
||||
repair_log( 2, [v(Ka,Pa),v(Kb,Pb)|As], As, R) :- !,
|
||||
repair_term( Ka, Pa, Ar),
|
||||
repair_term( Kb, Pb, Br),
|
||||
nf_add( Ar, Br, R).
|
||||
repair_log( N, A0, A2, R) :-
|
||||
P is N>>1,
|
||||
Q is N-P,
|
||||
repair_log( P, A0, A1, Rp),
|
||||
repair_log( Q, A1, A2, Rq),
|
||||
nf_add( Rp, Rq, R).
|
||||
|
||||
|
||||
repair_term( K, P, Norm) :-
|
||||
length( P, Len),
|
||||
arith_eval( 1, One),
|
||||
repair_p_log( Len, P, [], Pr, [v(One,[])], Sum),
|
||||
nf_mul_factor( v(K,Pr), Sum, Norm).
|
||||
|
||||
repair_p_log( 0, Ps, Ps, [], L0, L0) :- !.
|
||||
repair_p_log( 1, [X^P|Ps], Ps, R, L0, L1) :- !,
|
||||
repair_p( X, P, R, L0, L1).
|
||||
repair_p_log( 2, [X^Px,Y^Py|Ps], Ps, R, L0,L2) :- !,
|
||||
repair_p( X, Px, Rx, L0, L1),
|
||||
repair_p( Y, Py, Ry, L1, L2),
|
||||
pmerge( Rx, Ry, R).
|
||||
repair_p_log( N, P0, P2, R, L0, L2) :-
|
||||
P is N>>1,
|
||||
Q is N-P,
|
||||
repair_p_log( P, P0, P1, Rp, L0, L1),
|
||||
repair_p_log( Q, P1, P2, Rq, L1, L2),
|
||||
pmerge( Rp, Rq, R).
|
||||
|
||||
|
||||
repair_p( Term, P, [Term^P], L0, L0) :- var( Term).
|
||||
repair_p( Term, P, [], L0, L1) :- nonvar( Term),
|
||||
repair_p_one( Term, TermN),
|
||||
nf_power( P, TermN, TermNP),
|
||||
nf_mul( TermNP, L0, L1).
|
||||
|
||||
%
|
||||
% An undigested term a/b is distinguished from an
|
||||
% digested one by the fact that its arguments are
|
||||
% digested -> cuts after repair of args!
|
||||
%
|
||||
repair_p_one( Term, TermN) :-
|
||||
nf_number( Term, TermN), % freq. shortcut for nf/2 case below
|
||||
!.
|
||||
repair_p_one( A1/A2, TermN) :-
|
||||
repair( A1, A1n),
|
||||
repair( A2, A2n),
|
||||
!,
|
||||
nf_div( A2n, A1n, TermN).
|
||||
repair_p_one( Term, TermN) :-
|
||||
nonlin_1( Term, Arg, Skel, Sa),
|
||||
repair( Arg, An),
|
||||
!,
|
||||
nf_nonlin_1( Skel, An, Sa, TermN).
|
||||
repair_p_one( Term, TermN) :-
|
||||
nonlin_2( Term, A1,A2, Skel, Sa1, Sa2),
|
||||
repair( A1, A1n),
|
||||
repair( A2, A2n),
|
||||
!,
|
||||
nf_nonlin_2( Skel, A1n, A2n, Sa1, Sa2, TermN).
|
||||
repair_p_one( Term, TermN) :-
|
||||
nf( Term, TermN).
|
||||
|
||||
:- mode nf_length( +, +, -).
|
||||
%
|
||||
nf_length( [], Li, Li).
|
||||
nf_length( [_|R], Li, Lo) :-
|
||||
Lii is Li+1,
|
||||
nf_length( R, Lii, Lo).
|
||||
|
||||
% ------------------------------------------------------------------------------
|
||||
|
||||
nf2term( [], Z) :- arith_eval( 0, Z).
|
||||
nf2term( [F|Fs], T) :-
|
||||
f02t( F, T0),
|
||||
yfx( Fs, T0, T).
|
||||
|
||||
yfx( [], T0, T0).
|
||||
yfx( [F|Fs], T0, TN) :-
|
||||
fn2t( F, Ft, Op),
|
||||
T1 =.. [Op,T0,Ft],
|
||||
yfx( Fs, T1, TN).
|
||||
|
||||
f02t( v(K,P), T) :-
|
||||
( P = [] ->
|
||||
T = K
|
||||
; arith_eval( K=:=1) ->
|
||||
p2term( P, T)
|
||||
; arith_eval( K=:= -1) ->
|
||||
T = -Pt,
|
||||
p2term( P, Pt)
|
||||
;
|
||||
T = K*Pt,
|
||||
p2term( P, Pt)
|
||||
).
|
||||
|
||||
fn2t( v(K,P), Term, Op) :-
|
||||
( arith_eval( K=:=1) ->
|
||||
Term = Pt, Op = +
|
||||
; arith_eval( K=:= -1) ->
|
||||
Term = Pt, Op = -
|
||||
; arith_eval( K<0) ->
|
||||
arith_eval( -K, Kf),
|
||||
Term = Kf*Pt, Op = -
|
||||
;
|
||||
Term = K*Pt, Op = +
|
||||
),
|
||||
p2term( P, Pt).
|
||||
|
||||
p2term( [X^P|Xs], Term) :-
|
||||
( Xs=[] ->
|
||||
pe2term( X, Xt),
|
||||
exp2term( P, Xt, Term)
|
||||
; Xs=[_|_] ->
|
||||
Term = Xst*Xtp,
|
||||
pe2term( X, Xt),
|
||||
exp2term( P, Xt, Xtp),
|
||||
p2term( Xs, Xst)
|
||||
).
|
||||
|
||||
exp2term( 1, X, X) :- !.
|
||||
exp2term(-1, X, One/X) :- !, arith_eval( 1, One).
|
||||
exp2term( P, X, Term) :-
|
||||
arith_normalize( P, Pn),
|
||||
% Term = exp(X,Pn).
|
||||
Term = X^Pn.
|
||||
|
||||
pe2term( X, Term) :- var(X), Term = X.
|
||||
pe2term( X, Term) :- nonvar(X),
|
||||
X =.. [F|Args],
|
||||
pe2term_args( Args, Argst),
|
||||
Term =.. [F|Argst].
|
||||
|
||||
pe2term_args( [], []).
|
||||
pe2term_args( [A|As], [T|Ts]) :-
|
||||
nf2term( A, T),
|
||||
pe2term_args( As, Ts).
|
||||
|
@ -1,835 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.3 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: nf.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
:- use_module( library(terms), [term_variables/2]).
|
||||
:- use_module( geler).
|
||||
|
||||
% -------------------------------------------------------------------------
|
||||
|
||||
{ Rel } :- var( Rel), !, raise_exception(instantiation_error({Rel},1)).
|
||||
{ R,Rs } :- !, {R}, {Rs}.
|
||||
{ R;Rs } :- !, ({R} ; {Rs}). % for entailment checking
|
||||
{ L < R } :- !, nf( L-R, Nf), submit_lt( Nf).
|
||||
{ L > R } :- !, nf( R-L, Nf), submit_lt( Nf).
|
||||
{ L =< R } :- !, nf( L-R, Nf), submit_le( Nf).
|
||||
{ <=(L,R) } :- !, nf( L-R, Nf), submit_le( Nf).
|
||||
{ L >= R } :- !, nf( R-L, Nf), submit_le( Nf).
|
||||
{ L =\= R } :- !, nf( L-R, Nf), submit_ne( Nf).
|
||||
{ L =:= R } :- !, nf( L-R, Nf), submit_eq( Nf).
|
||||
{ L = R } :- !, nf( L-R, Nf), submit_eq( Nf).
|
||||
{ Rel } :- raise_exception( type_error({Rel},1,'a constraint',Rel)).
|
||||
|
||||
%
|
||||
% s -> c = ~s v c = ~(s /\ ~c)
|
||||
% where s is the store and c is the constraint for which
|
||||
% we want to know whether it is entailed.
|
||||
%
|
||||
entailed( C) :-
|
||||
negate( C, Cn),
|
||||
\+ { Cn }.
|
||||
|
||||
negate( Rel, _) :- var( Rel), !, raise_exception(instantiation_error(entailed(Rel),1)).
|
||||
negate( (A,B), (Na;Nb)) :- !, negate( A, Na), negate( B, Nb).
|
||||
negate( (A;B), (Na,Nb)) :- !, negate( A, Na), negate( B, Nb).
|
||||
negate( A<B, A>=B) :- !.
|
||||
negate( A>B, A=<B) :- !.
|
||||
negate( A=<B, A>B) :- !.
|
||||
negate( A>=B, A<B) :- !.
|
||||
negate( A=:=B, A=\=B) :- !.
|
||||
negate( A=B, A=\=B) :- !.
|
||||
negate( A=\=B, A=:=B) :- !.
|
||||
negate( Rel, _) :- raise_exception( type_error(entailed(Rel),1,'a constraint',Rel)).
|
||||
|
||||
/*
|
||||
Cases: a) Nf=[]
|
||||
b) Nf=[A]
|
||||
b1) A=k
|
||||
b2) invertible(A)
|
||||
b3) linear -> A=0
|
||||
b4) nonlinear -> geler
|
||||
c) Nf=[A,B|Rest]
|
||||
c1) A=k
|
||||
c11) B=X^+-1, Rest=[] -> B=
|
||||
c12) invertible(A,B)
|
||||
c13) linear(B|Rest)
|
||||
c14) geler
|
||||
c2) linear(Nf)
|
||||
c3) nonlinear -> geler
|
||||
*/
|
||||
submit_eq( []). % trivial success
|
||||
submit_eq( [T|Ts]) :-
|
||||
submit_eq( Ts, T).
|
||||
|
||||
submit_eq( [], A) :- submit_eq_b( A).
|
||||
submit_eq( [B|Bs], A) :- submit_eq_c( A, B, Bs).
|
||||
|
||||
submit_eq_b( v(_,[])) :- !, fail. % b1: trivial failure
|
||||
submit_eq_b( v(_,[X^P])) :- % b2,b3: n*x^p=0 -> x=0
|
||||
var( X),
|
||||
P > 0,
|
||||
!,
|
||||
arith_eval( 0, Z),
|
||||
export_binding( X, Z).
|
||||
submit_eq_b( v(_,[NL^1])) :- % b2
|
||||
nonvar( NL),
|
||||
arith_eval( 0, Z),
|
||||
nl_invertible( NL, X, Z, Inv),
|
||||
!,
|
||||
nf( -Inv, S),
|
||||
nf_add( X, S, New),
|
||||
submit_eq( New).
|
||||
submit_eq_b( Term) :- % b4
|
||||
term_variables( Term, Vs),
|
||||
geler( Vs, resubmit_eq([Term])).
|
||||
|
||||
submit_eq_c( v(I,[]), B, Rest) :- !,
|
||||
submit_eq_c1( Rest, B, I).
|
||||
submit_eq_c( A, B, Rest) :- % c2
|
||||
A=v(_,[X^1]), var(X),
|
||||
B=v(_,[Y^1]), var(Y),
|
||||
linear( Rest),
|
||||
!,
|
||||
Hom = [A,B|Rest],
|
||||
% 'solve_='( Hom).
|
||||
nf_length( Hom, 0, Len),
|
||||
log_deref( Len, Hom, [], HomD),
|
||||
solve( HomD).
|
||||
submit_eq_c( A, B, Rest) :- % c3
|
||||
Norm = [A,B|Rest],
|
||||
term_variables( Norm, Vs),
|
||||
geler( Vs, resubmit_eq(Norm)).
|
||||
|
||||
submit_eq_c1( [], v(K,[X^P]), I) :- % c11
|
||||
var( X),
|
||||
( P = 1, !, arith_eval( -I/K, Val), export_binding( X, Val)
|
||||
; P = -1, !, arith_eval( -K/I, Val), export_binding( X, Val)
|
||||
).
|
||||
submit_eq_c1( [], v(K,[NL^P]), I) :- % c12
|
||||
nonvar( NL),
|
||||
( P = 1, arith_eval( -I/K, Y)
|
||||
; P = -1, arith_eval( -K/I, Y)
|
||||
),
|
||||
nl_invertible( NL, X, Y, Inv),
|
||||
!,
|
||||
nf( -Inv, S),
|
||||
nf_add( X, S, New),
|
||||
submit_eq( New).
|
||||
submit_eq_c1( Rest, B, I) :- % c13
|
||||
B=v(_,[Y^1]), var(Y),
|
||||
linear( Rest),
|
||||
!,
|
||||
% 'solve_='( [v(I,[]),B|Rest]).
|
||||
Hom = [B|Rest],
|
||||
nf_length( Hom, 0, Len),
|
||||
normalize_scalar( I, Nonvar),
|
||||
log_deref( Len, Hom, [], HomD),
|
||||
add_linear_11( Nonvar, HomD, LinD),
|
||||
solve( LinD).
|
||||
submit_eq_c1( Rest, B, I) :- % c14
|
||||
Norm = [v(I,[]),B|Rest],
|
||||
term_variables( Norm, Vs),
|
||||
geler( Vs, resubmit_eq(Norm)).
|
||||
|
||||
% -----------------------------------------------------------------------
|
||||
|
||||
submit_lt( []) :- fail. % trivial failure
|
||||
submit_lt( [A|As]) :-
|
||||
submit_lt( As, A).
|
||||
|
||||
submit_lt( [], v(K,P)) :- submit_lt_b( P, K).
|
||||
submit_lt( [B|Bs], A) :- submit_lt_c( Bs, A, B).
|
||||
|
||||
submit_lt_b( [], I) :- !, arith_eval( I<0).
|
||||
submit_lt_b( [X^1], K) :-
|
||||
var(X),
|
||||
!,
|
||||
( arith_eval( K>0) ->
|
||||
ineq_one_s_p_0( X)
|
||||
;
|
||||
ineq_one_s_n_0( X)
|
||||
).
|
||||
submit_lt_b( P, K) :-
|
||||
term_variables( P, Vs),
|
||||
geler( Vs, resubmit_lt([v(K,P)])).
|
||||
|
||||
submit_lt_c( [], A, B) :-
|
||||
A=v(I,[]),
|
||||
B=v(K,[Y^1]), var(Y),
|
||||
!,
|
||||
ineq_one( strict, Y, K, I).
|
||||
submit_lt_c( Rest, A, B) :-
|
||||
Norm = [A,B|Rest],
|
||||
( linear(Norm) ->
|
||||
'solve_<'( Norm)
|
||||
;
|
||||
term_variables( Norm, Vs),
|
||||
geler( Vs, resubmit_lt(Norm))
|
||||
).
|
||||
|
||||
submit_le( []). % trivial success
|
||||
submit_le( [A|As]) :-
|
||||
submit_le( As, A).
|
||||
|
||||
submit_le( [], v(K,P)) :- submit_le_b( P, K).
|
||||
submit_le( [B|Bs], A) :- submit_le_c( Bs, A, B).
|
||||
|
||||
submit_le_b( [], I) :- !, arith_eval( I=<0).
|
||||
submit_le_b( [X^1], K) :-
|
||||
var(X),
|
||||
!,
|
||||
( arith_eval( K>0) ->
|
||||
ineq_one_n_p_0( X)
|
||||
;
|
||||
ineq_one_n_n_0( X)
|
||||
).
|
||||
submit_le_b( P, K) :-
|
||||
term_variables( P, Vs),
|
||||
geler( Vs, resubmit_le([v(K,P)])).
|
||||
|
||||
submit_le_c( [], A, B) :-
|
||||
A=v(I,[]),
|
||||
B=v(K,[Y^1]), var(Y),
|
||||
!,
|
||||
ineq_one( nonstrict, Y, K, I).
|
||||
submit_le_c( Rest, A, B) :-
|
||||
Norm = [A,B|Rest],
|
||||
( linear(Norm) ->
|
||||
'solve_=<'( Norm)
|
||||
;
|
||||
term_variables( Norm, Vs),
|
||||
geler( Vs, resubmit_le(Norm))
|
||||
).
|
||||
|
||||
submit_ne( Norm1) :-
|
||||
( nf_constant( Norm1, K) ->
|
||||
arith_eval( K=\=0)
|
||||
; linear( Norm1) ->
|
||||
'solve_=\\='( Norm1)
|
||||
;
|
||||
term_variables( Norm1, Vs),
|
||||
geler( Vs, resubmit_ne(Norm1))
|
||||
).
|
||||
|
||||
|
||||
linear( []).
|
||||
linear( v(_,Ps)) :- linear_ps( Ps).
|
||||
linear( [A|As]) :-
|
||||
linear( A),
|
||||
linear( As).
|
||||
|
||||
linear_ps( []).
|
||||
linear_ps( [V^1]) :- var( V). % excludes sin(_), ...
|
||||
|
||||
%
|
||||
% Goal delays until Term gets linear.
|
||||
% At this time, Var will be bound to the normalform of Term.
|
||||
%
|
||||
:- meta_predicate wait_linear( ?, ?, :).
|
||||
%
|
||||
wait_linear( Term, Var, Goal) :-
|
||||
nf( Term, Nf),
|
||||
( linear( Nf) ->
|
||||
Var = Nf,
|
||||
call( Goal)
|
||||
;
|
||||
term_variables( Nf, Vars),
|
||||
geler( Vars, wait_linear_retry(Nf,Var,Goal))
|
||||
).
|
||||
|
||||
%
|
||||
% geler clients
|
||||
%
|
||||
resubmit_eq( N) :-
|
||||
repair( N, Norm),
|
||||
submit_eq( Norm).
|
||||
|
||||
resubmit_lt( N) :-
|
||||
repair( N, Norm),
|
||||
submit_lt( Norm).
|
||||
|
||||
resubmit_le( N) :-
|
||||
repair( N, Norm),
|
||||
submit_le( Norm).
|
||||
|
||||
resubmit_ne( N) :-
|
||||
repair( N, Norm),
|
||||
submit_ne( Norm).
|
||||
|
||||
wait_linear_retry( Nf0, Var, Goal) :-
|
||||
repair( Nf0, Nf),
|
||||
( linear( Nf) ->
|
||||
Var = Nf,
|
||||
call( Goal)
|
||||
;
|
||||
term_variables( Nf, Vars),
|
||||
geler( Vars, wait_linear_retry(Nf,Var,Goal))
|
||||
).
|
||||
|
||||
% -----------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
invertible( [v(Mone,[]),v(One,[X^Px,Y^Py])], Norm) :-
|
||||
Px+Py =:= 0,
|
||||
abs(Px) mod 2 =:= 1, % odd powers only ...
|
||||
arith_eval( 1, One),
|
||||
arith_eval( -1, Mone),
|
||||
!,
|
||||
( Px < 0 ->
|
||||
{X=\=0}
|
||||
;
|
||||
{Y=\=0}
|
||||
),
|
||||
nf( X-Y, Norm). % x=y
|
||||
*/
|
||||
|
||||
nl_invertible( sin(X), X, Y, Res) :- arith_eval( asin(Y), Res).
|
||||
nl_invertible( cos(X), X, Y, Res) :- arith_eval( acos(Y), Res).
|
||||
nl_invertible( tan(X), X, Y, Res) :- arith_eval( atan(Y), Res).
|
||||
nl_invertible( exp(B,C), X, A, Res) :-
|
||||
( nf_constant( B, Kb) ->
|
||||
arith_eval(A>0),
|
||||
arith_eval(Kb>0),
|
||||
arith_eval(Kb=\=1),
|
||||
X = C,
|
||||
arith_eval( log(A)/log(Kb), Res)
|
||||
; nf_constant( C, Kc),
|
||||
\+ (arith_eval(A=:=0),arith_eval(Kc=<0)),
|
||||
X = B,
|
||||
arith_eval( exp(A,1/Kc), Res)
|
||||
).
|
||||
|
||||
% -----------------------------------------------------------------------
|
||||
|
||||
nf( X, Norm) :- var(X), !,
|
||||
Norm = [v(One,[X^1])],
|
||||
arith_eval( 1, One).
|
||||
nf( X, Norm) :- number(X), !,
|
||||
nf_number( X, Norm).
|
||||
%
|
||||
nf( rat(N,D), Norm) :- !,
|
||||
nf_number( rat(N,D), Norm).
|
||||
%
|
||||
nf( #(Const), Norm) :-
|
||||
monash_constant( Const, Value),
|
||||
!,
|
||||
( arith_eval( 1, rat(1,1)) ->
|
||||
nf_number( Value, Norm) % swallows #(zero) ... ok in Q
|
||||
;
|
||||
arith_normalize( Value, N), % in R we want it
|
||||
Norm = [v(N,[])]
|
||||
).
|
||||
%
|
||||
nf( -A, Norm) :- !,
|
||||
nf( A, An),
|
||||
arith_eval( -1, K),
|
||||
nf_mul_factor( v(K,[]), An, Norm).
|
||||
nf( +A, Norm) :- !,
|
||||
nf( A, Norm).
|
||||
%
|
||||
nf( A+B, Norm) :- !,
|
||||
nf( A, An),
|
||||
nf( B, Bn),
|
||||
nf_add( An, Bn, Norm).
|
||||
nf( A-B, Norm) :- !,
|
||||
nf( A, An),
|
||||
nf( -B, Bn),
|
||||
nf_add( An, Bn, Norm).
|
||||
%
|
||||
nf( A*B, Norm) :- !,
|
||||
nf( A, An),
|
||||
nf( B, Bn),
|
||||
nf_mul( An, Bn, Norm).
|
||||
nf( A/B, Norm) :- !,
|
||||
nf( A, An),
|
||||
nf( B, Bn),
|
||||
nf_div( Bn, An, Norm).
|
||||
%
|
||||
nf( Term, Norm) :-
|
||||
nonlin_1( Term, Arg, Skel, Sa1),
|
||||
!,
|
||||
nf( Arg, An),
|
||||
nf_nonlin_1( Skel, An, Sa1, Norm).
|
||||
nf( Term, Norm) :-
|
||||
nonlin_2( Term, A1,A2, Skel, Sa1, Sa2),
|
||||
!,
|
||||
nf( A1, A1n),
|
||||
nf( A2, A2n),
|
||||
nf_nonlin_2( Skel, A1n, A2n, Sa1, Sa2, Norm).
|
||||
%
|
||||
nf( Term, _) :-
|
||||
raise_exception( type_error(nf(Term,_),1,'a numeric expression',Term)).
|
||||
|
||||
nf_number( N, Res) :-
|
||||
nf_number( N),
|
||||
arith_normalize( N, Normal),
|
||||
( arith_eval( Normal=:=0) ->
|
||||
Res = []
|
||||
;
|
||||
Res = [v(Normal,[])]
|
||||
).
|
||||
|
||||
nf_number( N) :- number( N),
|
||||
!. /* MC 980507 */
|
||||
nf_number( N) :- compound( N), N=rat(_,_). % sicstus
|
||||
|
||||
nonlin_1( abs(X), X, abs(Y), Y).
|
||||
nonlin_1( sin(X), X, sin(Y), Y).
|
||||
nonlin_1( cos(X), X, cos(Y), Y).
|
||||
nonlin_1( tan(X), X, tan(Y), Y).
|
||||
|
||||
nonlin_2( min(A,B), A,B, min(X,Y), X, Y).
|
||||
nonlin_2( max(A,B), A,B, max(X,Y), X, Y).
|
||||
nonlin_2( exp(A,B), A,B, exp(X,Y), X, Y).
|
||||
nonlin_2( pow(A,B), A,B, exp(X,Y), X, Y). % pow->exp
|
||||
nonlin_2( A^B, A,B, exp(X,Y), X, Y).
|
||||
|
||||
nf_nonlin_1( Skel, An, S1, Norm) :-
|
||||
( nf_constant( An, S1) ->
|
||||
nl_eval( Skel, Res),
|
||||
nf_number( Res, Norm)
|
||||
;
|
||||
S1 = An,
|
||||
arith_eval( 1, One),
|
||||
Norm = [v(One,[Skel^1])]
|
||||
).
|
||||
|
||||
nf_nonlin_2( Skel, A1n, A2n, S1, S2, Norm) :-
|
||||
( nf_constant( A1n, S1),
|
||||
nf_constant( A2n, S2) ->
|
||||
nl_eval( Skel, Res),
|
||||
nf_number( Res, Norm)
|
||||
; Skel=exp(_,_),
|
||||
nf_constant( A2n, Exp),
|
||||
integerp( Exp, I) ->
|
||||
nf_power( I, A1n, Norm)
|
||||
;
|
||||
S1 = A1n,
|
||||
S2 = A2n,
|
||||
arith_eval( 1, One),
|
||||
Norm = [v(One,[Skel^1])]
|
||||
).
|
||||
|
||||
|
||||
nl_eval( abs(X), R) :- arith_eval( abs(X), R).
|
||||
nl_eval( sin(X), R) :- arith_eval( sin(X), R).
|
||||
nl_eval( cos(X), R) :- arith_eval( cos(X), R).
|
||||
nl_eval( tan(X), R) :- arith_eval( tan(X), R).
|
||||
%
|
||||
nl_eval( min(X,Y), R) :- arith_eval( min(X,Y), R).
|
||||
nl_eval( max(X,Y), R) :- arith_eval( max(X,Y), R).
|
||||
nl_eval( exp(X,Y), R) :- arith_eval( exp(X,Y), R).
|
||||
|
||||
monash_constant( X, _) :- var(X), !, fail.
|
||||
monash_constant( p, 3.14259265).
|
||||
monash_constant( pi, 3.14259265).
|
||||
monash_constant( e, 2.71828182).
|
||||
monash_constant( zero, Eps) :- arith_eps( Eps).
|
||||
|
||||
%
|
||||
% check if a Nf consists of just a constant
|
||||
%
|
||||
nf_constant( [], Z) :- arith_eval( 0, Z).
|
||||
nf_constant( [v(K,[])], K).
|
||||
|
||||
%
|
||||
% this depends on the polynf ordering, i.e. [] < [X^1] ...
|
||||
%
|
||||
split( [], [], Z) :- arith_eval( 0, Z).
|
||||
split( [First|T], H, I) :-
|
||||
( First=v(I,[]) ->
|
||||
H=T
|
||||
;
|
||||
arith_eval( 0, I),
|
||||
H = [First|T]
|
||||
).
|
||||
|
||||
%
|
||||
% runtime predicate
|
||||
%
|
||||
:- mode nf_add( +, +, ?).
|
||||
%
|
||||
nf_add( [], Bs, Bs).
|
||||
nf_add( [A|As], Bs, Cs) :-
|
||||
nf_add( Bs, A, As, Cs).
|
||||
|
||||
:- mode nf_add( +, +, +, ?).
|
||||
%
|
||||
nf_add( [], A, As, Cs) :- Cs = [A|As].
|
||||
nf_add( [B|Bs], A, As, Cs) :-
|
||||
A = v(Ka,Pa),
|
||||
B = v(Kb,Pb),
|
||||
compare( Rel, Pa, Pb),
|
||||
nf_add_case( Rel, A, As, Cs, B, Bs, Ka, Kb, Pa).
|
||||
|
||||
:- mode nf_add_case( +, +, +, -, +, +, +, +, +).
|
||||
%
|
||||
nf_add_case( <, A, As, Cs, B, Bs, _, _, _) :-
|
||||
Cs=[A|Rest],
|
||||
nf_add( As, B, Bs, Rest).
|
||||
nf_add_case( >, A, As, Cs, B, Bs, _, _, _) :-
|
||||
Cs=[B|Rest],
|
||||
nf_add( Bs, A, As, Rest).
|
||||
nf_add_case( =, _, As, Cs, _, Bs, Ka, Kb, Pa) :-
|
||||
arith_eval( Ka+Kb, Kc),
|
||||
( arith_eval( Kc=:=0 ) ->
|
||||
nf_add( As, Bs, Cs)
|
||||
;
|
||||
Cs=[v(Kc,Pa)|Rest],
|
||||
nf_add( As, Bs, Rest)
|
||||
).
|
||||
|
||||
:- mode nf_mul( +, +, -).
|
||||
%
|
||||
nf_mul( A, B, Res) :-
|
||||
nf_length( A, 0, LenA),
|
||||
nf_length( B, 0, LenB),
|
||||
nf_mul_log( LenA, A, [], LenB, B, Res).
|
||||
|
||||
nf_mul_log( 0, As, As, _, _, []) :- !.
|
||||
nf_mul_log( 1, [A|As], As, Lb, B, R) :- !,
|
||||
nf_mul_factor_log( Lb, B, [], A, R).
|
||||
nf_mul_log( 2, [A1,A2|As], As, Lb, B, R) :- !,
|
||||
nf_mul_factor_log( Lb, B, [], A1, A1b),
|
||||
nf_mul_factor_log( Lb, B, [], A2, A2b),
|
||||
nf_add( A1b, A2b, R).
|
||||
nf_mul_log( N, A0, A2, Lb, B, R) :-
|
||||
P is N>>1,
|
||||
Q is N-P,
|
||||
nf_mul_log( P, A0, A1, Lb, B, Rp),
|
||||
nf_mul_log( Q, A1, A2, Lb, B, Rq),
|
||||
nf_add( Rp, Rq, R).
|
||||
|
||||
:- mode nf_add_2( +, +, -).
|
||||
%
|
||||
nf_add_2( Af, Bf, Res) :- % unfold: nf_add( [Af], [Bf], Res).
|
||||
Af = v(Ka,Pa),
|
||||
Bf = v(Kb,Pb),
|
||||
compare( Rel, Pa, Pb),
|
||||
nf_add_2_case( Rel, Af, Bf, Res, Ka, Kb, Pa).
|
||||
|
||||
:- mode nf_add_2_case( +, +, +, -, +, +, +).
|
||||
%
|
||||
nf_add_2_case( <, Af, Bf, [Af,Bf], _, _, _).
|
||||
nf_add_2_case( >, Af, Bf, [Bf,Af], _, _, _).
|
||||
nf_add_2_case( =, _, _, Res, Ka, Kb, Pa) :-
|
||||
arith_eval( Ka+Kb, Kc),
|
||||
( arith_eval( Kc=:=0 ) ->
|
||||
Res = []
|
||||
;
|
||||
Res=[v(Kc,Pa)]
|
||||
).
|
||||
|
||||
%
|
||||
% multiply with a scalar =\= 0
|
||||
%
|
||||
nf_mul_k( [], _, []).
|
||||
nf_mul_k( [v(I,P)|Vs], K, [v(Ki,P)|Vks]) :-
|
||||
arith_eval( K*I, Ki),
|
||||
nf_mul_k( Vs, K, Vks).
|
||||
|
||||
nf_mul_factor( v(K,[]), Sum, Res) :- !, nf_mul_k( Sum, K, Res).
|
||||
nf_mul_factor( F, Sum, Res) :-
|
||||
nf_length( Sum, 0, Len),
|
||||
nf_mul_factor_log( Len, Sum, [], F, Res).
|
||||
|
||||
nf_mul_factor_log( 0, As, As, _, []) :- !.
|
||||
nf_mul_factor_log( 1, [A|As], As, F, [R]) :- !,
|
||||
mult( A, F, R).
|
||||
nf_mul_factor_log( 2, [A,B|As], As, F, Res) :- !,
|
||||
mult( A, F, Af),
|
||||
mult( B, F, Bf),
|
||||
nf_add_2( Af, Bf, Res).
|
||||
nf_mul_factor_log( N, A0, A2, F, R) :-
|
||||
P is N>>1,
|
||||
Q is N-P,
|
||||
nf_mul_factor_log( P, A0, A1, F, Rp),
|
||||
nf_mul_factor_log( Q, A1, A2, F, Rq),
|
||||
nf_add( Rp, Rq, R).
|
||||
|
||||
mult( v(Ka,La), v(Kb,Lb), v(Kc,Lc)) :-
|
||||
arith_eval( Ka*Kb, Kc),
|
||||
pmerge( La, Lb, Lc).
|
||||
|
||||
pmerge( [], Bs, Bs).
|
||||
pmerge( [A|As], Bs, Cs) :-
|
||||
pmerge( Bs, A, As, Cs).
|
||||
|
||||
:- mode pmerge(+,+,+,-).
|
||||
%
|
||||
pmerge( [], A, As, Res) :- Res = [A|As].
|
||||
pmerge( [B|Bs], A, As, Res) :-
|
||||
A=Xa^Ka,
|
||||
B=Xb^Kb,
|
||||
compare( R, Xa, Xb),
|
||||
pmerge_case( R, A, As, Res, B, Bs, Ka, Kb, Xa).
|
||||
|
||||
:- mode pmerge_case( +, +, +, -, +, +, +, +, ?).
|
||||
%
|
||||
pmerge_case( <, A, As, Res, B, Bs, _, _, _) :-
|
||||
Res = [A|Tail],
|
||||
pmerge( As, B, Bs, Tail).
|
||||
pmerge_case( >, A, As, Res, B, Bs, _, _, _) :-
|
||||
Res = [B|Tail],
|
||||
pmerge( Bs, A, As, Tail).
|
||||
pmerge_case( =, _, As, Res, _, Bs, Ka, Kb, Xa) :-
|
||||
Kc is Ka+Kb,
|
||||
( Kc=:=0 ->
|
||||
pmerge( As, Bs, Res)
|
||||
;
|
||||
Res = [Xa^Kc|Tail],
|
||||
pmerge( As, Bs, Tail)
|
||||
).
|
||||
|
||||
nf_div( [], _, _) :- !, zero_division.
|
||||
nf_div( [v(K,P)], Sum, Res) :- !,
|
||||
arith_eval( 1/K, Ki),
|
||||
mult_exp( P, -1, Pi),
|
||||
nf_mul_factor( v(Ki,Pi), Sum, Res).
|
||||
nf_div( D, A, [v(One,[(A/D)^1])]) :-
|
||||
arith_eval( 1, One).
|
||||
|
||||
zero_division :- fail. % raise_exception(_) ?
|
||||
|
||||
mult_exp( [], _, []).
|
||||
mult_exp( [X^P|Xs], K, [X^I|Tail]) :-
|
||||
I is K*P,
|
||||
mult_exp( Xs, K, Tail).
|
||||
|
||||
%
|
||||
% raise to integer powers
|
||||
%
|
||||
% | ?- time({(1+X+Y+Z)^15=0}).
|
||||
% Timing 00:00:02.610 2.610 iterative
|
||||
% Timing 00:00:00.660 0.660 binomial
|
||||
nf_power( N, Sum, Norm) :-
|
||||
integer( N),
|
||||
compare( Rel, N, 0),
|
||||
( Rel = < ->
|
||||
Pn is -N,
|
||||
% nf_power_pos( Pn, Sum, Inorm),
|
||||
binom( Sum, Pn, Inorm),
|
||||
arith_eval( 1, One),
|
||||
nf_div( Inorm, [v(One,[])], Norm)
|
||||
; Rel = > ->
|
||||
% nf_power_pos( N, Sum, Norm)
|
||||
binom( Sum, N, Norm)
|
||||
; Rel = = -> % 0^0 is indeterminate but we say 1
|
||||
arith_eval( 1, One),
|
||||
Norm = [v(One,[])]
|
||||
).
|
||||
|
||||
|
||||
%
|
||||
% N>0
|
||||
%
|
||||
nf_power_pos( 1, Sum, Norm) :- !, Sum = Norm.
|
||||
nf_power_pos( N, Sum, Norm) :-
|
||||
N1 is N-1,
|
||||
nf_power_pos( N1, Sum, Pn1),
|
||||
nf_mul( Sum, Pn1, Norm).
|
||||
|
||||
%
|
||||
% N>0
|
||||
%
|
||||
binom( Sum, 1, Power) :- !, Power = Sum.
|
||||
binom( [], _, []).
|
||||
binom( [A|Bs], N, Power) :-
|
||||
( Bs=[] ->
|
||||
nf_power_factor( A, N, Ap),
|
||||
Power = [Ap]
|
||||
; Bs=[_|_] ->
|
||||
arith_eval( 1, One),
|
||||
factor_powers( N, A, v(One,[]), Pas),
|
||||
sum_powers( N, Bs, [v(One,[])], Pbs, []),
|
||||
combine_powers( Pas, Pbs, 0, N, 1, [], Power)
|
||||
).
|
||||
|
||||
combine_powers( [], [], _, _, _, Pi, Pi).
|
||||
combine_powers( [A|As], [B|Bs], L, R, C, Pi, Po) :-
|
||||
nf_mul( A, B, Ab),
|
||||
arith_normalize( C, Cn),
|
||||
nf_mul_k( Ab, Cn, Abc),
|
||||
nf_add( Abc, Pi, Pii),
|
||||
L1 is L+1,
|
||||
R1 is R-1,
|
||||
C1 is C*R//L1,
|
||||
combine_powers( As, Bs, L1, R1, C1, Pii, Po).
|
||||
|
||||
|
||||
nf_power_factor( v(K,P), N, v(Kn,Pn)) :-
|
||||
arith_normalize( N, Nn),
|
||||
arith_eval( exp(K,Nn), Kn),
|
||||
mult_exp( P, N, Pn).
|
||||
|
||||
factor_powers( 0, _, Prev, [[Prev]]) :- !.
|
||||
factor_powers( N, F, Prev, [[Prev]|Ps]) :-
|
||||
N1 is N-1,
|
||||
mult( Prev, F, Next),
|
||||
factor_powers( N1, F, Next, Ps).
|
||||
|
||||
sum_powers( 0, _, Prev, [Prev|Lt], Lt) :- !.
|
||||
sum_powers( N, S, Prev, L0, Lt) :-
|
||||
N1 is N-1,
|
||||
nf_mul( S, Prev, Next),
|
||||
sum_powers( N1, S, Next, L0, [Prev|Lt]).
|
||||
|
||||
% ------------------------------------------------------------------------------
|
||||
|
||||
repair( Sum, Norm) :-
|
||||
nf_length( Sum, 0, Len),
|
||||
repair_log( Len, Sum, [], Norm).
|
||||
|
||||
repair_log( 0, As, As, []) :- !.
|
||||
repair_log( 1, [v(Ka,Pa)|As], As, R) :- !,
|
||||
repair_term( Ka, Pa, R).
|
||||
repair_log( 2, [v(Ka,Pa),v(Kb,Pb)|As], As, R) :- !,
|
||||
repair_term( Ka, Pa, Ar),
|
||||
repair_term( Kb, Pb, Br),
|
||||
nf_add( Ar, Br, R).
|
||||
repair_log( N, A0, A2, R) :-
|
||||
P is N>>1,
|
||||
Q is N-P,
|
||||
repair_log( P, A0, A1, Rp),
|
||||
repair_log( Q, A1, A2, Rq),
|
||||
nf_add( Rp, Rq, R).
|
||||
|
||||
|
||||
repair_term( K, P, Norm) :-
|
||||
length( P, Len),
|
||||
arith_eval( 1, One),
|
||||
repair_p_log( Len, P, [], Pr, [v(One,[])], Sum),
|
||||
nf_mul_factor( v(K,Pr), Sum, Norm).
|
||||
|
||||
repair_p_log( 0, Ps, Ps, [], L0, L0) :- !.
|
||||
repair_p_log( 1, [X^P|Ps], Ps, R, L0, L1) :- !,
|
||||
repair_p( X, P, R, L0, L1).
|
||||
repair_p_log( 2, [X^Px,Y^Py|Ps], Ps, R, L0,L2) :- !,
|
||||
repair_p( X, Px, Rx, L0, L1),
|
||||
repair_p( Y, Py, Ry, L1, L2),
|
||||
pmerge( Rx, Ry, R).
|
||||
repair_p_log( N, P0, P2, R, L0, L2) :-
|
||||
P is N>>1,
|
||||
Q is N-P,
|
||||
repair_p_log( P, P0, P1, Rp, L0, L1),
|
||||
repair_p_log( Q, P1, P2, Rq, L1, L2),
|
||||
pmerge( Rp, Rq, R).
|
||||
|
||||
|
||||
%vsc: added ! (01/06/06)
|
||||
repair_p( Term, P, [Term^P], L0, L0) :- var( Term), !.
|
||||
repair_p( Term, P, [], L0, L1) :- nonvar( Term),
|
||||
repair_p_one( Term, TermN),
|
||||
nf_power( P, TermN, TermNP),
|
||||
nf_mul( TermNP, L0, L1).
|
||||
|
||||
%
|
||||
% An undigested term a/b is distinguished from an
|
||||
% digested one by the fact that its arguments are
|
||||
% digested -> cuts after repair of args!
|
||||
%
|
||||
repair_p_one( Term, TermN) :-
|
||||
nf_number( Term, TermN), % freq. shortcut for nf/2 case below
|
||||
!.
|
||||
repair_p_one( A1/A2, TermN) :-
|
||||
repair( A1, A1n),
|
||||
repair( A2, A2n),
|
||||
!,
|
||||
nf_div( A2n, A1n, TermN).
|
||||
repair_p_one( Term, TermN) :-
|
||||
nonlin_1( Term, Arg, Skel, Sa),
|
||||
repair( Arg, An),
|
||||
!,
|
||||
nf_nonlin_1( Skel, An, Sa, TermN).
|
||||
repair_p_one( Term, TermN) :-
|
||||
nonlin_2( Term, A1,A2, Skel, Sa1, Sa2),
|
||||
repair( A1, A1n),
|
||||
repair( A2, A2n),
|
||||
!,
|
||||
nf_nonlin_2( Skel, A1n, A2n, Sa1, Sa2, TermN).
|
||||
repair_p_one( Term, TermN) :-
|
||||
nf( Term, TermN).
|
||||
|
||||
:- mode nf_length( +, +, -).
|
||||
%
|
||||
nf_length( [], Li, Li).
|
||||
nf_length( [_|R], Li, Lo) :-
|
||||
Lii is Li+1,
|
||||
nf_length( R, Lii, Lo).
|
||||
|
||||
% ------------------------------------------------------------------------------
|
||||
|
||||
nf2term( [], Z) :- arith_eval( 0, Z).
|
||||
nf2term( [F|Fs], T) :-
|
||||
f02t( F, T0),
|
||||
yfx( Fs, T0, T).
|
||||
|
||||
yfx( [], T0, T0).
|
||||
yfx( [F|Fs], T0, TN) :-
|
||||
fn2t( F, Ft, Op),
|
||||
T1 =.. [Op,T0,Ft],
|
||||
yfx( Fs, T1, TN).
|
||||
|
||||
f02t( v(K,P), T) :-
|
||||
( P = [] ->
|
||||
T = K
|
||||
; arith_eval( K=:=1) ->
|
||||
p2term( P, T)
|
||||
; arith_eval( K=:= -1) ->
|
||||
T = -Pt,
|
||||
p2term( P, Pt)
|
||||
;
|
||||
T = K*Pt,
|
||||
p2term( P, Pt)
|
||||
).
|
||||
|
||||
fn2t( v(K,P), Term, Op) :-
|
||||
( arith_eval( K=:=1) ->
|
||||
Term = Pt, Op = +
|
||||
; arith_eval( K=:= -1) ->
|
||||
Term = Pt, Op = -
|
||||
; arith_eval( K<0) ->
|
||||
arith_eval( -K, Kf),
|
||||
Term = Kf*Pt, Op = -
|
||||
;
|
||||
Term = K*Pt, Op = +
|
||||
),
|
||||
p2term( P, Pt).
|
||||
|
||||
p2term( [X^P|Xs], Term) :-
|
||||
( Xs=[] ->
|
||||
pe2term( X, Xt),
|
||||
exp2term( P, Xt, Term)
|
||||
; Xs=[_|_] ->
|
||||
Term = Xst*Xtp,
|
||||
pe2term( X, Xt),
|
||||
exp2term( P, Xt, Xtp),
|
||||
p2term( Xs, Xst)
|
||||
).
|
||||
|
||||
exp2term( 1, X, X) :- !.
|
||||
exp2term(-1, X, One/X) :- !, arith_eval( 1, One).
|
||||
exp2term( P, X, Term) :-
|
||||
arith_normalize( P, Pn),
|
||||
% Term = exp(X,Pn).
|
||||
Term = X^Pn.
|
||||
|
||||
pe2term( X, Term) :- var(X), Term = X.
|
||||
pe2term( X, Term) :- nonvar(X),
|
||||
X =.. [F|Args],
|
||||
pe2term_args( Args, Argst),
|
||||
Term =.. [F|Argst].
|
||||
|
||||
pe2term_args( [], []).
|
||||
pe2term_args( [A|As], [T|Ts]) :-
|
||||
nf2term( A, T),
|
||||
pe2term_args( As, Ts).
|
||||
|
@ -1,136 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.3 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: ordering.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%
|
||||
% Collect ordering constraints
|
||||
% Produce an arrangement via toplogical sorting
|
||||
%
|
||||
%
|
||||
|
||||
:- use_module( library(lists), [append/3]).
|
||||
|
||||
:- use_module( library(ugraphs),
|
||||
[
|
||||
top_sort/2,
|
||||
add_edges/3,
|
||||
add_vertices/3
|
||||
]).
|
||||
|
||||
ordering( X) :- var(X), !, fail.
|
||||
ordering( A>B) :- !, ordering( B<A).
|
||||
ordering( A<B) :-
|
||||
join_class( [A,B], Class),
|
||||
class_get_prio( Class, Ga),
|
||||
!,
|
||||
add_edges( [], [A-B], Gb), % [] = empty graph
|
||||
combine( Ga, Gb, Gc),
|
||||
class_put_prio( Class, Gc).
|
||||
ordering( Pb) :- Pb = [_|Xs],
|
||||
join_class( Pb, Class),
|
||||
class_get_prio( Class, Ga),
|
||||
!,
|
||||
( Xs=[],
|
||||
add_vertices( [], Pb, Gb)
|
||||
; Xs=[_|_],
|
||||
gen_edges( Pb, Es, []),
|
||||
add_edges( [], Es, Gb)
|
||||
),
|
||||
combine( Ga, Gb, Gc),
|
||||
class_put_prio( Class, Gc).
|
||||
ordering( _).
|
||||
|
||||
arrangement( Class, Arr) :-
|
||||
class_get_prio( Class, G),
|
||||
normalize( G, Gn),
|
||||
top_sort( Gn, Arr),
|
||||
!.
|
||||
arrangement( _, _) :-
|
||||
raise_exception( unsatisfiable_ordering).
|
||||
|
||||
join_class( [], _).
|
||||
join_class( [X|Xs], Class) :-
|
||||
( var(X), get_or_add_class( X, Class)
|
||||
; nonvar(X)
|
||||
),
|
||||
join_class( Xs, Class).
|
||||
|
||||
combine( Ga, Gb, Gc) :-
|
||||
normalize( Ga, Gan),
|
||||
normalize( Gb, Gbn),
|
||||
ugraphs:graph_union( Gan, Gbn, Gc).
|
||||
|
||||
%
|
||||
% both Ga and Gb might have their internal ordering invalidated
|
||||
% because of bindings and aliasings
|
||||
%
|
||||
normalize( [], []).
|
||||
normalize( G, Gsgn) :-
|
||||
G=[_|_],
|
||||
keysort( G, Gs),
|
||||
group( Gs, Gsg),
|
||||
normalize_vertices( Gsg, Gsgn).
|
||||
|
||||
normalize_vertices( [], []).
|
||||
normalize_vertices( [X-Xnb|Xs], Res) :-
|
||||
( normalize_vertex( X, Xnb, Xnorm) ->
|
||||
Res = [Xnorm|Xsn],
|
||||
normalize_vertices( Xs, Xsn)
|
||||
;
|
||||
normalize_vertices( Xs, Res)
|
||||
).
|
||||
|
||||
%
|
||||
% get rid of nonvar vertices/edges, and turn V-[V] into V-[]
|
||||
%
|
||||
normalize_vertex( X, Nbs, X-Nbsss) :-
|
||||
var(X),
|
||||
sort( Nbs, Nbss),
|
||||
strip_nonvar( Nbss, X, Nbsss).
|
||||
|
||||
strip_nonvar( [], _, []).
|
||||
strip_nonvar( [X|Xs], Y, Res) :-
|
||||
( X==Y -> strip_nonvar( Xs, Y, Res)
|
||||
; var(X) ->
|
||||
Res=[X|Stripped],
|
||||
strip_nonvar( Xs, Y, Stripped)
|
||||
; nonvar(X),
|
||||
Res=[] % because Vars<anything
|
||||
).
|
||||
|
||||
gen_edges( []) --> [].
|
||||
gen_edges( [X|Xs]) -->
|
||||
gen_edges( Xs, X),
|
||||
gen_edges( Xs).
|
||||
|
||||
gen_edges( [], _) --> [].
|
||||
gen_edges( [Y|Ys], X) -->
|
||||
[ X-Y ],
|
||||
gen_edges( Ys, X).
|
||||
|
||||
%
|
||||
% map k-La,k-Lb.... into k-LaLb
|
||||
%
|
||||
group( [], []).
|
||||
group( [K-Kl|Ks], Res) :-
|
||||
group( Ks, K, Kl, Res).
|
||||
|
||||
group( [], K, Kl, [K-Kl]).
|
||||
group( [L-Ll|Ls], K, Kl, Res) :-
|
||||
( K==L ->
|
||||
append( Kl, Ll, KLl),
|
||||
group( Ls, K, KLl, Res)
|
||||
;
|
||||
Res = [K-Kl|Tail],
|
||||
group( Ls, L, Ll, Tail)
|
||||
).
|
||||
|
@ -1,135 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.3 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: ordering.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%
|
||||
% Collect ordering constraints
|
||||
% Produce an arrangement via toplogical sorting
|
||||
%
|
||||
%
|
||||
|
||||
:- use_module( library(lists), [append/3]).
|
||||
|
||||
:- use_module( library(ugraphs),
|
||||
[
|
||||
top_sort/2,
|
||||
add_edges/3,
|
||||
add_vertices/3
|
||||
]).
|
||||
|
||||
ordering( X) :- var(X), !, fail.
|
||||
ordering( A>B) :- !, ordering( B<A).
|
||||
ordering( A<B) :-
|
||||
join_class( [A,B], Class),
|
||||
class_get_prio( Class, Ga),
|
||||
!,
|
||||
add_edges( [], [A-B], Gb), % [] = empty graph
|
||||
combine( Ga, Gb, Gc),
|
||||
class_put_prio( Class, Gc).
|
||||
ordering( Pb) :- Pb = [_|Xs],
|
||||
join_class( Pb, Class),
|
||||
class_get_prio( Class, Ga),
|
||||
!,
|
||||
( Xs=[],
|
||||
add_vertices( [], Pb, Gb)
|
||||
; Xs=[_|_],
|
||||
gen_edges( Pb, Es, []),
|
||||
add_edges( [], Es, Gb)
|
||||
),
|
||||
combine( Ga, Gb, Gc),
|
||||
class_put_prio( Class, Gc).
|
||||
ordering( _).
|
||||
|
||||
arrangement( Class, Arr) :-
|
||||
class_get_prio( Class, G),
|
||||
normalize( G, Gn),
|
||||
top_sort( Gn, Arr),
|
||||
!.
|
||||
arrangement( _, _) :-
|
||||
raise_exception( unsatisfiable_ordering).
|
||||
|
||||
join_class( [], _).
|
||||
join_class( [X|Xs], Class) :-
|
||||
( var(X), get_or_add_class( X, Class)
|
||||
; nonvar(X)
|
||||
),
|
||||
join_class( Xs, Class).
|
||||
|
||||
combine( Ga, Gb, Gc) :-
|
||||
normalize( Ga, Gan),
|
||||
normalize( Gb, Gbn),
|
||||
ugraphs:graph_union( Gan, Gbn, Gc).
|
||||
|
||||
%
|
||||
% both Ga and Gb might have their internal ordering invalidated
|
||||
% because of bindings and aliasings
|
||||
%
|
||||
normalize( [], []).
|
||||
normalize( [GH|GT], Gsgn) :- %vsc: added list in argument (01/06/06)
|
||||
keysort( [GH|GT], Gs),
|
||||
group( Gs, Gsg),
|
||||
normalize_vertices( Gsg, Gsgn).
|
||||
|
||||
normalize_vertices( [], []).
|
||||
normalize_vertices( [X-Xnb|Xs], Res) :-
|
||||
( normalize_vertex( X, Xnb, Xnorm) ->
|
||||
Res = [Xnorm|Xsn],
|
||||
normalize_vertices( Xs, Xsn)
|
||||
;
|
||||
normalize_vertices( Xs, Res)
|
||||
).
|
||||
|
||||
%
|
||||
% get rid of nonvar vertices/edges, and turn V-[V] into V-[]
|
||||
%
|
||||
normalize_vertex( X, Nbs, X-Nbsss) :-
|
||||
var(X),
|
||||
sort( Nbs, Nbss),
|
||||
strip_nonvar( Nbss, X, Nbsss).
|
||||
|
||||
strip_nonvar( [], _, []).
|
||||
strip_nonvar( [X|Xs], Y, Res) :-
|
||||
( X==Y -> strip_nonvar( Xs, Y, Res)
|
||||
; var(X) ->
|
||||
Res=[X|Stripped],
|
||||
strip_nonvar( Xs, Y, Stripped)
|
||||
; nonvar(X),
|
||||
Res=[] % because Vars<anything
|
||||
).
|
||||
|
||||
gen_edges( []) --> [].
|
||||
gen_edges( [X|Xs]) -->
|
||||
gen_edges( Xs, X),
|
||||
gen_edges( Xs).
|
||||
|
||||
gen_edges( [], _) --> [].
|
||||
gen_edges( [Y|Ys], X) -->
|
||||
[ X-Y ],
|
||||
gen_edges( Ys, X).
|
||||
|
||||
%
|
||||
% map k-La,k-Lb.... into k-LaLb
|
||||
%
|
||||
group( [], []).
|
||||
group( [K-Kl|Ks], Res) :-
|
||||
group( Ks, K, Kl, Res).
|
||||
|
||||
group( [], K, Kl, [K-Kl]).
|
||||
group( [L-Ll|Ls], K, Kl, Res) :-
|
||||
( K==L ->
|
||||
append( Kl, Ll, KLl),
|
||||
group( Ls, K, KLl, Res)
|
||||
;
|
||||
Res = [K-Kl|Tail],
|
||||
group( Ls, L, Ll, Tail)
|
||||
).
|
||||
|
@ -1,139 +0,0 @@
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% clp(q,r) version 1.3.2 %
|
||||
% %
|
||||
% (c) Copyright 1992,1993,1994,1995 %
|
||||
% Austrian Research Institute for Artificial Intelligence (OFAI) %
|
||||
% Schottengasse 3 %
|
||||
% A-1010 Vienna, Austria %
|
||||
% %
|
||||
% File: printf.pl %
|
||||
% Author: Christian Holzbaur christian@ai.univie.ac.at %
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%
|
||||
% a mockup for clp(R) printf/2
|
||||
%
|
||||
|
||||
:- module( printf, [printf/1,printf/2]).
|
||||
|
||||
printf( A) :- printf( A, []).
|
||||
|
||||
printf([], _).
|
||||
/* obsolete as of sicstus3 with escape sequences
|
||||
printf([0'\,Ch|Fmt],Args) :- !,
|
||||
printf_special(Ch),
|
||||
printf(Fmt,Args).
|
||||
*/
|
||||
printf([0'%|Spec],Args) :- !,
|
||||
argspec(Args,Restargs,Spec,Rest),
|
||||
printf(Rest,Restargs).
|
||||
printf([Ch|Fmt],Args) :-
|
||||
put(Ch),
|
||||
printf(Fmt,Args).
|
||||
|
||||
printf_special( 0'n) :- !, nl.
|
||||
printf_special( 0't) :- !, put( 9).
|
||||
printf_special( 0'r) :- !, put(13).
|
||||
printf_special( 0'b) :- !, put( 8).
|
||||
printf_special( 0'f) :- !, put(12).
|
||||
printf_special( N) :- put(N).
|
||||
|
||||
argspec(Ai,Ao) --> format_prefix( Prefix),
|
||||
format_action( Prefix, Ai,Ao).
|
||||
|
||||
format_prefix( -Pref) --> "-", !, format_prefix_1(Pref).
|
||||
format_prefix( +Pref) --> format_prefix_1(Pref).
|
||||
|
||||
format_prefix_1( two(0,N2)) --> ".", !, format_digits(N2).
|
||||
format_prefix_1( two(N1,N2)) --> format_digits(N1), ".", !,
|
||||
format_digits(N2).
|
||||
format_prefix_1( one(N1)) --> format_digits(N1), !.
|
||||
format_prefix_1( none) --> [].
|
||||
|
||||
format_digits( N) --> [D],
|
||||
{
|
||||
D >= "0",
|
||||
D =< "9",
|
||||
N0 is D-0'0
|
||||
},
|
||||
format_digits( N0,N).
|
||||
|
||||
format_digits( N0,N2) --> [D],
|
||||
{
|
||||
D >= "0",
|
||||
D =< "9",
|
||||
!,
|
||||
N1 is D-0'0 + N0*10
|
||||
},
|
||||
format_digits( N1,N2).
|
||||
format_digits( N0,N0) --> [].
|
||||
|
||||
format_action( Prefix, Ai,Ao) --> [F],
|
||||
{
|
||||
format_action_1( F, Prefix, Ai, Ao), !
|
||||
}.
|
||||
format_action( +none, [A|As], As) --> % 0'% without further spec.
|
||||
{
|
||||
( number(A) ->
|
||||
format( "~5g", [A])
|
||||
;
|
||||
print(A)
|
||||
)
|
||||
}.
|
||||
|
||||
fmt_norm( rat(N,D), Norm) :- !, ( D=1 -> Norm=N ; Norm is N/D ).
|
||||
fmt_norm( N, N).
|
||||
|
||||
format_action_1( 0'e, Prefix, [A|As], As) :- fmt_norm( A, An), action_e( Prefix, An).
|
||||
format_action_1( 0'f, Prefix, [A|As], As) :- fmt_norm( A, An), action_f( Prefix, An).
|
||||
format_action_1( 0'g, Prefix, [A|As], As) :- fmt_norm( A, An), action_g( Prefix, An).
|
||||
|
||||
format_action_1( 0'%, _, A, A) :- put("%").
|
||||
|
||||
%
|
||||
% todo
|
||||
%
|
||||
format_action_1( 0'd, Prefix, [A|As], As) :-
|
||||
fmt_norm( A, An),
|
||||
Ani is integer(round(An)),
|
||||
action_d( Prefix, Ani).
|
||||
format_action_1( 0'o, _Prefix, [A|As], As) :- print(A).
|
||||
format_action_1( 0'x, _Prefix, [A|As], As) :- print(A).
|
||||
format_action_1( 0'c, _Prefix, [A|As], As) :- print(A).
|
||||
format_action_1( 0'u, _Prefix, [A|As], As) :- print(A).
|
||||
format_action_1( 0's, _Prefix, [A|As], As) :- print(A).
|
||||
|
||||
action_d( +one(A), X) :- format( "~|~t~d~*+", [X,A]).
|
||||
action_d( +none, X) :- format( "~d", [X]).
|
||||
action_d( -one(A), X) :- format( "~|~d~t~*+", [X,A]).
|
||||
action_d( -none, X) :- format( "~d", [X]).
|
||||
|
||||
action_e( +two(A,B), X) :- format( "~|~t~*e~*+", [B,X,A]).
|
||||
action_e( +one(B), X) :- format( "~|~t~e~*+", [X,B]).
|
||||
action_e( +none, X) :- format( "~e", [X]).
|
||||
action_e( -two(A,B), X) :- format( "~|~*e~t~*+", [B,X,A]).
|
||||
action_e( -one(B), X) :- format( "~|~e~t~*+", [X,B]).
|
||||
action_e( -none, X) :- format( "~e", [X]).
|
||||
|
||||
action_f( +two(A,B), X) :- format( "~|~t~*f~*+", [B,X,A]).
|
||||
action_f( +one(B), X) :- format( "~|~t~f~*+", [X,B]).
|
||||
action_f( +none, X) :- format( "~f", [X]).
|
||||
action_f( -two(A,B), X) :- format( "~|~*f~t~*+", [B,X,A]).
|
||||
action_f( -one(B), X) :- format( "~|~f~t~*+", [X,B]).
|
||||
action_f( -none, X) :- format( "~f", [X]).
|
||||
|
||||
action_g( +two(A,B), X) :- format( "~|~t~*g~*+", [B,X,A]).
|
||||
action_g( +one(B), X) :- format( "~|~t~g~*+", [X,B]).
|
||||
action_g( +none, X) :- format( "~g", [X]).
|
||||
action_g( -two(A,B), X) :- format( "~|~*g~t~*+", [B,X,A]).
|
||||
action_g( -one(B), X) :- format( "~|~g~t~*+", [X,B]).
|
||||
action_g( -none, X) :- format( "~g", [X]).
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user