/usr/include/givaro/givpoly1factor.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 | // ================================================================= //
// 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
// Irreducibily test
// Factorisations de Polynomes dans Fp[X] :
// Distinct Degree
// Cantor-Zassenhaus
// Berlekamp : in LinBox
// Time-stamp: <26 Feb 08 13:37:26 Jean-Guillaume.Dumas@imag.fr>
// ================================================================= //
#ifndef __GIVARO_poly1_facto_INL
#define __GIVARO_poly1_facto_INL
#include <givaro/givpower.h>
#include <givaro/givcaster.h>
//!@todo use NTL if available ?
namespace Givaro {
// ---------------------------------------------------------------
// Splits a polynomial into prime factors of same degree
// ---------------------------------------------------------------
template<class Domain, class Tag, class RandomIterator>
template< template<class, class> class Container, template <class> class Alloc >
inline void Poly1FactorDom<Domain,Tag, RandomIterator>::SplitFactor(
Container< Rep, Alloc<Rep> > & L
, const Rep& G
, Degree d
, Residu_t MOD) const
{
Degree dG; this->degree(dG,G);
if (dG == d)
L.push_back(G);
else {
int splitted = 0;
while (! splitted) {
Rep G1, G2;
this->gcd(G1, G, this->random(_g, G2, dG-1) );
Degree dG1; this->degree(dG1,G1);
// write(std::cerr << "SF rd: ", G2) << std::endl;
// write(std::cerr << "SF G1: ", G1) << std::endl;
if ( dG1 != dG) {
if (dG1 > 0 ) {
splitted = 1;
SplitFactor ( L, G1, d, MOD) ;
this->div(G2, G, G1);
SplitFactor ( L, G2, d, MOD) ;
return ;
}
Integer iMOD; Caster(iMOD, MOD);
Integer pp = (power(iMOD, d.value()) - 1)/2;
// std::cerr << "pp: " << pp << std::endl;
Rep tp;
this->gcd(G1, G,
this->subin( this->powmod(tp, G2, pp, G),
_domain.one)
);
this->degree(dG1,G1);
// write(std::cerr << "SF t2: ", tp2) << std::endl;
// write(std::cerr << "SF G1: ", G1) << std::endl;
if ( ( dG1 != dG) && (dG1 > 0 ) ) {
splitted = 1 ;
SplitFactor ( L, G1, d, MOD) ;
this->div( G2, G, G1);
SplitFactor ( L, G2, d, MOD) ;
}
}
}
}
}
template<class Domain, class Tag, class RandomIterator>
inline typename Poly1FactorDom<Domain,Tag, RandomIterator>::Rep& Poly1FactorDom<Domain,Tag, RandomIterator>::SplitFactor(
Rep& G1
, const Rep& G
, Degree d
, Residu_t MOD) const {
Degree dG;this->degree(dG,G);
if (dG == d)
return G1.copy(G) ;
else {
while (1) {
Rep tmp;
this->gcd(G1, G, this->random(_g, tmp, d));
// write(std::cerr << "SF rd: ", tmp) << std::endl;
// write(std::cerr << "SF G1: ", G1) << std::endl;
Degree dG1; this->degree(dG1,G1);
if ( dG1 != dG) {
if (dG1 > 0 ) {
return G1;
}
Integer iMOD; Caster(iMOD, MOD);
Integer pp = (power(iMOD, d.value()) - 1)/2;
Rep tp, tp2, G2;
this->gcd(G2,G, this->sub(tp2, this->powmod(tp, tmp, pp, G) , _domain.one) );
Degree dG2; this->degree(dG2,G2);
// write(std::cerr << "SF t2: ", tp2) << std::endl;
// write(std::cerr << "SF G2: ", G2) << std::endl;
if ( dG2 != dG) {
if ( dG2 > 0 ) {
return G1.copy(G2);
}
// UNNECESSARY : ANYTHING FOUND BY G3 WOULD HAVE THE COFACTOR IN G2
Rep G3; this->gcd(G3, G, this->add(tp2,tp,_domain.one) );
Degree dG3; this->degree(dG3,G3);
// write(std::cerr << "SF t3: ", tp2) << std::endl;
// write(std::cerr << "SF G3: ", G3) << std::endl;
if (( dG3 != dG) && (dG3 > 0 )) {
return G1.copy(G3);
}
}
}
}
}
}
// ---------------------------------------------------------------
// Splits a polynomial into divisors of homogenous prime factors
// ---------------------------------------------------------------
template<class Domain, class Tag, class RandomIterator>
template< template<class, class> class Container, template <class> class Alloc >
inline void Poly1FactorDom<Domain,Tag, RandomIterator>::DistinctDegreeFactor(
Container< Rep, Alloc<Rep> > & L
, const Rep& f
, Residu_t MOD) const {
// write(std::cerr << "DD in: ", f) << std::endl;
Rep W, D, P = f;
Degree dP;
Rep Unit, G1;
this->init(Unit, Degree(1));
W.copy(Unit);
this->degree(dP,P); Degree dPo = (dP/2);
for(Degree dp = 1; dp <= dPo; ++dp) {
// std::cerr << "DD degree: " << dp << std::endl;
this->powmod(W, D.copy(W), MOD, P);
this->gcd (G1,this->sub(D,W,Unit), P) ;
Degree dG1; this->degree(dG1,G1);
// write(std::cerr << "DD found: ", G1) << ", of degree " << dG1 << std::endl;
if ( dG1 > 0 ) {
SplitFactor (L, G1, dp, MOD);
this->divin(P,G1);
}
}
this->degree(dP,P);
if (dP > 0)
L.push_back(P);
// write(std::cerr << "DD: ", P) << std::endl;
}
// ---------------------------------------------------------------
// Cantor-Zassenhaus Polynomial factorization over Z/pZ
// ---------------------------------------------------------------
template<class Domain, class Tag, class RandomIterator>
template< template<class, class> class Container, template <class> class Alloc>
inline void
Poly1FactorDom<Domain,Tag, RandomIterator>::CZfactor( Container< Rep, Alloc<Rep> > & Lf,
Container< uint64_t, Alloc<uint64_t> > & Le,
const Rep& P,
Residu_t MOD) const
{
// write(std::cerr << "CZ in: ", P) << std::endl;
Degree dp;
this->degree(dp,P);
size_t nb=(size_t)dp.value()+1;
Rep * g = new Rep[nb];
this->sqrfree(nb,g,P);
// std::cerr << "CZ sqrfree: " << nb << std::endl;
for(size_t i = 0; i<nb;++i) {
size_t this_multiplicity = Lf.size();
DistinctDegreeFactor(Lf, g[i], MOD) ;
Le.resize(Lf.size());
for( ; this_multiplicity < Lf.size(); ++this_multiplicity)
Le[this_multiplicity] = i+1;
// std::cerr << "multiplicities";
// for (typename Container< uint64_t, Alloc<uint64_t> >::const_iterator e=Le.begin(); e!=Le.end(); ++e)
// std::cerr << " " << *e;
// std::cerr << std::endl;
}
::delete [] g;
}
// ---------------------------------------------------------------
// Irreducibility tests
// ---------------------------------------------------------------
template<class Domain, class Tag, class RandomIterator>
inline bool Poly1FactorDom<Domain,Tag, RandomIterator>::is_irreducible( const Rep& P
, Residu_t MOD ) const
{
Rep W,D;
this->gcd(W,this->diff(D,P),P);
Degree d, dP;
if (this->degree(d,W) > 0) return 0;
// Distinct degree free ?
Rep Unit, G1;
this->init(Unit, Degree(1));
W.copy(Unit);
this->degree(dP,P); Degree dPo = (dP/2);
for(Degree dp = 1; dp <= dPo; ++dp) {
this->powmod(W, D.copy(W), MOD, P);
this->gcd (G1, this->sub(D,W,Unit), P) ;
if ( this->degree(d,G1) > 0 ) return 0;
}
return 1;
}
// ---------------------------------------------------------------
// Gives one non-trivial factor of P if P is reducible
// returns P otherwise
// ---------------------------------------------------------------
template<class Domain, class Tag, class RandomIterator>
inline typename Poly1FactorDom<Domain,Tag, RandomIterator>::Rep& Poly1FactorDom<Domain,Tag, RandomIterator>::factor(
Rep& W
, const Rep& P
, Residu_t MOD) const
{
// write(cerr << "In factor P:", P) << endl;
// Square free ?
Rep D; this->gcd(W,diff(D,P),P);
Degree d, dP;
// write(cerr << "In factor P':", D) << "(deg: " << degree(d,D) << ")" << endl;
// write(cerr << "In factor P^P':", W) << "(deg: " << degree(d,W) << ")" << endl;
if (this->degree(d,W) > 0) return W;
// Distinct degree free ?
Rep Unit, G1; init(Unit, Degree(1));
// write(cerr << "In factor U:", Unit) << endl;
W.copy(Unit);
this->degree(dP,P); Degree dPo = (dP/2);
for(Degree dp = 1; dp <= dPo; ++dp) {
// write(cerr << "In factor W:(deg: " << degree(d,W) << "):", W) << endl;
this->powmod(W, D.copy(W), MOD, P);
this->gcd (G1, sub(D,W,Unit), P) ;
Degree dG1; this->degree(dG1,G1);
if ( dG1 > 0 ) {
if (dG1 < dP)
return W.copy(G1);
else
return SplitFactor(W,G1,dp,MOD);
}
}
return W.copy(P);
}
} // Givaro
#endif // __GIVARO_poly1_facto_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
|