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 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 - modules - genus2red.c (source / functions) Hit Total Coverage
Test: PARI/GP v2.10.0 lcov report (development 21348-d75f58f) Lines: 1259 1381 91.2 %
Date: 2017-11-20 06:21:05 Functions: 51 51 100.0 %
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
      13             : #include "pari.h"
      14             : #include "paripriv.h"
      15             : 
      16             : /********************************************************************/
      17             : /**                                                                **/
      18             : /**                       IGUSA INVARIANTS                         **/
      19             : /**                       (GP2C-generated)                         **/
      20             : /**                                                                **/
      21             : /********************************************************************/
      22             : /*
      23             : j2(a0,a1,a2,a3,a4,a5,a6) = (-120*a0*a6+20*a1*a5-8*a2*a4+3*a3^2) / 4;
      24             : */
      25             : static GEN
      26        1351 : igusaj2(GEN a0, GEN a1, GEN a2, GEN a3, GEN a4, GEN a5, GEN a6)
      27             : {
      28        1351 :   pari_sp av = avma;
      29        1351 :   return gerepileupto(av, gmul2n(gadd(gsub(gadd(gmul(gmulsg(-120, a0), a6), gmul(gmulsg(20, a1), a5)), gmul(gmulsg(8, a2), a4)), gmulsg(3, gsqr(a3))), -2));
      30             : }
      31             : 
      32             : /*
      33             : j4(a0,a1,a2,a3,a4,a5,a6) = (240*(a0*a3*a4*a5+a1*a2*a3*a6)-400*(a0*a2*a5^2+a1^2*a4*a6)-64*(a0*a4^3+a2^3*a6)+16*(a1*a3*a4^2+a2^2*a3*a5)-672*a0*a3^2*a6+240*a1^2*a5^2-112*a1*a2*a4*a5-8*a1*a3^2*a5+16*a2^2*a4^2-16*a2*a3^2*a4+3*a3^4+2640*a0^2*a6^2-880*a0*a1*a5*a6+1312*a0*a2*a4*a6) / 2^7
      34             : */
      35             : static GEN
      36        1351 : igusaj4(GEN a0, GEN a1, GEN a2, GEN a3, GEN a4, GEN a5, GEN a6)
      37             : {
      38        1351 :   pari_sp av = avma;
      39        1351 :   return gerepileupto(av,
      40             : gmul2n(gadd(gsub(gadd(gadd(gsub(gadd(gsub(gsub(gadd(gsub(gadd(gsub(gsub(gmulsg(240,
      41             : gadd(gmul(gmul(gmul(a0, a3), a4), a5), gmul(gmul(gmul(a1, a2), a3), a6))),
      42             : gmulsg(400, gadd(gmul(gmul(a0, a2), gsqr(a5)), gmul(gmul(gsqr(a1), a4), a6)))),
      43             : gmulsg(64, gadd(gmul(a0, gpowgs(a4, 3)), gmul(gpowgs(a2, 3), a6)))), gmulsg(16,
      44             : gadd(gmul(gmul(a1, a3), gsqr(a4)), gmul(gmul(gsqr(a2), a3), a5)))),
      45             : gmul(gmul(gmulsg(672, a0), gsqr(a3)), a6)), gmul(gmulsg(240, gsqr(a1)),
      46             : gsqr(a5))), gmul(gmul(gmul(gmulsg(112, a1), a2), a4), a5)), gmul(gmul(gmulsg(8,
      47             : a1), gsqr(a3)), a5)), gmul(gmulsg(16, gsqr(a2)), gsqr(a4))),
      48             : gmul(gmul(gmulsg(16, a2), gsqr(a3)), a4)), gmulsg(3, gpowgs(a3, 4))),
      49             : gmul(gmulsg(2640, gsqr(a0)), gsqr(a6))), gmul(gmul(gmul(gmulsg(880, a0), a1),
      50             : a5), a6)), gmul(gmul(gmul(gmulsg(1312, a0), a2), a4), a6)), -7));
      51             : }
      52             : 
      53             : /*
      54             : j6(a0,a1,a2,a3,a4,a5,a6) = (1600*(a0^2*a4^2*a5^2+a1^2*a2^2*a6^2)+1600*(a0*a1*a2*a5^3+a1^3*a4*a5*a6)+640*(a0*a1*a3*a4*a5^2+a1^2*a2*a3*a5*a6)-4000*(a0^2*a3*a5^3+a1^3*a3*a6^2)-384*(a0*a1*a4^3*a5+a1*a2^3*a5*a6)-640*(a0*a2^2*a4*a5^2+a1^2*a2*a4^2*a6)+80*(a0*a2*a3^2*a5^2+a1^2*a3^2*a4*a6)+192*(a0*a2*a3*a4^2*a5+a1*a2^2*a3*a4*a6)-48*(a0*a3^3*a4*a5+a1*a2*a3^3*a6)-224*(a1^2*a3*a4^2*a5+a1*a2^2*a3*a5^2)+64*(a1^2*a4^4+a2^4*a5^2)-64*(a1*a2*a3*a4^3+a2^3*a3*a4*a5)+16*(a1*a3^3*a4^2+a2^2*a3^3*a5)-4096*(a0^2*a4^3*a6+a0*a2^3*a6^2)+6400*(a0^2*a2*a5^2*a6+a0*a1^2*a4*a6^2)+10560*(a0^2*a3*a4*a5*a6+a0*a1*a2*a3*a6^2)+2624*(a0*a1*a3*a4^2*a6+a0*a2^2*a3*a5*a6)-4432*a0*a1*a3^2*a5*a6-8*a2*a3^4*a4+a3^6-320*a1^3*a5^3+64*a1^2*a2*a4*a5^2+176*a1^2*a3^2*a5^2+128*a1*a2^2*a4^2*a5+112*a1*a2*a3^2*a4*a5-28*a1*a3^4*a5+16*a2^2*a3^2*a4^2+5120*a0^3*a6^3-2544*a0^2*a3^2*a6^2+312*a0*a3^4*a6-14336*a0^2*a2*a4*a6^2+1024*a0*a2^2*a4^2*a6-2560*a0^2*a1*a5*a6^2-2240*a0*a1^2*a5^2*a6-6528*a0*a1*a2*a4*a5*a6-1568*a0*a2*a3^2*a4*a6) / 2^10
      55             : */
      56             : static GEN
      57        1351 : igusaj6(GEN a0, GEN a1, GEN a2, GEN a3, GEN a4, GEN a5, GEN a6)
      58             : {
      59        1351 :   pari_sp av = avma;
      60        1351 :   return gerepileupto(av,
      61             : gmul2n(gsub(gsub(gsub(gsub(gadd(gsub(gadd(gsub(gadd(gadd(gsub(gadd(gadd(gadd(gadd(gsub(gadd(gsub(gsub(gadd(gadd(gadd(gsub(gadd(gsub(gadd(gsub(gsub(gadd(gadd(gsub(gsub(gsub(gadd(gadd(gmulsg(1600,
      62             : gadd(gmul(gmul(gsqr(a0), gsqr(a4)), gsqr(a5)), gmul(gmul(gsqr(a1), gsqr(a2)),
      63             : gsqr(a6)))), gmulsg(1600, gadd(gmul(gmul(gmul(a0, a1), a2), gpowgs(a5, 3)),
      64             : gmul(gmul(gmul(gpowgs(a1, 3), a4), a5), a6)))), gmulsg(640,
      65             : gadd(gmul(gmul(gmul(gmul(a0, a1), a3), a4), gsqr(a5)),
      66             : gmul(gmul(gmul(gmul(gsqr(a1), a2), a3), a5), a6)))), gmulsg(4000,
      67             : gadd(gmul(gmul(gsqr(a0), a3), gpowgs(a5, 3)), gmul(gmul(gpowgs(a1, 3), a3),
      68             : gsqr(a6))))), gmulsg(384, gadd(gmul(gmul(gmul(a0, a1), gpowgs(a4, 3)), a5),
      69             : gmul(gmul(gmul(a1, gpowgs(a2, 3)), a5), a6)))), gmulsg(640,
      70             : gadd(gmul(gmul(gmul(a0, gsqr(a2)), a4), gsqr(a5)), gmul(gmul(gmul(gsqr(a1),
      71             : a2), gsqr(a4)), a6)))), gmulsg(80, gadd(gmul(gmul(gmul(a0, a2), gsqr(a3)),
      72             : gsqr(a5)), gmul(gmul(gmul(gsqr(a1), gsqr(a3)), a4), a6)))), gmulsg(192,
      73             : gadd(gmul(gmul(gmul(gmul(a0, a2), a3), gsqr(a4)), a5), gmul(gmul(gmul(gmul(a1,
      74             : gsqr(a2)), a3), a4), a6)))), gmulsg(48, gadd(gmul(gmul(gmul(a0, gpowgs(a3, 3)),
      75             : a4), a5), gmul(gmul(gmul(a1, a2), gpowgs(a3, 3)), a6)))), gmulsg(224,
      76             : gadd(gmul(gmul(gmul(gsqr(a1), a3), gsqr(a4)), a5), gmul(gmul(gmul(a1,
      77             : gsqr(a2)), a3), gsqr(a5))))), gmulsg(64, gadd(gmul(gsqr(a1), gpowgs(a4, 4)),
      78             : gmul(gpowgs(a2, 4), gsqr(a5))))), gmulsg(64, gadd(gmul(gmul(gmul(a1, a2), a3),
      79             : gpowgs(a4, 3)), gmul(gmul(gmul(gpowgs(a2, 3), a3), a4), a5)))), gmulsg(16,
      80             : gadd(gmul(gmul(a1, gpowgs(a3, 3)), gsqr(a4)), gmul(gmul(gsqr(a2), gpowgs(a3,
      81             : 3)), a5)))), gmulsg(4096, gadd(gmul(gmul(gsqr(a0), gpowgs(a4, 3)), a6),
      82             : gmul(gmul(a0, gpowgs(a2, 3)), gsqr(a6))))), gmulsg(6400,
      83             : gadd(gmul(gmul(gmul(gsqr(a0), a2), gsqr(a5)), a6), gmul(gmul(gmul(a0,
      84             : gsqr(a1)), a4), gsqr(a6))))), gmulsg(10560, gadd(gmul(gmul(gmul(gmul(gsqr(a0),
      85             : a3), a4), a5), a6), gmul(gmul(gmul(gmul(a0, a1), a2), a3), gsqr(a6))))),
      86             : gmulsg(2624, gadd(gmul(gmul(gmul(gmul(a0, a1), a3), gsqr(a4)), a6),
      87             : gmul(gmul(gmul(gmul(a0, gsqr(a2)), a3), a5), a6)))),
      88             : gmul(gmul(gmul(gmul(gmulsg(4432, a0), a1), gsqr(a3)), a5), a6)),
      89             : gmul(gmul(gmulsg(8, a2), gpowgs(a3, 4)), a4)), gpowgs(a3, 6)), gmul(gmulsg(320,
      90             : gpowgs(a1, 3)), gpowgs(a5, 3))), gmul(gmul(gmul(gmulsg(64, gsqr(a1)), a2), a4),
      91             : gsqr(a5))), gmul(gmul(gmulsg(176, gsqr(a1)), gsqr(a3)), gsqr(a5))),
      92             : gmul(gmul(gmul(gmulsg(128, a1), gsqr(a2)), gsqr(a4)), a5)),
      93             : gmul(gmul(gmul(gmul(gmulsg(112, a1), a2), gsqr(a3)), a4), a5)),
      94             : gmul(gmul(gmulsg(28, a1), gpowgs(a3, 4)), a5)), gmul(gmul(gmulsg(16, gsqr(a2)),
      95             : gsqr(a3)), gsqr(a4))), gmul(gmulsg(5120, gpowgs(a0, 3)), gpowgs(a6, 3))),
      96             : gmul(gmul(gmulsg(2544, gsqr(a0)), gsqr(a3)), gsqr(a6))), gmul(gmul(gmulsg(312,
      97             : a0), gpowgs(a3, 4)), a6)), gmul(gmul(gmul(gmulsg(14336, gsqr(a0)), a2), a4),
      98             : gsqr(a6))), gmul(gmul(gmul(gmulsg(1024, a0), gsqr(a2)), gsqr(a4)), a6)),
      99             : gmul(gmul(gmul(gmulsg(2560, gsqr(a0)), a1), a5), gsqr(a6))),
     100             : gmul(gmul(gmul(gmulsg(2240, a0), gsqr(a1)), gsqr(a5)), a6)),
     101             : gmul(gmul(gmul(gmul(gmul(gmulsg(6528, a0), a1), a2), a4), a5), a6)),
     102             : gmul(gmul(gmul(gmul(gmulsg(1568, a0), a2), gsqr(a3)), a4), a6)), -10));
     103             : }
     104             : 
     105             : /********************************************************************/
     106             : /**                                                                **/
     107             : /**   A REDUCTION ALGORITHM "A LA TATE" FOR CURVES OF GENUS 2      **/
     108             : /**                                                                **/
     109             : /********************************************************************/
     110             : /* Based on genus2reduction-0.3, http://www.math.u-bordeaux.fr/~liu/G2R/
     111             :  * by Qing Liu <liu@math.u-bordeaux.fr>
     112             :  * and Henri Cohen <cohen@math.u-bordeaux.fr>
     113             : 
     114             :  * Qing Liu: Modeles minimaux des courbes de genre deux
     115             :  * J. fuer die Reine und Angew. Math., 453 (1994), 137-164.
     116             :  * http://www.math.u-bordeaux.fr/~liu/articles/modregE.ps */
     117             : 
     118             : /* some auxiliary polynomials, gp2c-generated */
     119             : 
     120             : /*
     121             : apol2(a0,a1,a2) = -5*a1^2+12*a0*a2;
     122             : */
     123             : static GEN
     124        1351 : apol2(GEN a0, GEN a1, GEN a2)
     125             : {
     126        1351 :   return gadd(gmulsg(-5, gsqr(a1)), gmul(gmulsg(12, a0), a2));
     127             : }
     128             : 
     129             : /*
     130             : apol3(a0,a1,a2,a3) = 5*a1^3+9*a0*(-2*a1*a2+3*a0*a3);
     131             : */
     132             : static GEN
     133        1351 : apol3(GEN a0, GEN a1, GEN a2, GEN a3)
     134             : {
     135        1351 :   return gadd(gmulsg(5, gpowgs(a1, 3)), gmul(gmulsg(9, a0), gadd(gmul(gmulsg(-2, a1), a2), gmul(gmulsg(3, a0), a3))));
     136             : }
     137             : 
     138             : /*
     139             : apol5(a0,a1,a2,a3,a4,a5) = a1^5+3*a0*(-2*a1^3*a2+9*a0*a1^2*a3-36*a0^2*a1*a4+108*a0^3*a5);
     140             : */
     141             : static GEN
     142        1351 : apol5(GEN a0, GEN a1, GEN a2, GEN a3, GEN a4, GEN a5)
     143             : {
     144        1351 :   return gadd(gpowgs(a1, 5), gmul(gmulsg(3, a0), gadd(gsub(gadd(gmul(gmulsg(-2, gpowgs(a1, 3)), a2), gmul(gmul(gmulsg(9, a0), gsqr(a1)), a3)), gmul(gmul(gmulsg(36, gsqr(a0)), a1), a4)), gmul(gmulsg(108, gpowgs(a0, 3)), a5))));
     145             : }
     146             : 
     147             : /*
     148             : bpol2(a0,a1,a2,a3,a4) = 2*a2^2-5*a1*a3+10*a0*a4;
     149             : */
     150             : static GEN
     151        1351 : bpol2(GEN a0, GEN a1, GEN a2, GEN a3, GEN a4)
     152             : {
     153        1351 :   return gadd(gsub(gmulsg(2, gsqr(a2)), gmul(gmulsg(5, a1), a3)), gmul(gmulsg(10, a0), a4));
     154             : }
     155             : 
     156             : static const long VERYBIG = (1L<<20);
     157             : static long
     158       50183 : myval(GEN x, GEN p) { return signe(x)? Z_pval(x,p): VERYBIG; }
     159             : static long
     160        2674 : my3val(GEN x) { return signe(x)? Z_lval(x,3): VERYBIG; }
     161             : /* largest power of p dividing pol */
     162             : static long
     163        3101 : polval(GEN pol, GEN p)
     164             : {
     165        3101 :   long v, i, lx = lg(pol);
     166        3101 :   if (!signe(pol)) return VERYBIG;
     167        3101 :   v = myval(gel(pol,2),p);
     168        3101 :   for(i = 3;i<lx;i++) v = minss(v, myval(gel(pol,i),p));
     169        3101 :   return v;
     170             : }
     171             : /* b in Z[i], return v_3(b) */
     172             : static long
     173        1337 : myval_zi(GEN b) { return minss(my3val(real_i(b)), my3val(imag_i(b))); }
     174             : /* b in Z[i, Y]/(Y^2-3), return v_Y(b) */
     175             : static long
     176         595 : myval_zi2(GEN b)
     177             : {
     178             :   long v0, v1;
     179         595 :   b = lift_shallow(b);
     180         595 :   v0 = myval_zi(RgX_coeff(b,0));
     181         595 :   v1 = myval_zi(RgX_coeff(b,1));
     182         595 :   return minss(2*v0, 2*v1+1);
     183             : }
     184             : 
     185             : /* min(a,b,c) */
     186             : static long
     187        1568 : min3(long a, long b, long c)
     188             : {
     189        1568 :   long m = a;
     190        1568 :   if (b < m) m = b;
     191        1568 :   if (c < m) m = c;
     192        1568 :   return m;
     193             : }
     194             : /* min(a,b,c) */
     195             : static GEN
     196         574 : gmin3(GEN a, GEN b, GEN c)
     197             : {
     198         574 :   GEN m = a;
     199         574 :   if (gcmp(b, m) < 0) m = b;
     200         574 :   if (gcmp(c, m) < 0) m = c;
     201         574 :   return m;
     202             : }
     203             : 
     204             : /* Vector of p-adic factors (over Q_p) to accuracy r of pol. */
     205             : static GEN
     206         119 : padicfactors(GEN pol, GEN p, long r) { return gel(factorpadic(pol,p,r),1); }
     207             : 
     208             : /* x(1/t)*t^6, deg x <= 6 */
     209             : static GEN
     210         301 : RgX_recip6(GEN x)
     211             : {
     212         301 :   long lx = lg(x), i, j;
     213         301 :   GEN y = cgetg(9, t_POL);
     214         301 :   y[1] = x[1];
     215         301 :   for (i=8,j=2; j < lx; i--,j++) gel(y,i) = gel(x,j);
     216         301 :   for (       ; j <  9; i--,j++) gel(y,i) = gen_0;
     217         301 :   return normalizepol_lg(y, 9);
     218             : }
     219             : /* extract coefficients of a polynomial a0 X^6 + ... + a6, of degree <= 6 */
     220             : static void
     221        6461 : RgX_to_6(GEN q, GEN *a0, GEN *a1, GEN *a2, GEN *a3, GEN *a4, GEN *a5, GEN *a6)
     222             : {
     223        6461 :   *a0 = gen_0;
     224        6461 :   *a1 = gen_0;
     225        6461 :   *a2 = gen_0;
     226        6461 :   *a3 = gen_0;
     227        6461 :   *a4 = gen_0;
     228        6461 :   *a5 = gen_0;
     229        6461 :   *a6 = gen_0;
     230        6461 :   switch(degpol(q))
     231             :   {
     232        4480 :     case 6: *a0 = gel(q,8); /*fall through*/
     233        6461 :     case 5: *a1 = gel(q,7); /*fall through*/
     234        6461 :     case 4: *a2 = gel(q,6); /*fall through*/
     235        6461 :     case 3: *a3 = gel(q,5); /*fall through*/
     236        6461 :     case 2: *a4 = gel(q,4); /*fall through*/
     237        6461 :     case 1: *a5 = gel(q,3); /*fall through*/
     238        6461 :     case 0: *a6 = gel(q,2); /*fall through*/
     239             :   }
     240        6461 : }
     241             : 
     242             : /* deg(H mod p) = 3, return v_p( disc(correspondig p-adic factor) ) */
     243             : static long
     244          14 : discpart(GEN H, GEN p, long prec)
     245             : {
     246             :   GEN list, prod, dis;
     247             :   long i, j;
     248             : 
     249          14 :   if (degpol(FpX_red(H,p)) != 3)
     250             :     pari_err_BUG("discpart [must not reach]"); /* LCOV_EXCL_LINE */
     251          14 :   list = padicfactors(H,p,prec);
     252          14 :   prod = pol_1(varn(H));
     253          56 :   for(i = 1; i < lg(list); i++)
     254             :   {
     255          42 :     GEN t = gel(list,i);
     256          84 :     for(j = 3; j < lg(t); j++) /* include if non-constant mod p */
     257          70 :       if (!valp(gel(t,j))) { prod = RgX_mul(prod,t); break; }
     258             :   }
     259          14 :   if (degpol(prod) != 3) pari_err_BUG("discpart [prod degree]");
     260          14 :   dis = RgX_disc(prod);
     261          14 :   return gequal0(dis)? prec+1: valp(dis);
     262             : }
     263             : 
     264             : /* B = b0 X^6 + ... + b6 a ZX, 0 <= j <= 3.
     265             :  * Return theta_j(H) := min { v_p(b_i) / (i - j), j < i <= 6 } >= 0.
     266             :  * N.B. 60 theta \in Z */
     267             : static GEN
     268        1834 : theta_j(GEN B, GEN p, long j)
     269             : {
     270        1834 :   GEN theta, b0, b1, b2, b3, b4, b5, b6, v = new_chunk(7);
     271             :   long i;
     272             : 
     273        1834 :   RgX_to_6(B, &b0,&b1,&b2,&b3,&b4,&b5,&b6);
     274        1834 :   v[0] = myval(b0,p);
     275        1834 :   v[1] = myval(b1,p);
     276        1834 :   v[2] = myval(b2,p);
     277        1834 :   v[3] = myval(b3,p);
     278        1834 :   v[4] = myval(b4,p);
     279        1834 :   v[5] = myval(b5,p);
     280        1834 :   v[6] = myval(b6,p);
     281        1834 :   theta = stoi(v[1+j]);
     282        1834 :   for(i = 2+j; i <= 6; i++) theta = gmin(theta, sstoQ(v[i], i-j));
     283        1834 :   return theta;
     284             : }
     285             : /* compute theta_3 for B in Z[i][X], p = 3 */
     286             : static GEN
     287          28 : theta_3_zi(GEN B)
     288             : {
     289          28 :   long v2 = myval_zi(RgX_coeff(B,2));
     290          28 :   long v1 = myval_zi(RgX_coeff(B,1));
     291          28 :   long v0 = myval_zi(RgX_coeff(B,0));
     292          28 :   return sstoQ(min3(6*v2, 3*v1, 2*v0), 6);
     293             : }
     294             : /* compute theta_3 for B in (Z[i,Y]/(Y^2-3))[X], p = 3 */
     295             : static GEN
     296          77 : theta_3_zi2(GEN B)
     297             : {
     298          77 :   long v2 = myval_zi2(RgX_coeff(B,2));
     299          77 :   long v1 = myval_zi2(RgX_coeff(B,1));
     300          77 :   long v0 = myval_zi2(RgX_coeff(B,0));
     301          77 :   return sstoQ(min3(6*v2, 3*v1, 2*v0), 6);
     302             : }
     303             : 
     304             : /* Set maxord to the maximal multiplicity of a factor. If there is at least
     305             :  * a triple root (=> maxord >= 3) return it, else return NULL */
     306             : static GEN
     307         728 : factmz(GEN Q, GEN p, long *maxord)
     308             : {
     309         728 :   GEN z = FpX_factor_squarefree(Q, p);
     310         728 :   long m = lg(z)-1; /* maximal multiplicity */
     311         728 :   *maxord = m;
     312         728 :   return (m >= 3)? FpX_oneroot(gel(z,m), p): NULL;
     313             : }
     314             : 
     315             : /* H integral ZX of degree 5 or 6, p > 2. Modify until
     316             :  *   y^2 = p^alpha H is minimal over Z_p, alpha = 0,1
     317             :  * Return [H,lambda,theta,alpha,quad,beta], were model
     318             :  * quad = 1 if H has a root of order 3 in F_p^2 \ F_p, 0 otherwise
     319             :  * 0 <= lambda <= 3, integer
     320             :  * theta = theta_j(H, p, lambda), 60*theta in Z.
     321             :  * beta >= 0, t_INT */
     322             : static GEN
     323        1645 : polymini(GEN H, GEN p)
     324             : {
     325        1645 :   GEN a0, a1, a2, a3, a4, a5, a6, Hp, rac, theta, polf, quad = gen_0;
     326             :   long alpha, beta, lambda, maxord;
     327             : 
     328        1645 :   alpha = polval(H,p);
     329        1645 :   if (alpha) H = ZX_Z_divexact(H, powiu(p,alpha));
     330        1645 :   RgX_to_6(H, &a0,&a1,&a2,&a3,&a4,&a5,&a6);
     331        1645 :   if (dvdii(a0,p) && dvdii(a1,p) && dvdii(a2,p) && dvdii(a3,p))
     332             :   {
     333          63 :     H = RgX_recip6(H);
     334          63 :     RgX_to_6(H, &a0,&a1,&a2,&a3,&a4,&a5,&a6);
     335             :   }
     336        1645 :   alpha &= 1;
     337        1645 :   beta = 0;
     338        1645 :   if (!dvdii(a3,p)) lambda = 3;
     339         714 :   else if (!dvdii(a2,p)) lambda = 2;
     340         539 :   else if (!dvdii(a1,p)) lambda = 1;
     341         392 :   else lambda = 0;
     342             : 
     343             :   for(;;)
     344             :   { /* lambda <= 3 */
     345        1834 :     theta = theta_j(H,p,lambda);
     346        1834 :     if (gcmp(theta,gen_1) >= 0)
     347             :     {
     348         952 :       long e = itos(gfloor(theta));
     349         952 :       GEN pe = powiu(p,e);
     350             :       /* H <- H(p^e X) / p^(e(6-lambda)) */
     351         952 :       H = ZX_Z_divexact(ZX_unscale_div(H,pe), powiu(pe,5-lambda));
     352         952 :       alpha = (alpha + lambda*e)&1;
     353         952 :       beta += e;
     354         952 :       theta = gsubgs(theta,e);
     355             :     }
     356             :     /* 0 <= theta < 1 */
     357        1834 :     Hp = FpX_red(H, p);
     358        1834 :     if (!gequal0(theta)) break;
     359             : 
     360         721 :     rac = factmz(Hp,p, &maxord);
     361         721 :     if (maxord <= 2)
     362             :     {
     363         511 :       if (degpol(Hp) <= 3) break;
     364          77 :       goto end;
     365             :     }
     366             :     else
     367             :     { /* maxord >= 3 */
     368         210 :       if (!rac) { quad = gen_1; goto end; }
     369         189 :       if (signe(rac)) H = ZX_translate(H, rac);
     370         189 :       lambda = 6-maxord;
     371             :     }
     372         189 :   }
     373             : 
     374        1547 :   if (lambda <= 2)
     375             :   {
     376        1218 :     if (myval(RgX_coeff(H,2),p) > 1-alpha &&
     377        1015 :         myval(RgX_coeff(H,1),p) > 2-alpha &&
     378         455 :         myval(RgX_coeff(H,0),p) > 3-alpha)
     379             :     {
     380          49 :       H = ZX_unscale(H, p);
     381          49 :       if (alpha) H = ZX_Z_mul(H, p);
     382          49 :       return polymini(H, p);
     383             :     }
     384             :   }
     385         889 :   else if (lambda == 3 && alpha == 1)
     386             :   {
     387         364 :     if (degpol(Hp) == 3)
     388             :     {
     389         651 :       if (myval(RgX_coeff(H,6),p) >= 3 &&
     390         322 :           myval(RgX_coeff(H,5),p) >= 2)
     391             :       {
     392         322 :         H = ZX_rescale(H, p); /* H(x/p)p^(deg H) */
     393         322 :         H = ZX_Z_divexact(H, powiu(p, degpol(H)-3)); /* H(x/p)p^3 */
     394         322 :         theta = gadd(theta,gen_1);
     395         322 :         alpha = 0;
     396         322 :         beta--;
     397             :       }
     398             :     }
     399          35 :     else if (degpol(Hp) == 6 && !gequal0(theta))
     400             :     {
     401           7 :       rac = factmz(RgX_mulXn(Hp, -3), p, &maxord);
     402           7 :       if (maxord == 3)
     403             :       {
     404           7 :         GEN t = ZX_unscale(ZX_translate(H,rac),p); /* H(rac + px) */
     405           7 :         if (polval(t,p)>= 3)
     406             :         {
     407           0 :           H = RgX_Rg_div(t, powiu(p,3));
     408           0 :           alpha = 0;
     409           0 :           beta--;
     410           0 :           theta = theta_j(H,p,3);
     411             :         }
     412             :       }
     413             :     }
     414             :   }
     415             : end:
     416        1596 :   polf = cgetg(7, t_VEC);
     417        1596 :   gel(polf,1) = H;
     418        1596 :   gel(polf,2) = stoi(lambda);
     419        1596 :   gel(polf,3) = theta;
     420        1596 :   gel(polf,4) = stoi(alpha);
     421        1596 :   gel(polf,5) = quad;
     422        1596 :   gel(polf,6) = stoi(beta);
     423        1596 :   return polf;
     424             : }
     425             : 
     426             : /* a in Q[i], return a^3 mod 3 */
     427             : static GEN
     428          14 : zi_pow3mod(GEN a)
     429             : {
     430             :   GEN x, y;
     431          14 :   if (typ(a) != t_COMPLEX) return gmodgs(a,3);
     432           7 :   x = gmodgs(gel(a,1), 3);
     433           7 :   y = gmodgs(gel(a,2), 3);
     434           7 :   return mkcomplex(x, negi(y));
     435             : }
     436             : static GEN
     437          21 : polymini_zi(GEN pol) /* polynome minimal dans Z[i] */
     438             : {
     439             :   GEN p, polh, rac, theta;
     440             :   GEN a0, a1, a2, a3, a4, a5, a6;
     441             :   long alpha,beta;
     442             : 
     443          21 :   p = stoi(3);
     444          21 :   alpha = polval(pol,p) & 1;
     445          21 :   polh = alpha? RgX_Rg_div(pol, p): pol;
     446          21 :   beta = 0;
     447          21 :   rac = mkcomplex(Fp_div(RgX_coeff(polh,3), RgX_coeff(polh,6), p), gen_1);
     448             :   for(;;)
     449             :   {
     450          28 :     polh = RgX_translate(polh, rac);
     451          28 :     theta = theta_3_zi(polh);
     452          28 :     if (gcmp(theta,gen_1) >= 0)
     453             :     {
     454          14 :       long ent = itos(gfloor(theta));
     455          14 :       GEN pent = powiu(p,ent);
     456          14 :       polh = RgX_Rg_div(RgX_unscale(polh,pent), powiu(pent,3));
     457          14 :       alpha = (alpha+ent)&1;
     458          14 :       beta += ent;
     459          14 :       theta = gsubgs(theta,ent);
     460             :     }
     461          28 :     RgX_to_6(polh, &a0,&a1,&a2,&a3,&a4,&a5,&a6);
     462          28 :     if (!gequal0(theta) || !myval_zi(a4) || !myval_zi(a5)) break;
     463           7 :     rac = zi_pow3mod(gdiv(a6, gneg(a3)));
     464           7 :   }
     465          21 :   if (alpha && myval_zi(a0) >= 3 && myval_zi(a1) >= 2 && myval_zi(a2) >= 1)
     466             :   {
     467          14 :     theta = gadd(theta, gen_1);
     468          14 :     beta--;
     469          14 :     alpha = 0;
     470             :   }
     471          21 :   return mkvec3(theta, stoi(alpha), stoi(beta));
     472             : }
     473             : 
     474             : /* pol is a ZX, minimal polynomial over Z_3[i,Y]/(Y^2-3) */
     475             : static GEN
     476          77 : polymini_zi2(GEN pol)
     477             : {
     478             :   long alpha, beta;
     479             :   GEN a0, a1, a2, a3, a4, a5, a6;
     480          77 :   GEN p, polh, rac, theta, y = pol_x(fetch_var());
     481             : 
     482          77 :   p = stoi(3);
     483          77 :   if (polval(pol,p)) pari_err_BUG("polymini_zi2 [polynomial not minimal]");
     484          77 :   y = mkpolmod(y, gsubgs(gsqr(y), 3)); /* mod(y,y^2-3) */
     485          77 :   polh = pol;
     486          77 :   polh = gdivgs(RgX_unscale(polh, y),27); /* H(y*x) / 27 */
     487         147 :   if (myval_zi2(RgX_coeff(polh,4)) <= 0 ||
     488          70 :       myval_zi2(RgX_coeff(polh,2)) <= 0)
     489             :   {
     490           7 :     (void)delete_var();
     491           7 :     return mkcol2(gen_0, gen_0);
     492             :   }
     493             : 
     494          70 :   if (myval_zi2(gsub(RgX_coeff(polh,6), RgX_coeff(polh,0))) > 0)
     495           0 :     rac = gen_I();
     496             :   else
     497          70 :     rac = gen_1;
     498          70 :   alpha = 0;
     499          70 :   beta  = 0;
     500             :   for(;;)
     501             :   {
     502          77 :     polh = RgX_translate(polh, rac);
     503          77 :     theta = theta_3_zi2(polh);
     504          77 :     if (gcmp(theta,gen_1) >= 0)
     505             :     {
     506          70 :       long ent = itos(gfloor(theta));
     507          70 :       GEN pent = gpowgs(y, ent);
     508          70 :       polh = RgX_Rg_div(RgX_unscale(polh, pent), gpowgs(pent,3));
     509          70 :       alpha = (alpha+ent)&1;
     510          70 :       beta += ent;
     511          70 :       theta = gsubgs(theta,ent);
     512             :     }
     513          77 :     RgX_to_6(polh, &a0,&a1,&a2,&a3,&a4,&a5,&a6);
     514          77 :     if (!gequal0(theta) || !myval_zi2(a4) || !myval_zi2(a5)) break;
     515           7 :     a3 = liftpol_shallow(a3); if (typ(a3)==t_POL) a3 = RgX_coeff(a3,0);
     516           7 :     a6 = liftpol_shallow(a6); if (typ(a6)==t_POL) a6 = RgX_coeff(a6,0);
     517           7 :     rac = zi_pow3mod(gdiv(a6,gneg(a3)));
     518           7 :   }
     519          70 :   if (alpha)
     520             :   {
     521          35 :     if (myval_zi2(a0) >= 3 && myval_zi2(a1) >= 2 && myval_zi2(a2) >= 1)
     522             :     {
     523          35 :       theta = gadd(theta,gen_1);
     524          35 :       beta--;
     525          35 :       alpha = 0;
     526             :     }
     527           0 :     else pari_err_BUG("polymini_zi2 [alpha]");
     528             :   }
     529          70 :   (void)delete_var();
     530          70 :   return mkcol2(theta, stoi(beta));
     531             : }
     532             : 
     533             : 
     534             : struct igusa {
     535             :   GEN j2, i4, j4, j6, j8, j10, i12;
     536             :   GEN a0, A2, A3, A5, B2;
     537             : };
     538             : struct igusa_p {
     539             :   long eps, eps2, tt, r1, r2, R, tame;
     540             :   GEN p, stable, val, neron;
     541             :   const char *type;
     542             : };
     543             : 
     544             : static void
     545        1372 : stable_reduction(struct igusa *I, struct igusa_p *Ip)
     546             : {
     547             :   static const long deg[9] = { 0,2,4,4,6,8,10,12 };
     548        1372 :   GEN j2 = I->j2, i4 = I->i4, j6 = I->j6, j8 = I->j8, j10 = I->j10;
     549        1372 :   GEN i12 = I->i12, p = Ip->p, val = Ip->val;
     550             :   GEN J, v, s, Ieps;
     551             :   long r1, r2, r3, r4, i, eps, eps2;
     552             : 
     553        1372 :   v = cgetg(8,t_COL);
     554        1372 :   for(i = 1; i <= 7; i++) gel(v,i) = sstoQ(val[i], deg[i]);
     555        1372 :   s = gel(v,1);
     556        9604 :   for(i = 2; i <= 7; i++)
     557        8232 :     if (gcmp(gel(v,i),s) < 0) s = gel(v,i);
     558        1372 :   switch(itos_or_0(p))
     559             :   {
     560          14 :     case 2:  eps = 4; eps2 = 5; Ieps = j8; break;
     561         434 :     case 3:  eps = 3; eps2 = 4; Ieps = j6; break;
     562         924 :     default: eps = 1; eps2 = 1; Ieps = gdivgs(j2,12); break;
     563             :   }
     564        1372 :   Ip->eps  = eps;
     565        1372 :   Ip->eps2 = eps2;
     566             : 
     567        1372 :   r1 = 3*eps*val[3];
     568        1372 :   r3 = eps*val[6] + val[eps2];
     569        1372 :   r2 = eps*val[7];
     570        1372 :   r4 = min3(r1, r2, r3);
     571             : 
     572             :   /* s = max(v_p(X) / deg(X)) */
     573        1372 :   J = cgetg(1, t_VEC);
     574        1372 :   if (gequal(s,gel(v,6)))
     575         133 :     Ip->tt = 1;
     576        1239 :   else if (gequal(s,gel(v,7)))
     577             :   {
     578         105 :     J = mkvec( Fp_to_mod(gmod(gdiv(gpowgs(i4,3),i12), p), p) );
     579         105 :     Ip->tt = 2;
     580             :   }
     581        1134 :   else if (gequal(s,gel(v,3)))
     582         210 :     Ip->tt = (val[2] == val[3] || 2*val[4] == 3*val[3])? 3: 4;
     583         924 :   else if (r3 == r4)
     584             :   {
     585         532 :     GEN a,b, P, sj, pj, t = gmul(gpowgs(j10,eps),Ieps);
     586         532 :     sj = gaddsg(1728, gdiv(gpowgs(i12,eps), t));
     587         532 :     pj = gdiv(gpowgs(i4,3*eps), t);
     588         532 :     a = gmod(sj, p);
     589         532 :     b = gmod(pj, p);
     590         532 :     P = mkpoln(3, gen_1, Fp_neg(a,p), b, 0); /* X^2 - SX + P: roots j1,j2 */
     591         532 :     J = FpX_roots(P, p);
     592         532 :     switch(lg(J)-1)
     593             :     {
     594             :       case 0:
     595           0 :         P = FpX_to_mod(P, p);
     596           0 :         a = FpX_to_mod(pol_x(0), p);
     597           0 :         b = FpX_to_mod(deg1pol_shallow(b, gen_m1,0), p);
     598           0 :         J = mkvec2(mkpolmod(a,P), mkpolmod(b,P)); break;
     599             :       case 1:
     600         350 :         a = Fp_to_mod(gel(J,1), p);
     601         350 :         J = mkvec2(a, a); break;
     602             :       case 2:
     603         182 :         settyp(J, t_VEC);
     604         182 :         J = FpV_to_mod(J, p); break;
     605             :     }
     606         532 :     Ip->tt = 5;
     607             :   }
     608         392 :   else if (r2 == r4)
     609             :   {
     610         280 :     J = mkvec( Fp_to_mod(gmod(gdiv(gpowgs(i4,3),i12), p), p) );
     611         280 :     Ip->tt = 6;
     612             :   }
     613             :   else
     614         112 :     Ip->tt = 7; /* r1 == r4 */
     615        1372 :   Ip->stable = mkvec2(stoi(Ip->tt), J);
     616        1372 : }
     617             : 
     618             : struct red {
     619             :   const char *t, *pages;
     620             :   double tnum;
     621             :   GEN g;
     622             : };
     623             : 
     624             : /* destroy v */
     625             : static GEN
     626        1358 : zv_snf(GEN v)
     627             : {
     628        1358 :   long i, l = lg(v);
     629        2989 :   for (i = 1; i < l; i++)
     630             :   {
     631        1631 :     long j, a = v[i];
     632        2331 :     for (j = i+1; j < l; j++)
     633             :     {
     634         700 :       long b = v[j], d = ugcd(a,b);
     635         700 :       v[i] = a = a*(b/d);
     636         700 :       v[j] = d;
     637             :     }
     638             :   }
     639        1442 :   for (i = l-1; i > 0; i--)
     640        1155 :     if (v[i] != 1) { setlg(v, i+1); break; }
     641        1358 :   return zv_to_ZV(v);
     642             : }
     643             : 
     644             : static GEN
     645        1274 : cyclic(long n)
     646        1274 : { return (n <= 1)? cgetg(1, t_VECSMALL): mkvecsmall(n); }
     647             : static GEN
     648         329 : dicyclic(long a, long b)
     649             : {
     650             :   long d;
     651         329 :   if (!a) a = 1;
     652         329 :   if (!b) b = 1;
     653         329 :   if (a < b) lswap(a,b);
     654         329 :   d = ugcd(a,b);
     655         329 :   if (d == 1) return cyclic(a*b);
     656         273 :   return mkvecsmall2(a*b/d, d);
     657             : }
     658             : /* Z/2xZ/2, resp Z/4 for n even, resp. odd */
     659             : static GEN
     660         280 : groupH(long n) { return odd(n)? cyclic(4): dicyclic(2,2); }
     661             : 
     662             : static long
     663         210 : get_red(struct red *S, struct igusa_p *Ip, GEN polh, GEN p, long alpha, long r)
     664             : {
     665         210 :   GEN val = Ip->val;
     666             :   long indice;
     667         210 :   switch(r)
     668             :   {
     669             :     case 0:
     670          84 :       indice = FpX_is_squarefree(FpX_red(polh,p), p)
     671             :                ? 0
     672          42 :                : val[6] - val[7] + val[Ip->eps2]/Ip->eps;
     673          42 :       S->t = stack_sprintf("I{%ld}", indice);
     674          42 :       S->tnum = 1;
     675          42 :       S->pages = "159-177";
     676          42 :       S->g = cyclic(indice);
     677          42 :       return indice ? indice: 1;
     678             :     case 6:
     679          35 :       if (alpha == 0) /* H(px) /p^3 */
     680          28 :         polh = ZX_Z_divexact(ZX_unscale_div(polh,p), sqri(p));
     681          70 :       indice = FpX_is_squarefree(FpX_red(polh,p), p)
     682             :                ? 0
     683          35 :                : val[6] - val[7] + val[Ip->eps2]/Ip->eps;
     684          35 :       S->t = stack_sprintf("I*{%ld}", indice);
     685          35 :       S->tnum = 1.5;
     686          35 :       S->pages = "159-177";
     687          35 :       S->g = groupH(indice);
     688          35 :       return indice + 5;
     689             :     case 3:
     690          21 :       S->t = "III";
     691          21 :       S->tnum = 3;
     692          21 :       S->pages = "161-177";
     693          21 :       S->g = cyclic(2);
     694          21 :       return 2;
     695             :     case 9:
     696          21 :       S->t = "III*";
     697          21 :       S->tnum = 3.5;
     698          21 :       S->pages = "162-177";
     699          21 :       S->g = cyclic(2);
     700          21 :       return 8;
     701             :     case 2:
     702          21 :       S->t = "II";
     703          21 :       S->tnum = 2;
     704          21 :       S->pages = "159-174";
     705          21 :       S->g = cyclic(1);
     706          21 :       return 1;
     707             :     case 8:
     708          35 :       S->t = "IV*";
     709          35 :       S->tnum = 4.5;
     710          35 :       S->pages = "160-175";
     711          35 :       S->g = cyclic(3);
     712          35 :       return 7;
     713             :     case 4:
     714          21 :       S->t = "IV";
     715          21 :       S->tnum = 4;
     716          21 :       S->pages = "160-174";
     717          21 :       S->g = cyclic(3);
     718          21 :       return 3;
     719             :     case 10:
     720          14 :       S->t = "II*";
     721          14 :       S->tnum = 2.5;
     722          14 :       S->pages = "160-174";
     723          14 :       S->g = cyclic(1);
     724          14 :       return 9;
     725           0 :     default: pari_err_BUG("get_red [type]");
     726           0 :       S->t = "";
     727           0 :       S->tnum = 0;
     728           0 :       S->pages = ""; /* gcc -Wall */
     729           0 :       S->g = NULL;
     730             :       return -1; /*LCOV_EXCL_LINE*/
     731             :   }
     732             : }
     733             : 
     734             : static long labelm3(GEN polh, GEN theta, long alpha, long Dmin, struct igusa *I, struct igusa_p *Ip);
     735             : 
     736             : /* Ip->tt = 1 */
     737             : static long
     738          21 : tame_1(struct igusa *I, struct igusa_p *Ip)
     739             : {
     740          21 :   GEN p = Ip->p, val = Ip->val;
     741             :   GEN r, n, pro1, pro2;
     742          21 :   long condp = -1, va0, va5;
     743          21 :   va0 = myval(I->a0,p);
     744          21 :   va5 = myval(I->A5,p);
     745          21 :   if (!gequal0(I->A5) && 20*va0+val[6] > 6*va5)
     746             :   {
     747          14 :     pro1 = sstoQ(val[6]-2*va5, 20);
     748          14 :     pro2 = sstoQ(5*val[6]-6*va5, 40);
     749             :   }
     750             :   else
     751             :   {
     752           7 :     pro1 = sstoQ(10*va0-val[6], 30);
     753           7 :     pro2 = sstoQ(5*va0-val[6], 10);
     754             :   }
     755          21 :   n = lcmii(denom(pro1),denom(pro2));
     756          21 :   r = modii(gmul(n,pro1), n);
     757          21 :   switch(itos(n))
     758             :   {
     759             :     case 1:
     760           0 :       condp = 0;
     761           0 :       Ip->type = "[I{0-0-0}] page 155";
     762           0 :       Ip->neron = cyclic(1); break;
     763             :     case 2:
     764          14 :       switch(itos(r))
     765             :       {
     766             :         case 0:
     767           7 :           condp = 4;
     768           7 :           Ip->type = "[I*{0-0-0}] page 155";
     769           7 :           Ip->neron = mkvecsmall4(2,2,2,2); break;
     770             :         case 1:
     771           7 :           condp = 2;
     772           7 :           Ip->type = "[II] page 155";
     773           7 :           Ip->neron = cyclic(1); break;
     774           0 :         default: pari_err_BUG("tame_1 [bug1]");
     775             :       }
     776          14 :       break;
     777             :     case 4:
     778           7 :       condp = 4;
     779           7 :       Ip->type = "[VI] page 156";
     780           7 :       Ip->neron = dicyclic(2,2); break;
     781           0 :     default: pari_err_BUG("tame_1 [bug8]");
     782             :   }
     783          21 :   return condp;
     784             : }
     785             : 
     786             : static void
     787         203 : tame_234_init(struct igusa *I, struct igusa_p *Ip, long v12,
     788             :                 long *pn, long *pq, long *pr, long *flc)
     789             : {
     790             :   long va0, va5, vb2;
     791         203 :   GEN p = Ip->p, pro1, pro2, n, r, q;
     792         203 :   va0 = myval(I->a0,p);
     793         203 :   va5 = myval(I->A5,p);
     794         203 :   vb2 = myval(I->B2,p);
     795         203 :   if (9*vb2 >= 6*va0+v12 && 36*va5 >= 120*va0+5*v12)
     796             :   {
     797          42 :     pro1 = sstoQ(12*va0-v12, 36);
     798          42 :     pro2 = sstoQ(6*va0-v12, 12);
     799          42 :     n = lcmii(denom(pro1),denom(pro2));
     800          42 :     r = gmul(n,pro1);
     801          42 :     q = gmul(n,pro2);
     802          42 :     *flc = 1;
     803             :   }
     804         161 :   else if (120*va0+5*v12 > 36*va5 && 60*vb2 >= 12*va5+5*v12)
     805             :   {
     806          49 :     pro1 = sstoQ(36*va5-25*v12, 240);
     807          49 :     n = denom(pro1);
     808          49 :     q = gmul(n,pro1);
     809          49 :     r = gmulsg(-2,q);
     810          49 :     *flc = 1;
     811             :   }
     812         112 :   else if (6*va0+v12 > 9*vb2 && 12*va5+5*v12 > 60*vb2)
     813             :   {
     814         112 :     pro1 = sstoQ(v12-6*vb2, 12);
     815         112 :     pro2 = sstoQ(v12-9*vb2, 12);
     816         112 :     n = lcmii(denom(pro1),denom(pro2));
     817         112 :     r = gmul(n,pro1);
     818         112 :     q = gmul(n,pro2);
     819         112 :     *flc = 2;
     820             :   }
     821             :   else
     822             :   {
     823           0 :     pari_err_BUG("tame234 [bug9]");
     824             :     return; /*LCOV_EXCL_LINE*/
     825             :   }
     826         203 :   r = gmod(r,n);
     827         203 :   q = gmod(q,n);
     828         203 :   *pn = itos(n);
     829         203 :   *pq = itos(q);
     830         203 :   *pr = itos(r);
     831             : }
     832             : 
     833             : /* Ip->tt = 2 */
     834             : static long
     835          91 : tame_2(struct igusa *I, struct igusa_p *Ip, long v12)
     836             : {
     837          91 :   long condp = -1, d, n, q, r, flc;
     838          91 :   GEN val = Ip->val;
     839          91 :   tame_234_init(I, Ip, v12, &n, &q, &r, &flc);
     840          91 :   d = n * (6*val[6]-5*val[7]) / 6;
     841          91 :   switch(n)
     842             :   {
     843           7 :     case 1: condp = 1;
     844           7 :       Ip->type = stack_sprintf("[I{%ld-0-0}] page 170", d);
     845           7 :       Ip->neron = cyclic(d); break;
     846             :     case 2:
     847          21 :       switch(r)
     848             :       {
     849           7 :         case 0: condp = 4;
     850           7 :           Ip->type = stack_sprintf("[I*{%ld-0-0}] page 171",d/2);
     851           7 :           Ip->neron = shallowconcat(dicyclic(2,2),groupH(d/2)); break;
     852             :         case 1:
     853          14 :           switch(q)
     854             :           {
     855           7 :             case 0: condp = 2;
     856           7 :               Ip->type = stack_sprintf("[II*{%ld-0}] page 172",d/2);
     857           7 :               Ip->neron = cyclic(1); break;
     858           7 :             case 1: condp = 3;
     859           7 :               Ip->type = stack_sprintf("[II{%ld-0}] page 171",d/2);
     860           7 :               Ip->neron = cyclic(2*d); break;
     861           0 :             default: pari_err_BUG("tame2 [bug10]");
     862             :           }
     863          14 :           break;
     864           0 :         default: pari_err_BUG("tame2 [bug11]");
     865             :       }
     866          21 :       break;
     867          14 :     case 3: condp = 3;
     868          14 :       Ip->neron = cyclic(d);
     869          14 :       switch(r)
     870             :       {
     871             :         case 1:
     872           7 :           Ip->type = stack_sprintf("[II{%ld}-IV] page 175", (d-2)/3);
     873           7 :           break;
     874             :         case 2:
     875           7 :           Ip->type = stack_sprintf("[II{%ld}-IV*] page 175", (d-1)/3);
     876           7 :           break;
     877           0 :         default: pari_err_BUG("tame2 [bug12]");
     878             :       }
     879          14 :       break;
     880             :     case 4:
     881          42 :       switch(r)
     882             :       {
     883             :         case 1:
     884          21 :           switch(q)
     885             :           {
     886          14 :             case 1: condp = 3;
     887          14 :               Ip->type = stack_sprintf("[II{%ld}-III] page 177",(d-2)/4);
     888          14 :               Ip->neron = cyclic(d/2); break;
     889           7 :             case 3: condp = 4;
     890           7 :               Ip->type = stack_sprintf("[II*{%ld}-III*] page 178",(d-2)/4);
     891           7 :               Ip->neron = cyclic(8); break;
     892           0 :             default: pari_err_BUG("tame2 [bug13]");
     893             :           }
     894          21 :           break;
     895             :         case 3:
     896          21 :           switch(q)
     897             :           {
     898           7 :             case 1: condp = 4;
     899           7 :               Ip->type = stack_sprintf("[II*{%ld}-III] page 178",(d-2)/4);
     900           7 :               Ip->neron = cyclic(8); break;
     901          14 :             case 3: condp = 3;
     902          14 :               Ip->type = stack_sprintf("[II{%ld}-III*] page 178",(d-2)/4);
     903          14 :               Ip->neron = cyclic(d/2); break;
     904           0 :             default: pari_err_BUG("tame2 [bug14]");
     905             :           }
     906          21 :           break;
     907           0 :         default: pari_err_BUG("tame2 [bug15]");
     908             :       }
     909          42 :       break;
     910             :     case 6:
     911           7 :       switch(r)
     912             :       {
     913           7 :         case 2: condp = 4;
     914           7 :           Ip->type = stack_sprintf("[II*-II*{%ld}] page 176", (d-4)/6);
     915           7 :           Ip->neron = groupH((d+2)/6); break;
     916           0 :         case 4: condp = 4;
     917           0 :           Ip->type = stack_sprintf("[II-II*{%ld}] page 176", (d-2)/6);
     918           0 :           Ip->neron = groupH((d+4)/6); break;
     919           0 :         default: pari_err_BUG("tame2 [bug16]");
     920             :       }
     921           7 :       break;
     922           0 :     default: pari_err_BUG("tame2 [bug17]");
     923             :   }
     924          91 :   return condp;
     925             : }
     926             : 
     927             : /* Ip->tt = 3 */
     928             : static long
     929          56 : tame_3(struct igusa *I, struct igusa_p *Ip, long v12)
     930             : {
     931          56 :   long condp = -1, n, q, r, flc;
     932             :   long va5, d1, d2;
     933          56 :   GEN val = Ip->val, e1, e2;
     934          56 :   tame_234_init(I, Ip, v12, &n, &q, &r, &flc);
     935             : 
     936          56 :   va5 = 2*val[6]-5*val[3];
     937          56 :   e1 = gmin(stoi(val[7]-3*val[3]),gmul2n(stoi(va5),-2));
     938          56 :   e2 = gsub(gmul2n(stoi(va5),-1),e1);
     939          56 :   d1 = itos(gmulsg(n,e1));
     940          56 :   d2 = itos(gmulsg(n,e2));
     941          56 :   switch(n)
     942             :   {
     943          14 :     case 1: condp = 2;
     944          14 :       Ip->type = stack_sprintf("[I{%ld-%ld-0}] page 179", d1,d2);
     945          14 :       Ip->neron = dicyclic(d1,d2); break;
     946             :     case 2:
     947          28 :       switch(r)
     948             :       {
     949          14 :         case 0: condp = 4;
     950          14 :           Ip->type = stack_sprintf("[I*{%ld-%ld-0}] page 180", d1/2,d2/2);
     951          14 :           Ip->neron = shallowconcat(groupH(d1/2),groupH(d2/2)); break;
     952             :         case 1:
     953          14 :           switch(flc)
     954             :           {
     955          14 :             case 1:condp = 3;
     956          14 :               Ip->type = stack_sprintf("[2I{%ld}-0] page 181", d1);
     957          14 :               Ip->neron = cyclic(d1); break;
     958           0 :             case 2: condp = 3;
     959           0 :               Ip->type = stack_sprintf("[II{%ld-%ld}] page 182",d1/2,d2/2);
     960           0 :               if ((d1*d2-4)&7)
     961           0 :                 Ip->neron = cyclic(2*d1);
     962             :               else
     963           0 :                 Ip->neron = dicyclic(d1,2);
     964             :               /* FIXME: "or" same with d1<->d2 */
     965           0 :               break;
     966             :           }
     967          14 :           break;
     968           0 :         default: pari_err_BUG("tame3 [bug20]");
     969             :       }
     970          28 :       break;
     971          14 :     case 4: condp = 4;
     972          14 :       Ip->type = stack_sprintf("[III{%ld}] page 182", d1/2);
     973          14 :       Ip->neron = groupH(d1/2); break;
     974           0 :     default: pari_err_BUG("tame3 [bug21]");
     975             :   }
     976          56 :   return condp;
     977             : }
     978             : 
     979             : /* Ip->tt = 4 */
     980             : static long
     981          56 : tame_4(struct igusa *I, struct igusa_p *Ip, long v12)
     982             : {
     983          56 :   long condp = -1, d1, d2, d3, f1, f2, g, h, n, q, r, flc;
     984          56 :   GEN val = Ip->val, e1, e2, e3, vl, vn, vm;
     985          56 :   tame_234_init(I, Ip, v12, &n, &q, &r, &flc);
     986          56 :   vl = stoi(val[6]-5*val[1]);
     987          56 :   vn = stoi(val[7]-6*val[1]);
     988          56 :   vm = stoi(val[2]-2*val[1]);
     989          56 :   e1 = gmin3(gdivgs(vl,3), gmul2n(vn,-1), vm);
     990          56 :   e2 = gmin(gmul2n(gsub(vl,e1),-1), gsub(vn,e1));
     991          56 :   e3 = gsub(vl,gadd(e1,e2));
     992          56 :   d1 = itos(gmulsg(n,e1));
     993          56 :   d2 = itos(gmulsg(n,e2));
     994          56 :   d3 = itos(gmulsg(n,e3));
     995          56 :   g = d1*d2 + d1*d3 + d2*d3;
     996          56 :   h = cgcd(cgcd(d1,d2),d3);
     997          56 :   switch(n)
     998             :   {
     999           7 :     case 1: condp = 2;
    1000           7 :       Ip->type = stack_sprintf("[I{%ld-%ld-%ld}] page 182",d1,d2,d3);
    1001           7 :       Ip->neron = dicyclic(h,g/h); break;
    1002             :     case 2:
    1003          49 :       switch(r)
    1004             :       {
    1005           7 :         case 0: condp = 4;
    1006           7 :           Ip->type = stack_sprintf("[I*{%ld-%ld-%ld}] page 183",d1/2,d2/2,d3/2);
    1007           7 :           Ip->neron = shallowconcat(groupH(g/4), groupH(2-((h&2)>>1))); break;
    1008             :         case 1:
    1009          42 :           if      (d1 == d2 || d1 == d3) f2 = d1;
    1010           0 :           else if (d2 == d3) f2 = d2;
    1011             :           else {
    1012           0 :             pari_err_BUG("tame4 [bug23]");
    1013             :             return -1; /*LCOV_EXCL_LINE*/
    1014             :           }
    1015          42 :           f1 = d1+d2+d3-2*f2;
    1016          42 :           switch(q)
    1017             :           {
    1018          14 :             case 0: condp = 3;
    1019          14 :               Ip->type = stack_sprintf("[II*{%ld-%ld}] page 184", f1/2,f2);
    1020          14 :               Ip->neron = cyclic(f2); break;
    1021          28 :             case 1: condp = 3;
    1022          28 :               Ip->type = stack_sprintf("[II{%ld-%ld}] page 183", f1/2,f2);
    1023          28 :               Ip->neron = cyclic(2*f1+f2); break;
    1024           0 :             default: pari_err_BUG("tame4 [bug24]");
    1025             :           }
    1026          42 :           break;
    1027           0 :         default: pari_err_BUG("tame4 [bug25]");
    1028             :       }
    1029          49 :       break;
    1030           0 :     case 3: condp = 4;
    1031           0 :       Ip->type = stack_sprintf("[III{%ld}] page 184",d1);
    1032           0 :       Ip->neron = (d1%3)? cyclic(9): dicyclic(3,3); break;
    1033           0 :     case 6: condp = 4;
    1034           0 :       Ip->type = stack_sprintf("[III*{%ld}] page 184",d1/2);
    1035           0 :       Ip->neron = cyclic(1); break;
    1036           0 :     default: pari_err_BUG("tame4 [bug26]");
    1037             :   }
    1038          56 :   return condp;
    1039             : }
    1040             : 
    1041             : /* p = 3 */
    1042             : static void
    1043          91 : tame_567_init_3(struct igusa_p *Ip, GEN dk,
    1044             :                 long *pd, long *pn, long *pdm, long *pr)
    1045             : {
    1046          91 :   long n = 1 + Ip->r1/6;
    1047          91 :   *pd = itos(gmulgs(dk,n));
    1048          91 :   *pn = n;
    1049          91 :   *pr = -1; /* unused */
    1050          91 :   *pdm = 0;
    1051          91 : }
    1052             : 
    1053             : static void
    1054         609 : tame_567_init(struct igusa *I, struct igusa_p *Ip, GEN dk,
    1055             :               long *pd, long *pn, long *pdm, long *pr)
    1056             : {
    1057             :   long va0, va2, va3, va5, vb2;
    1058             :   long d, v1, v2;
    1059             :   GEN r, n, m;
    1060             :   GEN pro1, dm, rk;
    1061         609 :   GEN p = Ip->p, val = Ip->val;
    1062             :   long v5;
    1063             : 
    1064         609 :   if (equalis(p, 3)) { tame_567_init_3(Ip, dk, pd, pn, pdm, pr); return; }
    1065             :   /* assume p > 3 */
    1066         518 :   va0 = myval(I->a0,p);
    1067         518 :   va2 = myval(I->A2,p);
    1068         518 :   va3 = myval(I->A3,p);
    1069         518 :   va5 = myval(I->A5,p);
    1070         518 :   vb2 = myval(I->B2,p);
    1071         518 :   v5 = myval(subii(mulii(I->A2,I->A3),mulsi(3,I->A5)),p);
    1072        1036 :   rk = gadd(sstoQ(va0, 2),
    1073             :             gmin3(gmul2n(dk,-1),
    1074         518 :                   sstoQ(2*va3-3*va2, 8),
    1075         518 :                   sstoQ(2*v5 - 5*va2, 12)));
    1076         518 :   v1 = 2*va3-4*va0-val[1];
    1077         518 :   v2 = 6*va5-20*va0-5*val[1];
    1078             :   /* the definition of n differs according to the parity of val[1] */
    1079         518 :   if (! odd(val[Ip->eps2]))
    1080             :   {
    1081         427 :     if (3*vb2 >= 2*va0+2*val[1] && v1 >= 0 && v2 >= 0
    1082         245 :                                 && (v1 == 0 || v2 == 0))
    1083             :     { /* Prop 4.3.1 (a) */
    1084          14 :       pro1 = sstoQ(va0+val[1], 6);
    1085          14 :       n = lcmii(denom(dk),denom(pro1));
    1086          14 :       r = gmul(n,pro1);
    1087             :     }
    1088         413 :     else if (20*va0+5*val[1] > 6*va5 && 10*vb2 >= 2*va5+5*val[1])
    1089             :     { /* Prop 4.3.1 (b) */
    1090         182 :       pro1 = sstoQ(2*va5+val[1], 8);
    1091         182 :       n = lcmii(denom(dk),denom(pro1));
    1092         182 :       r = gmul(n,pro1);
    1093             :     }
    1094         231 :     else if (2*va0+2*val[1] > 3*vb2 && 2*va5+5*val[1] > 10*vb2)
    1095             :     { /* Prop 4.3.1 (c) */
    1096           0 :       pro1 = gmul2n(stoi(vb2),-2);
    1097           0 :       n = lcmii(denom(dk),denom(pro1));
    1098           0 :       r = gmul(n,pro1);
    1099             :     }
    1100         231 :     else if (3*vb2 >= 2*va0+2*val[1] && 2*va3 > 4*va0+val[1]
    1101         231 :                                      && 6*va5 > 20*va0+5*val[1])
    1102             :     { /* Prop 4.3.1 (d) */
    1103         231 :       if (gequal0(I->A2)) pari_err_BUG("tame567 [bug27]");
    1104         231 :       n = lcmii(denom(dk),denom(rk));
    1105         231 :       r = gmul(n,rk);
    1106             :     }
    1107             :     else
    1108             :     {
    1109           0 :       pari_err_BUG("tame567 [bug29]");
    1110             :       return; /*LCOV_EXCL_LINE*/
    1111             :     }
    1112             :   }
    1113             :   else
    1114             :   {
    1115          91 :     m = denom(dk);
    1116          91 :     r = gmul(m,dk);
    1117          91 :     n = gmul2n(m,1);
    1118             :   }
    1119         518 :   d = itos(gmul(n,dk));
    1120         518 :   dm = modsi(d,n);
    1121         518 :   r = modii(r,n);
    1122         518 :   *pd = d;
    1123         518 :   *pn = itos(n);
    1124         518 :   *pr = itos(r);
    1125         518 :   *pdm = itos(dm);
    1126             : }
    1127             : 
    1128             : static long
    1129         329 : tame_5(struct igusa *I, struct igusa_p *Ip, GEN dk)
    1130             : {
    1131         329 :   long condp = -1, d, n, dm, r;
    1132         329 :   GEN val = Ip->val;
    1133             : 
    1134         329 :   tame_567_init(I, Ip, dk, &d, &n, &dm, &r);
    1135         329 :   if (! odd(val[Ip->eps2]))
    1136             :   {
    1137         266 :     switch(n)
    1138             :     {
    1139           7 :       case 1: condp = 0;
    1140           7 :         Ip->type = stack_sprintf("[I{0}-I{0}-%ld] page 158", d);
    1141           7 :         Ip->neron = cyclic(1); break;
    1142             :       case 2:
    1143          14 :         switch(dm)
    1144             :         {
    1145           7 :           case 0: condp = 4;
    1146           7 :             Ip->type = stack_sprintf("[I*{0}-I*{0}-%ld] page 158",(d-2)/2);
    1147           7 :             Ip->neron = mkvecsmall4(2,2,2,2); break;
    1148           7 :           case 1: condp = 2;
    1149           7 :             Ip->type = stack_sprintf("[I{0}-I*{0}-%ld] page 159",(d-1)/2);
    1150           7 :             Ip->neron = dicyclic(2,2); break;
    1151             :         }
    1152          14 :         break;
    1153             :       case 3:
    1154          35 :         switch(dm)
    1155             :         {
    1156           7 :           case 0: condp = 4;
    1157           7 :             Ip->type = stack_sprintf("[IV-IV*-%ld] page 165",(d-3)/3);
    1158           7 :             Ip->neron = dicyclic(3,3); break;
    1159             :           case 1:
    1160          14 :             switch(r)
    1161             :             {
    1162           7 :               case 0: case 1: condp = 2;
    1163           7 :                 Ip->type = stack_sprintf("[I{0}-IV-%ld] page 160",(d-1)/3);
    1164           7 :                 Ip->neron = cyclic(3); break;
    1165           7 :               case 2: condp = 4;
    1166           7 :                 Ip->type = stack_sprintf("[IV*-IV*-%ld] page 166",(d-4)/3);
    1167           7 :                 Ip->neron = dicyclic(3,3); break;
    1168             :             }
    1169          14 :             break;
    1170             :           case 2:
    1171          14 :             switch(r)
    1172             :             {
    1173           7 :               case 0: case 2: condp = 2;
    1174           7 :                 Ip->type = stack_sprintf("[I{0}-IV*-%ld] page 160",(d-2)/3);
    1175           7 :                 Ip->neron = cyclic(3); break;
    1176           7 :               case 1: condp = 4;
    1177           7 :                 Ip->type = stack_sprintf("[IV-IV-%ld] page 165",(d-2)/3);
    1178           7 :                 Ip->neron = dicyclic(3,3); break;
    1179             :             }
    1180          14 :             break;
    1181             :         }
    1182          35 :         break;
    1183             :       case 4:
    1184          49 :         switch(dm)
    1185             :         {
    1186           7 :           case 0: condp = 4;
    1187           7 :             Ip->type = stack_sprintf("[III-III*-%ld] page 169",(d-4)/4);
    1188           7 :             Ip->neron = dicyclic(2,2); break;
    1189             :           case 1:
    1190          14 :             switch(r)
    1191             :             {
    1192           7 :               case 0: case 1: condp = 2;
    1193           7 :                 Ip->type = stack_sprintf("[I{0}-III-%ld] page 161",(d-1)/4);
    1194           7 :                 Ip->neron = cyclic(2); break;
    1195           7 :               case 2: case 3: condp = 4;
    1196           7 :                 Ip->type = stack_sprintf("[I*{0}-III*-%ld] page 162",(d-5)/4);
    1197           7 :                 Ip->neron = mkvecsmall3(2,2,2); break;
    1198             :             }
    1199          14 :             break;
    1200          14 :           case 2: condp = 4;
    1201          14 :             Ip->neron = dicyclic(2,2);
    1202          14 :             switch(r)
    1203             :             {
    1204             :               case 1:
    1205           7 :                 Ip->type = stack_sprintf("[III-III-%ld] page 169",(d-2)/4);
    1206           7 :                 break;
    1207             :               case 3:
    1208           7 :                 Ip->type = stack_sprintf("[III*-III*-%ld] page 169",(d-6)/4);
    1209           7 :                 break;
    1210           0 :               default: pari_err_BUG("tame5 [bug29]");
    1211             :             }
    1212          14 :             break;
    1213             :           case 3:
    1214          14 :             switch(r)
    1215             :             {
    1216           7 :               case 0: case 3: condp = 2;
    1217           7 :                 Ip->type = stack_sprintf("[I{0}-III*-%ld] page 162",(d-3)/4);
    1218           7 :                 Ip->neron = cyclic(2); break;
    1219           7 :               case 1: case 2: condp = 4;
    1220           7 :                 Ip->type = stack_sprintf("[I*{0}-III-%ld] page 162",(d-3)/4);
    1221           7 :                 Ip->neron = mkvecsmall3(2,2,2); break;
    1222             :             }
    1223          14 :             break;
    1224             :         }
    1225          49 :         break;
    1226             :       case 6:
    1227         105 :         switch(dm)
    1228             :         {
    1229           7 :           case 0: condp = 4;
    1230           7 :             Ip->type = stack_sprintf("[II-II*-%ld] page 163",(d-6)/6);
    1231           7 :             Ip->neron = cyclic(1); break;
    1232             :           case 1:
    1233          21 :             switch(r)
    1234             :             {
    1235           7 :               case 0: case 1: condp = 2;
    1236           7 :                 Ip->type = stack_sprintf("[I{0}-II-%ld] page 159",(d-1)/6);
    1237           7 :                 Ip->neron = cyclic(1); break;
    1238           7 :               case 2: case 5: condp = 4;
    1239           7 :                 Ip->type = stack_sprintf("[II*-IV-%ld] page 164",(d-7)/6);
    1240           7 :                 Ip->neron = cyclic(3); break;
    1241           7 :               case 3: case 4: condp = 4;
    1242           7 :                 Ip->type = stack_sprintf("[I*{0}-IV*-%ld] page 161",(d-7)/6);
    1243           7 :                 Ip->neron = mkvecsmall2(6,2); break;
    1244             :             }
    1245          21 :             break;
    1246             :           case 2:
    1247          21 :             switch(r)
    1248             :             {
    1249          14 :               case 1: condp = 4;
    1250          14 :                 Ip->type = stack_sprintf("[II-II-%ld] page 163",(d-2)/6);
    1251          14 :                 Ip->neron = cyclic(1); break;
    1252           7 :               case 3: case 5: condp = 4;
    1253           7 :                 Ip->type = stack_sprintf("[I*{0}-II*-%ld] page 160",(d-8)/6);
    1254           7 :                 Ip->neron = dicyclic(2,2); break;
    1255           0 :               default: pari_err_BUG("tame5 [bug30]");
    1256             :             }
    1257          21 :             break;
    1258             :           case 3:
    1259          14 :             Ip->neron = cyclic(3);
    1260          14 :             switch(r)
    1261             :             {
    1262           7 :               case 1: case 2: condp = 4;
    1263           7 :                 Ip->type = stack_sprintf("[II-IV-%ld] page 164",(d-3)/6);
    1264           7 :                 break;
    1265           7 :               case 4: case 5: condp = 4;
    1266           7 :                 Ip->type = stack_sprintf("[II*-IV*-%ld] page 164",(d-9)/6);
    1267           7 :                 break;
    1268           0 :               default: pari_err_BUG("tame5 [bug31]");
    1269             :             }
    1270          14 :             break;
    1271             :           case 4:
    1272          21 :             switch(r)
    1273             :             {
    1274           7 :               case 1: case 3: condp = 4;
    1275           7 :                 Ip->type = stack_sprintf("[I*{0}-II-%ld] page 160",(d-4)/6);
    1276           7 :                 Ip->neron = dicyclic(2,2); break;
    1277          14 :               case 5: condp = 4;
    1278          14 :                 Ip->type = stack_sprintf("[II*-II*-%ld] page 163",(d-10)/6);
    1279          14 :                 Ip->neron = cyclic(1); break;
    1280           0 :               default: pari_err_BUG("tame5 [bug32]");
    1281             :             }
    1282          21 :             break;
    1283             :           case 5:
    1284          21 :             switch(r)
    1285             :             {
    1286           7 :               case 0: case 5: condp = 2;
    1287           7 :                 Ip->type = stack_sprintf("[I{0}-II*-%ld] page 160",(d-5)/6);
    1288           7 :                 Ip->neron = cyclic(1); break;
    1289           7 :               case 1: case 4: condp = 4;
    1290           7 :                 Ip->type = stack_sprintf("[II-IV*-%ld] page 164",(d-5)/6);
    1291           7 :                 Ip->neron = cyclic(3); break;
    1292           7 :               case 2: case 3: condp = 4;
    1293           7 :                 Ip->type = stack_sprintf("[I*{0}-IV-%ld] page 161",(d-5)/6);
    1294           7 :                 Ip->neron = mkvecsmall2(6,2); break;
    1295             :             }
    1296          21 :             break;
    1297           0 :           default: pari_err_BUG("tame5 [bug33]");
    1298             :         }
    1299         105 :         break;
    1300             :       case 12:
    1301          56 :         condp = 4;
    1302          56 :         switch(dm)
    1303             :         {
    1304             :           case 1:
    1305          14 :             switch(r)
    1306             :             {
    1307             :               case 3: case 10:
    1308           7 :                 Ip->type = stack_sprintf("[II*-III-%ld] page 166",(d-13)/12);
    1309           7 :                 Ip->neron = cyclic(2); break;
    1310             :               case 4: case 9:
    1311           7 :                 Ip->type = stack_sprintf("[III*-IV-%ld] page 167",(d-13)/12);
    1312           7 :                 Ip->neron = cyclic(6); break;
    1313           0 :               default: pari_err_BUG("tame5 [bug34]");
    1314             :             }
    1315          14 :             break;
    1316             :           case 5:
    1317          14 :             switch(r)
    1318             :             {
    1319             :               case 2: case 3:
    1320           7 :                 Ip->type = stack_sprintf("[II-III-%ld] page 166",(d-5)/12);
    1321           7 :                 Ip->neron = cyclic(2); break;
    1322             :               case 8: case 9:
    1323           7 :                 Ip->type = stack_sprintf("[III*-IV*-%ld] page 168",(d-17)/12);
    1324           7 :                 Ip->neron = cyclic(6); break;
    1325           0 :               default: pari_err_BUG("tame5 [bug35]");
    1326             :             }
    1327          14 :             break;
    1328             :           case 7:
    1329          14 :             switch(r)
    1330             :             {
    1331             :               case 3: case 4:
    1332           7 :                 Ip->type = stack_sprintf("[III-IV-%ld] page 167",(d-7)/12);
    1333           7 :                 Ip->neron = cyclic(6); break;
    1334             :               case 9: case 10:
    1335           7 :                 Ip->type = stack_sprintf("[II*-III*-%ld] page 167",(d-19)/12);
    1336           7 :                 Ip->neron = cyclic(2); break;
    1337           0 :               default: pari_err_BUG("tame5 [bug36]");
    1338             :             }
    1339          14 :             break;
    1340             :           case 11:
    1341          14 :             switch(r)
    1342             :             {
    1343             :               case 3: case 8:
    1344           7 :                 Ip->type = stack_sprintf("[III-IV*-%ld] page 168",(d-11)/12);
    1345           7 :                 Ip->neron = cyclic(6); break;
    1346             :               case 2: case 9:
    1347           7 :                 Ip->type = stack_sprintf("[II-III*-%ld] page 166",(d-11)/12);
    1348           7 :                 Ip->neron = cyclic(2); break;
    1349           0 :               default: pari_err_BUG("tame5 [bug37]");
    1350             :             }
    1351          14 :             break;
    1352           0 :           default: pari_err_BUG("tame5 [bug38]");
    1353             :         }
    1354          56 :         break;
    1355           0 :       default: pari_err_BUG("tame5 [bug39]");
    1356             :     }
    1357             :   }
    1358             :   else
    1359             :   {
    1360          63 :     r %= (n >> 1);
    1361          63 :     switch(n)
    1362             :     {
    1363           7 :       case 2: condp = 2;
    1364           7 :         Ip->type = stack_sprintf("[2I{0}-%ld] page 159",(d/2));
    1365           7 :         Ip->neron = cyclic(1); break;
    1366          14 :       case 4: condp = 4;
    1367          14 :         Ip->type = stack_sprintf("[2I*{0}-%ld] page 159",(d/2-1)/2);
    1368          14 :         Ip->neron = dicyclic(2,2); break;
    1369          14 :       case 6: condp = 4;
    1370          14 :         Ip->neron = cyclic(3);
    1371          14 :         switch(r)
    1372             :           {
    1373             :           case 1:
    1374           7 :             Ip->type = stack_sprintf("[2IV-%ld] page 165",(d/2-1)/3);
    1375           7 :             break;
    1376             :           case 2:
    1377           7 :             Ip->type = stack_sprintf("[2IV*-%ld] page 165",(d/2-2)/3);
    1378           7 :             break;
    1379           0 :           default: pari_err_BUG("tame5 [bug40]");
    1380             :           }
    1381          14 :         break;
    1382          14 :       case 8: condp = 4;
    1383          14 :         Ip->neron = cyclic(2);
    1384          14 :         switch(r)
    1385             :         {
    1386             :           case 1:
    1387           7 :             Ip->type = stack_sprintf("[2III-%ld] page 168",(d/2-1)/4);
    1388           7 :             break;
    1389             :           case 3:
    1390           7 :             Ip->type = stack_sprintf("[2III*-%ld] page 168",(d/2-3)/4);
    1391           7 :             break;
    1392           0 :           default: pari_err_BUG("tame5 [bug41]");
    1393             :         }
    1394          14 :         break;
    1395          14 :       case 12: condp = 4;
    1396          14 :         Ip->neron = cyclic(1);
    1397          14 :         switch(r)
    1398             :         {
    1399             :           case 1:
    1400           7 :             Ip->type = stack_sprintf("[2II-%ld] page 162",(d/2-1)/6);
    1401           7 :             break;
    1402             :           case 5:
    1403           7 :             Ip->type = stack_sprintf("[2II*-%ld] page 163",(d/2-5)/6);
    1404           7 :             break;
    1405           0 :           default: pari_err_BUG("tame5 [bug42]");
    1406             :         }
    1407          14 :         break;
    1408           0 :       default: pari_err_BUG("tame5 [bug43]");
    1409             :     }
    1410             :   }
    1411         329 :   return condp;
    1412             : }
    1413             : 
    1414             : static long
    1415         189 : tame_6(struct igusa *I, struct igusa_p *Ip, GEN dk,
    1416             :        GEN polh, GEN theta, long alpha, long Dmin)
    1417             : {
    1418         189 :   long condp = -1, d, d1, n, dm, r;
    1419         189 :   GEN val = Ip->val, d1k;
    1420             : 
    1421         189 :   tame_567_init(I, Ip, dk, &d, &n, &dm, &r);
    1422         189 :   d1k = sstoQ(Ip->eps*(val[6]-val[7])+val[Ip->eps2], Ip->eps);
    1423         189 :   d1 = itos(gmulsg(n,d1k));
    1424         189 :   switch(n)
    1425             :   {
    1426          56 :     case 1: condp = 1;
    1427          56 :       Ip->type = stack_sprintf("[I{0}-I{%ld}-%ld] page 170",d1,d);
    1428          56 :       Ip->neron = cyclic(d1); break;
    1429             :     case 2:
    1430          28 :       switch(dm)
    1431             :       {
    1432           7 :         case 0: condp = 4;
    1433           7 :           Ip->type=stack_sprintf("[I*{0}-I*{%ld}-%ld] page 171", d1/2,(d-2)/2);
    1434           7 :           Ip->neron = shallowconcat(groupH(d1/2), dicyclic(2,2)); break;
    1435          21 :         case 1: return labelm3(polh,theta,alpha,Dmin,I,Ip);
    1436           0 :         default: pari_err_BUG("tame6 [bug44]");
    1437             :       }
    1438           7 :       break;
    1439          14 :     case 3: condp = 3;
    1440          14 :       Ip->neron = dicyclic(3,d1/3);
    1441          14 :       switch(dm)
    1442             :       {
    1443             :         case 1:
    1444           7 :           Ip->type = stack_sprintf("[I{%ld}-IV-%ld] page 173",d1/3,(d-1)/3);
    1445           7 :           break;
    1446             :         case 2:
    1447           7 :           Ip->type = stack_sprintf("[I{%ld}-IV*-%ld] page 173",d1/3,(d-2)/3);
    1448           7 :           break;
    1449           0 :         default: pari_err_BUG("tame6 [bug45]");
    1450             :       }
    1451          14 :       break;
    1452             :     case 4:
    1453          35 :       switch(dm)
    1454             :       {
    1455             :         case 1:
    1456          21 :           switch(r)
    1457             :           {
    1458           7 :             case 0: case 1: condp = 3;
    1459           7 :               Ip->type=stack_sprintf("[I{%ld}-III-%ld] page 176",d1/4,(d-1)/4);
    1460           7 :               Ip->neron = dicyclic(2,d1/4); break;
    1461          14 :             case 2: case 3: condp = 4;
    1462          14 :               Ip->type=stack_sprintf("[I*{%ld}-III*-%ld] page 177",d1/4,(d-5)/4);
    1463          14 :               Ip->neron = shallowconcat(groupH(d1/4), cyclic(2)); break;
    1464           0 :             default: pari_err_BUG("tame6 [bug46]");
    1465             :           }
    1466          21 :           break;
    1467             :         case 3:
    1468          14 :           switch(r)
    1469             :           {
    1470           7 :             case 0: case 3: condp = 3;
    1471           7 :               Ip->type=stack_sprintf("[I{%ld}-III*-%ld] page 176",d1/4,(d-3)/4);
    1472           7 :               Ip->neron = dicyclic(2,d1/4); break;
    1473           7 :             case 1: case 2: condp = 4;
    1474           7 :               Ip->type=stack_sprintf("[I*{%ld}-III-%ld] page 177",d1/4,(d-3)/4);
    1475           7 :               Ip->neron = shallowconcat(groupH(d1/4), cyclic(2)); break;
    1476           0 :             default: pari_err_BUG("tame6 [bug47]");
    1477             :           }
    1478          14 :           break;
    1479           0 :         default: pari_err_BUG("tame6 [bug48]");
    1480             :       }
    1481          35 :       break;
    1482             :     case 6:
    1483          56 :       switch(dm)
    1484             :       {
    1485             :         case 1:
    1486          21 :           switch(r)
    1487             :           {
    1488           7 :             case 0: case 1: condp = 3;
    1489           7 :               Ip->type = stack_sprintf("[I{%ld}-II-%ld] page 172",d1/6,(d-1)/6);
    1490           7 :               Ip->neron = cyclic(d1/6); break;
    1491          14 :             case 3: case 4: condp = 4;
    1492          14 :               Ip->type=stack_sprintf("[I*{%ld}-IV*-%ld] page 174",d1/6,(d-7)/6);
    1493          14 :               Ip->neron = shallowconcat(groupH(d1/6), cyclic(3)); break;
    1494           0 :             default: pari_err_BUG("tame6 [bug49]");
    1495             :           }
    1496          21 :           break;
    1497          14 :         case 2: condp = 4;
    1498          14 :           Ip->type = stack_sprintf("[I*{%ld}-II*-%ld] page 174",d1/6,(d-8)/6);
    1499          14 :           Ip->neron = groupH(d1/6); break;
    1500           7 :         case 4: condp = 4;
    1501           7 :           Ip->type = stack_sprintf("[I*{%ld}-II-%ld] page 173",d1/6,(d-4)/6);
    1502           7 :           Ip->neron = groupH(d1/6); break;
    1503             :         case 5:
    1504          14 :           switch(r)
    1505             :           {
    1506           7 :             case 0: case 5: condp = 3;
    1507           7 :               Ip->type=stack_sprintf("[I{%ld}-II*-%ld] page 172",d1/6,(d-5)/6);
    1508           7 :               Ip->neron = cyclic(d1/6); break;
    1509           7 :             case 2: case 3: condp = 4;
    1510           7 :               Ip->type=stack_sprintf("[I*{%ld}-IV-%ld] page 174",d1/6,(d-5)/6);
    1511           7 :               Ip->neron = shallowconcat(groupH(d1/6), cyclic(3)); break;
    1512           0 :             default: pari_err_BUG("tame6 [bug50]");
    1513             :           }
    1514          14 :           break;
    1515           0 :         default: pari_err_BUG("tame6 [bug51]");
    1516             :       }
    1517          56 :       break;
    1518           0 :     default: pari_err_BUG("tame6 [bug52]");
    1519             :   }
    1520         168 :   return condp;
    1521             : }
    1522             : 
    1523             : static long
    1524          91 : tame_7(struct igusa *I, struct igusa_p *Ip, GEN dk,
    1525             :          GEN polh, GEN theta, long alpha, long Dmin)
    1526             : {
    1527          91 :   long condp = -1, d, d1, d2, n, dm, r;
    1528          91 :   GEN val = Ip->val, d1k, d2k, pro1;
    1529             : 
    1530          91 :   tame_567_init(I, Ip, dk, &d, &n, &dm, &r);
    1531          91 :   pro1 = sstoQ(Ip->eps*val[6]+val[Ip->eps2]-3*Ip->eps*val[3], Ip->eps);
    1532          91 :   d1k = gmin(stoi(val[7]-3*val[3]),gmul2n(pro1,-1));
    1533          91 :   d2k = gsub(pro1,d1k);
    1534             : 
    1535          91 :   d1 = itos(gmulsg(n,d1k));
    1536          91 :   d2 = itos(gmulsg(n,d2k)); /* d1 <= d2 */
    1537          91 :   switch(n)
    1538             :   {
    1539          42 :     case 1: condp = 2;
    1540          42 :       Ip->type = stack_sprintf("[I{%ld}-I{%ld}-%ld] page 179",d1,d2,d);
    1541          42 :       Ip->neron = dicyclic(d1,d2); break;
    1542             :     case 2:
    1543          35 :       if ( odd(val[Ip->eps2]) )
    1544             :       {
    1545          14 :         condp = 3;
    1546          14 :         Ip->type = stack_sprintf("[2I{%ld}-%ld] page 181",d1,d/2);
    1547          14 :         Ip->neron = cyclic(d1);
    1548             :       }
    1549          21 :       else if (dm == 0)
    1550             :       {
    1551          14 :         condp = 4;
    1552          14 :         Ip->type = stack_sprintf("[I*{%ld}-I*{%ld}-%ld] page 180", d1/2,d2/2,(d-2)/2);
    1553          14 :         Ip->neron = shallowconcat(groupH(d1/2),groupH(d2/2));
    1554             :       }
    1555             :       else
    1556             :       {
    1557             :         GEN H;
    1558           7 :         if (d1 != d2) return labelm3(polh,theta,alpha,Dmin,I,Ip);
    1559           0 :         condp = 3; H = groupH(d1/2);
    1560           0 :         Ip->type = stack_sprintf("[I{%ld}-I*{%ld}-%ld] page 180", d1/2,d1/2,(d-1)/2);
    1561           0 :         Ip->neron = shallowconcat(H, H);
    1562             :       }
    1563          28 :       break;
    1564          14 :     case 4: condp = 4;
    1565          14 :       Ip->type = stack_sprintf("[2I*{%ld}-%ld] page 181",d1/2,(d-2)/4);
    1566          14 :       Ip->neron = groupH(d1/2); break;
    1567           0 :     default: pari_err_BUG("tame7 [bug55]");
    1568             :   }
    1569          84 :   return condp;
    1570             : }
    1571             : 
    1572             : static long
    1573         833 : tame(GEN polh, GEN theta, long alpha, long Dmin, struct igusa *I, struct igusa_p *Ip)
    1574             : {
    1575         833 :   GEN val = Ip->val, dk;
    1576         833 :   Ip->tame = 1;
    1577         833 :   switch(Ip->tt)
    1578             :   {
    1579          21 :     case 1: return tame_1(I, Ip);
    1580          91 :     case 2: return tame_2(I, Ip, myval(I->i12,  Ip->p));
    1581          56 :     case 3: return tame_3(I, Ip, 3*myval(I->i4, Ip->p));
    1582          56 :     case 4: return tame_4(I, Ip, 6*myval(I->j2, Ip->p));
    1583             :     case 5:
    1584         329 :       dk = sstoQ(Ip->eps*val[6]-5*val[Ip->eps2], 12*Ip->eps);
    1585         329 :       return tame_5(I, Ip, dk);
    1586             :     case 6:
    1587         189 :       dk = sstoQ(Ip->eps*val[7]-6*val[Ip->eps2], 12*Ip->eps);
    1588         189 :       return tame_6(I, Ip, dk, polh, theta, alpha, Dmin);
    1589             :     case 7:
    1590          91 :       dk = sstoQ(Ip->eps*val[3]-2*val[Ip->eps2], 4*Ip->eps);
    1591          91 :       return tame_7(I, Ip, dk, polh, theta, alpha, Dmin);
    1592             :   }
    1593             :   return -1; /*LCOV_EXCL_LINE*/
    1594             : }
    1595             : 
    1596             : /* maxc = maximum conductor valuation at p */
    1597             : static long
    1598         462 : get_maxc(GEN p)
    1599             : {
    1600         462 :   switch (itos_or_0(p))
    1601             :   {
    1602           0 :     case 2:  return 20; break;
    1603         273 :     case 3:  return 10; break;
    1604           7 :     case 5:  return 9; break;
    1605         182 :     default: return 4; break; /* p > 5 */
    1606             :   }
    1607             : }
    1608             : 
    1609             : /* p = 3 */
    1610             : static long
    1611          77 : quartic(GEN polh, long alpha, long Dmin, struct igusa_p *Ip)
    1612             : {
    1613          77 :   GEN theta, val = Ip->val, p = Ip->p;
    1614          77 :   GEN polf = polymini_zi2(ZX_Z_mul(polh, powiu(p, alpha)));
    1615          77 :   long condp = -1, d, R, r1, beta;
    1616          77 :   theta = gel(polf,1);
    1617          77 :   beta = itos(gel(polf,2));
    1618          77 :   if (odd(beta)) pari_err_BUG("quartic [type over Z[i] must be [K-K-(2*m)]]");
    1619          77 :   R = beta/2;
    1620          77 :   r1 = itos(gmulgs(theta,6));
    1621          77 :   switch(Ip->tt)
    1622             :   {
    1623          63 :     case 1: case 5: d = 0;break;
    1624           0 :     case 3: d = val[6] - 5*val[3]/2;break;
    1625          14 :     case 7: d = val[6] - 3*val[3] + val[Ip->eps2]/Ip->eps;break;
    1626           0 :     default: pari_err_BUG("quartic [type choices]");
    1627             :              d = 0; /*LCOV_EXCL_LINE*/
    1628             :   }
    1629          77 :   switch(r1)
    1630             :   {
    1631             :     case 0:
    1632          21 :       if (d)
    1633             :       {
    1634           7 :         condp = 3;
    1635           7 :         Ip->type = stack_sprintf("[2I{%ld}-%ld] page 181",d,R);
    1636           7 :         Ip->neron = cyclic(d);
    1637             :       }
    1638             :       else
    1639             :       {
    1640          14 :         condp = 2;
    1641          14 :         Ip->neron = cyclic(1);
    1642          14 :         if (R) Ip->type = stack_sprintf("[2I{0}-%ld] page 159",R);
    1643           7 :         else   Ip->type = "[II] page 155";
    1644             :       }
    1645          21 :       break;
    1646           7 :     case 6: condp = 4;
    1647           7 :       Ip->type = stack_sprintf("[2I*{%ld}-%ld] pages 159, 181",d,R);
    1648           7 :       Ip->neron = dicyclic(2,2); break;
    1649           7 :     case 3: condp = 4;
    1650           7 :       Ip->type = stack_sprintf("[2III-%ld] page 168",R);
    1651           7 :       Ip->neron = cyclic(2); break;
    1652           7 :     case 9: condp = 4;
    1653           7 :       Ip->type = stack_sprintf("[2III*-%ld] page 168",R);
    1654           7 :       Ip->neron = cyclic(2); break;
    1655           7 :     case 2: condp = Dmin-12*R-13;
    1656           7 :       Ip->type = stack_sprintf("[2II-%ld] page 162",R);
    1657           7 :       Ip->neron = cyclic(1); break;
    1658          14 :     case 8: condp = Dmin-12*R-19;
    1659          14 :       Ip->type = stack_sprintf("[2IV*-%ld] page 165",R);
    1660          14 :       Ip->neron = cyclic(3); break;
    1661           7 :     case 4: condp = Dmin-12*R-15;
    1662           7 :       Ip->type = stack_sprintf("[2IV-%ld] page 165",R);
    1663           7 :       Ip->neron = cyclic(3); break;
    1664           7 :     case 10: condp = Dmin-12*R-21;
    1665           7 :       Ip->type = stack_sprintf("[2II*-%ld] page 163",R);
    1666           7 :       Ip->neron = cyclic(1); break;
    1667           0 :     default: pari_err_BUG("quartic [type1]");
    1668             :   }
    1669          77 :   if (condp > get_maxc(p) || condp < 0) pari_err_BUG("quartic [conductor]");
    1670          77 :   return condp;
    1671             : }
    1672             : 
    1673             : static long
    1674         259 : litredtp(long alpha, long alpha1, GEN theta, GEN theta1, GEN polh, GEN polh1,
    1675             :          long Dmin, struct igusa *I, struct igusa_p *Ip)
    1676             : {
    1677         259 :   GEN val = Ip->val, p = Ip->p;
    1678         259 :   long condp = -1, indice, d, R = Ip->R;
    1679             : 
    1680         259 :   if ((Ip->r1 == 0||Ip->r1 == 6) && (Ip->r2 == 0||Ip->r2 == 6))
    1681             :   { /* (r1,r2) = (0,0), (0,6), (6,0) or (6,6) */
    1682         154 :     if (Ip->tt == 5)
    1683             :     {
    1684          21 :       switch(Ip->r1 + Ip->r2)
    1685             :       {
    1686             :       case 0: /* (0,0) */
    1687           7 :         condp = 0;
    1688           7 :         Ip->type = stack_sprintf("[I{0}-I{0}-%ld] page 158",R);
    1689           7 :         Ip->neron = cyclic(1); break;
    1690             :       case 6: /* (0,6) or (6,0) */
    1691           7 :         condp = 2;
    1692           7 :         Ip->type = stack_sprintf("[I{0}-I*{0}-%ld] page 159",R);
    1693           7 :         Ip->neron = dicyclic(2,2); break;
    1694             :       case 12: /* (6,6) */
    1695           7 :         condp = 4;
    1696           7 :         Ip->type = stack_sprintf("[I*{0}-I*{0}-%ld] page 158",R);
    1697           7 :         Ip->neron = mkvecsmall4(2,2,2,2); break;
    1698             :       }
    1699          21 :       return condp;
    1700             :     }
    1701         133 :     if (Ip->r1 == Ip->r2) return tame(polh, theta, alpha, Dmin, I, Ip);
    1702          42 :     if (Ip->tt == 6)
    1703             :     {
    1704          28 :       d = val[6] - val[7] + (val[Ip->eps2]/Ip->eps);
    1705          28 :       if (Ip->r1 && alpha1 == 0) /* H(px) / p^3 */
    1706          21 :         polh1 = ZX_Z_divexact(ZX_unscale_div(polh1,p), sqri(p));
    1707          28 :       if (FpX_is_squarefree(FpX_red(polh1,p),p))
    1708           7 :       { indice = 0; condp = 3-Ip->r2/6; }
    1709             :       else
    1710          21 :       { indice = d; condp = 3-Ip->r1/6; }
    1711             :     }
    1712             :     else
    1713             :     { /* Ip->tt == 7 */
    1714             :       long d1;
    1715          14 :       d = val[6] - 3*val[3] + (val[Ip->eps2]/Ip->eps);
    1716          14 :       if (gequal1(theta1)) /* H(px) / p^3 */
    1717          14 :         polh1 = ZX_Z_divexact(ZX_unscale_div(polh1,p), sqri(p));
    1718          14 :       d1 = minss(val[7]-3*val[3],d/2);
    1719          14 :       if (d == 2*d1) indice = d1;
    1720             :       else
    1721             :       {
    1722          14 :         indice = discpart(polh1,p,d1+1);
    1723          14 :         if (indice>= d1+1) indice = d-d1; else indice = d1;
    1724             :       }
    1725          14 :       condp = 3;
    1726             :     }
    1727          42 :     if (Ip->r1) indice = d - indice; /* (r1,r2) = (6,0) */
    1728          42 :     Ip->neron = shallowconcat(cyclic(indice),groupH(d-indice));
    1729          42 :     Ip->type = stack_sprintf("[I{%ld}-I*{%ld}-%ld] page %ld",
    1730          42 :                              indice,d-indice,R, (Ip->tt==6)? 170L: 180L);
    1731          42 :     return condp;
    1732             :   }
    1733         105 :   if (Ip->tt == 7) pari_err_BUG("litredtp [switch ri]");
    1734             :   {
    1735         105 :     struct red __S1, __S2, *S1 = &__S1, *S2 = &__S2;
    1736         105 :     long f1 = get_red(S1, Ip, polh1, p, alpha1, Ip->r1);
    1737         105 :     long f2 = get_red(S2, Ip, polh,  p, alpha,  Ip->r2);
    1738             :     /* reorder to normalize representation */
    1739         105 :     if (S1->tnum > S2->tnum || (S1->tnum == S2->tnum && f1 > f2))
    1740          56 :     { struct red *S = S1; S1 = S2; S2 = S; }
    1741         105 :     Ip->type = stack_sprintf("[%s-%s-%ld] pages %s", S1->t,S2->t, R, S1->pages);
    1742         105 :     Ip->neron = shallowconcat(S1->g, S2->g);
    1743         105 :     condp = Dmin - (f1 + f2) + ((R >= 0)? 2-12*R: 4);
    1744             :   }
    1745         105 :   if (condp > get_maxc(p)) pari_err_BUG("litredtp [conductor]");
    1746         105 :   return condp;
    1747             : }
    1748             : 
    1749             : static long
    1750         238 : labelm3(GEN polh, GEN theta, long alpha, long Dmin, struct igusa *I, struct igusa_p *Ip)
    1751             : {
    1752         238 :   GEN polh1, theta1, polf, val = Ip->val, p = Ip->p;
    1753             :   long alpha1, lambda, beta, R;
    1754             : 
    1755         238 :   polh1 = polh;
    1756         238 :   theta1 = theta;
    1757         238 :   alpha1 = alpha;
    1758         238 :   polf = polymini(ZX_Z_mul(RgX_recip6(polh), powiu(p,alpha)), p);
    1759         238 :   polh  = gel(polf,1);
    1760         238 :   lambda= itos(gel(polf,2));
    1761         238 :   theta = gel(polf,3);
    1762         238 :   alpha = itos(gel(polf,4));
    1763         238 :   beta  = itos(gel(polf,6));
    1764         238 :   if (lambda != 3) pari_err_BUG("labelm3 [lambda != 3]");
    1765         238 :   R = beta-(alpha1+alpha);
    1766         238 :   if (odd(R)) pari_err_BUG("labelm3 [R odd]");
    1767         238 :   R /= 2;
    1768         238 :   if (R <= -2) pari_err_BUG("labelm3 [R <= -2]");
    1769         238 :   if (val[Ip->eps2] % (2*Ip->eps)) pari_err_BUG("labelm3 [val(eps2)]");
    1770         238 :   if (R >= 0 && (alpha+alpha1) >= 1) pari_err_BUG("labelm3 [minimal equation]");
    1771         238 :   Ip->r1 = itos(gmulgs(theta1,6)) + 6*alpha1;
    1772         238 :   Ip->r2 = itos(gmulgs(theta, 6)) + 6*alpha;
    1773         238 :   Ip->R = R;
    1774         238 :   return litredtp(alpha, alpha1, theta, theta1, polh, polh1, Dmin, I, Ip);
    1775             : }
    1776             : 
    1777             : /* p = 3 */
    1778             : static long
    1779          21 : quadratic(GEN polh, long alpha, long Dmin, struct igusa *I, struct igusa_p *Ip)
    1780             : {
    1781             :   long alpha1, beta, R;
    1782             :   GEN polf, polh1, theta, theta1;
    1783          21 :   alpha1 = alpha;
    1784          21 :   polf = polymini_zi(ZX_Z_mul(polh, powiu(Ip->p,alpha)));
    1785          21 :   theta = gel(polf,1);
    1786          21 :   alpha = itos(gel(polf,2));
    1787          21 :   beta  = itos(gel(polf,3));
    1788          21 :   if (alpha && beta >= 1) pari_err_BUG("quadratc");
    1789          21 :   R = beta-alpha;
    1790          21 :   if (R >= 0 && alpha1)
    1791             :   {
    1792           0 :     Dmin -= 10;
    1793           0 :     if (DEBUGLEVEL)
    1794           0 :       err_printf("(Care: minimal discriminant over Z[i] smaller than over Z)\n");
    1795             :   }
    1796          21 :   Ip->r1 = itos(gmulgs(theta,6))+6*alpha;
    1797          21 :   Ip->r2 = Ip->r1;
    1798          21 :   Ip->R = R;
    1799          21 :   alpha1 = alpha;
    1800          21 :   theta1 = theta;
    1801          21 :   polh1 = polh; /* FIXME !!! */
    1802          21 :   return litredtp(alpha, alpha1, theta, theta1, polh, polh1, Dmin, I, Ip);
    1803             : }
    1804             : 
    1805             : static long
    1806        1372 : genus2localred(struct igusa *I, struct igusa_p *Ip, GEN p, GEN polmini)
    1807             : {
    1808             :   GEN val, polh, theta, list, c1, c2, c3, c4, c5, c6, prod;
    1809             :   long i, vb5, vb6, d, Dmin, alpha, lambda;
    1810        1372 :   long condp = -1, indice, vc6, mm, nb, dism;
    1811             : 
    1812        1372 :   val = cgetg(8, t_VECSMALL);
    1813        1372 :   Ip->tame = 0;
    1814        1372 :   Ip->neron = NULL;
    1815        1372 :   Ip->type = NULL;
    1816        1372 :   Ip->p = p;
    1817        1372 :   Ip->val = val;
    1818        1372 :   val[1] = myval(I->j2,p);
    1819        1372 :   val[2] = myval(I->j4,p);
    1820        1372 :   val[3] = myval(I->i4,p);
    1821        1372 :   val[4] = myval(I->j6,p);
    1822        1372 :   val[5] = myval(I->j8,p);
    1823        1372 :   val[6] = myval(I->j10,p);
    1824        1372 :   val[7] = myval(I->i12,p);
    1825        1372 :   Dmin = val[6];
    1826        1372 :   stable_reduction(I, Ip);
    1827        1372 :   if (Dmin == 0)
    1828             :   {
    1829           7 :     Ip->tame = 1;
    1830           7 :     Ip->type = "[I{0-0-0}] page 155";
    1831           7 :     Ip->neron = cyclic(1); return 0;
    1832             :   }
    1833        1365 :   if (Dmin == 1)
    1834             :   {
    1835           0 :     Ip->type = "[I{1-0-0}] page 170";
    1836           0 :     Ip->neron = cyclic(1); return 1;
    1837             :   }
    1838        1365 :   if (Dmin == 2) switch(Ip->tt)
    1839             :   {
    1840             :     case 2:
    1841           0 :       Ip->type = "[I{2-0-0}] page 170";
    1842           0 :       Ip->neron = cyclic(2); return 1;
    1843             :     case 3:
    1844           0 :       Ip->type = "[I{1-1-0}] page 179";
    1845           0 :       Ip->neron = cyclic(1); return 2;
    1846             :     case 5:
    1847          14 :       if (cmpis(p,3) <= 0) pari_err_BUG("genus2localred [tt 1]");
    1848          14 :       Ip->type = "[I{0}-II-0] page 159";
    1849          14 :       Ip->neron = cyclic(1); return 2;
    1850           0 :     default: pari_err_BUG("genus2localred [tt 2]");
    1851             :   }
    1852        1351 :   if (absequaliu(p,2)) return -1;
    1853        1337 :   polh = gel(polmini,1);
    1854        1337 :   lambda = itos(gel(polmini,2));
    1855        1337 :   theta = gel(polmini,3);
    1856        1337 :   alpha = itos(gel(polmini,4));
    1857        1337 :   if (!gequal0(gel(polmini,5)))
    1858          21 :     return equalis(p,3)? quadratic(polh, alpha, Dmin, I, Ip):
    1859             :                          tame(polh, theta, alpha, Dmin, I, Ip);
    1860        1316 :   if (gequal0(theta) && lambda<= 2)
    1861             :   {
    1862           7 :     if (Ip->tt >= 5) pari_err_BUG("genus2localred [tt 3]");
    1863           7 :     return tame(polh, theta, alpha, Dmin, I, Ip);
    1864             :   }
    1865        1309 :   if (Dmin == 3)
    1866             :   {
    1867           7 :     switch(Ip->tt)
    1868             :     {
    1869           0 :       case 2: return tame(polh, theta, alpha, Dmin, I, Ip);
    1870           0 :       case 3: Ip->type = "[I{2-1-0}] page 179"; Ip->neron = cyclic(2); return 2;
    1871           7 :       case 4: Ip->type = "[I{1-1-1}] page 182"; Ip->neron = cyclic(3); return 2;
    1872             :       case 5:
    1873           0 :         if (equalis(p,3) && !gequal(theta,ghalf))
    1874           0 :           return labelm3(polh,theta,alpha,Dmin,I,Ip);
    1875           0 :         Ip->type = "[I{0}-III-0] page 161"; Ip->neron = cyclic(2); return 2;
    1876             :       case 6:
    1877           0 :         if (equalis(p,3)) pari_err_BUG("genus2localred [conductor]");
    1878           0 :         Ip->type = "[I{1}-II-0] page 172"; Ip->neron = cyclic(1); return 3;
    1879             :     }
    1880           0 :     pari_err_BUG("genus2localred [switch tt 4]");
    1881             :     return -1; /* LCOV_EXCL_LINE */
    1882             :   }
    1883        1302 :   switch(lambda)
    1884             :   {
    1885             :     case 0:
    1886         357 :       switch(itos(gmulgs(theta, 60))+alpha)
    1887             :       {
    1888             :         case 10:
    1889           7 :           condp = Dmin-1;
    1890           7 :           Ip->type = "[V] page 156";
    1891           7 :           Ip->neron = cyclic(3); break;
    1892             :         case 11:
    1893           7 :           condp = Dmin-11;
    1894           7 :           Ip->type = "[V*] page 156";
    1895           7 :           Ip->neron = cyclic(3); break;
    1896             :         case 12:
    1897           7 :           condp = Dmin-2;
    1898           7 :           Ip->type = "[IX-2] page 157";
    1899           7 :           Ip->neron = cyclic(5); break;
    1900             :         case 13:
    1901          14 :           condp = Dmin-12;
    1902          14 :           Ip->type = "[VIII-4] page 157";
    1903          14 :           Ip->neron = cyclic(1); break;
    1904             :         case 24:
    1905           7 :           condp = Dmin-8;
    1906           7 :           Ip->type = "[IX-4] page 158";
    1907           7 :           Ip->neron = cyclic(5);
    1908           7 :           break;
    1909             :         case 15: case 16:
    1910          14 :           if (Ip->tt>= 5) pari_err_BUG("genus2localred [tt 6]");
    1911          14 :           return tame(polh, theta, alpha, Dmin, I, Ip);
    1912             :         case 20: case 21:
    1913             :           {
    1914             :             GEN b0, b1, b2, b3, b4, b5, b6, b02, b03, b04, b05;
    1915         112 :             RgX_to_6(polh, &b0,&b1,&b2,&b3,&b4,&b5,&b6);
    1916         112 :             vb5 = myval(b5,p);
    1917         112 :             vb6 = myval(b6,p);
    1918         112 :             if (vb6 >= 3)
    1919             :             {
    1920          14 :               if (vb5 < 2) pari_err_BUG("genus2localred [red1]");
    1921          14 :               if (vb5 >= 3)
    1922             :               {
    1923           7 :                 condp = Dmin-8;
    1924           7 :                 Ip->type = "[II*-IV-(-1)] page 164";
    1925           7 :                 Ip->neron = cyclic(3);
    1926             :               }
    1927             :               else
    1928             :               {
    1929           7 :                 condp = Dmin-7;
    1930           7 :                 Ip->type = "[IV-III*-(-1)] page 167";
    1931           7 :                 Ip->neron = cyclic(6);
    1932             :               }
    1933          14 :               break;
    1934             :             }
    1935          98 :             if (dvdii(b0,p)) pari_err_BUG("genus2localred [b0]");
    1936          98 :             b02 = gsqr(b0);
    1937          98 :             b03 = gmul(b02, b0);
    1938          98 :             b04 = gmul(b03, b0);
    1939          98 :             b05 = gmul(b04, b0);
    1940          98 :             c1 = gmul2n(b1,-1);
    1941          98 :             c2 = gmul2n(gsub(gmul(b0,b2), gsqr(c1)),-1);
    1942          98 :             c3 = gmul2n(gsub(gmul(b02,b3), gmul2n(gmul(c1,c2),1)),-1);
    1943          98 :             c4 = gsub(gmul(b03,b4), gadd(gmul2n(gmul(c1,c3),1),gsqr(c2)));
    1944          98 :             c5 = gsub(gmul(b04,b5), gmul2n(gmul(c2,c3),1));
    1945          98 :             c6 = gsub(gmul(b05,b6), gsqr(c3));
    1946             :             /* b0^5*H(x/b0) = (x^3+c1*x^2+c2*x+c3)^2+c4*x^2+c5*x+c6 */
    1947          98 :             vc6 = myval(c6,p);
    1948          98 :             if (vc6 == 2)
    1949             :             {
    1950           7 :               if (alpha)
    1951             :               {
    1952           0 :                 condp = Dmin-16;
    1953           0 :                 Ip->type = "[IV] page 155";
    1954           0 :                 Ip->neron = cyclic(1);
    1955             :               }
    1956             :               else
    1957             :               {
    1958           7 :                 condp = Dmin-6;
    1959           7 :                 Ip->type = "[III] page 155";
    1960           7 :                 Ip->neron = dicyclic(3,3);
    1961             :               }
    1962             :             }
    1963             :             else
    1964             :             {
    1965          91 :               if (myval(c3,p) > 1) pari_err_BUG("genus2localred [c3]");
    1966          91 :               mm = min3(3*myval(c4,p)-4, 3*myval(c5,p)-5, 3*vc6-6);
    1967          91 :               if (alpha)
    1968             :               {
    1969          35 :                 condp = Dmin-mm-16;
    1970          35 :                 Ip->type = stack_sprintf("[III*{%ld}] page 184", mm);
    1971          35 :                 Ip->neron = cyclic(1);
    1972             :               }
    1973             :               else
    1974             :               {
    1975          56 :                 condp = Dmin-mm-6;
    1976          56 :                 Ip->type = stack_sprintf("[III{%ld}] page 184", mm);
    1977          56 :                 Ip->neron = (mm%3)? cyclic(9): dicyclic(3,3);
    1978             :               }
    1979             :             }
    1980             :           }
    1981          98 :           break;
    1982             :         case 30:
    1983         378 :           return equalis(p,3)? quartic(polh, alpha, Dmin, Ip)
    1984         189 :                              : tame(polh, theta, alpha, Dmin, I, Ip);
    1985           0 :         default: pari_err_BUG("genus2localred [red2]");
    1986             :       }
    1987         154 :       break;
    1988             :     case 1:
    1989         105 :       switch(itos(gmulgs(theta, 60))+alpha)
    1990             :       {
    1991             :         case 12:
    1992           7 :           condp = Dmin;
    1993           7 :           Ip->type = "[VIII-1] page 156";
    1994           7 :           Ip->neron = cyclic(1); break;
    1995             :         case 13:
    1996           7 :           condp = Dmin-10;
    1997           7 :           Ip->type = "[IX-3] page 157";
    1998           7 :           Ip->neron = cyclic(5); break;
    1999             :         case 24:
    2000           7 :           condp = Dmin-4;
    2001           7 :           Ip->type = "[IX-1] page 157";
    2002           7 :           Ip->neron = cyclic(5); break;
    2003             :         case 25:
    2004           7 :           condp = Dmin-14;
    2005           7 :           Ip->type = "[VIII-3] page 157";
    2006           7 :           Ip->neron = cyclic(1); break;
    2007             :         case 36:
    2008           7 :           condp = Dmin-8;
    2009           7 :           Ip->type = "[VIII-2] page 157";
    2010           7 :           Ip->neron = cyclic(1); break;
    2011             :         case 15:
    2012           7 :           condp = Dmin-1;
    2013           7 :           Ip->type = "[VII] page 156";
    2014           7 :           Ip->neron = cyclic(2); break;
    2015             :         case 16:
    2016           7 :           condp = Dmin-11;
    2017           7 :           Ip->type = "[VII*] page 156";
    2018           7 :           Ip->neron = cyclic(2); break;
    2019             :         case 20:
    2020          14 :           if (cmpis(p,3))
    2021             :           {
    2022           7 :             d = 6*val[6]-5*val[7]-2;
    2023           7 :             if (d%6) pari_err_BUG("genus2localred [index]");
    2024           7 :             dism = (d/6);
    2025             :           }
    2026             :           else
    2027             :           {
    2028           7 :             list = padicfactors(polh,p,Dmin-5);
    2029           7 :             nb = lg(list);
    2030           7 :             prod = pol_1(varn(polh));
    2031          21 :             for(i = 1;i<nb;i++)
    2032             :             {
    2033          14 :               GEN c = gel(list,i);
    2034          14 :               if (valp(gel(c,2)) && degpol(c)<= 2) prod = RgX_mul(prod,c);
    2035             :             }
    2036           7 :             if (degpol(prod) > 2) pari_err_BUG("genus2localred [padicfactors]");
    2037           7 :             dism = valp(RgX_disc(prod)) - 1;
    2038             :           }
    2039          14 :           condp = Dmin-dism-3;
    2040          14 :           Ip->type = stack_sprintf("[II-II*{%ld}] page 176", dism);
    2041          14 :           Ip->neron = groupH(dism+1); break;
    2042             :         case 21:
    2043          14 :           vb6 = myval(RgX_coeff(polh,0),p);
    2044          14 :           if (vb6<2) pari_err_BUG("genus2localred [red3]");
    2045          14 :           condp = Dmin-14;
    2046          14 :           Ip->type = "[IV*-II{0}] page 175";
    2047          14 :           Ip->neron = cyclic(1); break;
    2048             :         case 30:
    2049          28 :           vb5 = myval(RgX_coeff(polh,1),p);
    2050          28 :           if (vb5 == 2)
    2051             :           {
    2052          21 :             if (Ip->tt >= 5) pari_err_BUG("genus2localred [tt 6]");
    2053          21 :             return tame(polh, theta, alpha, Dmin, I, Ip);
    2054             :           }
    2055           7 :           condp = Dmin-7;
    2056           7 :           Ip->type = "[II*-III-(-1)] page 167";
    2057           7 :           Ip->neron = cyclic(2); break;
    2058             :       }
    2059          84 :       break;
    2060             :     case 2:
    2061         147 :       if (equalis(denom(theta),4))
    2062             :       {
    2063          28 :         if (Ip->tt>4) pari_err_BUG("genus2localred [tt 5]");
    2064          28 :         return tame(polh, theta, alpha, Dmin, I, Ip);
    2065             :       }
    2066         119 :       if (!equalis(p,3) && equalis(denom(theta),3))
    2067          21 :         return tame(polh, theta, alpha, Dmin, I, Ip);
    2068          98 :       list = padicfactors(polh,p,Dmin-10*alpha);
    2069          98 :       nb = lg(list); prod = pol_1(varn(polh));
    2070         336 :       for(i = 1;i<nb;i++)
    2071             :       {
    2072         238 :         GEN c = gel(list,i);
    2073         238 :         if (!valp(gel(c,2))) prod = RgX_mul(prod,c);
    2074             :       }
    2075          98 :       switch(degpol(prod))
    2076             :       {
    2077             :         GEN e0, e1, e2;
    2078             :         case 0:
    2079           0 :           dism = 0; break;
    2080             :         case 1:
    2081           7 :           e1 = gel(prod,3);
    2082           7 :           dism = 2*valp(e1); break;
    2083             :         case 2:
    2084          91 :           e0 = gel(prod,2);
    2085          91 :           e1 = gel(prod,3);
    2086          91 :           e2 = gel(prod,4);
    2087          91 :           dism = valp(gsub(gsqr(e1),gmul2n(gmul(e0,e2),2))); break;
    2088             :         default:
    2089           0 :           pari_err_BUG("genus2localred [padicfactors 2]");
    2090           0 :           dism = 0;
    2091             :       }
    2092          98 :       switch(itos(gmulgs(theta,12))+alpha-4)
    2093             :       {
    2094             :         case 0:
    2095          14 :           condp = Dmin-dism-1;
    2096          14 :           Ip->type = stack_sprintf("[IV-II{%ld}] page 175", dism);
    2097          14 :           Ip->neron = cyclic(3*dism+2); break;
    2098             :         case 1:
    2099           7 :           condp = Dmin-dism-10;
    2100           7 :           Ip->type = stack_sprintf("[II*-II*{%ld}] page 176",dism);
    2101           7 :           Ip->neron = groupH(dism+1); break;
    2102             :         case 2: case 3:
    2103          70 :           if (myval(RgX_coeff(polh,0),p) == 2)
    2104             :           {
    2105          56 :             if (Ip->tt>4) pari_err_BUG("genus2localred [tt 5]");
    2106          56 :             return tame(polh, theta, alpha, Dmin, I, Ip);
    2107             :           }
    2108          14 :           dism++;
    2109          14 :           indice = val[6]-(5*val[3]/2)-dism;
    2110          14 :           condp = Dmin-dism-indice-2;
    2111          14 :           Ip->type = stack_sprintf("[II{%ld-%ld}] page 182", dism,indice);
    2112          14 :           Ip->neron = both_odd(dism,indice)? dicyclic(2,2*dism): cyclic(4*dism);
    2113          14 :           break;
    2114             :         case 4:
    2115           7 :           condp = Dmin-dism-5;
    2116           7 :           Ip->type = stack_sprintf("[IV*-II{%ld}] page 175",dism+1);
    2117           7 :           Ip->neron = cyclic(3*dism+4); break;
    2118             :       }
    2119          42 :       break;
    2120             :     case 3:
    2121         693 :       if (!equalis(p,3) || Ip->tt <= 4)
    2122         483 :         return tame(polh, theta, alpha, Dmin, I, Ip);
    2123         210 :       return labelm3(polh,theta,alpha,Dmin,I,Ip); /* p = 3 */
    2124           0 :     default: pari_err_BUG("genus2localred [switch lambda]");
    2125             :   }
    2126         280 :   if (condp < 2 || condp > get_maxc(p))
    2127           0 :     pari_err_BUG("genus2localred [conductor]");
    2128         280 :   return condp;
    2129             : }
    2130             : 
    2131             : static long
    2132        2702 : chk_pol(GEN P) {
    2133        2702 :   switch(typ(P))
    2134             :   {
    2135        1309 :     case t_INT: break;
    2136        1393 :     case t_POL: RgX_check_ZX(P,"genus2red"); return varn(P); break;
    2137           0 :     default: pari_err_TYPE("genus2red", P);
    2138             :   }
    2139        1309 :   return -1;
    2140             : }
    2141             : 
    2142             : /* P,Q are ZX, study Y^2 + Q(X) Y = P(X) */
    2143             : GEN
    2144        1351 : genus2red(GEN PQ, GEN p)
    2145             : {
    2146        1351 :   pari_sp av = avma;
    2147             :   struct igusa I;
    2148             :   GEN P, Q, D;
    2149             :   GEN j22, j42, j2j6, a0,a1,a2,a3,a4,a5,a6, V,polr,facto,factp, vecmini, cond;
    2150             :   long i, l, dd, vP,vQ;
    2151             : 
    2152        1351 :   PQ = Q_remove_denom(PQ, &D);
    2153        1351 :   if (typ(PQ) == t_VEC && lg(PQ) == 3)
    2154             :   {
    2155          70 :     P = gel(PQ,1);
    2156          70 :     Q = gel(PQ,2);
    2157             :   }
    2158             :   else
    2159             :   {
    2160        1281 :     P = PQ;
    2161        1281 :     Q = gen_0;
    2162             :   }
    2163             : 
    2164        1351 :   vP = chk_pol(P);
    2165        1351 :   vQ = chk_pol(Q);
    2166        1351 :   if (vP < 0)
    2167             :   {
    2168           7 :     if (vQ < 0) pari_err_TYPE("genus2red",mkvec2(P,Q));
    2169           7 :     P = scalarpol(P,vQ);
    2170             :   }
    2171        1344 :   else if (vQ < 0) Q = scalarpol(Q,vP);
    2172        1351 :   if (p && typ(p) != t_INT) pari_err_TYPE("genus2red", p);
    2173        1351 :   if (D) P = ZX_Z_mul(P,D);
    2174             : 
    2175        1351 :   polr = ZX_add(ZX_sqr(Q), gmul2n(P,2)); /* ZX */
    2176        1351 :   switch(degpol(polr))
    2177             :   {
    2178        1351 :     case 5: case 6: break;
    2179           0 :     default: pari_err_DOMAIN("genus2red","genus","!=", gen_2,mkvec2(P,Q));
    2180             :   }
    2181             : 
    2182        1351 :   RgX_to_6(polr, &a0,&a1,&a2,&a3,&a4,&a5,&a6);
    2183        1351 :   I.j10 = !signe(a0)? mulii(sqri(a1), ZX_disc(polr)): ZX_disc(polr);
    2184        1351 :   if (!signe(I.j10))
    2185           0 :     pari_err_DOMAIN("genus2red","genus","<",gen_2,mkvec2(P,Q));
    2186        1351 :   I.j10 = gmul2n(I.j10, -12); /* t_INT */
    2187             : 
    2188        1351 :   if (p == NULL)
    2189             :   {
    2190          28 :     facto = factor(absi(I.j10));
    2191          28 :     factp = gel(facto,1);
    2192             :   }
    2193             :   else
    2194             :   {
    2195        1323 :     factp = mkcol(p);
    2196        1323 :     facto = mkmat2(factp, mkcol(gen_1));
    2197             :   }
    2198        1351 :   l = lg(factp);
    2199        1351 :   vecmini = cgetg(l, t_COL);
    2200        2723 :   for(i = 1; i<l; i++)
    2201             :   {
    2202        1372 :     GEN l = gel(factp,i), pm;
    2203        1372 :     if (i == 1 && absequaliu(l, 2)) { gel(vecmini,1) = gen_0; continue; }
    2204        1358 :     gel(vecmini,i) = pm = polymini(polr, l);
    2205        1358 :     polr = RgX_Rg_mul(gel(pm,1), powii(l, gel(pm,4)));
    2206             :   }
    2207        1351 :   RgX_to_6(polr, &a0,&a1,&a2,&a3,&a4,&a5,&a6);
    2208        1351 :   I.j10 = !signe(a0)? mulii(sqri(a1), ZX_disc(polr)): ZX_disc(polr);
    2209        1351 :   I.j10 = gmul2n(I.j10,-12);
    2210             : 
    2211        1351 :   I.a0 = a0;
    2212        1351 :   I.A2 = apol2(a0,a1,a2);
    2213        1351 :   I.A3 = apol3(a0,a1,a2,a3);
    2214        1351 :   I.A5 = apol5(a0,a1,a2,a3,a4,a5);
    2215        1351 :   I.B2 = bpol2(a0,a1,a2,a3,a4);
    2216             : 
    2217        1351 :   I.j2 = igusaj2(a0,a1,a2,a3,a4,a5,a6);
    2218        1351 :   I.j4 = igusaj4(a0,a1,a2,a3,a4,a5,a6);
    2219        1351 :   I.i4 = gsub(gsqr(I.j2), gmulsg(24,I.j4));
    2220        1351 :   I.j6 = igusaj6(a0,a1,a2,a3,a4,a5,a6);
    2221        1351 :   j42 = gsqr(I.j4);
    2222        1351 :   j22 = gsqr(I.j2);
    2223        1351 :   j2j6 = gmul(I.j2,I.j6);
    2224        1351 :   I.j8 = gmul2n(gsub(j2j6,j42), -2);
    2225        1351 :   I.i12= gmul2n(gsub(gadd(gmul(j22,j42),gmulsg(36,gmul(j2j6,I.j4))),
    2226             :                      gadd(gadd(gmulsg(32,gmul(j42,I.j4)),gmul(j2j6,j22)),gmulsg(108,gsqr(I.j6)))),-2);
    2227             : 
    2228        2723 :   for(i = 1; i < l; i++)
    2229        1372 :     gcoeff(facto,i,2) = stoi(Q_pval(I.j10, gel(factp,i)));
    2230        1351 :   dd = polval(polr,gen_2) & (~1); /* = 2 floor(val/2) */
    2231        1351 :   polr = gmul2n(polr, -dd);
    2232             : 
    2233        1351 :   V = cgetg(l, t_VEC);
    2234        2723 :   for (i = 1; i < l; i++)
    2235             :   {
    2236        1372 :     GEN q = gel(factp,i), red, N = NULL;
    2237             :     struct igusa_p Ip;
    2238        1372 :     long f = genus2localred(&I, &Ip, q, gel(vecmini,i));
    2239        1372 :     gcoeff(facto,i,2) = stoi(f);
    2240        1372 :     if (Ip.tame) Ip.type = stack_strcat("(tame) ", Ip.type);
    2241        1372 :     if (f >= 0)
    2242        1358 :       N = zv_snf(Ip.neron);
    2243        1372 :     if (DEBUGLEVEL)
    2244             :     {
    2245           0 :       if (!p) err_printf("p = %Ps\n", q);
    2246           0 :       err_printf("(potential) stable reduction: %Ps\n", Ip.stable);
    2247           0 :       if (f >= 0) {
    2248           0 :         err_printf("reduction at p: %s, %Ps", Ip.type, N);
    2249           0 :         err_printf(", f = %ld\n", f);
    2250             :       }
    2251             :     }
    2252        1372 :     red = f >= 0? mkvec2(strtoGENstr(Ip.type), N): cgetg(1, t_VEC);
    2253        1372 :     gel(V, i) = mkvec3(q, Ip.stable, red);
    2254             :   }
    2255        1351 :   if (p) V = gel(V,1);
    2256        1351 :   cond = factorback(facto);
    2257             :   /* remove denominator 2 coming from f = -1 in genuslocalred(, p = 2) */
    2258        1351 :   if (typ(cond) != t_INT) cond = gel(cond,1);
    2259        1351 :   return gerepilecopy(av, mkvec4(cond, facto, polr, V));
    2260             : }

Generated by: LCOV version 1.11