Exemplo n.º 1
0
NTL_START_IMPL

static
void HessCharPoly(zz_pX& g, const zz_pX& a, const zz_pX& f)
{
   long n = deg(f);
   if (n <= 0 || deg(a) >= n)
      Error("HessCharPoly: bad args");

   mat_zz_p M;
   M.SetDims(n, n);

   long i, j;

   zz_pX t;
   t = a;

   for (i = 0; i < n; i++) {
      for (j = 0; j < n; j++) 
         M[i][j] = coeff(t, j);

      if (i < n-1) 
         MulByXMod(t, t, f);
   }

   CharPoly(g, M);
}
Exemplo n.º 2
0
NTL_CLIENT

int main()
{
   mat_ZZ B, X;
   vec_ZZ v, w;

   cin >> B;
   cin >> v;

   ZZ d;

   double t;
   cerr << "matrix inverse...";
   t = GetTime();
   inv(d, X, B);
   cerr << (GetTime()-t) << "\n";

   cout << d << "\n";
   cout << X << "\n";

   cout << "\n\n\n";

   cerr << "hensel solve...";
   t = GetTime();
   HenselSolve1(d, w, B, v);
   cerr << (GetTime()-t) << "\n";

   cout << d << "\n";
   cout << w << "\n";

   cout << "\n\n\n";

   ZZX f;

   cerr << "char poly...";
   t = GetTime();
   CharPoly(f, B);
   cerr << (GetTime()-t) << "\n";

   cout << f << "\n";

   cout << "\n\n\n";

   cerr << "HNF...";
   t = GetTime();
   HNF(X, B, d);
   cerr << (GetTime()-t) << "\n";

   cout << X;

   return 0;
}
Exemplo n.º 3
0
static CYTHON_INLINE struct ZZX* mat_ZZ_charpoly(const mat_ZZ* A)
{
    ZZX* f = new ZZX();
    CharPoly(*f, *A);
    return f;
}
void CharPoly(ZZX& gg, const mat_ZZ& a, long deterministic)
{
   long n = a.NumRows();
   if (a.NumCols() != n)
      LogicError("CharPoly: nonsquare matrix");

   if (n == 0) {
      set(gg);
      return;
   }


   if (n == 1) {
      ZZ t;
      SetX(gg);
      negate(t, a(1, 1));
      SetCoeff(gg, 0, t);
      return;
   }

   long bound = 2 + CharPolyBound(a);

   zz_pBak bak;
   bak.save();

   ZZ_pBak bak1;
   bak1.save();

   ZZX g;
   ZZ prod;

   clear(g);
   set(prod);

   long i;

   long instable = 1;

   long gp_cnt = 0;

   for (i = 0; ; i++) {
      if (NumBits(prod) > bound)
         break;

      if (!deterministic &&
          !instable && bound > 1000 && NumBits(prod) < 0.25*bound) {
         long plen = 90 + NumBits(max(bound, MaxBits(g)));

         ZZ P;

         GenPrime(P, plen, 90 + 2*NumBits(gp_cnt++));

         ZZ_p::init(P);
         mat_ZZ_p A;
         ZZ_pX G;
         conv(A, a);
         CharPoly(G, A);

         if (CRT(g, prod, G))
            instable = 1;
         else
            break;
      }

      zz_p::FFTInit(i);

      mat_zz_p A;
      zz_pX G;
      conv(A, a);
      CharPoly(G, A);
      instable = CRT(g, prod, G);
   }

   gg = g;

   bak.restore();
   bak1.restore();
}