This file is indexed.

/usr/include/givaro/givpoly1proot.inl is in libgivaro-dev 4.0.2-5.

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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
// =================================================================== //
// Copyright(c)'1994-2009 by The Givaro group
// This file is part of Givaro.
// Givaro is governed by the CeCILL-B license under French law
// and abiding by the rules of distribution of free software.
// see the COPYRIGHT file for more details.
// Givaro / Athapascan-1
// Irreducible polynomial finder
// Primitive root finder
// Time-stamp: <10 Jul 07 15:31:18 Jean-Guillaume.Dumas@imag.fr>
// =================================================================== //
#ifndef __GIVARO_poly_primitive_root_INL
#define __GIVARO_poly_primitive_root_INL

// Reasonible cyclotomic polynomial size
#define CYCLO_DEGREE_BOUND 1000
#define CYCLO_TIMES_FACTOR 8

#include <stdlib.h>
#include <list>
#include <vector>
#include <givaro/givinteger.h>
#include <givaro/givintnumtheo.h>
#include <givaro/givdegree.h>
#include <givaro/givpoly1factor.h>
#include <givaro/givpoly1cyclo.inl>

namespace Givaro {

	////////////////////////////////////////////
	// BINOM
	////////////////////////////////////////////

	template<class Domain, class Tag, class RandomIterator >
	template<class Residue>
	inline bool Poly1FactorDom<Domain,Tag, RandomIterator>::find_irred_binomial (Element& R, Degree n, Residue MOD) const
	{
		for(Residue a=0; a<MOD; ++a) {
			_domain.assign(R[0],(Type_t)a);
			if (is_irreducible(R))
				return true;
		}
		return false;
	}

	template<class Domain, class Tag, class RandomIterator >
	// template<>
	inline bool Poly1FactorDom<Domain,Tag, RandomIterator>::find_irred_binomial (Element& R, Degree n, bool MOD) const
	{
		return false;
	}

	template<class Domain, class Tag, class RandomIterator >
	template<class Residue>
	inline bool Poly1FactorDom<Domain,Tag, RandomIterator>::find_irred_binomial (Element& R, Degree n, Residue MOD, Element IXE) const
	{
		for(Residu_t a=0; a<MOD; ++a) {
			_domain.assign(R[0],static_cast<Element_t>(a));
			if (is_irreducible(R) && (is_prim_root(IXE,R) ))
				return true;
		}

		return false;
	}

	template<class Domain, class Tag, class RandomIterator >
	// template<>
	inline bool Poly1FactorDom<Domain,Tag, RandomIterator>::find_irred_binomial (Element& R, Degree n, bool MOD, Element IXE) const
	{
		return false;
	}


	template<class Domain, class Tag, class RandomIterator >
	template<class Residue>
	inline bool Poly1FactorDom<Domain,Tag, RandomIterator>::find_irred_binomial2 (Element& R, Degree n, Residue MOD, Element IXE) const
	{
		for(Residu_t a=0; a<MOD; ++a) {
			_domain.assign(R[0],(Element_t)a);
			if (is_irreducible2(R) && (is_prim_root(IXE,R) ))
				return true;
		}

		return false;
	}

	template<class Domain, class Tag, class RandomIterator >
	// template<>
	inline bool Poly1FactorDom<Domain,Tag, RandomIterator>::find_irred_binomial2 (Element& R, Degree n, bool MOD, Element IXE) const
	{
		return false;
	}

	////////////////////////////////////////////
	// TRINOM
	////////////////////////////////////////////

	template<class Domain, class Tag, class RandomIterator >
	template<class Residue>
	inline bool Poly1FactorDom<Domain,Tag, RandomIterator>::find_irred_trinomial (Element& R, Degree n, Residue MOD) const
	{

		for(long d=1;d<=(n.value()/2);++d) {
			for(Residu_t b=0; b<MOD; ++b) {
				_domain.assign(R[(size_t)d],(Type_t)b);
				for(Residu_t a=1; a<MOD; ++a) {
					_domain.assign(R[0],(Type_t)a);
					if (is_irreducible(R))
						return true;
				}
			}
			// _domain.assign(R[0],_domain.zero);
			// JGD 21.10.02
			_domain.assign(R[(size_t)d],_domain.zero);
		}
		return false ;
	}

	template<class Domain, class Tag, class RandomIterator >
	// template<>
	inline bool Poly1FactorDom<Domain,Tag, RandomIterator>::find_irred_trinomial (Element& R, Degree n, bool MOD) const
	{

		_domain.assign(R[0],_domain.one);
		for(long d=1;d<=(n.value()/2);++d) {
			_domain.assign(R[(size_t)d],_domain.one);
			if (is_irreducible(R))
				return true;
			_domain.assign(R[(size_t)d],_domain.zero);
		}
		return false ;
	}

	template<class Domain, class Tag, class RandomIterator >
	template<class Residue>
	inline bool Poly1FactorDom<Domain,Tag, RandomIterator>::find_irred_trinomial (Element& R, Degree n, Residue MOD, Element IXE) const
	{
		for(long d=2;d<=(n.value()/2);++d) {
			for(Residu_t b=0; b<MOD; ++b) {
				_domain.assign(R[(size_t)d],(Element_t)b);
				for(Residu_t a=1; a<MOD; ++a) {
					_domain.assign(R[0],(Element_t)a);
					if (is_irreducible(R) && (is_prim_root(IXE,R) ))
						return true;
				}
			}
			// _domain.assign(R[0],_domain.zero);
			// JGD 21.10.02
			_domain.assign(R[(size_t)d],_domain.zero);
		}
		return false;
	}

	template<class Domain, class Tag, class RandomIterator >
	// template<>
	inline bool Poly1FactorDom<Domain,Tag, RandomIterator>::find_irred_trinomial (Element& R, Degree n, bool MOD, Element IXE) const
	{

		_domain.assign(R[0],_domain.one);
		for(long d=2;d<=(n.value()/2);++d) {
			_domain.assign(R[(size_t)d],_domain.one);
			if (is_irreducible(R) && (is_prim_root(IXE,R) ))
				return true;
			_domain.assign(R[(size_t)d],_domain.zero);
		}
		return false ;
	}

	template<class Domain, class Tag, class RandomIterator >
	template<class Residue>
	inline bool Poly1FactorDom<Domain,Tag, RandomIterator>::find_irred_trinomial2 (Element& R, Degree n, Residue MOD, Element IXE) const
	{
		for(long d=2;d<n.value();++d) {
			for(Residu_t b=0; b<MOD; ++b) {
				_domain.assign(R[(size_t)d],(Element_t)b);
				for(Residu_t a=1; a<MOD; ++a) {
					_domain.assign(R[0],(Element_t)a);
					if (is_irreducible2(R) && (is_prim_root(IXE,R) ))
						return true;
				}
			}
			_domain.assign(R[0],_domain.zero);
		}
		return false;

	}

	template<class Domain, class Tag, class RandomIterator >
	// template<>
	inline bool Poly1FactorDom<Domain,Tag, RandomIterator>::find_irred_trinomial2 (Element& R, Degree n, bool MOD, Element IXE) const
	{

		_domain.assign(R[0],_domain.one);
		for(long d=2;d<=n.value();++d) {
			_domain.assign(R[(size_t)d],_domain.one);
			if (is_irreducible2(R) && (is_prim_root(IXE,R) ))
				return true;
			_domain.assign(R[(size_t)d],_domain.zero);
		}
		return false ;
	}

	////////////////////////////////////////////
	// RANDOM
	////////////////////////////////////////////
	template<class Domain, class Tag, class RandomIterator >
	template<class Residue>
	inline bool Poly1FactorDom<Domain,Tag, RandomIterator>::find_irred_randomial (Element& R, Degree n, Residue MOD) const
	{
#ifdef INFLOOPDEBUG
		int no_inf_loop =(int) n.value()/2+5 ;
#endif

		do {
			this->random( (RandomIterator&)_g, R, n); // must cast away const
			_domain.assign(R[(size_t)n.value()],_domain.one);
			for(Residu_t a=0; a<MOD; ++a) {
				_domain.assign(R[0],(Type_t)a);
				if (is_irreducible(R))
					return true;
			}
		}
#ifdef INFLOOPDEBUG
		while(--no_inf_loop);
#else
		while(1);
#endif

		return false;
	}

	template<class Domain, class Tag, class RandomIterator >
	// template<>
	inline bool Poly1FactorDom<Domain,Tag, RandomIterator>::find_irred_randomial (Element& R, Degree n, bool MOD) const
	{
#ifdef INFLOOPDEBUG
		int no_inf_loop = n.value()/2+5 ;
#endif

		do {
			this->random( (RandomIterator&)_g, R, n); // must cast away const
			_domain.assign(R[(size_t)n.value()],_domain.one);
			_domain.assign(R[0],_domain.one);
			if (is_irreducible(R))
				return true;
		}
#ifdef INFLOOPDEBUG
		while(--no_inf_loop);
#else
		while(1);
#endif

		return false;
	}

	template<class Domain, class Tag, class RandomIterator >
	template<class Residue>
	inline bool Poly1FactorDom<Domain,Tag, RandomIterator>::find_irred_randomial (Element& R, Degree n, Residue MOD, Element IXE) const
	{
#ifdef INFLOOPDEBUG
		int no_inf_loop = (int)n.value()/2+5 ;
#endif
		do {
			this->random( (RandomIterator&)_g, R, n); // must cast away const
			_domain.assign(R[(size_t)n.value()],_domain.one);
			for(Residu_t a=0; a<MOD; ++a) {
				_domain.assign(R[0],(Element_t)a);
				if (is_irreducible(R) && (is_prim_root(IXE,R) ))
					return true;
			}
		}
#ifdef INFLOOPDEBUG
		while(--no_inf_loop);
#else
		while(1);
#endif

		return false;
	}

	template<class Domain, class Tag, class RandomIterator >
	// template<>
	inline bool Poly1FactorDom<Domain,Tag, RandomIterator>::find_irred_randomial (Element& R, Degree n, bool MOD, Element IXE) const
	{
#ifdef INFLOOPDEBUG
		int no_inf_loop = n.value()/2+5 ;
#endif

		do {
			this->random( (RandomIterator&)_g, R, n); // must cast away const
			_domain.assign(R[(size_t)n.value()],_domain.one);
			_domain.assign(R[0],_domain.one);
			if (is_irreducible(R) && (is_prim_root(IXE,R) ))
				return true;
		}
#ifdef INFLOOPDEBUG
		while(--no_inf_loop);
#else
		while(1);
#endif

		return false;
	}

	template<class Domain, class Tag, class RandomIterator >
	template<class Residue>
	inline bool Poly1FactorDom<Domain,Tag, RandomIterator>::find_irred_randomial2 (Element& R, Degree n, Residue MOD, Element IXE) const
	{
#ifdef INFLOOPDEBUG
		int no_inf_loop = n.value()/2+5 ;
#endif
		do {
			this->random( (RandomIterator&)_g, R, n); // must cast away const
			_domain.assign(R[(size_t)n.value()],_domain.one);
			for(Residu_t a=0; a<MOD; ++a) {
				_domain.assign(R[0],(Element_t)a);
				if (is_irreducible2(R) && (is_prim_root(IXE,R) ))
					return true;
			}
		}
#ifdef INFLOOPDEBUG
		while(--no_inf_loop);
#else
		while(1);
#endif

		return false;
	}

	template<class Domain, class Tag, class RandomIterator >
	// template<>
	inline bool Poly1FactorDom<Domain,Tag, RandomIterator>::find_irred_randomial2 (Element& R, Degree n, bool MOD, Element IXE) const
	{
#ifdef INFLOOPDEBUG
		int no_inf_loop = n.value()/2+5 ;
#endif
		do {
			this->random( (RandomIterator&)_g, R, n); // must cast away const
			_domain.assign(R[(size_t)n.value()],_domain.one);
			_domain.assign(R[0],_domain.one);
			if (is_irreducible2(R) && (is_prim_root(IXE,R) ))
				return true;
		}
#ifdef INFLOOPDEBUG
		while(--no_inf_loop);
#else
		while(1);
#endif
		return false;

	}

	////////////////////////////////////////////


	// ---------------------------------------------------------------
	// Monic irreducible polynomial of degree n over Z/pZ
	// having 2, 3 nonzero terms or dividing a cyclotomic polynomial
	// of degree < CYCLO_DEGREE_BOUND or a random one.
	// ---------------------------------------------------------------

	template<class Domain, class Tag, class RandomIterator >
	inline typename Poly1FactorDom<Domain,Tag, RandomIterator>::Element& Poly1FactorDom<Domain,Tag, RandomIterator>::creux_random_irreducible (Element& R, Degree n) const
	{
		this->init(R, n);

		Residu_t MOD = _domain.residu();


		// Search for an irreducible BINOMIAL : X^n + a
		// WARNING : Here we may have X^n + x,
		// where a = representation of x, and sometimes a != x.
		if (find_irred_binomial(R,n,MOD))
		    return R ;

		// Search for an irreducible TRINOMIAL : X^n + b*X^i + a
		// Precondition : n >= 2
		assert(n.value()>=2);
		// WARNING : same warning as for the binomial.
		// JGD 21.10.02
		// for(Residu_t d=2;d<n.value();++d)

		if (find_irred_trinomial(R,n,MOD))
			return R ;

		// Search for a monic irreducible Polynomial
		// with random Elements

		if (find_irred_randomial(R,n,MOD))
			return R ;
		else
			throw "could not find a random polynomial" ;

	}

	template<class Domain, class Tag, class RandomIterator >
	inline typename Poly1FactorDom<Domain,Tag, RandomIterator>::Element& Poly1FactorDom<Domain,Tag, RandomIterator>::random_irreducible (Element& R, Degree n) const
	{
		// Search for a monic irreducible Polynomial
		// with random Elements
		this->init(R, n);
		Residu_t MOD = _domain.residu();

		if (find_irred_randomial(R,n,MOD))
			return R ;
		else
			throw "could not find a random polynomial" ;

	}


	// ---------------------------------------------------------------
	// Monic irreducible polynomial of degree n over Z/pZ
	// having 2, 3 nonzero terms or or a random one,
	// with X as a primitive root.
	// ---------------------------------------------------------------
	template<class Domain, class Tag, class RandomIterator >
	inline typename Poly1FactorDom<Domain,Tag, RandomIterator>::Element& Poly1FactorDom<Domain,Tag, RandomIterator>::ixe_irreducible (Element& R, Degree n) const
	{
		this->init(R, n);
		Element IXE;
		this->init(IXE,Degree(1));
		Residu_t MOD = _domain.residu();

		// Search for an irreducible BINOMIAL : X^n + a
		// WARNING : Here we may have X^n + x,
		// where a = representation of x, and sometimes a != x.

		if (find_irred_binomial(R,n,MOD,IXE))
		    return R ;

		// Search for an irreducible TRINOMIAL : X^n + b*X^i + a
		// Precondition : n >= 2
		assert(n.value()>=2);
		// WARNING : same warning as for the binomial.
		// // JGD 21.10.02
		// for(unsigned long d=2;d<n.value();++d)

		if (find_irred_trinomial(R,n,MOD,IXE))
			return R ;


		// Search for a monic irreducible Polynomial
		// with random Elements
		if (find_irred_randomial(R,n,MOD,IXE))
			return R ;
		else
			throw "could not find a random polynomial" ;


	}

	template<class Domain, class Tag, class RandomIterator >
	inline typename Poly1FactorDom<Domain,Tag, RandomIterator>::Element& Poly1FactorDom<Domain,Tag, RandomIterator>::ixe_irreducible2 (Element& R, Degree n) const
	{
		this->init(R, n);
		Element IXE;
		this->init(IXE,Degree(1));
		Residu_t MOD = _domain.residu();

		// Search for an irreducible BINOMIAL : X^n + a
		// WARNING : Here we may have X^n + x,
		// where a = representation of x, and sometimes a != x.

		if (find_irred_binomial2(R,n,MOD,IXE))
			return R ;

		// Search for an irreducible TRINOMIAL : X^n + b*X^i + a
		// Precondition : n >= 2
		assert(n.value()>=2);
		// WARNING : same warning as for the binomial.

		if (find_irred_trinomial2(R,n,MOD,IXE))
			return R ;



		// Search for a monic irreducible Polynomial
		// with random Elements

		if (find_irred_randomial2(R,n,MOD,IXE))
			return R ;
		else
			throw "could not find a random polynomial" ;


	}
	// ---------------------------------------------------------------
	// Irreducibility tests
	// ---------------------------------------------------------------

	template<class Domain, class Tag, class RandomIterator>
	inline bool Poly1FactorDom<Domain,Tag, RandomIterator>::is_irreducible2( const Rep& P
									  , Residu_t MOD ) const
	{
		// Square free ?
		Rep W,D; this->gcd(W,diff(D,P),P);
		Degree d, dP;
		if (this->degree(d,W) > 0) return 0;
		IntFactorDom<> FD;

		int64_t n = this->degree(dP,P).value();
		IntFactorDom<>::Rep qn;

		FD.pow( qn, IntFactorDom<>::Rep(MOD), n);
		Rep Unit, G1; this->init(Unit, Degree(1));
		this->powmod(G1, Unit, qn, P);
		if (this->degree(d, sub(D,G1,Unit)) >= 0) return 0;

		std::vector<IntFactorDom<>::Rep> Lp; std::vector<uint64_t> Le;
		FD.set(Lp, Le, n );
		for( std::vector<IntFactorDom<>::Rep>::const_iterator p = Lp.begin(); p != Lp.end(); ++p) {
			int64_t ttmp;
			FD.pow( qn, IntFactorDom<>::Rep(MOD), n/FD.convert(ttmp,*p) );
			this->powmod(G1, Unit, qn, P);
			if (this->degree(d, sub(D,G1,Unit)) < 0) return 0;
		}

		return 1;
	}




	// ---------------------------------------------------------------
	// Primitive Root over Z/pZ / F
	// returns 1 if P is a generator.
	// ---------------------------------------------------------------

	template<class Domain, class Tag, class RandomIterator>
	bool Poly1FactorDom<Domain,Tag, RandomIterator>::is_prim_root( const Rep& P, const Rep& F)  const
	{
		bool isproot = 0;
		Rep A, G;
		this->mod(A,P,F);
		Degree d;
		if ( this->degree(d, this->gcd(G,A,F)) == 0) {
			Residu_t MOD = _domain.residu();
			IntFactorDom<> FD;
			IntFactorDom<>::Element IMOD( MOD ), q, qp;
			this->degree(d,F);
			//         FD.pow(q ,IMOD, d.value());
			//         FD.sub(qp, q, FD.one);
			FD.subin( FD.pow(qp ,IMOD, d.value()) , FD.one);
			std::list< IntFactorDom<>::Element > L;
			FD.set(L, qp);
			L.sort();
			std::list< IntFactorDom<>::Element >::iterator li = L.begin();
			isproot = 1;
			for(;(li != L.end()) && isproot; ++li) {
				isproot = ( ! this->isOne(this->powmod(G, A, FD.div(q, qp , *li), F) ) );
			}
		}
		return isproot;
	}

	template<class Domain, class Tag, class RandomIterator>
	inline typename IntegerDom::Element Poly1FactorDom<Domain,Tag, RandomIterator>::order( const Rep& P, const Rep& F)  const
	{
		bool isproot = 0;
		Rep A, G; mod(A,P,F);
		Degree d;
		if ( this->degree(d, this->gcd(G,A,F)) == 0) {
			Residu_t MOD = _domain.residu();
			IntFactorDom<> FD;
			IntFactorDom<>::Element IMOD( MOD ), g, gg, tt, qp;
			this->degree(d,F);
			//         FD.pow(q ,IMOD, d.value());
			//         FD.sub(qp, q, FD.one);
			FD.subin( FD.pow(qp ,IMOD, d.value()) , FD.one);
			std::list< IntFactorDom<>::Element > L;
			FD.set(L, qp);
			L.sort();
			std::list< IntFactorDom<>::Element >::iterator li = L.begin();
			isproot = 1;
			for(;(li != L.end()) && isproot; ++li)
				isproot = ( ! this->isOne(this->powmod(G, A, FD.div(g, qp , *li), F) ) );

			if (isproot)
				return qp;
			else {
				for(--li;li!=L.end();++li)
					while ( FD.isZero(FD.mod(tt,g,*li)) && (this->isOne(this->powmod(G, A, FD.div(gg,g,*li), F))))
						g.copy(gg);
				return g;
			}
		}
		IntegerDom ID;
		return ID.zero;
	}

	template<class Domain, class Tag, class RandomIterator >
	inline typename Poly1FactorDom<Domain,Tag, RandomIterator>::Rep& Poly1FactorDom<Domain,Tag, RandomIterator>::give_prim_root(Rep& R, const Rep& F)  const
	{
		Degree n; this->degree(n,F);
		Residu_t MOD = _domain.residu();
		//    this->write(std::cout << "Give Pr: ", F) << std::endl;


		// Search for a primitive BINOMIAL : X^i + a
		for(Degree di=1;di<n;++di) {
			this->init(R, di);
			//         for(Residu_t a=MOD; a--; )
			for(Residu_t a=0; a<MOD;++a ) {
				_domain.assign(R[0],(Element_t)a);
				if (is_prim_root(R,F))
					return R;
			}
		}
		// Search for a primitive TRINOMIAL : X^i + b*X^j + a
		for(Degree di=2;di<n;++di) {
			this->init(R, di);
			for(Degree dj=1;dj<di;++dj)
				//             for(Residu_t b=MOD; b--;)
				for(Residu_t b=0; b<MOD;++b) {
					_domain.assign(R[(size_t)dj.value()],(Element_t)b);
					//                 for(Residu_t a=MOD; a--;)
					for(Residu_t a=0; a<MOD;++a ) {
						_domain.assign(R[0],(Element_t)a);
						if (is_prim_root(R,F))
							return R;
					}
				}
		}

		// Search for a primitive Polynomial
		// with random Elements
		do {
			this->random( (RandomIterator&)_g, R, n); // must cast away const
			_domain.assign(R[(size_t)n.value()],_domain.one);
			for(Residu_t a=0; a<MOD; ++a) {
				_domain.assign(R[0],(Element_t)a);
				if (is_prim_root(R,F))
					return R;
			}
		} while(1);
	}


	template<class Domain, class Tag, class RandomIterator >
	inline typename Poly1FactorDom<Domain,Tag, RandomIterator>::Rep& Poly1FactorDom<Domain,Tag, RandomIterator>::give_random_prim_root(Rep& R, const Rep& F)  const
	{
		Degree n; this->degree(n,F);
		Residu_t MOD = _domain.residu();

		// Search for a primitive Polynomial
		// with random Elements
		do {
			this->random( (RandomIterator&)_g, R, n); // must cast away const
			_domain.assign(R[(size_t)n.value()],_domain.one);
			for(Residu_t a=0; a<MOD; ++a) {
				_domain.assign(R[0],(Element_t)a);
				if (is_prim_root(R,F))
					return R;
			}
		} while(1);
	}


	template<class Domain, class Tag, class RandomIterator >
	inline typename Poly1FactorDom<Domain,Tag, RandomIterator>::Rep& Poly1FactorDom<Domain,Tag, RandomIterator>::random_prim_root(Rep& P, Rep& R, Degree n)  const
	{
		// P is irreducible
		// R is a primitive root. i.e R generates (Z_p)/P.
		// returns R
		return give_prim_root(R, random_irreducible(P,n));
	}

} // Givaro

#endif // __GIVARO_poly_primitive_root_INL

/* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
// vim:sts=8:sw=8:ts=8:noet:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s