This file is indexed.

/usr/include/linbox/algorithms/double-det.h is in liblinbox-dev 1.1.6~rc0-4.1.

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
298
299
300
301
302
303
/* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */

/* linbox/algorithms/doubledet.h
 * 
 *  Written by Clement Pernet <clement.pernet@gmail.com>
 *
 * See COPYING for license information.
 */

#ifndef __DOUBLEDET_H
#define __DOUBLEDET_H

#include "linbox/ffpack/ffpack.h"
#include "linbox/algorithms/matrix-hom.h"	
#include "linbox/algorithms/cra-domain.h"
#include "linbox/algorithms/cra-full-multip.h"
#include "linbox/algorithms/cra-early-multip.h"
#include "linbox/randiter/random-prime.h"	
#include "linbox/solutions/solve.h"
#include "linbox/solutions/methods.h"
#include <vector>
namespace LinBox 
{
	
	/* Given a (n-1) x n full rank matrix A and 2 vectors b,c mod p,
	 * compute
	 * d1 = det( [ A ] ) mod p and d2 = det ( [ A ]) mod p
	 *           [ b ]                        [ c ]
	 *
	 * 
	 * A, b, c will be overwritten.
	 */
	template <class Field>
	void doubleDetModp (const Field& F, const size_t N,
			    typename Field::Element& d1,
			    typename Field::Element& d2,
			    typename Field::Element* A, const size_t lda,
			    typename Field::Element* b, const size_t incb,
			    typename Field::Element* c, const size_t incc){

		size_t* P = new size_t[N];
		size_t* Qt = new size_t[N-1];
		
		FFPACK::LUdivine (F, FFLAS::FflasUnit, FFLAS::FflasNoTrans, N-1, N,
				  A, lda, P, Qt);
		typename Field::Element d;

		// Multiplying all (N-1) first pivots)
		F.init(d, 1UL);
		for (size_t i=0; i<N-1; ++i)
			F.mulin (d, *(A + i*(lda+1)));

		bool count = false;
		for (size_t i=0;i<N-1;++i)
			if (P[i] != i) count = !count;
		if (count)
			F.negin(d);

		// Trick: instead of Right-Trans, do Left-NoTrans in order to use inc*
		FFPACK::applyP (F, FFLAS::FflasLeft, FFLAS::FflasNoTrans, 1, 0, N-1,
				b, incb, P);
		FFPACK::applyP (F, FFLAS::FflasLeft, FFLAS::FflasNoTrans, 1, 0, N-1,
				c, incc, P);
		FFLAS::ftrsv (F, FFLAS::FflasUpper, FFLAS::FflasTrans,
			      FFLAS::FflasUnit, N, A, lda, b, incb);
		FFLAS::ftrsv (F, FFLAS::FflasUpper, FFLAS::FflasTrans,
			      FFLAS::FflasUnit, N, A, lda, c, incc);


		F.mul (d1, d, *(b + (N-1) * incb));
		F.mul (d2, d, *(c + (N-1) * incc));
		
		delete[] P;
		delete[] Qt;
	}

	// Iteration class for the Chinese remaindering phase
	template <class BlackBox>
	struct IntegerDoubleDetIteration{

		const BlackBox& _A;
		const typename BlackBox::Field::Element _s1;
		const typename BlackBox::Field::Element _s2;
		IntegerDoubleDetIteration(const BlackBox& A,
					  const typename BlackBox::Field::Element& s1,
					  const typename BlackBox::Field::Element& s2)
			: _A(A), _s1(s1), _s2(s2) {}

		template<class Field>
		std::vector<typename Field::Element>&
		operator () (std::vector<typename Field::Element>& dd,
			     const Field& F) const {

			typedef typename BlackBox::template rebind<Field>::other FBlackbox;
			FBlackbox * Ap;
			typename Field::Element s1p, s2p;
			dd.resize(2);
			F.init(s1p, _s1);
			F.init(s2p, _s2);
			MatrixHom::map(Ap, _A, F);
			const size_t N = _A.coldim();
			//Timer tim;
			//tim.clear();
			//tim.start();
			doubleDetModp (F,  N, dd[0], dd[1],
				       Ap->getPointer(), Ap->getStride(),
				       Ap->getPointer() + (N-1) * Ap->getStride(), 1,
				       Ap->getPointer() + N * Ap->getStride(), 1);

			F.divin (dd[0], s1p);
			F.divin (dd[1], s2p);
			//tim.stop();
			//std::cerr<<"doubleDetModp took "<<tim.usertime()<<std::endl;
			delete Ap;
			return dd;
		}
	};

	/* Computes the actual Hadamard bound of the matrix A by taking the minimum 
	 * of the column-wise and the row-wise euclidean norm.
	 * 
	 * A is supposed to be over integers.
	 *
	 */
	// should use multiprec floating pt arith, wait, maybe not!
	template<class BlackBox>
	integer& HadamardBound (integer& hadamarBound, const BlackBox& A){
		
		
		integer res1 = 1;
		integer res2 = 1;
		integer temp;
		
		typename BlackBox::ConstRowIterator rowIt;
		typename BlackBox::ConstRow::const_iterator col;
		
		for( rowIt = A.rowBegin(); rowIt != A.rowEnd(); ++rowIt ) {
			temp = 0;
			for( col = rowIt->begin(); col != rowIt->end(); ++col )
				temp += static_cast<integer>((*col)) * (*col);
			res1 *= temp;
		}
		res1 = sqrt(res1);

		typename BlackBox::ConstColIterator colIt;
		typename BlackBox::ConstCol::const_iterator row;
		
		for( colIt = A.colBegin(); colIt != A.colEnd(); ++colIt ) {
			temp = 0;
			for( row = colIt->begin(); row != colIt->end(); ++row )
				temp += static_cast<integer>((*row)) * (*row);
			res2 *= temp;
		}
		res2 = sqrt(res2);
		
		return hadamarBound = MIN(res1, res2);
	}
// 	template<class BlackBox>
// 	double& HadamardBound (double& hadamarBound, const BlackBox& A){
		
		
// 		double res1 = 0;
// 		double res2 = 0;
// 		integer temp;
		
// 		typename BlackBox::ConstRowIterator rowIt;
// 		typename BlackBox::ConstRow::const_iterator col;
		
// 		for( rowIt = A.rowBegin(); rowIt != A.rowEnd(); ++rowIt ) {
// 			temp = 0;
// 			for( col = rowIt->begin(); col != rowIt->end(); ++col )
// 				temp += static_cast<integer>((*col)) * (*col);
// 			res1 += log ((double)temp);
// 		}
// 		res1 = res1/2;

// 		typename BlackBox::ConstColIterator colIt;
// 		typename BlackBox::ConstCol::const_iterator row;
		
// 		for( colIt = A.colBegin(); colIt != A.colEnd(); ++colIt ) {
// 			temp = 0;
// 			for( row = colIt->begin(); row != colIt->end(); ++row )
// 				temp += static_cast<integer>((*row)) * (*row);
// 			res2 += log((double)temp);
// 		}
// 		res2 = res2/2;
		
// 		return hadamarBound = MIN(res1, res2);
// 	}

	/* Given a (N+1) x N full rank matrix
	 * [ A ]
	 * [ b ]
	 * [ c ]
	 * where b and c are the last 2 rows,
	 * and given s1 and s2, respectively divisors of d1 and d2 defined as
	 * d1 = det ([ A ])
	 *          ([ b ])
	 * and
	 * d2 = det ([ A ])
	 *          ([ c ]),
	 * compute d1 and d2.
	 * Assumes d1 and d2 are non zero.
	 * Result is probablistic if proof=true
	 */
	template <class BlackBox>
	void doubleDetGivenDivisors (const BlackBox& A,
				     typename BlackBox::Field::Element& d1,
				     typename BlackBox::Field::Element& d2,
				     const typename BlackBox::Field::Element& s1,
				     const typename BlackBox::Field::Element& s2,
				     const bool proof){

		typename BlackBox::Field F = A.field();
		IntegerDoubleDetIteration<BlackBox> iteration(A, s1, s2);
		// 0.7213475205 is an upper approximation of 1/(2log(2))
		RandomPrimeIterator genprime( 25-(int)ceil(log((double)A.rowdim())*0.7213475205)); 
		
		std::vector<typename BlackBox::Field::Element> dd;
		if (proof) {
			integer bound;
			double logbound;
			//Timer t_hd,t_cra;
			//t_hd.clear();
			//t_hd.start();
			HadamardBound (bound, A);
			logbound = (logtwo (bound) - logtwo (MIN(abs(s1),abs(s2))))*0.693147180559945;
			//t_hd.stop();
			//std::cerr<<"Hadamard bound = : "<<logbound<<" in "<<t_hd.usertime()<<"s"<<std::endl;

			ChineseRemainder <FullMultipCRA <Modular <double> > > cra(logbound);

			//t_hd.clear();
			//t_cra.start();
			cra (dd, iteration, genprime);
			//t_cra.stop();
			//std::cerr<<"CRA : "<<t_cra.usertime()<<"s"<<std::endl;

		} else {
			ChineseRemainder <EarlyMultipCRA <Modular<double> > > cra(4UL);
			cra (dd, iteration, genprime);
		}
		F.mul (d1, dd[0], s1);
		F.mul (d2, dd[1], s2);
	}

	/* Given a (n + 1) x n full rank matrix
	 * A = [ B ]
	 *     [ b ]
	 *     [ c ]
	 * over Z, compute
	 * d1 = det( [ A ] ) and d2 = det ( [ A ])
	 *           [ b ]                  [ c ]
	 */
	
	template <class BlackBox>
	void doubleDet (typename BlackBox::Field::Element& d1,
			typename BlackBox::Field::Element& d2,
			const BlackBox& A,
			//const vector<typename BlackBox::Field::Element>& b,
			//const vector<typename BlackBox::Field::Element>& c,
			bool proof){

		linbox_check (A.coldim() == A.rowdim()+1);
		
		const size_t N = A.coldim();
		//		BlasBlackbox<typename BlackBox::Field> B (A,0,0,N,N);
		BlasBlackbox<typename BlackBox::Field> B (A.field(),N,N);
		typename BlackBox::Field::Element den1, den2;
		std::vector<typename BlackBox::Field::Element> x1(N);
		for (size_t i=0; i<N; ++i){
			x1[i] = 0;
			for (size_t j=0; j<N; ++j)
				B.setEntry(j,i, A.getEntry(i,j));
		}
		// 		for (size_t i=0; i<N; ++i)
		// 			B.setEntry (i, N-1, b[i]);

		std::vector<typename BlackBox::Field::Element> c(N);
		for (size_t i=0; i<N; ++i)
			c[i] = A.getEntry (N, i);
		//Timer tim;
		//tim.clear();
		//tim.start();
		solve (x1, den1, B, c);
		//tim.stop();
		//std::cerr<<"Solve took "<<tim.usertime()<<std::endl;
		
		den1 = den1;
		// Should work:
		// den (y[n]) = den (-den1/x[n]) = x[n] 
		den2 = -x1[N-1];
		//tim.clear();
		//tim.start();
		doubleDetGivenDivisors (A, d1, d2, den1, den2, proof);
		//tim.stop();
		//std::cerr<<"CRA "<<(proof?"Determinist":"Probablistic")
		//	 <<" took "<<tim.usertime()<<std::endl;
	}
}


#endif // __DOUBLEDET_H