/usr/include/linbox/algorithms/one-invariant-factor.h is in liblinbox-dev 1.3.2-1.1build2.
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 | /* Copyright (C) LinBox
*
* Author: Zhendong Wan
*
*
* ========LICENCE========
* This file is part of the library LinBox.
*
* LinBox is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* ========LICENCE========
*/
#ifndef __LINBOX_ith_invariant_factor_H
#define __LINBOX_ith_invariant_factor_H
#include "linbox/util/debug.h"
#include "linbox/algorithms/default.h"
#include "linbox/blackbox/compose.h"
#include "linbox/blackbox/random-matrix-traits.h"
namespace LinBox
{
/// \brief Limited doc so far.
template<class _Ring,
class _LastInvariantFactor,
class _Compose,
class _RandomMatrix>
class OneInvariantFactor {
public:
typedef _LastInvariantFactor LastInvariantFactor;
typedef _Ring Ring;
typedef _Compose Compose;
typedef _RandomMatrix RandomMatrix;
typedef typename Ring::Element Integer;
protected:
Ring r;
LastInvariantFactor lif;
Compose compose;
RandomMatrix randomMatrix;
int threshold;
double crossover;
public:
OneInvariantFactor(const Ring& _r = Ring(),
const LastInvariantFactor& _lif =LastInvariantFactor(),
const Compose& _compose =Compose(),
const RandomMatrix& _randomMatrix = RandomMatrix(),
int _threshold =DEFAULTOIFTHRESHOLD) :
r(_r), lif(_lif), compose(_compose), randomMatrix(_randomMatrix),
threshold(_threshold), crossover(CROSSOVER)
{
if (_threshold <= 0) threshold = DEFAULTOIFTHRESHOLD;
}
void setThreshold (int _threshold)
{
if (_threshold > 0) {
threshold = _threshold;
}
}
int getThreshold () const
{
return threshold;
}
void setCrossover(double t)
{
if(0 <= t <= 1)
crossover = t;
}
double getCrossover() const
{
return crossover;
}
LastInvariantFactor& getLastInvariantFactor ()
{
return lif;
}
const LastInvariantFactor& getLastInvariantFactor () const
{
return lif;
}
/** \brief Compute the i-th invariant factor of A,
* ignoring those factors of prime in PrimeL list.
* It implements EGV++ (by bds), the adaptive algorithm of EGV and EGV+.
*/
template<class IMatrix, class Vector>
Integer& oneInvariantFactor(Integer& oif, const IMatrix& A,
int i, Vector& PrimeL) const
{
// some check
linbox_check(0 < i);
linbox_check((unsigned int)i <= A.rowdim());
linbox_check((unsigned int)i <= A.coldim());
// if oif is the last invariant factor of A
if ( ((unsigned int)i == A.rowdim()) && (A.rowdim() == A.coldim())) {
lif.lastInvariantFactor(oif, A, PrimeL);
return oif;
}
r.init (oif, 0);
int count;
Integer prev, tmp_i;
//typename RandomMatrixTraits<IMatrix>::value_type *L, *U;
typename RandomMatrixTraits<IMatrix>::value_type *R, *L;
typename ComposeTraits<IMatrix>::value_type* LAR;//*AUV;
// repeat threshold times
for (count =0; count < threshold; ++ count) {
r.assign (prev, oif);
/*
// Use A + UV
if ((A.rowdim() == A.coldim()) && (i > crossover * A.rowdim())) {
randomMatrix.randomMatrix(U, r, A.rowdim(), A.coldim() - i);
randomMatrix.randomMatrix(V, r, A.rowdim() - i, A.coldim());
compose.composeBig(AUV, A, *U, *V);
// compute the last invariant factor of RAL
lif.lastInvariantFactor(tmp_i, *AUV, PrimeL);
// free memory.
delete U;
delete V;
delete AUV;
}
else {
}
*/
// Always use LAR please refer ISSAC'04 paper by BDS and ZW
randomMatrix.randomMatrix(L, r, i, (int)A.rowdim());
randomMatrix.randomMatrix(R, r, (int)A.coldim(), i);
compose.compose(LAR, *L, A, *R);
lif.lastInvariantFactor(tmp_i, *LAR, PrimeL);
//free memory
delete L;
delete R;
delete LAR;
r.gcd(oif, tmp_i, prev);
// if oif reaches one
if ( r.isOne(oif) ) break;
}
return oif;
}
/** \brief Compute the i-th invariant factor of A.
* It implements the adaptive algorithm of EGV and EGV+.
*/
template<class IMatrix>
Integer& oneInvariantFactor(Integer& oif, const IMatrix& A, int i) const
{
std::vector<Integer> empty_v;
oneInvariantFactor (oif, A, i, empty_v);
return oif;
}
/** \brief Compute the i-th invariant factor of A with bonus,
* ignoring those factors of prime in PrimeL list.
* It implements EGV++ (by bds), the adaptive algorithm of EGV and EGV+.
*/
template<class IMatrix, class Vector>
Integer& oneInvariantFactor_Bonus(Integer& oif, Integer& bonus, const IMatrix& A,
int i, Vector& PrimeL) const
{
// some check
linbox_check(0 < i);
linbox_check((unsigned int)i <= A.rowdim());
linbox_check((unsigned int)i <= A.coldim());
// if oif is the last invariant factor of A
if ( ((unsigned int)i == A.rowdim()) && (A.rowdim() == A.coldim())) {
lif.lastInvariantFactor_Bonus(oif, bonus, A, PrimeL);
return oif;
}
r.init (oif, 0); r. init (bonus, 0);
int count;
Integer prev, tmp_i, p_bonus;
//typename RandomMatrixTraits<IMatrix>::value_type *L, *U;
typename RandomMatrixTraits<IMatrix>::value_type *R, *L;
typename ComposeTraits<IMatrix>::value_type* LAR;//*AUV;
// repeat threshold times
for (count =0; count < threshold; ++ count) {
r.assign (prev, oif); r. assign (p_bonus, bonus);
// Always use LAR please refer ISSAC'04 papre by BDS and ZW
randomMatrix.randomMatrix(L, r, i, (int)A.rowdim());
randomMatrix.randomMatrix(R, r, (int)A.coldim(), i);
compose.compose(LAR, *L, A, *R);
lif.lastInvariantFactor_Bonus(tmp_i, bonus, *LAR, PrimeL);
//free memory
delete L;
delete R;
delete LAR;
r. gcd(oif, tmp_i, prev);
r. gcdin (bonus, p_bonus);
// if oif reaches one
if ( r.isOne(oif) ) break;
}
return oif;
}
/** \brief Compute the i-th invariant factor of A.
* It implements the adaptive algorithm of EGV and EGV+.
*/
template<class IMatrix>
Integer& oneInvariantFactor_Bonus(Integer& oif, Integer& bonus, const IMatrix& A, int i) const
{
std::vector<Integer> empty_v;
oneInvariantFactor_Bonus (oif, bonus, A, i, empty_v);
return oif;
}
};
}
#endif //__LINBOX_ith_invariant_factor_H
// vim:sts=8:sw=8:ts=8:noet:sr:cino=>s,f0,{0,g0,(0,:0,t0,+0,=s
// Local Variables:
// mode: C++
// tab-width: 8
// indent-tabs-mode: nil
// c-basic-offset: 8
// End:
|