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

Generated by: LCOV version 1.11