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
|
#include <linbox/linbox-config.h>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <linbox/util/timer.h>
#include <linbox/ring/modular.h>
#include <linbox/ring/pir-modular-int32.h>
#include <linbox/ring/givaro-poly.h>
#include <linbox/ring/givaro-poly-local.h>
#include <linbox/ring/givaro-poly-quotient.h>
#include <linbox/randiter/givaro-poly.h>
using namespace LinBox;
using namespace std;
typedef Givaro::Modular<double> Field;
typedef typename Field::Element Element;
typedef Givaro::Poly1Dom<Field,Givaro::Dense> PolyDom;
typedef GivaroPoly<Field> PolyRing;
typedef GivaroPolyQuotient<PolyDom> QuotRing;
typedef typename QuotRing::Element QElm;
typedef GivaroPolyLocal<PolyDom> LocalRing;
typedef typename LocalRing::Element LElm;
typedef GivaroPolyRandIter<PolyRing> PolyRandIter;
typedef typename PolyRing::Element PolyElement;
bool testMul(QuotRing QR, LocalRing LR, QElm qa, QElm qb, LElm la, LElm lb) {
QElm qc;
QR.mul(qc, qa, qb);
LElm lc;
LR.mul(lc, la, lb);
if (LR.areEqual(lc, qc)) {
return true;
}
QR.write(cout << "(", qa) << ") * (";
QR.write(cout, qb) << ") = ";
QR.write(cout, qc) << endl;
LR.write(cout << "(", la) << ") * (";
LR.write(cout, lb) << ") = ";
LR.write(cout, lc) << endl << endl;
LR.write2(cout, la) << endl;
LR.write2(cout, lb) << endl;
return false;
}
bool testAdd(QuotRing QR, LocalRing LR, QElm qa, QElm qb, LElm la, LElm lb) {
QElm qc;
QR.add(qc, qa, qb);
LElm lc;
LR.add(lc, la, lb);
if (LR.areEqual(lc, qc)) {
return true;
}
QR.write(cout << "(", qa) << ") + (";
QR.write(cout, qb) << ") = ";
QR.write(cout, qc) << endl;
LR.write(cout << "(", la) << ") + (";
LR.write(cout, lb) << ") = ";
LR.write(cout, lc) << endl << endl;
LR.write2(cout, la) << endl;
LR.write2(cout, lb) << endl;
return false;
}
bool testAxpy(
QuotRing QR, LocalRing LR,
QElm qa, QElm qb, QElm qc,
LElm la, LElm lb, LElm lc
) {
QElm qd;
QR.axpy(qd, qa, qb, qc);
LElm ld;
LR.axpy(ld, la, lb, lc);
if (LR.areEqual(ld, qd)) {
return true;
}
QR.write(cout << "(", qa) << ") * (";
QR.write(cout, qb) << ") + (";
QR.write(cout, qc) << ") = ";
QR.write(cout, qd) << endl;
LR.write(cout << "(", la) << ") * (";
LR.write(cout, lb) << ") + (";
LR.write(cout, lc) << ") = ";
LR.write(cout, ld) << endl;
LR.write2(cout, la) << endl;
LR.write2(cout, lb) << endl;
LR.write2(cout, lc) << endl;
return false;
}
int main(int argc, char* argv[]) {
size_t p = 3;
size_t e = 3;
Field F(p);
PolyRing R(F, "x");
PolyRandIter PRI(R, 0, 10);
PolyElement g, f;
R.init(g, {2, 1, 1});
R.write(cout << "irred: ", g) << endl;
R.pow(f, g, e);
R.write(cout << "quotient: ", f) << endl;
integer max;
R.convert(max, f);
QuotRing QR(R, f);
LocalRing LR(R, g, e);
QElm qa, qb, qc;
LElm la, lb, lc;
for (integer i = 1; i <= max; i++) {
QR.init(qa, i);
LR.init(la, i);
for (integer j = 1; j <= max; j++) {
cout << i << ", " << j << ":" << endl;
QR.init(qb, j);
LR.init(lb, j);
//if (!QR.isDivisor(qa, qb)) {
// continue;
//}
if (!testMul(QR, LR, qa, qb, la, lb)) {
return 0;
}
if (!testAdd(QR, LR, qa, qb, la, lb)) {
return 0;
}
for (integer k = 1; k <= max; k++) {
QR.init(qc, k);
LR.init(lc, k);
if (!testAxpy(QR, LR, qa, qb, qc, la, lb, lc)) {
return 0;
}
}
}
}
}
// Local Variables:
// mode: C++
// tab-width: 4
// indent-tabs-mode: nil
// c-basic-offset: 4
// End:
// vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s
|