bridge/class-master/depend/pari/src/basemath/mftrace.c
/* Diagonalize and normalize. See mfsplit for meaning of flag. */
Diagonalize and normalize. See mfsplit for meaning of flag.
Diagonalize and normalize . See mfsplit for meaning of flag .
static GEN
mfspclean(GEN mf, GEN mf0, GEN NF, long ord, GEN simplesp, long flag)
{
  const long vz = 1;
  long i, l = lg(simplesp), dim = MF_get_dim(mf);
  GEN res = cgetg(l, t_MAT), pols = cgetg(l, t_VEC);
  GEN zeros = (mf == mf0)? NULL: zerocol(dim - MF_get_dim(mf0));
  for (i = 1; i < l; i++)
  {
    GEN ATP = gel(simplesp, i), A = gel(ATP,1), P = gel(ATP,3);
    long d = degpol(P);
    GEN a, v = (flag && d > flag)? NULL: gel(A,1);
    if (d == 1) P = pol_x(vz);
    else
    {
      pol_red(NF, &P, &a, !!v);
      if (v)
      { 
        GEN K, den, M = cgetg(d+1, t_MAT), T = gel(ATP,2);
        long j;
        T = shallowtrans(T);
        gel(M,1) = vec_ei(d,1); 
        for (j = 2; j <= d; j++) gel(M,j) = RgM_RgC_mul(T, gel(M,j-1));
        M = Q_primpart(M);
        K = NF? ZabM_inv(liftpol_shallow(M), nf_get_pol(NF), ord, &den)
              : ZM_inv(M,&den);
        K = shallowtrans(K);
        v = gequalX(a)? pol_x_powers(d, vz): RgXQ_powers(a, d-1, P);
        v = gmodulo(RgM_RgC_mul(A, RgM_RgC_mul(K,v)), P);
      }
    }
    if (v)
    {
      v = mf_normalize(mf0, v); if (zeros) v = shallowconcat(zeros,v);
      gel(res,i) = v; if (flag) setlg(res,i+1);
    }
    else
      gel(res,i) = zerocol(dim);
    gel(pols,i) = P;
  }
  return mkvec2(res, pols);
}
static GEN mfspclean ( GEN mf , GEN mf0 , GEN NF , long ord , GEN simplesp , long flag ) { const long vz = 1 ; long i , l = lg ( simplesp ) , dim = MF_get_dim ( mf ) ; GEN res = cgetg ( l , t_MAT ) , pols = cgetg ( l , t_VEC ) ; GEN zeros = ( mf == mf0 ) ? NULL : zerocol ( dim - MF_get_dim ( mf0 ) ) ; for ( i = 1 ; i < l ; i ++ ) { GEN ATP = gel ( simplesp , i ) , A = gel ( ATP , 1 ) , P = gel ( ATP , 3 ) ; long d = degpol ( P ) ; GEN a , v = ( flag && d > flag ) ? NULL : gel ( A , 1 ) ; if ( d == 1 ) P = pol_x ( vz ) ; else { pol_red ( NF , & P , & a , ! ! v ) ; if ( v ) { GEN K , den , M = cgetg ( d + 1 , t_MAT ) , T = gel ( ATP , 2 ) ; long j ; T = shallowtrans ( T ) ; gel ( M , 1 ) = vec_ei ( d , 1 ) ; for ( j = 2 ; j <= d ; j ++ ) gel ( M , j ) = RgM_RgC_mul ( T , gel ( M , j - 1 ) ) ; M = Q_primpart ( M ) ; K = NF ? ZabM_inv ( liftpol_shallow ( M ) , nf_get_pol ( NF ) , ord , & den ) : ZM_inv ( M , & den ) ; K = shallowtrans ( K ) ; v = gequalX ( a ) ? pol_x_powers ( d , vz ) : RgXQ_powers ( a , d - 1 , P ) ; v = gmodulo ( RgM_RgC_mul ( A , RgM_RgC_mul ( K , v ) ) , P ) ; } } if ( v ) { v = mf_normalize ( mf0 , v ) ; if ( zeros ) v = shallowconcat ( zeros , v ) ; gel ( res , i ) = v ; if ( flag ) setlg ( res , i + 1 ) ; } else gel ( res , i ) = zerocol ( dim ) ; gel ( pols , i ) = P ; } return mkvec2 ( res , pols ) ; }
Diagonalize and normalize.
Diagonalize and normalize .
/* Mod(a,P) root of charpoly(T), K*gpowers(a) = eigenvector of T */ /* basis of cyclic vectors */