This file is indexed.

/usr/include/linbox/algorithms/massey-domain.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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
/* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */

/* linbox/algorithms/massey-domain.h
 * Copyright (C) 1999, 2001 Jean-Guillaume Dumas, Bradford Hovinen
 *
 * Written by Jean-Guillaume Dumas <Jean-Guillaume.Dumas@imag.fr>,
 *            Bradford Hovinen <hovinen@cis.udel.edu>
 *            JGD 12.06.2002 : 
 *            			-- Put back domain.zero
 *            			-- Put back domain.one
 *            			-- Put back full_poly
 *            			-- Put back pseudo_minpoly as it was before
 *            			-- not yet fully checked since previous changes
 *
 * ------------------------------------
 *
 * See COPYING for license information.
 */
#ifndef __MASSEY_DOMAIN_H
#define __MASSEY_DOMAIN_H

// ======================================================================= 
// Linbox project 1999
// Domain Massey
// - Computation is stopped when the polynomials remain the same
//   for more than EARLY_TERM_THRESOLD
// - When minimal polynomial equals characteristic polynomial,
//   2 additional iterations are needed to compute it 
//   (parameter DEFAULT_ADDITIONAL_ITERATION), but those
//   iterations are not needed for the rank
// Time-stamp: <27 Aug 01 18:18:12 Jean-Guillaume.Dumas@imag.fr> 
// ======================================================================= 

#include "linbox/util/commentator.h"
#include "linbox/vector/reverse.h"
#include "linbox/vector/subvector.h"
#include "linbox/vector/vector-domain.h"
#include "linbox/util/timer.h"

namespace LinBox 
{

#ifndef MIN
#  define MIN(a,b) ((a)<(b)?(a):(b))
#endif

#define DEFAULT_EARLY_TERM_THRESHOLD 20
#define DEFAULT_ADDITIONAL_ITERATION 2

const long _DEGINFTY_ = -1;

/** \brief Berlekamp/Massey algorithm. 

   Domain Massey
   - Computation is stopped when the polynomials remain the same
     for more than EARLY_TERM_THRESOLD
   - When minimal polynomial equals characteristic polynomial,
     2 additional iterations are needed to compute it 
     (parameter DEFAULT_ADDITIONAL_ITERATION), but those
     iterations are not needed for the rank
*/
template<class Field, class Sequence>
class MasseyDomain {
    private:
	Sequence            *_container;
	Field                _F;
	VectorDomain<Field>  _VD;
	unsigned long         EARLY_TERM_THRESHOLD;

#ifdef INCLUDE_TIMING
	// Timings
	double                _discrepencyTime;
	double                _fixTime;
#endif // INCLUDE_TIMING

    public:
	typedef typename Field::Element Element;

        //-- Constructors
	MasseyDomain (unsigned long ett_default = DEFAULT_EARLY_TERM_THRESHOLD) 
		: _container           (), 
		  _F                   (), 
		  _VD                  (_F),
		  EARLY_TERM_THRESHOLD (ett_default)
		{}

	MasseyDomain (const MasseyDomain<Field, Sequence> &M, unsigned long ett_default = DEFAULT_EARLY_TERM_THRESHOLD) 
		: _container           (M._container), 
		  _F                   (M._F), 
		  _VD                  (M._F),
		  EARLY_TERM_THRESHOLD (ett_default)
		{}

	MasseyDomain (Sequence *D, unsigned long ett_default = DEFAULT_EARLY_TERM_THRESHOLD) 
		: _container           (D), 
		  _F                   (D->getField ()),
		  _VD                  (D->getField ()),
		  EARLY_TERM_THRESHOLD (ett_default)
		{}
  
	MasseyDomain (Sequence *MD, const Field &F, unsigned long ett_default = DEFAULT_EARLY_TERM_THRESHOLD) 
		: _container           (MD), 
		  _F                   (F),
		  _VD                  (F),
		  EARLY_TERM_THRESHOLD (ett_default) 
		{}

        //-- Principal method
	template<class Polynomial>
	void operator () (Polynomial &C, bool full_poly = false) {
		massey (C, full_poly);
	}

        //-- Domains access
	const Field &getField    () const { return _F; }
	Sequence    *getSequence () const { return _container; }

#ifdef INCLUDE_TIMING
	double       discrepencyTime () const { return _discrepencyTime; }
	double       fixTime         () const { return _fixTime; }
#endif // INCLUDE_TIMING

    private:
	// -----------------------------------------------
	// Polynomial emulation
	// Only container aspects of polynomials
	// AND degree and valuation are needed !
	// -----------------------------------------------

	// Degree of v
	template <class V>
	long v_degree (V& v) {
		long i = v.size()-1;

		if (i == _DEGINFTY_)
			return _DEGINFTY_;

		else if (!_F.isZero (v[i]))
			return i;

		// We must re-compute the degree :
		for (long j = i - 1; j >= 0; j--) {
			if (!_F.isZero (v[j])) {
				v.resize (j + 1);
				return j;
			}
		}

		return _DEGINFTY_ ;
	}

	// Valuation of v
	template <class V>
	long v_val(V& v) {
		long i = v.size() - 1;

		if (i == _DEGINFTY_)
			return _DEGINFTY_;

		else if (!_F.isZero (v[0]))
			return 0;

		// We must compute the valuation :
		for (long j = 1; j <= i; j++)
			if (!_F.isZero ((v)[j])) return j ;

		return _DEGINFTY_ ;
	}

	// -------------------------------------------------------------------
	// Berlekamp/Massey algorithm with Massey's Sequence generation
	// -------------------------------------------------------------------

	template<class Polynomial>
	long massey (Polynomial &C, bool full_poly = false) { 
//              const long ni = _container->n_row (), nj = _container->n_col ();
//              const long n = MIN(ni,nj);
		const long END = _container->size () + (full_poly ? DEFAULT_ADDITIONAL_ITERATION:0);
		const long n = END >> 1;

#ifdef INCLUDE_TIMING
		Timer timer;

		_discrepencyTime = _fixTime = 0.0;
#endif // INCLUDE_TIMING

		integer card;

		commentator.start ("Massey", "masseyd", END);

		// ====================================================
		// Sequence and iterator initialization
		//
		typename Sequence::const_iterator _iter (_container->begin ());
		Polynomial S (END + 1);
		
		Element Zero, One;
		_F.init(Zero, 0);
		_F.init(One, 1);

		// -----------------------------------------------
		// Preallocation. No further allocation.
		//
		C.reserve    (n + 1); C.resize (1); _F.assign (C[0], One);
		Polynomial B (n + 1); B.resize (1); _F.assign (B[0], One);

		long L = 0;
		Element b, d, Ds;
		long x = 1, b_deg = 0, c_deg = 0, l_deg;
		long COMMOD = (END > 25) ? (END / 25) : 1;

		_F.assign (b, One);

		for (long N = 0; N < END && x < (long) EARLY_TERM_THRESHOLD; ++N, ++_iter) {
			if (!(N % COMMOD)) 
				commentator.progress (N);

			// ====================================================
			// Next coefficient in the sequence
			// Discrepancy computation
			// 
			S[N] = *_iter; 

#ifdef INCLUDE_TIMING
			timer.start ();
#endif // INCLUDE_TIMING

			long poly_len = MIN (L, c_deg);
			Subvector<typename Polynomial::iterator> Cp (C.begin () + 1, C.begin () + poly_len + 1);
			Subvector<typename Polynomial::iterator> Sp (S.begin () + (N - poly_len), S.begin () + N);
			ReverseVector<Subvector<typename Polynomial::iterator> > Spp (Sp);
			_VD.dot (d, Cp, Spp);

			_F.addin (d, S[N]);

#ifdef INCLUDE_TIMING
			timer.stop ();

			_discrepencyTime += timer.realtime ();

			timer.start ();
#endif // INCLUDE_TIMING

			if (_F.isZero (d)) {
				++x;
			} else {
				if (L > (N >> 1)) {
					// -----------------------------------------------
					// C = C + (Polynome(X,x,-d/b) * B);
					// 
					_F.divin (_F.neg (Ds, d), b);
					long i = l_deg = (x + b_deg);
					if (l_deg > c_deg) {
						C.resize (l_deg + 1);
						if (x > c_deg) {
							for (; i >= x; --i)
								_F.mul (C[i], Ds, B[i-x]);
							for (; i > c_deg; --i)
								_F.assign (C[i], Zero);
						} else {
							for (; i > c_deg; --i)
								_F.mul (C[i], Ds, B[i-x]);
							for (; i >= x; --i)
								_F.axpyin (C[i], Ds, B[i-x]);
						}
					} else {
						for (; i >= x; --i)
							_F.axpyin (C[i], Ds, B[i-x]);
					}
					// -----------------------------------------------
					c_deg = v_degree(C);
					++x;
				} else {
					// -----------------------------------------------
					// C = C + (Polynome(X,x,-d/b) * B); 					// 
					_F.divin (_F.neg (Ds, d), b);
					long i = l_deg = x + b_deg;
					B.resize (C.size ());
					if (l_deg > c_deg) {
						C.resize (l_deg+1);
						if (x > c_deg) {
							for (; i >= x; --i)
								_F.mul (C[i], Ds, B[i-x]);
							for (; i > c_deg; --i)
								_F.assign (C[i], Zero);
						} else {
							for (; i > c_deg; --i)
								_F.mul (C[i], Ds, B[i-x]);
							for (; i >= x; --i)
								_F.axpy (C[i], Ds, B[i-x], B[i] = C[i]);
						}
					} else {
						for (i = c_deg; i > l_deg; --i)
							B[i] = C[i];
						for (; i >= x; --i)
							_F.axpy (C[i], Ds, B[i-x], B[i] = C[i] );
					}

					for (; i >= 0; --i) B[i] = C[i];

					// -----------------------------------------------
					L = N+1-L;
					b_deg = c_deg;
					c_deg = v_degree (C);
					b = d;
					x = 1;
				}
			}
			// ====================================================

#ifdef INCLUDE_TIMING
			timer.stop ();

			_fixTime += timer.realtime ();
#endif // INCLUDE_TIMING
		}

                commentator.stop ("done", NULL, "masseyd");
//		commentator.stop ("Done", "Done", "LinBox::MasseyDomain::massey");

		return L;
	}

public:
	// ---------------------------------------------
	// Massey
	//
	void pseudo_rank (unsigned long &rank) {
		std::vector<Element> phi;
		massey (phi, 0);
		rank = v_degree (phi) - v_val (phi);
	}
 
	void valence (Element &valence, unsigned long &rank) {
		commentator.start ("Valence", "LinBox::MasseyDomain::valence");

		std::vector<Element> phi;
		massey (phi, 1);
		rank = v_degree (phi) - v_val (phi);
		valence = phi[v_degree (phi)];

		commentator.stop ("Done", "Done", "LinBox::MasseyDomain::valence");
	}

	template<class Polynomial>
	unsigned long pseudo_minpoly (Polynomial &phi, unsigned long &rank, bool full_poly = true) {
		unsigned long L = massey (phi, full_poly);
		long dp = v_degree(phi);
		rank = dp - v_val (phi);
        	if (phi.size()) {
			for(long i = dp >> 1;i > 0; --i) {
				phi[0] = phi[i];
				phi[i] = phi[dp-i];
				phi[dp-i] = phi[0];
			}
			phi[0] = phi[dp];
			_F.init (phi[dp], 1);
		}
                return L;
	}

	template<class Polynomial>
	void minpoly (Polynomial &phi, unsigned long &rank, bool full_poly = true) {
            long dp = massey (phi, full_poly);
            rank = v_degree(phi) - v_val (phi);
		if (phi.size () > 0) {
			phi.resize (dp+1);
			for (long i = dp >> 1; i > 0; --i)
				std::swap (phi[i], phi[dp-i]);
			phi[0] = phi[dp];
			_F.init (phi[dp], 1);
		}
	}
};
 
}
    
#endif // __MASSEY_DOMAIN_H