Skip to content

Commit 7277fb2

Browse files
committed
modify sequence container for wiedemann minpoly to ensure that generatedsequence is never the zero sequence, add proper test for charpoly
1 parent 9eb98c9 commit 7277fb2

File tree

6 files changed

+69
-17
lines changed

6 files changed

+69
-17
lines changed

linbox/algorithms/bbcharpoly.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ namespace LinBox
285285

286286
/* Computation of the minimal polynomial */
287287
Polynomial minPoly(F);
288-
minpoly (minPoly, A, M);
289-
// PD.write(std::cerr<<"Minpoly = ",minPoly) << std::endl;
288+
minpoly (minPoly, A, M);
289+
//PD.write(std::cerr<<"Minpoly = ",minPoly) << std::endl;
290290

291291
if (minPoly.size() == n+1){
292292
commentator().stop ("done", NULL, "MbbCharpoly");

linbox/algorithms/blackbox-container-base.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,20 @@ namespace LinBox
157157
{
158158
casenumber = 1;
159159
u.resize (_BB->coldim ());
160-
for (long i = (long)u.size (); i--;)
161-
g.random (u[(size_t)i]);
162-
v.resize (_BB->rowdim ());
163-
return _VD.dot (_value, u, u);
164-
}
160+
v.resize (_BB->rowdim ());
161+
162+
size_t trials=0;
163+
do {
164+
for (long i = (long)this->u.size (); i--;)
165+
g.random (this->u[(size_t)i]);
166+
this->_VD.dot (this->_value, this->u, this->u);
167+
} while(_field->isZero(this->_value) && ++trials<= LINBOX_DEFAULT_TRIALS_BEFORE_FAILURE);
168+
169+
if (trials >= LINBOX_DEFAULT_TRIALS_BEFORE_FAILURE)
170+
std::cerr<<"ERROR in "<<__FILE__<<" at line "<<__LINE__<<" -> projection always auto-orthogonal after "<<LINBOX_DEFAULT_TRIALS_BEFORE_FAILURE<<" attempts\n";;
171+
172+
return _value;
173+
}
165174

166175
/// User Left vectors, Zero Right vector
167176
template<class Vector>

linbox/algorithms/blackbox-container.h

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,23 @@ namespace LinBox
8787
{
8888
this->casenumber = 1;
8989
this->u.resize (this->_BB->coldim ());
90-
for (long i = (long)this->u.size (); i--;)
91-
g.random (this->u[(size_t)i]);
92-
this->w.resize (this->_BB->coldim ());
93-
for (long i = (long)this->w.size (); i--;)
94-
g.random (this->w[(size_t)i]);
95-
this->v.resize (this->_BB->rowdim ());
96-
this->_VD.dot (this->_value, this->u, this->w);
90+
this->w.resize (this->_BB->coldim ());
91+
this->v.resize (this->_BB->rowdim ());
92+
93+
size_t trials=0;
94+
do {
95+
for (long i = (long)this->u.size (); i--;)
96+
g.random (this->u[(size_t)i]);
97+
98+
for (long i = (long)this->w.size (); i--;)
99+
g.random (this->w[(size_t)i]);
100+
101+
this->_VD.dot (this->_value, this->u, this->w);
102+
} while(F.isZero(this->_value) && ++trials<= LINBOX_DEFAULT_TRIALS_BEFORE_FAILURE);
103+
104+
if (trials >= LINBOX_DEFAULT_TRIALS_BEFORE_FAILURE)
105+
std::cerr<<"ERROR in "<<__FILE__<<" at line "<<__LINE__<<" -> projection always orthogonal after "<<LINBOX_DEFAULT_TRIALS_BEFORE_FAILURE<<" attempts\n";;
106+
97107
#ifdef INCLUDE_TIMING
98108
_applyTime = _dotTime = 0.0;
99109
#endif

linbox/algorithms/massey-domain.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ namespace LinBox
348348

349349
commentator().stop ("done", NULL, "masseyd");
350350
// commentator().stop ("Done", "Done", "LinBox::MasseyDomain::massey");
351-
351+
std::cerr<<"SEQ: "<<S<<std::endl;
352352
return L;
353353
}
354354

@@ -398,7 +398,8 @@ namespace LinBox
398398
{
399399
long dp = massey (phi, full_poly);
400400
rank = (size_t) (v_degree(phi) - v_val (phi));
401-
401+
//std::cerr<<"dp="<<dp<<" rank="<<rank<<" -> "<<phi.size()<<" : "<<phi<<std::endl;
402+
402403
if (dp==0){// empty sequence, its minpoly is 1
403404
phi.resize(1);
404405
field().assign(phi[0],field().one);

linbox/algorithms/wiedemann.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ namespace LinBox
129129
<< "Time required for LSR fix: " << WD.fixTime () << std::endl;
130130
#endif // INCLUDE_TIMING
131131
}
132-
132+
133133
commentator().stop ("done", NULL, "minpoly");
134134

135135
return P;

tests/test-regression.C

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,37 @@ bool testZeroMatrixCharPoly() {
600600

601601
return success;
602602
}
603+
bool testZeroSymmetricMatrixCharPoly() {
604+
bool success;
605+
using Ring = Givaro::Modular<double>;
606+
using Matrix = SparseMatrix<Ring>;
607+
Ring R(3);
608+
609+
Matrix A(R, 1, 1);
610+
A.setEntry(0, 0, R.zero);
611+
612+
PolynomialRing<Ring>::Element c_A, Ex;
613+
614+
615+
charpoly(c_A, A, RingCategories::ModularTag(), Method::Blackbox(Shape::Symmetric));
616+
617+
PolynomialRing<Ring> PZ(R,'X'); PZ.assign(Ex, Givaro::Degree(1), R.one);
618+
619+
success = PZ.areEqual(c_A, Ex);
620+
621+
if (!success) {
622+
if (writing) {
623+
std::clog<<"**** ERROR **** Fail ZSMCP " <<std::endl;
624+
625+
PZ.write(std::clog << "Ex: ", Ex) << std::endl;
626+
PZ.write(std::clog << "cA: ", c_A) << std::endl;
627+
}
628+
return false;
629+
} else
630+
if (writing) std::cout << "ZSMCP: PASSED" << std::endl;
631+
632+
return success;
633+
}
603634

604635
bool testFourFourMatrix() {
605636
bool success;
@@ -676,6 +707,7 @@ int main (int argc, char **argv)
676707
pass &= testZeroDimensionalCharPoly ();
677708
pass &= testZeroDimensionalMinPoly ();
678709
pass &= testZeroMatrixCharPoly();
710+
pass &= testZeroSymmetricMatrixCharPoly();
679711
pass &= testBigScalarCharPoly ();
680712
pass &= testLocalSmith ();
681713
pass &= testInconsistent<DenseMatrix<ZRingInts>> (Method::DenseElimination());

0 commit comments

Comments
 (0)