Code coverage tests

This page documents the degree to which the PARI/GP source code is tested by our public test suite, distributed with the source distribution in directory src/test/. This is measured by the gcov utility; we then process gcov output using the lcov frond-end.

We test a few variants depending on Configure flags on the pari.math.u-bordeaux.fr machine (x86_64 architecture), and agregate them in the final report:

The target is to exceed 90% coverage for all mathematical modules (given that branches depending on DEBUGLEVEL or DEBUGMEM are not covered). This script is run to produce the results below.

LCOV - code coverage report
Current view: top level - basemath - kummer.c (source / functions) Hit Total Coverage
Test: PARI/GP v2.12.0 lcov report (development 23010-740a36cf0) Lines: 741 857 86.5 %
Date: 2018-09-21 05:37:29 Functions: 54 59 91.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* Copyright (C) 2000  The PARI group.
       2             : 
       3             : This file is part of the PARI/GP package.
       4             : 
       5             : PARI/GP is free software; you can redistribute it and/or modify it under the
       6             : terms of the GNU General Public License as published by the Free Software
       7             : Foundation. It is distributed in the hope that it will be useful, but WITHOUT
       8             : ANY WARRANTY WHATSOEVER.
       9             : 
      10             : Check the License for details. You should have received a copy of it, along
      11             : with the package; see the file 'COPYING'. If not, write to the Free Software
      12             : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
      13             : 
      14             : /*******************************************************************/
      15             : /*                                                                 */
      16             : /*                      KUMMER EXTENSIONS                          */
      17             : /*                                                                 */
      18             : /*******************************************************************/
      19             : #include "pari.h"
      20             : #include "paripriv.h"
      21             : 
      22             : typedef struct {
      23             :   GEN R; /* nf.pol */
      24             :   GEN x; /* tau ( Mod(x, R) ) */
      25             :   GEN zk;/* action of tau on nf.zk (as t_MAT) */
      26             : } tau_s;
      27             : 
      28             : typedef struct {
      29             :   GEN polnf, invexpoteta1, powg;
      30             :   tau_s *tau;
      31             :   long m;
      32             : } toK_s;
      33             : 
      34             : typedef struct {
      35             :   GEN R; /* ZX, compositum(P,Q) */
      36             :   GEN p; /* QX, Mod(p,R) root of P */
      37             :   GEN q; /* QX, Mod(q,R) root of Q */
      38             :   long k; /* Q[X]/R generated by q + k p */
      39             :   GEN rev;
      40             : } compo_s;
      41             : 
      42             : static long
      43        1225 : prank(GEN cyc, long ell)
      44             : {
      45             :   long i;
      46        3311 :   for (i=1; i<lg(cyc); i++)
      47        2408 :     if (smodis(gel(cyc,i),ell)) break;
      48        1225 :   return i-1;
      49             : }
      50             : 
      51             : /* increment y, which runs through [0,d-1]^(k-1). Return 0 when done. */
      52             : static int
      53         140 : increment(GEN y, long k, long d)
      54             : {
      55         140 :   long i = k, j;
      56             :   do
      57             :   {
      58         161 :     if (--i == 0) return 0;
      59         133 :     y[i]++;
      60         133 :   } while (y[i] >= d);
      61         112 :   for (j = i+1; j < k; j++) y[j] = 0;
      62         112 :   return 1;
      63             : }
      64             : 
      65             : static int
      66         609 : ok_congruence(GEN X, ulong ell, long lW, GEN vecMsup)
      67             : {
      68             :   long i, l;
      69         609 :   if (zv_equal0(X)) return 0;
      70         609 :   l = lg(X);
      71        1064 :   for (i=lW; i<l; i++)
      72         483 :     if (X[i] == 0) return 0;
      73         581 :   l = lg(vecMsup);
      74         868 :   for (i=1; i<l; i++)
      75         287 :     if (zv_equal0(Flm_Flc_mul(gel(vecMsup,i),X, ell))) return 0;
      76         581 :   return 1;
      77             : }
      78             : 
      79             : static int
      80         329 : ok_sign(GEN X, GEN msign, GEN arch)
      81             : {
      82         329 :   return zv_equal(Flm_Flc_mul(msign, X, 2), arch);
      83             : }
      84             : 
      85             : /* REDUCTION MOD ell-TH POWERS */
      86             : 
      87             : #if 0
      88             : static GEN
      89             : logarch2arch(GEN x, long r1, long prec)
      90             : {
      91             :   long i, lx;
      92             :   GEN y = cgetg_copy(x, &lx);
      93             :   if (typ(x) == t_MAT)
      94             :   {
      95             :     for (i=1; i<lx; i++) gel(y,i) = logarch2arch(gel(x,i), r1, prec);
      96             :   }
      97             :   else
      98             :   {
      99             :     for (i=1; i<=r1;i++) gel(y,i) = gexp(gel(x,i),prec);
     100             :     for (   ; i<lx; i++) gel(y,i) = gexp(gmul2n(gel(x,i),-1),prec);
     101             :   }
     102             :   return y;
     103             : }
     104             : #endif
     105             : 
     106             : /* make be integral by multiplying by t in (Q^*)^ell */
     107             : static GEN
     108         504 : reduce_mod_Qell(GEN bnfz, GEN be, GEN gell)
     109             : {
     110             :   GEN c;
     111         504 :   be = nf_to_scalar_or_basis(bnfz, be);
     112         504 :   be = Q_primitive_part(be, &c);
     113         504 :   if (c)
     114             :   {
     115         308 :     GEN d, fa = factor(c);
     116         308 :     gel(fa,2) = FpC_red(gel(fa,2), gell);
     117         308 :     d = factorback(fa);
     118         308 :     be = typ(be) == t_INT? mulii(be,d): ZC_Z_mul(be, d);
     119             :   }
     120         504 :   return be;
     121             : }
     122             : 
     123             : /* return q, q^n r = x, v_pr(r) < n for all pr. Insist q is a genuine n-th
     124             :  * root (i.e r = 1) if strict != 0. */
     125             : static GEN
     126        1330 : idealsqrtn(GEN nf, GEN x, GEN gn, int strict)
     127             : {
     128        1330 :   long i, l, n = itos(gn);
     129             :   GEN fa, q, Ex, Pr;
     130             : 
     131        1330 :   fa = idealfactor(nf, x);
     132        1330 :   Pr = gel(fa,1); l = lg(Pr);
     133        1330 :   Ex = gel(fa,2); q = NULL;
     134        3535 :   for (i=1; i<l; i++)
     135             :   {
     136        2205 :     long ex = itos(gel(Ex,i));
     137        2205 :     GEN e = stoi(ex / n);
     138        2205 :     if (strict && ex % n) pari_err_SQRTN("idealsqrtn", fa);
     139        2205 :     if (q) q = idealmulpowprime(nf, q, gel(Pr,i), e);
     140         539 :     else   q = idealpow(nf, gel(Pr,i), e);
     141             :   }
     142        1330 :   return q? q: gen_1;
     143             : }
     144             : 
     145             : static GEN
     146         504 : reducebeta(GEN bnfz, GEN b, GEN ell)
     147             : {
     148         504 :   GEN y, cb, nf = bnf_get_nf(bnfz);
     149             : 
     150         504 :   if (DEBUGLEVEL>1) err_printf("reducing beta = %Ps\n",b);
     151         504 :   b = reduce_mod_Qell(nf, b, ell);
     152             :   /* reduce l-th root */
     153         504 :   y = idealsqrtn(nf, b, ell, 0); /* (b) = y^ell I, I integral */
     154         504 :   if (typ(y) == t_MAT && !is_pm1(gcoeff(y,1,1)))
     155             :   {
     156         168 :     GEN T = idealred(nf, mkvec2(y, gen_1)), t = gel(T,2);
     157             :     /* (t)*T[1] = y, T[1] integral and small */
     158         168 :     if (gcmp(idealnorm(nf,t), gen_1) > 0)
     159         154 :       b = nfmul(nf, b, nfpow(nf, t, negi(ell)));
     160             :   }
     161         504 :   if (DEBUGLEVEL>1) err_printf("beta reduced via ell-th root = %Ps\n",b);
     162         504 :   b = Q_primitive_part(b, &cb);
     163         504 :   if (cb)
     164             :   {
     165         231 :     y = nfroots(nf, gsub(monomial(gen_1, itou(ell), fetch_var_higher()),
     166             :                          basistoalg(nf,b)));
     167         231 :     delete_var();
     168             :   }
     169         504 :   if (cb && lg(y) != 1) b = gen_1;
     170             :   else
     171             :   { /* log. embeddings of fu^ell */
     172         483 :     GEN fu = bnf_get_fu_nocheck(bnfz), logfu = bnf_get_logfu(bnfz);
     173         483 :     GEN elllogfu = RgM_Rg_mul(real_i(logfu), ell);
     174         483 :     long prec = nf_get_prec(nf);
     175             :     for (;;)
     176          21 :     {
     177         504 :       GEN emb, z = get_arch_real(nf, b, &emb, prec);
     178         504 :       if (z)
     179             :       {
     180         483 :         GEN ex = RgM_Babai(elllogfu, z);
     181         483 :         if (ex)
     182             :         {
     183         483 :           y = nffactorback(nf, fu, RgC_Rg_mul(ex,ell));
     184         966 :           b = nfdiv(nf, b, y); break;
     185             :         }
     186             :       }
     187          21 :       prec = precdbl(prec);
     188          21 :       if (DEBUGLEVEL) pari_warn(warnprec,"reducebeta",prec);
     189          21 :       nf = nfnewprec_shallow(nf,prec);
     190             :     }
     191             :   }
     192         504 :   if (cb) b = gmul(b, cb);
     193         504 :   if (DEBUGLEVEL>1) err_printf("beta LLL-reduced mod U^l = %Ps\n",b);
     194         504 :   return b;
     195             : }
     196             : 
     197             : /* FIXME: remove */
     198             : static GEN
     199         455 : tauofalg(GEN x, tau_s *tau) {
     200         455 :   long tx = typ(x);
     201         455 :   if (tx == t_POLMOD) { x = gel(x,2); tx = typ(x); }
     202         455 :   if (tx == t_POL) x = RgX_RgXQ_eval(x, tau->x, tau->R);
     203         455 :   return mkpolmod(x, tau->R);
     204             : }
     205             : 
     206             : /* compute Gal(K(\zeta_l)/K) */
     207             : static void
     208         231 : get_tau(tau_s *tau, GEN nf, compo_s *C, ulong g)
     209             : {
     210             :   GEN U;
     211             : 
     212             :   /* compute action of tau: q^g + kp */
     213         231 :   U = RgX_add(RgXQ_powu(C->q, g, C->R), RgX_muls(C->p, C->k));
     214         231 :   U = RgX_RgXQ_eval(C->rev, U, C->R);
     215             : 
     216         231 :   tau->x  = U;
     217         231 :   tau->R  = C->R;
     218         231 :   tau->zk = nfgaloismatrix(nf, U);
     219         231 : }
     220             : 
     221             : static GEN tauoffamat(GEN x, tau_s *tau);
     222             : 
     223             : static GEN
     224        9898 : tauofelt(GEN x, tau_s *tau)
     225             : {
     226        9898 :   switch(typ(x))
     227             :   {
     228        8281 :     case t_COL: return RgM_RgC_mul(tau->zk, x);
     229        1162 :     case t_MAT: return tauoffamat(x, tau);
     230         455 :     default: return tauofalg(x, tau);
     231             :   }
     232             : }
     233             : static GEN
     234        1330 : tauofvec(GEN x, tau_s *tau)
     235             : {
     236             :   long i, l;
     237        1330 :   GEN y = cgetg_copy(x, &l);
     238        1330 :   for (i=1; i<l; i++) gel(y,i) = tauofelt(gel(x,i), tau);
     239        1330 :   return y;
     240             : }
     241             : /* [x, tau(x), ..., tau^(m-1)(x)] */
     242             : static GEN
     243         630 : powtau(GEN x, long m, tau_s *tau)
     244             : {
     245         630 :   GEN y = cgetg(m+1, t_VEC);
     246             :   long i;
     247         630 :   gel(y,1) = x;
     248         630 :   for (i=2; i<=m; i++) gel(y,i) = tauofelt(gel(y,i-1), tau);
     249         630 :   return y;
     250             : }
     251             : /* x^lambda */
     252             : static GEN
     253         539 : lambdaofelt(GEN x, toK_s *T)
     254             : {
     255         539 :   tau_s *tau = T->tau;
     256         539 :   long i, m = T->m;
     257         539 :   GEN y = trivial_fact(), powg = T->powg; /* powg[i] = g^i */
     258        1372 :   for (i=1; i<m; i++)
     259             :   {
     260         833 :     y = famat_mulpows_shallow(y, x, uel(powg,m-i+1));
     261         833 :     x = tauofelt(x, tau);
     262             :   }
     263         539 :   return famat_mul_shallow(y, x);
     264             : }
     265             : static GEN
     266         448 : lambdaofvec(GEN x, toK_s *T)
     267             : {
     268             :   long i, l;
     269         448 :   GEN y = cgetg_copy(x, &l);
     270         448 :   for (i=1; i<l; i++) gel(y,i) = lambdaofelt(gel(x,i), T);
     271         448 :   return y;
     272             : }
     273             : 
     274             : static GEN
     275        1162 : tauoffamat(GEN x, tau_s *tau)
     276             : {
     277        1162 :   return mkmat2(tauofvec(gel(x,1), tau), gel(x,2));
     278             : }
     279             : 
     280             : static GEN
     281         140 : tauofideal(GEN id, tau_s *tau)
     282             : {
     283         140 :   return ZM_hnfmodid(RgM_mul(tau->zk, id), gcoeff(id, 1,1));
     284             : }
     285             : 
     286             : static int
     287         644 : isprimeidealconj(GEN P, GEN Q, tau_s *tau)
     288             : {
     289         644 :   GEN p = pr_get_p(P);
     290         644 :   GEN x = pr_get_gen(P);
     291         644 :   if (!equalii(p, pr_get_p(Q))
     292         490 :    || pr_get_e(P) != pr_get_e(Q)
     293         490 :    || pr_get_f(P) != pr_get_f(Q)) return 0;
     294         483 :   if (ZV_equal(x, pr_get_gen(Q))) return 1;
     295             :   for(;;)
     296             :   {
     297        2107 :     if (ZC_prdvd(x,Q)) return 1;
     298         980 :     x = FpC_red(tauofelt(x, tau), p);
     299         980 :     if (ZC_prdvd(x,P)) return 0;
     300             :   }
     301             : }
     302             : 
     303             : static int
     304        1232 : isconjinprimelist(GEN S, GEN pr, tau_s *tau)
     305             : {
     306             :   long i, l;
     307             : 
     308        1232 :   if (!tau) return 0;
     309         756 :   l = lg(S);
     310        1085 :   for (i=1; i<l; i++)
     311         644 :     if (isprimeidealconj(gel(S,i),pr,tau)) return 1;
     312         441 :   return 0;
     313             : }
     314             : 
     315             : /* assume x in basistoalg form */
     316             : static GEN
     317        1036 : downtoK(toK_s *T, GEN x)
     318             : {
     319        1036 :   long degKz = lg(T->invexpoteta1) - 1;
     320        1036 :   GEN y = gmul(T->invexpoteta1, Rg_to_RgC(lift_shallow(x), degKz));
     321        1036 :   return gmodulo(gtopolyrev(y,varn(T->polnf)), T->polnf);
     322             : }
     323             : 
     324             : static GEN
     325           0 : no_sol(long all, long i)
     326             : {
     327           0 :   if (!all) pari_err_BUG(stack_sprintf("kummer [bug%ld]", i));
     328           0 :   return cgetg(1,t_VEC);
     329             : }
     330             : 
     331             : static GEN
     332         490 : get_gell(GEN bnr, GEN subgp, long all)
     333             : {
     334             :   GEN gell;
     335         490 :   if (all && all != -1) return utoipos(labs(all));
     336         469 :   if (!subgp) return ZV_prod(bnr_get_cyc(bnr));
     337         469 :   gell = det(subgp);
     338         469 :   if (typ(gell) != t_INT) pari_err_TYPE("rnfkummer",gell);
     339         469 :   return gell;
     340             : }
     341             : 
     342             : typedef struct {
     343             :   GEN Sm, Sml1, Sml2, Sl, ESml2;
     344             : } primlist;
     345             : 
     346             : static int
     347         483 : build_list_Hecke(primlist *L, GEN nfz, GEN fa, GEN gothf, GEN gell, tau_s *tau)
     348             : {
     349             :   GEN listpr, listex, pr, factell;
     350         483 :   long vp, i, l, ell = itos(gell), degKz = nf_get_degree(nfz);
     351             : 
     352         483 :   if (!fa) fa = idealfactor(nfz, gothf);
     353         483 :   listpr = gel(fa,1);
     354         483 :   listex = gel(fa,2); l = lg(listpr);
     355         483 :   L->Sm  = vectrunc_init(l);
     356         483 :   L->Sml1= vectrunc_init(l);
     357         483 :   L->Sml2= vectrunc_init(l);
     358         483 :   L->Sl  = vectrunc_init(l+degKz);
     359         483 :   L->ESml2=vecsmalltrunc_init(l);
     360        1414 :   for (i=1; i<l; i++)
     361             :   {
     362         931 :     pr = gel(listpr,i);
     363         931 :     vp = itos(gel(listex,i));
     364         931 :     if (!equalii(pr_get_p(pr), gell))
     365             :     {
     366         644 :       if (vp != 1) return 1;
     367         644 :       if (!isconjinprimelist(L->Sm,pr,tau)) vectrunc_append(L->Sm,pr);
     368             :     }
     369             :     else
     370             :     {
     371         287 :       long e = pr_get_e(pr), vd = (vp-1)*(ell-1)-ell*e;
     372         287 :       if (vd > 0) return 4;
     373         287 :       if (vd==0)
     374             :       {
     375          63 :         if (!isconjinprimelist(L->Sml1,pr,tau)) vectrunc_append(L->Sml1, pr);
     376             :       }
     377             :       else
     378             :       {
     379         224 :         if (vp==1) return 2;
     380         224 :         if (!isconjinprimelist(L->Sml2,pr,tau))
     381             :         {
     382         224 :           vectrunc_append(L->Sml2, pr);
     383         224 :           vecsmalltrunc_append(L->ESml2, vp);
     384             :         }
     385             :       }
     386             :     }
     387             :   }
     388         483 :   factell = idealprimedec(nfz,gell); l = lg(factell);
     389        1071 :   for (i=1; i<l; i++)
     390             :   {
     391         588 :     pr = gel(factell,i);
     392         588 :     if (!idealval(nfz,gothf,pr) && !isconjinprimelist(L->Sl,pr,tau))
     393         294 :       vectrunc_append(L->Sl, pr);
     394             :   }
     395         483 :   return 0; /* OK */
     396             : }
     397             : 
     398             : /* Return a Flm */
     399             : static GEN
     400         742 : logall(GEN nf, GEN vec, long lW, long mginv, long ell, GEN pr, long ex)
     401             : {
     402         742 :   GEN m, M, sprk = log_prk_init(nf, pr, ex);
     403         742 :   long ellrank, i, l = lg(vec);
     404             : 
     405         742 :   ellrank = prank(gel(sprk,1), ell);
     406         742 :   M = cgetg(l,t_MAT);
     407        3045 :   for (i=1; i<l; i++)
     408             :   {
     409        2303 :     m = log_prk(nf, gel(vec,i), sprk);
     410        2303 :     setlg(m, ellrank+1);
     411        2303 :     if (i < lW) m = gmulsg(mginv, m);
     412        2303 :     gel(M,i) = ZV_to_Flv(m, ell);
     413             :   }
     414         742 :   return M;
     415             : }
     416             : 
     417             : /* compute the u_j (see remark 5.2.15.) */
     418             : static GEN
     419         483 : get_u(GEN cyc, long rc, ulong ell)
     420             : {
     421         483 :   long i, l = lg(cyc);
     422         483 :   GEN u = cgetg(l,t_VECSMALL);
     423         483 :   for (i=1; i<=rc; i++) uel(u,i) = 0;
     424         483 :   for (   ; i<  l; i++) uel(u,i) = Fl_inv(uel(cyc,i), ell);
     425         483 :   return u;
     426             : }
     427             : 
     428             : /* alg. 5.2.15. with remark */
     429             : static GEN
     430         539 : isprincipalell(GEN bnfz, GEN id, GEN cycgen, GEN u, ulong ell, long rc)
     431             : {
     432         539 :   long i, l = lg(cycgen);
     433         539 :   GEN v, b, db, y = bnfisprincipal0(bnfz, id, nf_FORCE|nf_GENMAT);
     434             : 
     435         539 :   v = ZV_to_Flv(gel(y,1), ell);
     436         539 :   b = gel(y,2);
     437         539 :   if (typ(b) == t_COL)
     438             :   {
     439         476 :     b = Q_remove_denom(gel(y,2), &db);
     440         476 :     if (db) b = famat_mulpows_shallow(b, db, -1);
     441             :   }
     442         742 :   for (i=rc+1; i<l; i++)
     443             :   {
     444         203 :     ulong e = Fl_mul( uel(v,i), uel(u,i), ell);
     445         203 :     b = famat_mulpows_shallow(b, gel(cycgen,i), e);
     446             :   }
     447         539 :   setlg(v,rc+1); return mkvec2(v, b);
     448             : }
     449             : 
     450             : static GEN
     451         140 : famat_factorback(GEN v, GEN e)
     452             : {
     453         140 :   long i, l = lg(e);
     454         140 :   GEN V = trivial_fact();
     455         140 :   for (i=1; i<l; i++) V = famat_mulpow_shallow(V, gel(v,i), gel(e,i));
     456         140 :   return V;
     457             : }
     458             : 
     459             : static GEN
     460        1260 : famat_factorbacks(GEN v, GEN e)
     461             : {
     462        1260 :   long i, l = lg(e);
     463        1260 :   GEN V = trivial_fact();
     464        1260 :   for (i=1; i<l; i++) V = famat_mulpows_shallow(V, gel(v,i), uel(e,i));
     465        1260 :   return V;
     466             : }
     467             : 
     468             : static GEN
     469         504 : compute_beta(GEN X, GEN vecWB, GEN ell, GEN bnfz)
     470             : {
     471             :   GEN BE, be;
     472         504 :   BE = famat_reduce(famat_factorbacks(vecWB, X));
     473         504 :   gel(BE,2) = centermod(gel(BE,2), ell);
     474         504 :   be = nffactorback(bnfz, BE, NULL);
     475         504 :   be = reducebeta(bnfz, be, ell);
     476         504 :   if (DEBUGLEVEL>1) err_printf("beta reduced = %Ps\n",be);
     477         504 :   return be;
     478             : }
     479             : 
     480             : static GEN
     481         483 : get_Selmer(GEN bnf, GEN cycgen, long rc)
     482             : {
     483         483 :   GEN U = bnf_build_units(bnf), tu = gel(U,1), fu = vecslice(U, 2, lg(U)-1);
     484         483 :   return shallowconcat(shallowconcat(fu,mkvec(tu)), vecslice(cycgen,1,rc));
     485             : }
     486             : 
     487             : GEN
     488       45038 : lift_if_rational(GEN x)
     489             : {
     490             :   long lx, i;
     491             :   GEN y;
     492             : 
     493       45038 :   switch(typ(x))
     494             :   {
     495        5845 :     default: break;
     496             : 
     497             :     case t_POLMOD:
     498       26845 :       y = gel(x,2);
     499       26845 :       if (typ(y) == t_POL)
     500             :       {
     501       10892 :         long d = degpol(y);
     502       10892 :         if (d > 0) return x;
     503        1834 :         return (d < 0)? gen_0: gel(y,2);
     504             :       }
     505       15953 :       return y;
     506             : 
     507        5537 :     case t_POL: lx = lg(x);
     508        5537 :       for (i=2; i<lx; i++) gel(x,i) = lift_if_rational(gel(x,i));
     509        5537 :       break;
     510        6811 :     case t_VEC: case t_COL: case t_MAT: lx = lg(x);
     511        6811 :       for (i=1; i<lx; i++) gel(x,i) = lift_if_rational(gel(x,i));
     512             :   }
     513       18193 :   return x;
     514             : }
     515             : 
     516             : /* A column vector representing a subgroup of prime index */
     517             : static GEN
     518           0 : grptocol(GEN H)
     519             : {
     520           0 :   long i, j, l = lg(H);
     521           0 :   GEN col = cgetg(l, t_VECSMALL);
     522           0 :   for (i = 1; i < l; i++)
     523             :   {
     524           0 :     ulong ell = itou( gcoeff(H,i,i) );
     525           0 :     if (ell == 1) col[i] = 0; else { col[i] = ell-1; break; }
     526             :   }
     527           0 :   for (j=i; ++j < l; ) col[j] = itou( gcoeff(H,i,j) );
     528           0 :   return col;
     529             : }
     530             : 
     531             : /* Reorganize kernel basis so that the tests of ok_congruence can be ok
     532             :  * for y[ncyc]=1 and y[1..ncyc]=1 */
     533             : static GEN
     534           0 : fix_kernel(GEN K, GEN M, GEN vecMsup, long lW, long ell)
     535             : {
     536           0 :   pari_sp av = avma;
     537           0 :   long i, j, idx, ffree, dK = lg(K)-1;
     538           0 :   GEN Ki, Kidx = cgetg(dK+1, t_VECSMALL);
     539             : 
     540             :   /* First step: Gauss elimination on vectors lW...lg(M) */
     541           0 :   for (idx = lg(K), i=lg(M); --i >= lW; )
     542             :   {
     543           0 :     for (j=dK; j > 0; j--) if (coeff(K, i, j)) break;
     544           0 :     if (!j)
     545             :     { /* Do our best to ensure that K[dK,i] != 0 */
     546           0 :       if (coeff(K, i, dK)) continue;
     547           0 :       for (j = idx; j < dK; j++)
     548           0 :         if (coeff(K, i, j) && coeff(K, Kidx[j], dK) != ell - 1)
     549           0 :           Flv_add_inplace(gel(K,dK), gel(K,j), ell);
     550             :     }
     551           0 :     if (j != --idx) swap(gel(K, j), gel(K, idx));
     552           0 :     Kidx[idx] = i;
     553           0 :     if (coeff(K,i,idx) != 1)
     554           0 :       Flv_Fl_div_inplace(gel(K,idx), coeff(K,i,idx), ell);
     555           0 :     Ki = gel(K,idx);
     556           0 :     if (coeff(K,i,dK) != 1)
     557             :     {
     558           0 :       ulong t = Fl_sub(coeff(K,i,dK), 1, ell);
     559           0 :       Flv_sub_inplace(gel(K,dK), Flv_Fl_mul(Ki, t, ell), ell);
     560             :     }
     561           0 :     for (j = dK; --j > 0; )
     562             :     {
     563           0 :       if (j == idx) continue;
     564           0 :       if (coeff(K,i,j))
     565           0 :         Flv_sub_inplace(gel(K,j), Flv_Fl_mul(Ki, coeff(K,i,j), ell), ell);
     566             :     }
     567             :   }
     568             :   /* ffree = first vector that is not "free" for the scalar products */
     569           0 :   ffree = idx;
     570             :   /* Second step: for each hyperplane equation in vecMsup, do the same
     571             :    * thing as before. */
     572           0 :   for (i=1; i < lg(vecMsup); i++)
     573             :   {
     574           0 :     GEN Msup = gel(vecMsup,i);
     575             :     ulong dotprod;
     576           0 :     if (lgcols(Msup) != 2) continue;
     577           0 :     Msup = zm_row(Msup, 1);
     578           0 :     for (j=ffree; --j > 0; )
     579             :     {
     580           0 :       dotprod = Flv_dotproduct(Msup, gel(K,j), ell);
     581           0 :       if (dotprod)
     582             :       {
     583           0 :         if (j != --ffree) swap(gel(K, j), gel(K, ffree));
     584           0 :         if (dotprod != 1) Flv_Fl_div_inplace(gel(K, ffree), dotprod, ell);
     585           0 :         break;
     586             :       }
     587             :     }
     588           0 :     if (!j)
     589             :     { /* Do our best to ensure that vecMsup.K[dK] != 0 */
     590           0 :       if (Flv_dotproduct(Msup, gel(K,dK), ell) == 0)
     591             :       {
     592           0 :         for (j = ffree-1; j <= dK; j++)
     593           0 :           if (Flv_dotproduct(Msup, gel(K,j), ell)
     594           0 :               && coeff(K,Kidx[j],dK) != ell-1)
     595           0 :             Flv_add_inplace(gel(K,dK), gel(K,j), ell);
     596             :       }
     597           0 :       continue;
     598             :     }
     599           0 :     Ki = gel(K,ffree);
     600           0 :     dotprod = Flv_dotproduct(Msup, gel(K,dK), ell);
     601           0 :     if (dotprod != 1)
     602             :     {
     603           0 :       ulong t = Fl_sub(dotprod,1,ell);
     604           0 :       Flv_sub_inplace(gel(K,dK), Flv_Fl_mul(Ki,t,ell), ell);
     605             :     }
     606           0 :     for (j = dK; --j > 0; )
     607             :     {
     608           0 :       if (j == ffree) continue;
     609           0 :       dotprod = Flv_dotproduct(Msup, gel(K,j), ell);
     610           0 :       if (dotprod) Flv_sub_inplace(gel(K,j), Flv_Fl_mul(Ki,dotprod,ell), ell);
     611             :     }
     612             :   }
     613           0 :   if (ell == 2)
     614             :   {
     615           0 :     for (i = ffree, j = ffree-1; i <= dK && j; i++, j--)
     616           0 :     { swap(gel(K,i), gel(K,j)); }
     617             :   }
     618             :   /* Try to ensure that y = vec_ei(n, i) gives a good candidate */
     619           0 :   for (i = 1; i < dK; i++) Flv_add_inplace(gel(K,i), gel(K,dK), ell);
     620           0 :   return gerepilecopy(av, K);
     621             : }
     622             : 
     623             : static GEN
     624           0 : Flm_init(long m, long n)
     625             : {
     626           0 :   GEN M = cgetg(n+1, t_MAT);
     627           0 :   long i; for (i = 1; i <= n; i++) gel(M,i) = cgetg(m+1, t_VECSMALL);
     628           0 :   return M;
     629             : }
     630             : static void
     631           0 : Flv_fill(GEN v, GEN y)
     632             : {
     633           0 :   long i, l = lg(y);
     634           0 :   for (i = 1; i < l; i++) v[i] = y[i];
     635           0 : }
     636             : 
     637             : static GEN
     638         686 : get_badbnf(GEN bnf)
     639             : {
     640             :   long i, l;
     641         686 :   GEN bad = gen_1, gen = bnf_get_gen(bnf);
     642         686 :   l = lg(gen);
     643        1134 :   for (i = 1; i < l; i++)
     644             :   {
     645         448 :     GEN g = gel(gen,i);
     646         448 :     bad = lcmii(bad, gcoeff(g,1,1));
     647             :   }
     648         686 :   return bad;
     649             : }
     650             : /* Let K base field, L/K described by bnr (conductor f) + H. Return a list of
     651             :  * primes coprime to f*ell of degree 1 in K whose images in Cl_f(K) generate H:
     652             :  * thus they all split in Lz/Kz; t in Kz is such that
     653             :  * t^(1/p) generates Lz => t is an ell-th power in k(pr) for all such primes.
     654             :  * Restrict to primes not dividing
     655             :  * - the index fz of the polynomial defining Kz, or
     656             :  * - the modulus, or
     657             :  * - ell, or
     658             :  * - a generator in bnf.gen or bnfz.gen */
     659             : static GEN
     660         469 : get_prlist(GEN bnr, GEN H, ulong ell, GEN bnfz)
     661             : {
     662         469 :   pari_sp av0 = avma;
     663             :   forprime_t T;
     664             :   ulong p;
     665             :   GEN L, nf, cyc, bad, cond, condZ, Hsofar;
     666         469 :   L = cgetg(1, t_VEC);
     667         469 :   cyc = bnr_get_cyc(bnr);
     668         469 :   nf = bnr_get_nf(bnr);
     669             : 
     670         469 :   cond = gel(bnr_get_mod(bnr), 1);
     671         469 :   condZ = gcoeff(cond,1,1);
     672         469 :   bad = get_badbnf(bnr_get_bnf(bnr));
     673         469 :   if (bnfz)
     674             :   {
     675         217 :     GEN badz = lcmii(get_badbnf(bnfz), nf_get_index(bnf_get_nf(bnfz)));
     676         217 :     bad = mulii(bad,badz);
     677             :   }
     678         469 :   bad = lcmii(muliu(condZ, ell), bad);
     679             :   /* restrict to primes not dividing bad */
     680             : 
     681         469 :   u_forprime_init(&T, 2, ULONG_MAX);
     682         469 :   Hsofar = cgetg(1, t_MAT);
     683        7616 :   while ((p = u_forprime_next(&T)))
     684             :   {
     685             :     GEN LP;
     686             :     long i, l;
     687        7147 :     if (p == ell || !umodiu(bad, p)) continue;
     688        5915 :     LP = idealprimedec_limit_f(nf, utoipos(p), 1);
     689        5915 :     l = lg(LP);
     690        9597 :     for (i = 1; i < l; i++)
     691             :     {
     692        4151 :       pari_sp av = avma;
     693        4151 :       GEN M, P = gel(LP,i), v = bnrisprincipal(bnr, P, 0);
     694        4151 :       if (!hnf_invimage(H, v)) { set_avma(av); continue; }
     695        1288 :       M = shallowconcat(Hsofar, v);
     696        1288 :       M = ZM_hnfmodid(M, cyc);
     697        1288 :       if (ZM_equal(M, Hsofar)) continue;
     698         903 :       L = shallowconcat(L, mkvec(P));
     699         903 :       Hsofar = M;
     700             :       /* the primes in L generate H */
     701         903 :       if (ZM_equal(M, H)) return gerepilecopy(av0, L);
     702             :     }
     703             :   }
     704           0 :   pari_err_BUG("rnfkummer [get_prlist]");
     705           0 :   return NULL;
     706             : }
     707             : /*Lprz list of prime ideals in Kz that must split completely in Lz/Kz, vecWA
     708             :  * generators for the S-units used to build the Kummer generators. Return
     709             :  * matsmall M such that \prod WA[j]^x[j] ell-th power mod pr[i] iff
     710             :  * \sum M[i,j] x[j] = 0 (mod ell) */
     711             : static GEN
     712         469 : subgroup_info(GEN bnfz, GEN Lprz, long ell, GEN vecWA)
     713             : {
     714         469 :   GEN nfz = bnf_get_nf(bnfz), M, gell = utoipos(ell), Lell = mkvec(gell);
     715         469 :   long i, j, l = lg(vecWA), lz = lg(Lprz);
     716         469 :   M = cgetg(l, t_MAT);
     717         469 :   for (j=1; j<l; j++) gel(M,j) = cgetg(lz, t_VECSMALL);
     718        1372 :   for (i=1; i < lz; i++)
     719             :   {
     720         903 :     GEN pr = gel(Lprz,i), EX = subiu(pr_norm(pr), 1);
     721         903 :     GEN N, g,T,p, prM = idealhnf(nfz, pr);
     722         903 :     GEN modpr = zk_to_Fq_init(nfz, &pr,&T,&p);
     723         903 :     long v = Z_lvalrem(divis(EX,ell), ell, &N) + 1; /* Norm(pr)-1 = N * ell^v */
     724         903 :     GEN ellv = powuu(ell, v);
     725         903 :     g = gener_Fq_local(T,p, Lell);
     726         903 :     g = Fq_pow(g,N, T,p); /* order ell^v */
     727        4396 :     for (j=1; j < l; j++)
     728             :     {
     729        3493 :       GEN logc, c = gel(vecWA,j);
     730        3493 :       if (typ(c) == t_MAT) /* famat */
     731        1071 :         c = famat_makecoprime(nfz, gel(c,1), gel(c,2), pr, prM, EX);
     732        3493 :       c = nf_to_Fq(nfz, c, modpr);
     733        3493 :       c = Fq_pow(c, N, T,p);
     734        3493 :       logc = Fq_log(c, g, ellv, T,p);
     735        3493 :       ucoeff(M, i,j) = umodiu(logc, ell);
     736             :     }
     737             :   }
     738         469 :   return M;
     739             : }
     740             : 
     741             : /* if all!=0, give all equations of degree 'all'. Assume bnr modulus is the
     742             :  * conductor */
     743             : static GEN
     744         252 : rnfkummersimple(GEN bnr, GEN subgroup, GEN gell, long all)
     745             : {
     746             :   long ell, i, j, degK, dK;
     747             :   long lSml2, lSl2, lSp, rc, lW;
     748             :   long prec;
     749         252 :   long rk=0, ncyc=0;
     750         252 :   GEN mat=NULL, matgrp=NULL, xell, be1 = NULL;
     751         252 :   long firstpass = all<0;
     752             : 
     753             :   GEN bnf,nf,bid,ideal,arch,cycgen;
     754             :   GEN cyc;
     755             :   GEN Sp,listprSp,matP;
     756         252 :   GEN res=NULL,u,M,K,y,vecMsup,vecW,vecWB,vecBp,msign;
     757             :   primlist L;
     758             : 
     759         252 :   bnf = bnr_get_bnf(bnr); (void)bnf_build_units(bnf);
     760         252 :   nf  = bnf_get_nf(bnf);
     761         252 :   degK = nf_get_degree(nf);
     762             : 
     763         252 :   bid = bnr_get_bid(bnr);
     764         252 :   ideal= bid_get_ideal(bid);
     765         252 :   arch = bid_get_arch(bid); /* this is the conductor */
     766         252 :   ell = itos(gell);
     767         252 :   i = build_list_Hecke(&L, nf, bid_get_fact2(bid), ideal, gell, NULL);
     768         252 :   if (i) return no_sol(all,i);
     769             : 
     770         252 :   lSml2 = lg(L.Sml2);
     771         252 :   Sp = shallowconcat(L.Sm, L.Sml1); lSp = lg(Sp);
     772         252 :   listprSp = shallowconcat(L.Sml2, L.Sl); lSl2 = lg(listprSp);
     773             : 
     774         252 :   cycgen = bnf_build_cycgen(bnf);
     775         252 :   cyc = bnf_get_cyc(bnf); rc = prank(cyc, ell);
     776             : 
     777         252 :   vecW = get_Selmer(bnf, cycgen, rc);
     778         252 :   u = get_u(ZV_to_Flv(cyc,ell), rc, ell);
     779             : 
     780         252 :   vecBp = cgetg(lSp, t_VEC);
     781         252 :   matP  = cgetg(lSp, t_MAT);
     782         497 :   for (j = 1; j < lSp; j++)
     783             :   {
     784         245 :     GEN L = isprincipalell(bnf,gel(Sp,j), cycgen,u,ell,rc);
     785         245 :     gel( matP,j) = gel(L,1);
     786         245 :     gel(vecBp,j) = gel(L,2);
     787             :   }
     788         252 :   vecWB = shallowconcat(vecW, vecBp);
     789             : 
     790         252 :   prec = DEFAULTPREC +
     791         252 :       nbits2extraprec(((degK-1) * (gexpo(vecWB) + gexpo(nf_get_M(nf)))));
     792         252 :   if (nf_get_prec(nf) < prec) nf = nfnewprec_shallow(nf, prec);
     793         252 :   msign = nfsign(nf, vecWB);
     794         252 :   arch = ZV_to_zv(arch);
     795             : 
     796         252 :   vecMsup = cgetg(lSml2,t_VEC);
     797         252 :   M = NULL;
     798         483 :   for (i = 1; i < lSl2; i++)
     799             :   {
     800         231 :     GEN pr = gel(listprSp,i);
     801         231 :     long e = pr_get_e(pr), z = ell * (e / (ell-1));
     802             : 
     803         231 :     if (i < lSml2)
     804             :     {
     805          91 :       z += 1 - L.ESml2[i];
     806          91 :       gel(vecMsup,i) = logall(nf, vecWB, 0,0, ell, pr,z+1);
     807             :     }
     808         231 :     M = vconcat(M, logall(nf, vecWB, 0,0, ell, pr,z));
     809             :   }
     810         252 :   lW = lg(vecW);
     811         252 :   M = vconcat(M, shallowconcat(zero_Flm(rc,lW-1), matP));
     812         252 :   if (!all)
     813             :   { /* primes landing in subgroup must be totally split */
     814         252 :     GEN Lpr = get_prlist(bnr, subgroup, ell, NULL);
     815         252 :     GEN M2 = subgroup_info(bnf, Lpr, ell, vecWB);
     816         252 :     M = vconcat(M, M2);
     817             :   }
     818         252 :   K = Flm_ker(M, ell);
     819         252 :   dK = lg(K)-1;
     820             : 
     821         252 :   if (all < 0)
     822           0 :     K = fix_kernel(K, M, vecMsup, lW, ell);
     823             : 
     824         252 :   y = cgetg(dK+1,t_VECSMALL);
     825         252 :   if (all) res = cgetg(1,t_VEC); /* in case all = 1 */
     826         252 :   if (all < 0)
     827             :   {
     828           0 :     ncyc = dK;
     829           0 :     mat = Flm_init(dK, ncyc);
     830           0 :     if (all == -1) matgrp = Flm_init(lg(bnr_get_cyc(bnr)), ncyc+1);
     831           0 :     rk = 0;
     832             :   }
     833         252 :   xell = pol_xn(ell, 0);
     834             :   do {
     835         252 :     dK = lg(K)-1;
     836         511 :     while (dK)
     837             :     {
     838         259 :       for (i=1; i<dK; i++) y[i] = 0;
     839         259 :       y[i] = 1; /* y = [0,...,0,1,0,...,0], 1 at dK'th position */
     840             :       do
     841             :       {
     842         357 :         pari_sp av = avma;
     843         357 :         GEN be, P=NULL, X;
     844         357 :         if (all < 0)
     845             :         {
     846           0 :           Flv_fill(gel(mat, rk+1), y);
     847           0 :           setlg(mat, rk+2);
     848           0 :           if (Flm_rank(mat, ell) <= rk) continue;
     849             :         }
     850         357 : FOUND:  X = Flm_Flc_mul(K, y, ell);
     851         357 :         if (ok_congruence(X, ell, lW, vecMsup) && ok_sign(X, msign, arch))
     852             :         {/* be satisfies all congruences, x^ell - be is irreducible, signature
     853             :           * and relative discriminant are correct */
     854         252 :           if (all < 0) rk++;
     855         252 :           be = compute_beta(X, vecWB, gell, bnf);
     856         252 :           be = nf_to_scalar_or_alg(nf, be);
     857         252 :           if (typ(be) == t_POL) be = mkpolmod(be, nf_get_pol(nf));
     858         252 :           if (all == -1)
     859             :           {
     860           0 :             pari_sp av2 = avma;
     861           0 :             GEN Kgrp, colgrp = grptocol(rnfnormgroup(bnr, gsub(xell, be)));
     862           0 :             if (ell != 2)
     863             :             {
     864           0 :               if (rk == 1) be1 = be;
     865             :               else
     866             :               { /* Compute the pesky scalar */
     867           0 :                 GEN K2, C = cgetg(4, t_MAT);
     868           0 :                 gel(C,1) = gel(matgrp,1);
     869           0 :                 gel(C,2) = colgrp;
     870           0 :                 gel(C,3) = grptocol(rnfnormgroup(bnr, gsub(xell, gmul(be1,be))));
     871           0 :                 K2 = Flm_ker(C, ell);
     872           0 :                 if (lg(K2) != 2) pari_err_BUG("linear algebra");
     873           0 :                 K2 = gel(K2,1);
     874           0 :                 if (K2[1] != K2[2])
     875           0 :                   Flv_Fl_mul_inplace(colgrp, Fl_div(K2[2],K2[1],ell), ell);
     876             :               }
     877             :             }
     878           0 :             Flv_fill(gel(matgrp,rk), colgrp);
     879           0 :             setlg(matgrp, rk+1);
     880           0 :             Kgrp = Flm_ker(matgrp, ell);
     881           0 :             if (lg(Kgrp) == 2)
     882             :             {
     883           0 :               setlg(gel(Kgrp,1), rk+1);
     884           0 :               y = Flm_Flc_mul(mat, gel(Kgrp,1), ell);
     885           0 :               all = 0; goto FOUND;
     886             :             }
     887           0 :             set_avma(av2);
     888             :           }
     889             :           else
     890             :           {
     891         252 :             P = gsub(xell, be);
     892         252 :             if (all)
     893           0 :               res = shallowconcat(res, gerepileupto(av, P));
     894             :             else
     895             :             {
     896         252 :               if (ZM_equal(rnfnormgroup(bnr,P),subgroup)) return P; /*DONE*/
     897           0 :               set_avma(av); continue;
     898             :             }
     899             :           }
     900           0 :           if (all < 0 && rk == ncyc) return res;
     901           0 :           if (firstpass) break;
     902             :         }
     903         105 :         else set_avma(av);
     904         105 :       } while (increment(y, dK, ell));
     905           7 :       y[dK--] = 0;
     906             :     }
     907           0 :   } while (firstpass--);
     908           0 :   return all? res: gen_0;
     909             : }
     910             : 
     911             : /* alg. 5.3.11 (return only discrete log mod ell) */
     912             : static GEN
     913         826 : isvirtualunit(GEN bnf, GEN v, GEN cycgen, GEN cyc, GEN gell, long rc)
     914             : {
     915         826 :   GEN L, b, eps, y, q, nf = bnf_get_nf(bnf);
     916         826 :   GEN w = idealsqrtn(nf, v, gell, 1);
     917         826 :   long i, l = lg(cycgen);
     918             : 
     919         826 :   L = bnfisprincipal0(bnf, w, nf_GENMAT|nf_FORCE);
     920         826 :   q = gel(L,1);
     921         826 :   if (ZV_equal0(q)) { eps = v; y = q; }
     922             :   else
     923             :   {
     924         140 :     y = cgetg(l,t_COL);
     925         140 :     for (i=1; i<l; i++) gel(y,i) = diviiexact(mulii(gell,gel(q,i)), gel(cyc,i));
     926         140 :     eps = famat_mulpow_shallow(famat_factorback(cycgen,y), gel(L,2), gell);
     927         140 :     eps = famat_mul_shallow(famat_inv(eps), v);
     928             :   }
     929         826 :   setlg(y, rc+1);
     930         826 :   b = bnfisunit(bnf,eps);
     931         826 :   if (lg(b) == 1) pari_err_BUG("isvirtualunit");
     932         826 :   return shallowconcat(lift_shallow(b), y);
     933             : }
     934             : 
     935             : /* J a vector of elements in nfz = relative extension of nf by polrel,
     936             :  * return the Steinitz element attached to the module generated by J */
     937             : static GEN
     938         651 : Stelt(GEN nf, GEN J, GEN polrel)
     939             : {
     940         651 :   long i, l = lg(J), vx = varn(polrel);
     941         651 :   GEN A = cgetg(l, t_VEC), I = cgetg(l, t_VEC);
     942        4487 :   for (i = 1; i < l; i++)
     943             :   {
     944        3836 :     GEN v = gel(J,i);
     945        3836 :     if (typ(v) == t_POL) { v = RgX_rem(v, polrel); setvarn(v,vx); }
     946        3836 :     gel(A,i) = v;
     947        3836 :     gel(I,i) = gen_1;
     948             :   }
     949         651 :   A = RgV_to_RgM(A, degpol(polrel));
     950         651 :   return idealprod(nf, gel(nfhnf(nf, mkvec2(A,I)),2));
     951             : }
     952             : 
     953             : static GEN
     954         126 : polrelKzK(toK_s *T, GEN x)
     955             : {
     956         126 :   GEN P = roots_to_pol(powtau(x, T->m, T->tau), 0);
     957         126 :   long i, l = lg(P);
     958         126 :   for (i=2; i<l; i++) gel(P,i) = downtoK(T, gel(P,i));
     959         126 :   return P;
     960             : }
     961             : 
     962             : /* N: Cl_m(Kz) --> Cl_m(K), lift subgroup from bnr to bnrz using Algo 4.1.11 */
     963             : static GEN
     964         126 : invimsubgroup(GEN bnrz, GEN bnr, GEN subgroup, toK_s *T)
     965             : {
     966             :   long l, j;
     967             :   GEN P, cyc, gen, U, polrel, StZk;
     968         126 :   GEN nf = bnr_get_nf(bnr), nfz = bnr_get_nf(bnrz);
     969         126 :   GEN polz = nf_get_pol(nfz), zkzD = nf_get_zkprimpart(nfz);
     970             : 
     971         126 :   polrel = polrelKzK(T, pol_x(varn(polz)));
     972         126 :   StZk = Stelt(nf, zkzD, polrel);
     973         126 :   cyc = bnr_get_cyc(bnrz); l = lg(cyc);
     974         126 :   gen = bnr_get_gen(bnrz);
     975         126 :   P = cgetg(l,t_MAT);
     976         651 :   for (j=1; j<l; j++)
     977             :   {
     978         525 :     GEN g, id = idealhnf_shallow(nfz, gel(gen,j));
     979         525 :     g = Stelt(nf, RgV_RgM_mul(zkzD, id), polrel);
     980         525 :     g = idealdiv(nf, g, StZk); /* N_{Kz/K}(gen[j]) */
     981         525 :     gel(P,j) = isprincipalray(bnr, g);
     982             :   }
     983         126 :   (void)ZM_hnfall_i(shallowconcat(P, subgroup), &U, 1);
     984         126 :   setlg(U, l); for (j=1; j<l; j++) setlg(U[j], l);
     985         126 :   return ZM_hnfmodid(U, cyc);
     986             : }
     987             : 
     988             : static GEN
     989         252 : pol_from_Newton(GEN S)
     990             : {
     991         252 :   long i, k, l = lg(S);
     992         252 :   GEN C = cgetg(l+1, t_VEC), c = C + 1;
     993         252 :   gel(c,0) = gen_1;
     994         252 :   gel(c,1) = gel(S,1); /* gen_0 in our case */
     995         882 :   for (k = 2; k < l; k++)
     996             :   {
     997         630 :     GEN s = gel(S,k);
     998         630 :     for (i = 2; i < k-1; i++) s = gadd(s, gmul(gel(S,i), gel(c,k-i)));
     999         630 :     gel(c,k) = gdivgs(s, -k);
    1000             :   }
    1001         252 :   return gtopoly(C, 0);
    1002             : }
    1003             : 
    1004             : /* - mu_b = sum_{0 <= i < m} floor(r_b r_{d-1-i} / ell) tau^i */
    1005             : static GEN
    1006         602 : get_mmu(long b, GEN r, long ell)
    1007             : {
    1008         602 :   long i, m = lg(r)-1;
    1009         602 :   GEN M = cgetg(m+1, t_VEC);
    1010         602 :   for (i = 0; i < m; i++) gel(M,i+1) = stoi((r[b + 1] * r[m - i]) / ell);
    1011         602 :   return M;
    1012             : }
    1013             : 
    1014             : /* coeffs(x, a..b) in variable v >= varn(x) */
    1015             : static GEN
    1016        5964 : split_pol(GEN x, long v, long a, long b)
    1017             : {
    1018        5964 :   long i, l = degpol(x);
    1019        5964 :   GEN y = x + a, z;
    1020             : 
    1021        5964 :   if (l < b) b = l;
    1022        5964 :   if (a > b || varn(x) != v) return pol_0(v);
    1023        5320 :   l = b-a + 3;
    1024        5320 :   z = cgetg(l, t_POL); z[1] = x[1];
    1025        5320 :   for (i = 2; i < l; i++) gel(z,i) = gel(y,i);
    1026        5320 :   return normalizepol_lg(z, l);
    1027             : }
    1028             : 
    1029             : /* return (den_a * z) mod (v^ell - num_a/den_a), assuming deg(z) < 2*ell
    1030             :  * allow either num/den to be NULL (= 1) */
    1031             : static GEN
    1032        2982 : mod_Xell_a(GEN z, long v, long ell, GEN num_a, GEN den_a)
    1033             : {
    1034        2982 :   GEN z1 = split_pol(z, v, ell, degpol(z));
    1035        2982 :   GEN z0 = split_pol(z, v, 0,   ell-1); /* z = v^ell z1 + z0*/
    1036        2982 :   if (den_a) z0 = gmul(den_a, z0);
    1037        2982 :   if (num_a) z1 = gmul(num_a, z1);
    1038        2982 :   return gadd(z0, z1);
    1039             : }
    1040             : static GEN
    1041         854 : to_alg(GEN nfz, GEN c, long v)
    1042             : {
    1043             :   GEN z, D;
    1044         854 :   if (typ(c) != t_COL) return c;
    1045         602 :   z = gmul(nf_get_zkprimpart(nfz), c);
    1046         602 :   if (typ(z) == t_POL) setvarn(z, v);
    1047         602 :   D = nf_get_zkden(nfz);
    1048         602 :   if (!equali1(D)) z = RgX_Rg_div(z, D);
    1049         602 :   return z;
    1050             : }
    1051             : 
    1052             : /* th. 5.3.5. and prop. 5.3.9. */
    1053             : static GEN
    1054         252 : compute_polrel(GEN nfz, toK_s *T, GEN be, long g, long ell)
    1055             : {
    1056         252 :   long i, k, m = T->m, vT = fetch_var(), vz = fetch_var();
    1057             :   GEN r, powtaubet, S, p1, root, num_t, den_t, nfzpol, powtau_prim_invbe;
    1058             :   GEN prim_Rk, C_Rk, prim_root, C_root, prim_invbe, C_invbe;
    1059             :   pari_timer ti;
    1060             : 
    1061         252 :   r = cgetg(m+1,t_VECSMALL); /* r[i+1] = g^i mod ell */
    1062         252 :   r[1] = 1;
    1063         252 :   for (i=2; i<=m; i++) r[i] = (r[i-1] * g) % ell;
    1064         252 :   powtaubet = powtau(be, m, T->tau);
    1065         252 :   if (DEBUGLEVEL>1) { err_printf("Computing Newton sums: "); timer_start(&ti); }
    1066         252 :   prim_invbe = Q_primitive_part(nfinv(nfz, be), &C_invbe);
    1067         252 :   powtau_prim_invbe = powtau(prim_invbe, m, T->tau);
    1068             : 
    1069         252 :   root = cgetg(ell + 2, t_POL);
    1070         252 :   root[1] = evalsigne(1) | evalvarn(0);
    1071         252 :   for (i = 0; i < ell; i++) gel(root,2+i) = gen_0;
    1072         854 :   for (i = 0; i < m; i++)
    1073             :   { /* compute (1/be) ^ (-mu) instead of be^mu [mu << 0].
    1074             :      * 1/be = C_invbe * prim_invbe */
    1075         602 :     GEN mmu = get_mmu(i, r, ell);
    1076             :     /* p1 = prim_invbe ^ -mu */
    1077         602 :     p1 = to_alg(nfz, nffactorback(nfz, powtau_prim_invbe, mmu), vz);
    1078         602 :     if (C_invbe) p1 = gmul(p1, powgi(C_invbe, RgV_sumpart(mmu, m)));
    1079             :     /* root += zeta_ell^{r_i} T^{r_i} be^mu_i */
    1080         602 :     gel(root, 2 + r[i+1]) = monomial(p1, r[i+1], vT);
    1081             :   }
    1082             :   /* Other roots are as above with z_ell --> z_ell^j.
    1083             :    * Treat all contents (C_*) and principal parts (prim_*) separately */
    1084         252 :   prim_Rk = prim_root = Q_primitive_part(root, &C_root);
    1085         252 :   C_Rk = C_root;
    1086             : 
    1087         252 :   r = vecsmall_reverse(r); /* theta^ell = be^( sum tau^a r_{d-1-a} ) */
    1088             :   /* Compute modulo X^ell - 1, T^ell - t, nfzpol(vz) */
    1089         252 :   p1 = to_alg(nfz, nffactorback(nfz, powtaubet, r), vz);
    1090         252 :   num_t = Q_remove_denom(p1, &den_t);
    1091             : 
    1092         252 :   nfzpol = leafcopy(nf_get_pol(nfz));
    1093         252 :   setvarn(nfzpol, vz);
    1094         252 :   S = cgetg(ell+1, t_VEC); /* Newton sums */
    1095         252 :   gel(S,1) = gen_0;
    1096         882 :   for (k = 2; k <= ell; k++)
    1097             :   { /* compute the k-th Newton sum */
    1098         630 :     pari_sp av = avma;
    1099         630 :     GEN z, D, Rk = gmul(prim_Rk, prim_root);
    1100         630 :     C_Rk = mul_content(C_Rk, C_root);
    1101         630 :     Rk = mod_Xell_a(Rk, 0, ell, NULL, NULL); /* mod X^ell - 1 */
    1102        3010 :     for (i = 2; i < lg(Rk); i++)
    1103             :     {
    1104        2380 :       if (typ(gel(Rk,i)) != t_POL) continue;
    1105        2352 :       z = mod_Xell_a(gel(Rk,i), vT, ell, num_t,den_t); /* mod T^ell - t */
    1106        2352 :       gel(Rk,i) = RgXQX_red(z, nfzpol); /* mod nfz.pol */
    1107             :     }
    1108         630 :     if (den_t) C_Rk = mul_content(C_Rk, ginv(den_t));
    1109         630 :     prim_Rk = Q_primitive_part(Rk, &D);
    1110         630 :     C_Rk = mul_content(C_Rk, D); /* root^k = prim_Rk * C_Rk */
    1111             : 
    1112             :     /* Newton sum is ell * constant coeff (in X), which has degree 0 in T */
    1113         630 :     z = polcoef_i(prim_Rk, 0, 0);
    1114         630 :     z = polcoef_i(z      , 0,vT);
    1115         630 :     z = downtoK(T, gmulgs(z, ell));
    1116         630 :     if (C_Rk) z = gmul(z, C_Rk);
    1117         630 :     gerepileall(av, C_Rk? 3: 2, &z, &prim_Rk, &C_Rk);
    1118         630 :     if (DEBUGLEVEL>1) { err_printf("%ld(%ld) ", k, timer_delay(&ti)); err_flush(); }
    1119         630 :     gel(S,k) = z;
    1120             :   }
    1121         252 :   if (DEBUGLEVEL>1) err_printf("\n");
    1122         252 :   (void)delete_var();
    1123         252 :   (void)delete_var(); return pol_from_Newton(S);
    1124             : }
    1125             : 
    1126             : /* lift elt t in nf to nfz, algebraic form */
    1127             : static GEN
    1128         343 : lifttoKz(GEN nf, GEN t, compo_s *C)
    1129             : {
    1130         343 :   GEN x = nf_to_scalar_or_alg(nf, t);
    1131         343 :   if (typ(x) != t_POL) return x;
    1132         343 :   return RgX_RgXQ_eval(x, C->p, C->R);
    1133             : }
    1134             : /* lift ideal id in nf to nfz */
    1135             : static GEN
    1136         231 : ideallifttoKz(GEN nfz, GEN nf, GEN id, compo_s *C)
    1137             : {
    1138         231 :   GEN I = idealtwoelt(nf,id);
    1139         231 :   GEN x = nf_to_scalar_or_alg(nf, gel(I,2));
    1140         231 :   if (typ(x) != t_POL) return gel(I,1);
    1141         147 :   gel(I,2) = algtobasis(nfz, RgX_RgXQ_eval(x, C->p, C->R));
    1142         147 :   return idealhnf_two(nfz,I);
    1143             : }
    1144             : /* lift ideal pr in nf to ONE prime in nfz (the others are conjugate under tau
    1145             :  * and bring no further information on e_1 W). Assume pr coprime to
    1146             :  * index of both nf and nfz, and unramified in Kz/K (minor simplification) */
    1147             : static GEN
    1148         378 : prlifttoKz(GEN nfz, GEN nf, GEN pr, compo_s *C)
    1149             : {
    1150         378 :   GEN F, p = pr_get_p(pr), t = pr_get_gen(pr), T = nf_get_pol(nfz);
    1151         378 :   if (nf_get_degree(nf) != 1)
    1152             :   { /* restrict to primes above pr */
    1153         343 :     t = Q_primpart( lifttoKz(nf,t,C) );
    1154         343 :     T = FpX_gcd(FpX_red(T,p), FpX_red(t,p), p);
    1155         343 :     T = FpX_normalize(T, p);
    1156             :   }
    1157         378 :   F = FpX_factor(T, p);
    1158         378 :   return idealprimedec_kummer(nfz,gcoeff(F,1,1), pr_get_e(pr), p);
    1159             : }
    1160             : static GEN
    1161         217 : get_przlist(GEN L, GEN nfz, GEN nf, compo_s *C)
    1162             : {
    1163             :   long i, l;
    1164         217 :   GEN M = cgetg_copy(L, &l);
    1165         217 :   for (i = 1; i < l; i++) gel(M,i) = prlifttoKz(nfz, nf, gel(L,i), C);
    1166         217 :   return M;
    1167             : }
    1168             : 
    1169             : static void
    1170         231 : compositum_red(compo_s *C, GEN P, GEN Q)
    1171             : {
    1172         231 :   GEN p, q, a, z = gel(compositum2(P, Q),1);
    1173         231 :   a = gel(z,1);
    1174         231 :   p = gel(gel(z,2), 2);
    1175         231 :   q = gel(gel(z,3), 2);
    1176         231 :   C->k = itos( gel(z,4) );
    1177             :   /* reduce R. FIXME: should be polredbest(a, 1), but breaks rnfkummer bench */
    1178         231 :   z = polredabs0(a, nf_ORIG|nf_PARTIALFACT);
    1179         231 :   C->R = gel(z,1);
    1180         231 :   a = gel(gel(z,2), 2);
    1181         231 :   C->p = RgX_RgXQ_eval(p, a, C->R);
    1182         231 :   C->q = RgX_RgXQ_eval(q, a, C->R);
    1183         231 :   C->rev = QXQ_reverse(a, C->R);
    1184         231 :   if (DEBUGLEVEL>1) err_printf("polred(compositum) = %Ps\n",C->R);
    1185         231 : }
    1186             : 
    1187             : /* replace P->C^(-deg P) P(xC) for the largest integer C such that coefficients
    1188             :  * remain algebraic integers. Lift *rational* coefficients */
    1189             : static void
    1190         252 : nfX_Z_normalize(GEN nf, GEN P)
    1191             : {
    1192             :   long i, l;
    1193         252 :   GEN C, Cj, PZ = cgetg_copy(P, &l);
    1194         252 :   PZ[1] = P[1];
    1195        1386 :   for (i = 2; i < l; i++) /* minor variation on RgX_to_nfX (create PZ) */
    1196             :   {
    1197        1134 :     GEN z = nf_to_scalar_or_basis(nf, gel(P,i));
    1198        1134 :     if (typ(z) == t_INT)
    1199         735 :       gel(PZ,i) = gel(P,i) = z;
    1200             :     else
    1201         399 :       gel(PZ,i) = ZV_content(z);
    1202             :   }
    1203         252 :   (void)ZX_Z_normalize(PZ, &C);
    1204             : 
    1205         252 :   if (C == gen_1) return;
    1206          77 :   Cj = C;
    1207         322 :   for (i = l-2; i > 1; i--)
    1208             :   {
    1209         245 :     if (i != l-2) Cj = mulii(Cj, C);
    1210         245 :     gel(P,i) = gdiv(gel(P,i), Cj);
    1211             :   }
    1212             : }
    1213             : 
    1214             : static GEN
    1215         231 : _rnfkummer_step4(GEN bnfz, GEN gen, GEN cycgen, GEN u, ulong ell, long rc,
    1216             :                  long d, long m, long g, tau_s *tau)
    1217             : {
    1218             :   long i, j;
    1219             :   GEN vecB, vecC, Tc, Q;
    1220         231 :   vecB=cgetg(rc+1,t_VEC);
    1221         231 :   Tc=cgetg(rc+1,t_MAT);
    1222         371 :   for (j=1; j<=rc; j++)
    1223             :   {
    1224         140 :     GEN p1 = tauofideal(gel(gen,j), tau);
    1225         140 :     p1 = isprincipalell(bnfz, p1, cycgen,u,ell,rc);
    1226         140 :     gel(Tc,j)  = gel(p1,1);
    1227         140 :     gel(vecB,j)= gel(p1,2);
    1228             :   }
    1229             : 
    1230         231 :   if (!rc) vecC = cgetg(1,t_VEC);
    1231             :   else
    1232             :   {
    1233             :     GEN p1, p2;
    1234         126 :     vecC = const_vec(rc, trivial_fact());
    1235         126 :     p1 = Flm_powers(Tc, m-2, ell);
    1236         126 :     p2 = vecB;
    1237         294 :     for (j=1; j<=m-1; j++)
    1238             :     {
    1239         168 :       GEN z = Flm_Fl_mul(gel(p1,m-j), Fl_mul(j,d,ell), ell);
    1240         168 :       p2 = tauofvec(p2, tau);
    1241         364 :       for (i=1; i<=rc; i++)
    1242         392 :         gel(vecC,i) = famat_mul_shallow(gel(vecC,i),
    1243         196 :                                         famat_factorbacks(p2, gel(z,i)));
    1244             :     }
    1245         126 :     for (i=1; i<=rc; i++) gel(vecC,i) = famat_reduce(gel(vecC,i));
    1246             :   }
    1247         231 :   Q = Flm_ker(Flm_Fl_add(Flm_transpose(Tc), Fl_neg(g, ell), ell), ell);
    1248         231 :   return mkvec2(vecC, Q);
    1249             : }
    1250             : 
    1251             : static GEN
    1252         231 : _rnfkummer_step5(GEN bnfz, GEN vselmer, GEN cycgen, GEN gell, long rc,
    1253             :                  long rv, long g, tau_s *tau)
    1254             : {
    1255             :   GEN Tv, P, vecW;
    1256             :   long j, lW;
    1257         231 :   ulong ell = itou(gell);
    1258         231 :   GEN cyc = bnf_get_cyc(bnfz);
    1259         231 :   Tv = cgetg(rv+1,t_MAT);
    1260        1057 :   for (j=1; j<=rv; j++)
    1261             :   {
    1262         826 :     GEN p1 = tauofelt(gel(vselmer,j), tau);
    1263         826 :     if (typ(p1) == t_MAT) /* famat */
    1264         140 :       p1 = nffactorback(bnfz, gel(p1,1), FpC_red(gel(p1,2),gell));
    1265         826 :     gel(Tv,j) = ZV_to_Flv(isvirtualunit(bnfz, p1, cycgen,cyc,gell,rc), ell);
    1266             :   }
    1267         231 :   P = Flm_ker(Flm_Fl_add(Tv, Fl_neg(g, ell), ell), ell);
    1268         231 :   lW = lg(P);
    1269         231 :   vecW = cgetg(lW,t_VEC);
    1270         231 :   for (j=1; j<lW; j++) gel(vecW,j) = famat_factorbacks(vselmer, gel(P,j));
    1271         231 :   return vecW;
    1272             : }
    1273             : 
    1274             : static GEN
    1275         231 : _rnfkummer_step18(toK_s *T, GEN bnr, GEN subgroup, GEN bnfz, GEN M,
    1276             :      GEN vecWB, GEN vecMsup, ulong g, GEN gell, long lW, long all)
    1277             : {
    1278         231 :   GEN K, y, res = NULL, mat = NULL;
    1279         231 :   long i, dK, ncyc = 0;
    1280         231 :   ulong ell = itou(gell);
    1281         231 :   GEN bnf = bnr_get_bnf(bnr);
    1282         231 :   GEN nf  = bnf_get_nf(bnf);
    1283         231 :   GEN polnf = nf_get_pol(nf);
    1284         231 :   GEN nfz = bnf_get_nf(bnfz);
    1285         231 :   long firstpass = all<0;
    1286         231 :   long rk=0;
    1287         231 :   K = Flm_ker(M, ell);
    1288         231 :   if (all < 0)
    1289           0 :     K = fix_kernel(K, M, vecMsup, lW, ell);
    1290         231 :   if (DEBUGLEVEL>2) err_printf("Step 18\n");
    1291         231 :   dK = lg(K)-1;
    1292         231 :   y = cgetg(dK+1,t_VECSMALL);
    1293         231 :   if (all) res = cgetg(1, t_VEC);
    1294         231 :   if (all < 0) { ncyc = dK; rk = 0; mat = zero_Flm(lg(M)-1, ncyc); }
    1295             : 
    1296             :   do {
    1297         231 :     dK = lg(K)-1;
    1298         483 :     while (dK)
    1299             :     {
    1300         238 :       for (i=1; i<dK; i++) y[i] = 0;
    1301         238 :       y[i] = 1; /* y = [0,...,0,1,0,...,0], 1 at dK'th position */
    1302             :       do
    1303             :       { /* cf. algo 5.3.18 */
    1304         252 :         GEN H, be, P, X = Flm_Flc_mul(K, y, ell);
    1305         252 :         if (ok_congruence(X, ell, lW, vecMsup))
    1306             :         {
    1307         252 :           pari_sp av = avma;
    1308         252 :           if (all < 0)
    1309             :           {
    1310           0 :             gel(mat, rk+1) = X;
    1311           0 :             if (Flm_rank(mat,ell) <= rk) continue;
    1312           0 :             rk++;
    1313             :           }
    1314         252 :           be = compute_beta(X, vecWB, gell, bnfz);
    1315         252 :           P = compute_polrel(nfz, T, be, g, ell);
    1316         252 :           nfX_Z_normalize(nf, P);
    1317         252 :           if (DEBUGLEVEL>1) err_printf("polrel(beta) = %Ps\n", P);
    1318         252 :           if (!all) {
    1319         217 :             H = rnfnormgroup(bnr, P);
    1320         217 :             if (ZM_equal(subgroup, H)) return P; /* DONE */
    1321           0 :             set_avma(av); continue;
    1322             :           } else {
    1323          35 :             GEN P0 = Q_primpart(lift_shallow(P));
    1324          35 :             GEN g = nfgcd(P0, RgX_deriv(P0), polnf, nf_get_index(nf));
    1325          35 :             if (degpol(g)) continue;
    1326          35 :             H = rnfnormgroup(bnr, P);
    1327          35 :             if (!ZM_equal(subgroup,H) && !bnrisconductor(bnr,H)) continue;
    1328             :           }
    1329          35 :           P = gerepilecopy(av, P);
    1330          35 :           res = shallowconcat(res, P);
    1331          35 :           if (all < 0 && rk == ncyc) return res;
    1332          35 :           if (firstpass) break;
    1333             :         }
    1334          35 :       } while (increment(y, dK, ell));
    1335          21 :       y[dK--] = 0;
    1336             :     }
    1337          14 :   } while (firstpass--);
    1338          14 :   return res;
    1339             : }
    1340             : 
    1341             : static GEN
    1342         490 : _rnfkummer(GEN bnr, GEN subgroup, long all, long prec)
    1343             : {
    1344             :   long i, j, m, d, dc, rc, ru, rv, mginv, degK, degKz, vnf;
    1345             :   long lSp, lSml2, lSl2, lW;
    1346             :   ulong g, ell;
    1347             :   GEN polnf,bnf,nf,bnfz,nfz,bid,ideal,cycgen,gell,p1,vselmer;
    1348             :   GEN cyc, gen, step4;
    1349             :   GEN Q,idealz,gothf;
    1350         490 :   GEN res=NULL,u,M,vecMsup,vecW,vecWA,vecWB,vecC,vecAp,vecBp;
    1351             :   GEN matP, Sp, listprSp;
    1352             :   primlist L;
    1353             :   toK_s T;
    1354             :   tau_s tau;
    1355             :   compo_s COMPO;
    1356             :   pari_timer t;
    1357             : 
    1358         490 :   if (DEBUGLEVEL) timer_start(&t);
    1359         490 :   checkbnr(bnr);
    1360         490 :   bnf = bnr_get_bnf(bnr);
    1361         490 :   nf  = bnf_get_nf(bnf);
    1362         490 :   polnf = nf_get_pol(nf); vnf = varn(polnf);
    1363         490 :   if (!vnf) pari_err_PRIORITY("rnfkummer", polnf, "=", 0);
    1364             :   /* step 7 */
    1365         490 :   p1 = bnrconductor_i(bnr, subgroup, 2);
    1366         490 :   if (DEBUGLEVEL) timer_printf(&t, "[rnfkummer] conductor");
    1367         490 :   bnr      = gel(p1,2);
    1368         490 :   subgroup = gel(p1,3);
    1369         490 :   gell = get_gell(bnr,subgroup,all);
    1370         490 :   ell = itou(gell);
    1371         490 :   if (ell == 1) return pol_x(0);
    1372         490 :   if (!uisprime(ell)) pari_err_IMPL("kummer for composite relative degree");
    1373         490 :   if (all && all != -1 && umodiu(bnr_get_no(bnr), ell))
    1374           7 :     return cgetg(1, t_VEC);
    1375         483 :   if (bnf_get_tuN(bnf) % ell == 0)
    1376         252 :     return rnfkummersimple(bnr, subgroup, gell, all);
    1377             : 
    1378         231 :   if (all == -1) all = 0;
    1379         231 :   bid = bnr_get_bid(bnr);
    1380         231 :   ideal = bid_get_ideal(bid);
    1381             :   /* step 1 of alg 5.3.5. */
    1382         231 :   if (DEBUGLEVEL>2) err_printf("Step 1\n");
    1383         231 :   compositum_red(&COMPO, polnf, polcyclo(ell,vnf));
    1384             :   /* step 2 */
    1385         231 :   if (DEBUGLEVEL>2) err_printf("Step 2\n");
    1386         231 :   if (DEBUGLEVEL) timer_printf(&t, "[rnfkummer] compositum");
    1387         231 :   degK  = degpol(polnf);
    1388         231 :   degKz = degpol(COMPO.R);
    1389         231 :   m = degKz / degK;
    1390         231 :   d = (ell-1) / m;
    1391         231 :   g = Fl_powu(pgener_Fl(ell), d, ell);
    1392         231 :   if (Fl_powu(g, m, ell*ell) == 1) g += ell;
    1393             :   /* ord(g) = m in all (Z/ell^k)^* */
    1394             :   /* step 3 */
    1395         231 :   if (DEBUGLEVEL>2) err_printf("Step 3\n");
    1396             :   /* could factor disc(R) using th. 2.1.6. */
    1397         231 :   bnfz = Buchall(COMPO.R, nf_FORCE, maxss(prec,BIGDEFAULTPREC));
    1398         231 :   if (DEBUGLEVEL) timer_printf(&t, "[rnfkummer] bnfinit(Kz)");
    1399         231 :   cycgen = bnf_build_cycgen(bnfz);
    1400         231 :   nfz = bnf_get_nf(bnfz);
    1401         231 :   cyc = bnf_get_cyc(bnfz); rc = prank(cyc,ell);
    1402         231 :   gen = bnf_get_gen(bnfz);
    1403         231 :   u = get_u(ZV_to_Flv(cyc, ell), rc, ell);
    1404             : 
    1405         231 :   vselmer = get_Selmer(bnfz, cycgen, rc);
    1406         231 :   if (DEBUGLEVEL) timer_printf(&t, "[rnfkummer] Selmer group");
    1407         231 :   ru = (degKz>>1)-1;
    1408         231 :   rv = rc+ru+1;
    1409         231 :   get_tau(&tau, nfz, &COMPO, g);
    1410             : 
    1411             :   /* step 4 */
    1412         231 :   if (DEBUGLEVEL>2) err_printf("Step 4\n");
    1413         231 :   step4 = _rnfkummer_step4(bnfz, gen, cycgen, u, ell, rc, d, m, g, &tau);
    1414         231 :   vecC = gel(step4,1);
    1415         231 :   Q    = gel(step4,2);
    1416             :   /* step 5 */
    1417         231 :   if (DEBUGLEVEL>2) err_printf("Step 5\n");
    1418         231 :   vecW = _rnfkummer_step5(bnfz, vselmer, cycgen, gell, rc, rv, g, &tau);
    1419         231 :   lW = lg(vecW);
    1420             :   /* step 8 */
    1421         231 :   if (DEBUGLEVEL>2) err_printf("Step 8\n");
    1422         231 :   p1 = RgXQ_matrix_pow(COMPO.p, degKz, degK, COMPO.R);
    1423         231 :   T.invexpoteta1 = RgM_inv(p1); /* left inverse */
    1424         231 :   T.polnf = polnf;
    1425         231 :   T.tau = &tau;
    1426         231 :   T.m = m;
    1427         231 :   T.powg = Fl_powers(g, m, ell);
    1428             : 
    1429         231 :   idealz = ideallifttoKz(nfz, nf, ideal, &COMPO);
    1430         231 :   if (umodiu(gcoeff(ideal,1,1), ell)) gothf = idealz;
    1431             :   else
    1432             :   { /* ell | N(ideal) */
    1433         126 :     GEN bnrz = Buchray(bnfz, idealz, nf_INIT|nf_GEN);
    1434         126 :     GEN subgroupz = invimsubgroup(bnrz, bnr, subgroup, &T);
    1435         126 :     gothf = bnrconductor_i(bnrz,subgroupz,0);
    1436             :   }
    1437             :   /* step 9, 10, 11 */
    1438         231 :   if (DEBUGLEVEL>2) err_printf("Step 9, 10 and 11\n");
    1439         231 :   i = build_list_Hecke(&L, nfz, NULL, gothf, gell, &tau);
    1440         231 :   if (i) return no_sol(all,i);
    1441             : 
    1442         231 :   lSml2 = lg(L.Sml2);
    1443         231 :   Sp = shallowconcat(L.Sm, L.Sml1); lSp = lg(Sp);
    1444         231 :   listprSp = shallowconcat(L.Sml2, L.Sl); lSl2 = lg(listprSp);
    1445             : 
    1446             :   /* step 12 */
    1447         231 :   if (DEBUGLEVEL>2) err_printf("Step 12\n");
    1448         231 :   vecAp = cgetg(lSp, t_VEC);
    1449         231 :   vecBp = cgetg(lSp, t_VEC);
    1450         231 :   matP  = cgetg(lSp, t_MAT);
    1451             : 
    1452         385 :   for (j = 1; j < lSp; j++)
    1453             :   {
    1454             :     GEN e, a;
    1455         154 :     p1 = isprincipalell(bnfz, gel(Sp,j), cycgen,u,ell,rc);
    1456         154 :     e = gel(p1,1); gel(matP,j) = gel(p1, 1);
    1457         154 :     a = gel(p1,2);
    1458         154 :     gel(vecBp,j) = famat_mul_shallow(famat_factorbacks(vecC, zv_neg(e)), a);
    1459             :   }
    1460         231 :   vecAp = lambdaofvec(vecBp, &T);
    1461             :   /* step 13 */
    1462         231 :   if (DEBUGLEVEL>2) err_printf("Step 13\n");
    1463         231 :   vecWA = shallowconcat(vecW, vecAp);
    1464         231 :   vecWB = shallowconcat(vecW, vecBp);
    1465             : 
    1466             :   /* step 14, 15, and 17 */
    1467         231 :   if (DEBUGLEVEL>2) err_printf("Step 14, 15 and 17\n");
    1468         231 :   mginv = Fl_div(m, g, ell);
    1469         231 :   vecMsup = cgetg(lSml2,t_VEC);
    1470         231 :   M = NULL;
    1471         518 :   for (i = 1; i < lSl2; i++)
    1472             :   {
    1473         287 :     GEN pr = gel(listprSp,i);
    1474         287 :     long e = pr_get_e(pr), z = ell * (e / (ell-1));
    1475             : 
    1476         287 :     if (i < lSml2)
    1477             :     {
    1478         133 :       z += 1 - L.ESml2[i];
    1479         133 :       gel(vecMsup,i) = logall(nfz, vecWA,lW,mginv,ell, pr,z+1);
    1480             :     }
    1481         287 :     M = vconcat(M, logall(nfz, vecWA,lW,mginv,ell, pr,z));
    1482             :   }
    1483         231 :   dc = lg(Q)-1;
    1484         231 :   if (dc)
    1485             :   {
    1486         105 :     GEN QtP = Flm_mul(Flm_transpose(Q), matP, ell);
    1487         105 :     M = vconcat(M, shallowconcat(zero_Flm(dc,lW-1), QtP));
    1488             :   }
    1489         231 :   if (!M) M = zero_Flm(1, lSp-1 + lW-1);
    1490             : 
    1491         231 :   if (!all)
    1492             :   { /* primes landing in subgroup must be totally split */
    1493         217 :     GEN lambdaWB = shallowconcat(lambdaofvec(vecW, &T), vecAp);/*vecWB^lambda*/
    1494         217 :     GEN Lpr = get_prlist(bnr, subgroup, ell, bnfz);
    1495         217 :     GEN Lprz= get_przlist(Lpr, nfz, nf, &COMPO);
    1496         217 :     GEN M2 = subgroup_info(bnfz, Lprz, ell, lambdaWB);
    1497         217 :     M = vconcat(M, M2);
    1498             :   }
    1499         231 :   if (DEBUGLEVEL>2) err_printf("Step 16\n");
    1500             :   /* step 16 && 18 & ff */
    1501         231 :   res = _rnfkummer_step18(&T,bnr,subgroup,bnfz, M, vecWB, vecMsup, g, gell, lW, all);
    1502         231 :   return res? res: gen_0;
    1503             : }
    1504             : 
    1505             : GEN
    1506         490 : rnfkummer(GEN bnr, GEN subgroup, long all, long prec)
    1507             : {
    1508         490 :   pari_sp av = avma;
    1509         490 :   return gerepilecopy(av, _rnfkummer(bnr, subgroup, all, prec));
    1510             : }

Generated by: LCOV version 1.13