This file is indexed.

/usr/share/Yap/clpqr/redund.pl is in yap 6.2.2-6.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/*  

    Part of CLP(Q,R) (Constraint Logic Programming over Rationals and Reals)

    Author:        Leslie De Koninck
    E-mail:        Leslie.DeKoninck@cs.kuleuven.be
    WWW:           http://www.swi-prolog.org
		   http://www.ai.univie.ac.at/cgi-bin/tr-online?number+95-09
    Copyright (C): 2006, K.U. Leuven and
		   1992-1995, Austrian Research Institute for
		              Artificial Intelligence (OFAI),
			      Vienna, Austria

    This software is based on CLP(Q,R) by Christian Holzbaur for SICStus
    Prolog and distributed under the license details below with permission from
    all mentioned authors.
    
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    As a special exception, if you link this library with other files,
    compiled with a Free Software compiler, to produce an executable, this
    library does not by itself cause the resulting executable to be covered
    by the GNU General Public License. This exception does not however
    invalidate any other reasons why the executable file might be covered by
    the GNU General Public License.
*/

:- module(redund,
	[
	    redundancy_vars/1,
	    systems/3
	]).
:- use_module(class,
	[
	    class_allvars/2
	]).

%
% redundancy removal (semantic definition)
%
% done:
%	+) deal with active bounds
%	+) indep t_[lu] -> t_none invalidates invariants (fixed)
%

% systems(Vars,SystemsIn,SystemsOut)
%
% Returns in SystemsOut the different classes to which variables in Vars
% belong. Every class only appears once in SystemsOut.

systems([],Si,Si).
systems([V|Vs],Si,So) :-
	(   var(V),
	    get_attr(V,itf,Att),
	    arg(6,Att,class(C)),
	    not_memq(Si,C)
	->  systems(Vs,[C|Si],So)
	;   systems(Vs,Si,So)
	).

% not_memq(Lst,El)
%
% Succeeds if El is not a member of Lst (does not use unification).

not_memq([],_).
not_memq([Y|Ys],X) :-
	X \== Y,
	not_memq(Ys,X).

% redundancy_systems(Classes)
%
% Does redundancy removal via redundancy_vs/1 on all variables in the classes Classes. 

redundancy_systems([]).
redundancy_systems([S|Sys]) :-
	class_allvars(S,All),
	redundancy_vs(All),
	redundancy_systems(Sys).

% redundancy_vars(Vs)
%
% Does the same thing as redundancy_vs/1 but has some extra timing facilities that
% may be used.

redundancy_vars(Vs) :-
	!,
	redundancy_vs(Vs).
redundancy_vars(Vs) :-
	statistics(runtime,[Start|_]),
	redundancy_vs(Vs),
	statistics(runtime,[End|_]),
	Duration is End-Start,
	format(user_error,"% Redundancy elimination took ~d msec~n",Duration).


% redundancy_vs(Vs)
%
% Removes redundant bounds from the variables in Vs via redundant/3

redundancy_vs(Vs) :- 
	var(Vs),
	!.
redundancy_vs([]).
redundancy_vs([V|Vs]) :-
	(   get_attr(V,itf,Att),
	    arg(2,Att,type(Type)),
	    arg(3,Att,strictness(Strict)),
	    redundant(Type,V,Strict)
	->  redundancy_vs(Vs)
	;   redundancy_vs(Vs)
	).

% redundant(Type,Var,Strict)
%
% Removes redundant bounds from variable Var with type Type and strictness Strict.
% A redundant bound is one that is satisfied anyway (so adding the inverse of the bound
% makes the system infeasible. This predicate can either fail or succeed but a success
% doesn't necessarily mean a redundant bound.

redundant(t_l(L),X,Strict) :-
	get_attr(X,itf,Att),
	arg(1,Att,CLP),
	detach_bounds(CLP,X),	% drop temporarily
	% if not redundant, backtracking will restore bound
	negate_l(Strict,CLP,L,X),
	red_t_l.	% negate_l didn't fail, redundant bound
redundant(t_u(U),X,Strict) :-
	get_attr(X,itf,Att),
	arg(1,Att,CLP),
	detach_bounds(CLP,X),
	negate_u(Strict,CLP,U,X),
	red_t_u.
redundant(t_lu(L,U),X,Strict) :-
	strictness_parts(Strict,Sl,Su),
	(   get_attr(X,itf,Att),
	    arg(1,Att,CLP),
	    setarg(2,Att,type(t_u(U))),
	    setarg(3,Att,strictness(Su)),
	    negate_l(Strict,CLP,L,X)
	->  red_t_l,
	    (   redundant(t_u(U),X,Strict)
	    ->  true
	    ;   true
	    )
	;   get_attr(X,itf,Att),
	    arg(1,Att,CLP),
	    setarg(2,Att,type(t_l(L))),
	    setarg(3,Att,strictness(Sl)),
	    negate_u(Strict,CLP,U,X)
	->  red_t_u
	;   true
	).
redundant(t_L(L),X,Strict) :-
	get_attr(X,itf,Att),
	arg(1,Att,CLP),
	Bound is -L,
	intro_at(CLP,X,Bound,t_none),	% drop temporarily
	detach_bounds(CLP,X),
	negate_l(Strict,CLP,L,X),
	red_t_L.
redundant(t_U(U),X,Strict) :-
	get_attr(X,itf,Att),
	arg(1,Att,CLP),
	Bound is -U,
	intro_at(CLP,X,Bound,t_none),	% drop temporarily
	detach_bounds(CLP,X),
	negate_u(Strict,CLP,U,X),
	red_t_U.
redundant(t_Lu(L,U),X,Strict) :-
	strictness_parts(Strict,Sl,Su),
	(   Bound is -L,
	    get_attr(X,itf,Att),
	    arg(1,Att,CLP),
	    intro_at(CLP,X,Bound,t_u(U)),
	    get_attr(X,itf,Att2), % changed?
	    setarg(3,Att2,strictness(Su)),
	    negate_l(Strict,CLP,L,X)
	->  red_t_l,
	    (   redundant(t_u(U),X,Strict)
	    ->  true
	    ;   true
	    )
	;   get_attr(X,itf,Att),
	    arg(1,Att,CLP),
	    setarg(2,Att,type(t_L(L))),
	    setarg(3,Att,strictness(Sl)),
	    negate_u(Strict,CLP,U,X)
	->  red_t_u
	;   true
	).
redundant(t_lU(L,U),X,Strict) :-
	strictness_parts(Strict,Sl,Su),
	(   get_attr(X,itf,Att),
	    arg(1,Att,CLP),
	    setarg(2,Att,type(t_U(U))),
	    setarg(3,Att,strictness(Su)),
	    negate_l(Strict,CLP,L,X)
	->  red_t_l,
	    (   redundant(t_U(U),X,Strict)
	    ->  true
	    ;   true
	    )
	;   get_attr(X,itf,Att),
	    arg(1,Att,CLP),
	    Bound is -U,
	    intro_at(CLP,X,Bound,t_l(L)),
	    get_attr(X,itf,Att2), % changed?
	    setarg(3,Att2,strictness(Sl)),
	    negate_u(Strict,CLP,U,X)
	->  red_t_u
	;   true
	).

% strictness_parts(Strict,Lower,Upper)
%
% Splits strictness Strict into two parts: one related to the lowerbound and
% one related to the upperbound.

strictness_parts(Strict,Lower,Upper) :-
	Lower is Strict /\ 2,
	Upper is Strict /\ 1.

% negate_l(Strict,Lowerbound,X)
%
% Fails if X does not necessarily satisfy the lowerbound and strictness
% In other words: if adding the inverse of the lowerbound (X < L or X =< L)
% does not result in a failure, this predicate fails.

negate_l(0,CLP,L,X) :- 
	CLP:{L > X},
	!,
	fail.
negate_l(1,CLP,L,X) :- 
	CLP:{L > X},
	!,
	fail.
negate_l(2,CLP,L,X) :-
	CLP:{L >= X},
	!,
	fail.
negate_l(3,CLP,L,X) :-
	CLP:{L >= X},
	!,
	fail.
negate_l(_,_,_,_).

% negate_u(Strict,Upperbound,X)
%
% Fails if X does not necessarily satisfy the upperbound and strictness
% In other words: if adding the inverse of the upperbound (X > U or X >= U)
% does not result in a failure, this predicate fails.

negate_u(0,CLP,U,X) :-
	CLP:{U < X},
	!,
	fail.
negate_u(1,CLP,U,X) :- 
	CLP:{U =< X},
	!,
	fail.
negate_u(2,CLP,U,X) :- 
	CLP:{U < X},
	!,
	fail.
negate_u(3,CLP,U,X) :- 
	CLP:{U =< X},
	!,
	fail.
negate_u(_,_,_,_).

% CLP(Q,R)

detach_bounds(clpq,X) :- bv_q:detach_bounds(X).
detach_bounds(clpr,X) :- bv_r:detach_bounds(X).

intro_at(clpq,A,B,C) :- bv_q:intro_at(A,B,C).
intro_at(clpr,A,B,C) :- bv_r:intro_at(A,B,C).

% Profiling: these predicates are called during redundant and can be used
% to count the number of redundant bounds.

red_t_l.
red_t_u.
red_t_L.
red_t_U.