Code coverage tests

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

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

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

LCOV - code coverage report
Current view: top level - basemath - char.c (source / functions) Hit Total Coverage
Test: PARI/GP v2.14.0 lcov report (development 27775-aca467eab2) Lines: 812 842 96.4 %
Date: 2022-07-03 07:33:15 Functions: 63 63 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; either version 2 of the License, or (at your option) any later
       8             : version. It is distributed in the hope that it will be useful, but WITHOUT
       9             : ANY WARRANTY WHATSOEVER.
      10             : 
      11             : Check the License for details. You should have received a copy of it, along
      12             : with the package; see the file 'COPYING'. If not, write to the Free Software
      13             : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
      14             : #include "pari.h"
      15             : #include "paripriv.h"
      16             : 
      17             : /*********************************************************************/
      18             : /**                                                                 **/
      19             : /**                  GENERIC ABELIAN CHARACTERS                     **/
      20             : /**                                                                 **/
      21             : /*********************************************************************/
      22             : /* check whether G is a znstar */
      23             : int
      24     3791557 : checkznstar_i(GEN G)
      25             : {
      26     3791340 :   return (typ(G) == t_VEC && lg(G) == 6
      27     3790962 :       && typ(znstar_get_faN(G)) == t_VEC
      28     7582897 :       && typ(gel(G,1)) == t_VEC && lg(gel(G,1)) == 3);
      29             : }
      30             : 
      31             : int
      32      111272 : char_check(GEN cyc, GEN chi)
      33      111272 : { return typ(chi) == t_VEC && lg(chi) == lg(cyc) && RgV_is_ZV(chi); }
      34             : 
      35             : /* Shallow; return [ d[1],  d[1]/d[2],...,d[1]/d[n] ] */
      36             : GEN
      37      232330 : cyc_normalize(GEN d)
      38             : {
      39      232330 :   long i, l = lg(d);
      40             :   GEN C, D;
      41      232330 :   if (l == 1) return mkvec(gen_1);
      42      232309 :   D = cgetg(l, t_VEC); gel(D,1) = C = gel(d,1);
      43      576604 :   for (i = 2; i < l; i++) gel(D,i) = diviiexact(C, gel(d,i));
      44      232309 :   return D;
      45             : }
      46             : 
      47             : /* chi character [D,C] given by chi(g_i) = \zeta_D^C[i] for all i, return
      48             :  * [d,c] such that chi(g_i) = \zeta_d^c[i] for all i and d minimal */
      49             : GEN
      50      272944 : char_simplify(GEN D, GEN C)
      51             : {
      52      272944 :   GEN d = D;
      53      272944 :   if (lg(C) == 1) d = gen_1;
      54             :   else
      55             :   {
      56      272559 :     GEN t = gcdii(d, ZV_content(C));
      57      272559 :     if (!equali1(t))
      58             :     {
      59      199906 :       long tc = typ(C);
      60      199906 :       C = ZC_Z_divexact(C, t); settyp(C, tc);
      61      199906 :       d = diviiexact(d, t);
      62             :     }
      63             :   }
      64      272944 :   return mkvec2(d,C);
      65             : }
      66             : 
      67             : /* Shallow; ncyc from cyc_normalize(): ncyc[1] = cyc[1],
      68             :  * ncyc[i] = cyc[i]/cyc[1] for i > 1; chi character on G ~ cyc.
      69             :  * Return [d,c] such that: chi( g_i ) = e(chi[i] / cyc[i]) = e(c[i]/ d) */
      70             : GEN
      71      272251 : char_normalize(GEN chi, GEN ncyc)
      72             : {
      73      272251 :   long i, l = lg(chi);
      74      272251 :   GEN c = cgetg(l, t_VEC);
      75      272251 :   if (l > 1) {
      76      272230 :     gel(c,1) = gel(chi,1);
      77      717857 :     for (i = 2; i < l; i++) gel(c,i) = mulii(gel(chi,i), gel(ncyc,i));
      78             :   }
      79      272251 :   return char_simplify(gel(ncyc,1), c);
      80             : }
      81             : 
      82             : /* Called by function 's'. x is a group object affording ".cyc" method, and
      83             :  * chi an abelian character. Return NULL if the group is (Z/nZ)^* [special
      84             :  * case more character types allowed] and x.cyc otherwise */
      85             : static GEN
      86         532 : get_cyc(GEN x, GEN chi, const char *s)
      87             : {
      88         532 :   switch(nftyp(x))
      89             :   {
      90         448 :     case typ_BIDZ:
      91         448 :       if (!zncharcheck(x, chi)) pari_err_TYPE(s, chi);
      92         448 :       return NULL;
      93           0 :     case typ_GCHAR:
      94           0 :       x = gchar_get_cyc(x);
      95           0 :       if (!is_vec_t(typ(chi)) || lg(chi) != lg(x) || !RgV_is_ZV(chi))
      96           0 :         pari_err_TYPE(s, chi); /* FIXME: handle norm component */
      97           0 :       return x;
      98          84 :     default:
      99          84 :       if (typ(x) != t_VEC || !RgV_is_ZV(x)) x = member_cyc(x);
     100          84 :       if (!char_check(x, chi)) pari_err_TYPE(s, chi);
     101          84 :       return x;
     102             :   }
     103             : }
     104             : 
     105             : /* conjugate character [ZV/ZC] */
     106             : GEN
     107        3339 : charconj(GEN cyc, GEN chi)
     108             : {
     109             :   long i, l;
     110        3339 :   GEN z = cgetg_copy(chi, &l);
     111        7322 :   for (i = 1; i < l; i++)
     112             :   {
     113        3983 :     GEN c = gel(chi,i);
     114        3983 :     gel(z,i) = signe(c)? subii(gel(cyc,i), c): gen_0;
     115             :   }
     116        3339 :   return z;
     117             : }
     118             : GEN
     119          28 : charconj0(GEN x, GEN chi)
     120             : {
     121          28 :   GEN cyc = get_cyc(x, chi, "charconj");
     122          28 :   return cyc? charconj(cyc, chi): zncharconj(x, chi);
     123             : }
     124             : 
     125             : GEN
     126      380184 : charorder(GEN cyc, GEN x)
     127             : {
     128      380184 :   pari_sp av = avma;
     129      380184 :   long i, l = lg(cyc);
     130      380184 :   GEN f = gen_1;
     131     1613430 :   for (i = 1; i < l; i++)
     132     1233246 :     if (signe(gel(x,i)))
     133             :     {
     134      796705 :       GEN c, o = gel(cyc,i);
     135      796705 :       if (!signe(o))
     136           0 :         return gerepileupto(av,mkoo());
     137      796705 :       c = gcdii(o, gel(x,i));
     138      796705 :       if (!is_pm1(c)) o = diviiexact(o,c);
     139      796705 :       f = lcmii(f, o);
     140             :     }
     141      380184 :   return gerepileuptoint(av, f);
     142             : }
     143             : GEN
     144         210 : charorder0(GEN x, GEN chi)
     145             : {
     146         210 :   GEN cyc = get_cyc(x, chi, "charorder");
     147         210 :   return cyc? charorder(cyc, chi): zncharorder(x, chi);
     148             : }
     149             : 
     150             : /* chi character of abelian G: chi[i] = chi(z_i), where G = \oplus Z/cyc[i] z_i.
     151             :  * Return Ker chi */
     152             : GEN
     153       96166 : charker(GEN cyc, GEN chi)
     154             : {
     155       96166 :   long i, l = lg(cyc);
     156             :   GEN nchi, ncyc, m, U;
     157             : 
     158       96166 :   if (l == 1) return cgetg(1,t_MAT); /* trivial subgroup */
     159       96117 :   ncyc = cyc_normalize(cyc);
     160       96117 :   nchi = char_normalize(chi, ncyc);
     161       96117 :   m = shallowconcat(gel(nchi,2), gel(nchi,1));
     162       96117 :   U = gel(ZV_extgcd(m), 2); setlg(U,l);
     163      264061 :   for (i = 1; i < l; i++) setlg(U[i], l);
     164       96117 :   return hnfmodid(U, gel(ncyc,1));
     165             : }
     166             : GEN
     167          35 : charker0(GEN x, GEN chi)
     168             : {
     169          35 :   GEN cyc = get_cyc(x, chi, "charker");
     170          35 :   return cyc? charker(cyc, chi): zncharker(x, chi);
     171             : }
     172             : 
     173             : GEN
     174         189 : charpow(GEN cyc, GEN a, GEN N)
     175             : {
     176             :   long i, l;
     177         189 :   GEN v = cgetg_copy(a, &l);
     178         350 :   for (i = 1; i < l; i++) gel(v,i) = Fp_mul(gel(a,i), N, gel(cyc,i));
     179         189 :   return v;
     180             : }
     181             : GEN
     182      302008 : charmul(GEN cyc, GEN a, GEN b)
     183             : {
     184             :   long i, l;
     185      302008 :   GEN v = cgetg_copy(a, &l);
     186     1350328 :   for (i = 1; i < l; i++) gel(v,i) = Fp_add(gel(a,i), gel(b,i), gel(cyc,i));
     187      302008 :   return v;
     188             : }
     189             : GEN
     190        5348 : chardiv(GEN cyc, GEN a, GEN b)
     191             : {
     192             :   long i, l;
     193        5348 :   GEN v = cgetg_copy(a, &l);
     194       11676 :   for (i = 1; i < l; i++) gel(v,i) = Fp_sub(gel(a,i), gel(b,i), gel(cyc,i));
     195        5348 :   return v;
     196             : }
     197             : GEN
     198          63 : charpow0(GEN x, GEN a, GEN N)
     199             : {
     200          63 :   GEN cyc = get_cyc(x, a, "charpow");
     201          63 :   return cyc? charpow(cyc, a, N): zncharpow(x, a, N);
     202             : }
     203             : GEN
     204         154 : charmul0(GEN x, GEN a, GEN b)
     205             : {
     206         154 :   const char *s = "charmul";
     207         154 :   GEN cyc = get_cyc(x, a, s);
     208         154 :   if (!cyc)
     209             :   {
     210         154 :     if (!zncharcheck(x, b)) pari_err_TYPE(s, b);
     211         154 :     return zncharmul(x, a, b);
     212             :   }
     213             :   else
     214             :   {
     215           0 :     if (!char_check(cyc, b)) pari_err_TYPE(s, b);
     216           0 :     return charmul(cyc, a, b);
     217             :   }
     218             : }
     219             : GEN
     220          42 : chardiv0(GEN x, GEN a, GEN b)
     221             : {
     222          42 :   const char *s = "chardiv";
     223          42 :   GEN cyc = get_cyc(x, a, s);
     224          42 :   if (!cyc)
     225             :   {
     226          42 :     if (!zncharcheck(x, b)) pari_err_TYPE(s, b);
     227          42 :     return znchardiv(x, a, b);
     228             :   }
     229             :   else
     230             :   {
     231           0 :     if (!char_check(cyc, b)) pari_err_TYPE(s, b);
     232           0 :     return chardiv(cyc, a, b);
     233             :   }
     234             : }
     235             : 
     236             : static GEN
     237     2511467 : chareval_i(GEN nchi, GEN dlog, GEN z)
     238             : {
     239     2511467 :   GEN o, q, r, b = gel(nchi,1);
     240     2511467 :   GEN a = FpV_dotproduct(gel(nchi,2), dlog, b);
     241             :   /* image is a/b in Q/Z */
     242     2511467 :   if (!z) return gdiv(a,b);
     243     2511089 :   if (typ(z) == t_INT)
     244             :   {
     245     2507911 :     q = dvmdii(z, b, &r);
     246     2507911 :     if (signe(r)) pari_err_TYPE("chareval", z);
     247     2507911 :     return mulii(a, q);
     248             :   }
     249             :   /* return z^(a*o/b), assuming z^o = 1 and b | o */
     250        3178 :   if (typ(z) != t_VEC || lg(z) != 3) pari_err_TYPE("chareval", z);
     251        3178 :   o = gel(z,2); if (typ(o) != t_INT) pari_err_TYPE("chareval", z);
     252        3178 :   q = dvmdii(o, b, &r); if (signe(r)) pari_err_TYPE("chareval", z);
     253        3178 :   q = mulii(a, q); /* in [0, o[ since a is reduced mod b */
     254        3178 :   z = gel(z,1);
     255        3178 :   if (typ(z) == t_VEC)
     256             :   {
     257        1862 :     if (itos_or_0(o) != lg(z)-1) pari_err_TYPE("chareval", z);
     258        1862 :     return gcopy(gel(z, itos(q)+1));
     259             :   }
     260             :   else
     261        1316 :     return gpow(z, q, DEFAULTPREC);
     262             : }
     263             : 
     264             : static GEN
     265        1855 : not_coprime(GEN z)
     266        1855 : { return (!z || typ(z) == t_INT)? gen_m1: gen_0; }
     267             : 
     268             : static GEN
     269          35 : get_chi(GEN cyc, GEN chi)
     270             : {
     271          35 :   if (!char_check(cyc,chi)) pari_err_TYPE("chareval", chi);
     272          35 :   return char_normalize(chi, cyc_normalize(cyc));
     273             : }
     274             : /* G a bnr.  FIXME: horribly inefficient to check that (x,N)=1, what to do ? */
     275             : static int
     276          42 : bnr_coprime(GEN G, GEN x)
     277             : {
     278          42 :   GEN t, N = gel(bnr_get_mod(G), 1);
     279          42 :   if (typ(x) == t_INT) /* shortcut */
     280             :   {
     281          14 :     t = gcdii(gcoeff(N,1,1), x);
     282          14 :     if (equali1(t)) return 1;
     283           0 :     t = idealadd(G, N, x);
     284           0 :     return equali1(gcoeff(t,1,1));
     285             :   }
     286          28 :   x = idealnumden(G, x);
     287          28 :   t = idealadd(G, N, gel(x,1));
     288          28 :   if (!equali1(gcoeff(t,1,1))) return 0;
     289          21 :   t = idealadd(G, N, gel(x,2));
     290          21 :   return equali1(gcoeff(t,1,1));
     291             : }
     292             : GEN
     293        7532 : chareval(GEN G, GEN chi, GEN x, GEN z)
     294             : {
     295        7532 :   pari_sp av = avma;
     296             :   GEN nchi, L;
     297             : 
     298        7532 :   switch(nftyp(G))
     299             :   {
     300          42 :     case typ_BNR:
     301          42 :       if (!bnr_coprime(G, x)) return not_coprime(z);
     302          28 :       L = isprincipalray(G, x);
     303          28 :       nchi = get_chi(bnr_get_cyc(G), chi);
     304          28 :       break;
     305           7 :     case typ_BNF:
     306           7 :       L = isprincipal(G, x);
     307           7 :       nchi = get_chi(bnf_get_cyc(G), chi);
     308           7 :       break;
     309        3542 :     case typ_BIDZ:
     310        3542 :       if (checkznstar_i(G)) return gerepileupto(av, znchareval(G, chi, x, z));
     311             :       /* don't implement chars on general bid: need an nf... */
     312             :     case typ_GCHAR:
     313        3934 :       if (z == NULL)
     314        3934 :         return gerepilecopy(av, gchareval(G, chi, x, 0));
     315             :       else
     316           0 :         pari_err_IMPL("evaluation of grossenchar only given in R/Z");
     317           7 :     default:
     318           7 :       pari_err_TYPE("chareval", G);
     319             :       return NULL;/* LCOV_EXCL_LINE */
     320             :   }
     321          35 :   return gerepileupto(av, chareval_i(nchi, L, z));
     322             : }
     323             : 
     324             : /* nchi = [ord,D] a quasi-normalized character (ord may be a multiple of
     325             :  * the character order); return v such that v[n] = -1 if (n,N) > 1 else
     326             :  * chi(n) = e(v[n]/ord), 1 <= n <= N */
     327             : GEN
     328       33691 : ncharvecexpo(GEN G, GEN nchi)
     329             : {
     330       33691 :   long N = itou(znstar_get_N(G)), ord = itou(gel(nchi,1)), i, j, l;
     331             :   GEN cyc, gen, d, t, t1, t2, t3, e, u, u1, u2, u3;
     332       33691 :   GEN D = gel(nchi,2), v = const_vecsmall(N,-1);
     333       33691 :   pari_sp av = avma;
     334       33691 :   if (typ(D) == t_COL) {
     335       33691 :     cyc = znstar_get_conreycyc(G);
     336       33691 :     gen = znstar_get_conreygen(G);
     337             :   } else {
     338           0 :     cyc = znstar_get_cyc(G);
     339           0 :     gen = znstar_get_gen(G);
     340             :   }
     341       33691 :   l = lg(cyc);
     342       33691 :   e = u = cgetg(N+1,t_VECSMALL);
     343       33691 :   d = t = cgetg(N+1,t_VECSMALL);
     344       33691 :   *++d = 1;
     345       33691 :   *++e = 0; v[*d] = *e;
     346       71792 :   for (i = 1; i < l; i++)
     347             :   {
     348       38101 :     ulong g = itou(gel(gen,i)), c = itou(gel(cyc,i)), x = itou(gel(D,i));
     349      536284 :     for (t1=t,u1=u,j=c-1; j; j--,t1=t2,u1=u2)
     350     1103319 :       for (t2=d,u2=e, t3=t1,u3=u1; t3<t2; )
     351             :       {
     352      605136 :         *++d = Fl_mul(*++t3, g, N);
     353      605136 :         *++e = Fl_add(*++u3, x, ord); v[*d] = *e;
     354             :       }
     355             :   }
     356       33691 :   set_avma(av); return v;
     357             : }
     358             : 
     359             : /*****************************************************************************/
     360             : 
     361             : static ulong
     362      256991 : lcmuu(ulong a, ulong b) { return (a/ugcd(a,b)) * b; }
     363             : static ulong
     364      101206 : zv_charorder(GEN cyc, GEN x)
     365             : {
     366      101206 :   long i, l = lg(cyc);
     367      101206 :   ulong f = 1;
     368      332031 :   for (i = 1; i < l; i++)
     369      230825 :     if (x[i])
     370             :     {
     371      155785 :       ulong o = cyc[i];
     372      155785 :       f = lcmuu(f, o / ugcd(o, x[i]));
     373             :     }
     374      101206 :   return f;
     375             : }
     376             : 
     377             : /* N > 0 */
     378             : GEN
     379      517398 : coprimes_zv(ulong N)
     380             : {
     381      517398 :   GEN v = const_vecsmall(N,1);
     382      517398 :   pari_sp av = avma;
     383      517398 :   GEN P = gel(factoru(N),1);
     384      517398 :   long i, l = lg(P);
     385     1218378 :   for (i = 1; i < l; i++)
     386             :   {
     387      700980 :     ulong p = P[i], j;
     388     3256057 :     for (j = p; j <= N; j += p) v[j] = 0;
     389             :   }
     390      517398 :   set_avma(av); return v;
     391             : }
     392             : /* cf zv_cyc_minimal: return k such that g*k is minimal (wrt lex) */
     393             : long
     394       46627 : zv_cyc_minimize(GEN cyc, GEN g, GEN coprime)
     395             : {
     396       46627 :   pari_sp av = avma;
     397       46627 :   long d, k, e, i, maxi, k0, bestk, l = lg(g), o = lg(coprime)-1;
     398             :   GEN best, gk, gd;
     399             :   ulong t;
     400       46627 :   if (o == 1) return 1;
     401       54187 :   for (i = 1; i < l; i++)
     402       54187 :     if (g[i]) break;
     403       46627 :   if (g[i] == 1) return 1;
     404       38423 :   k0 = Fl_invgen(g[i], cyc[i], &t);
     405       38423 :   d = cyc[i] / (long)t;
     406       38423 :   if (k0 > 1) g = vecmoduu(Flv_Fl_mul(g, k0, cyc[i]), cyc);
     407       50785 :   for (i++; i < l; i++)
     408       44751 :     if (g[i]) break;
     409       38423 :   if (i == l) return k0;
     410       32389 :   cyc = vecslice(cyc,i,l-1);
     411       32389 :   g   = vecslice(g,  i,l-1);
     412       32389 :   e = cyc[1];
     413       32389 :   gd = Flv_Fl_mul(g, d, e);
     414       32389 :   bestk = 1; best = g; maxi = e/ugcd(d,e);
     415       48643 :   for (gk = g, k = d+1, i = 1; i < maxi; k += d, i++)
     416             :   {
     417       16254 :     long ko = k % o;
     418       16254 :     gk = Flv_add(gk, gd, e); if (!ko || !coprime[ko]) continue;
     419        7357 :     gk = vecmoduu(gk, cyc);
     420        7357 :     if (vecsmall_lexcmp(gk, best) < 0) { best = gk; bestk = k; }
     421             :   }
     422       32389 :   return gc_long(av, bestk == 1? k0: (long) Fl_mul(k0, bestk, o));
     423             : }
     424             : /* g of order o in abelian group G attached to cyc. Is g a minimal generator
     425             :  * [wrt lex order] of the cyclic subgroup it generates;
     426             :  * coprime = coprimes_zv(o) */
     427             : long
     428      100758 : zv_cyc_minimal(GEN cyc, GEN g, GEN coprime)
     429             : {
     430      100758 :   pari_sp av = avma;
     431      100758 :   long i, maxi, d, k, e, l = lg(g), o = lg(coprime)-1; /* elt order */
     432             :   GEN gd, gk;
     433      100758 :   if (o == 1) return 1;
     434      106365 :   for (k = 1; k < l; k++)
     435      106365 :     if (g[k]) break;
     436      100758 :   if (g[k] == 1) return 1;
     437       80332 :   if (cyc[k] % g[k]) return 0;
     438       80332 :   d = cyc[k] / g[k]; /* > 1 */
     439       97069 :   for (k++; k < l; k++) /* skip following 0s */
     440       97069 :     if (g[k]) break;
     441       80332 :   if (k == l) return 1;
     442       80332 :   cyc = vecslice(cyc,k,l-1);
     443       80332 :   g   = vecslice(g,  k,l-1);
     444       80332 :   e = cyc[1];
     445             :   /* find k in (Z/e)^* such that g*k mod cyc is lexicographically minimal,
     446             :    * k = 1 mod d to fix the first nonzero entry */
     447       80332 :   gd = Flv_Fl_mul(g, d, e); maxi = e/ugcd(d,e);
     448      138159 :   for (gk = g, k = d+1, i = 1; i < maxi; i++, k += d)
     449             :   {
     450       67823 :     long ko = k % o;
     451       67823 :     gk = Flv_add(gk, gd, e); if (!coprime[ko]) continue;
     452       36141 :     gk = vecmoduu(gk, cyc);
     453       36141 :     if (vecsmall_lexcmp(gk, g) < 0) return gc_long(av,0);
     454             :   }
     455       70336 :   return gc_long(av,1);
     456             : }
     457             : 
     458             : static GEN
     459        5712 : coprime_tables(long N)
     460             : {
     461        5712 :   GEN D = divisorsu(N), v = const_vec(N, NULL);
     462        5712 :   long i, l = lg(D);
     463       38920 :   for (i = 1; i < l; i++) gel(v, D[i]) = coprimes_zv(D[i]);
     464        5712 :   return v;
     465             : }
     466             : /* enumerate all group elements, modulo (Z/cyc[1])^* */
     467             : static GEN
     468        5740 : cyc2elts_normal(GEN cyc, long maxord, GEN ORD)
     469             : {
     470        5740 :   long i, n, o, N, j = 1;
     471             :   GEN z, vcoprime;
     472             : 
     473        5740 :   if (typ(cyc) != t_VECSMALL) cyc = vec_to_vecsmall(cyc);
     474        5740 :   n = lg(cyc)-1;
     475        5740 :   N = zv_prod(cyc);
     476        5740 :   z = cgetg(N+1, t_VEC);
     477        5740 :   if (1 <= maxord && (!ORD|| zv_search(ORD,1)))
     478        5355 :     gel(z,j++) = zero_zv(n);
     479        5740 :   if (n == 0) { setlg(z, j); return z; }
     480        5712 :   vcoprime = coprime_tables(cyc[1]);
     481       18550 :   for (i = n; i > 0; i--)
     482             :   {
     483       12838 :     GEN cyc0 = vecslice(cyc,i+1,n), pre = zero_zv(i);
     484       12838 :     GEN D = divisorsu(cyc[i]), C = cyc2elts(cyc0);
     485       12838 :     long s, t, lD = lg(D), nC = lg(C)-1; /* remove last element */
     486       48461 :     for (s = 1; s < lD-1; s++)
     487             :     {
     488       35623 :       long o0 = D[lD-s]; /* cyc[i] / D[s] */
     489       35623 :       if (o0 > maxord) continue;
     490       34132 :       pre[i] = D[s];
     491       34132 :       if (!ORD || zv_search(ORD,o0))
     492             :       {
     493       33831 :         GEN c = vecsmall_concat(pre, zero_zv(n-i));
     494       33831 :         gel(z,j++) = c;
     495             :       }
     496      135338 :       for (t = 1; t < nC; t++)
     497             :       {
     498      101206 :         GEN chi0 = gel(C,t);
     499      101206 :         o = lcmuu(o0, zv_charorder(cyc0,chi0));
     500      101206 :         if (o <= maxord && (!ORD || zv_search(ORD,o)))
     501             :         {
     502      100758 :           GEN c = vecsmall_concat(pre, chi0);
     503      100758 :           if (zv_cyc_minimal(cyc, c, gel(vcoprime,o))) gel(z,j++) = c;
     504             :         }
     505             :       }
     506             :     }
     507             :   }
     508        5712 :   setlg(z,j); return z;
     509             : }
     510             : 
     511             : GEN
     512        6195 : chargalois(GEN G, GEN ORD)
     513             : {
     514        6195 :   pari_sp av = avma;
     515             :   long maxord, i, l;
     516        6195 :   GEN v, cyc = (typ(G) == t_VEC && RgV_is_ZVpos(G))? G: member_cyc(G);
     517        6195 :   if (lg(cyc) == 1 && !ORD) retmkvec(cgetg(1,t_VEC));
     518        5747 :   maxord = itou(cyc_get_expo(cyc));
     519        5747 :   if (ORD)
     520         441 :     switch(typ(ORD))
     521             :     {
     522             :       long l;
     523          42 :       case t_VEC:
     524          42 :         ORD = ZV_to_zv(ORD);
     525         406 :       case t_VECSMALL:
     526         406 :         l = lg(ORD);
     527         406 :         if (l > 2)
     528             :         {
     529         371 :           ORD = leafcopy(ORD);
     530         371 :           vecsmall_sort(ORD);
     531             :         }
     532         406 :         if (l == 1) { set_avma(av); return cgetg(1, t_VEC); }
     533         399 :         maxord = minss(maxord, ORD[l-1]);
     534         399 :         break;
     535          35 :       case t_INT:
     536          35 :         maxord = minss(maxord, itos(ORD));
     537          35 :         ORD = NULL;
     538          35 :         break;
     539           0 :       default: pari_err_TYPE("chargalois", ORD);
     540             :     }
     541        5740 :   v = cyc2elts_normal(cyc, maxord, ORD); l = lg(v);
     542      135688 :   for(i = 1; i < l; i++) gel(v,i) = zv_to_ZV(gel(v,i));
     543        5740 :   return gerepileupto(av, v);
     544             : }
     545             : 
     546             : /*********************************************************************/
     547             : /**                                                                 **/
     548             : /**                  (Z/NZ)^* AND DIRICHLET CHARACTERS              **/
     549             : /**                                                                 **/
     550             : /*********************************************************************/
     551             : 
     552             : GEN
     553       82663 : znstar0(GEN N, long flag)
     554             : {
     555       82663 :   GEN F = NULL, P, E, cyc, gen, mod, G;
     556             :   long i, i0, l, nbprimes;
     557       82663 :   pari_sp av = avma;
     558             : 
     559       82663 :   if (flag && flag != 1) pari_err_FLAG("znstar");
     560       82663 :   if ((F = check_arith_all(N,"znstar")))
     561             :   {
     562        9975 :     F = clean_Z_factor(F);
     563        9975 :     N = typ(N) == t_VEC? gel(N,1): factorback(F);
     564             :   }
     565       82663 :   if (!signe(N))
     566             :   {
     567          21 :     if (flag) pari_err_IMPL("znstar(0,1)");
     568          14 :     set_avma(av);
     569          14 :     retmkvec3(gen_2, mkvec(gen_2), mkvec(gen_m1));
     570             :   }
     571       82642 :   N = absi_shallow(N);
     572       82642 :   if (abscmpiu(N,2) <= 0)
     573             :   {
     574        8337 :     G = mkvec3(gen_1, cgetg(1,t_VEC), cgetg(1,t_VEC));
     575        8337 :     if (flag)
     576             :     {
     577        8309 :       GEN v = const_vec(6,cgetg(1,t_VEC));
     578        8309 :       gel(v,3) = cgetg(1,t_MAT);
     579       16583 :       F = equali1(N)? mkvec2(cgetg(1,t_COL),cgetg(1,t_VECSMALL))
     580        8309 :                     : mkvec2(mkcol(gen_2), mkvecsmall(1));
     581        8309 :       G = mkvec5(mkvec2(N,mkvec(gen_0)), G, F, v, cgetg(1,t_MAT));
     582             :     }
     583        8337 :     return gerepilecopy(av,G);
     584             :   }
     585       74305 :   if (!F) F = Z_factor(N);
     586       74305 :   P = gel(F,1); nbprimes = lg(P)-1;
     587       74305 :   E = ZV_to_nv( gel(F,2) );
     588       74305 :   switch(mod8(N))
     589             :   {
     590       19831 :     case 0:
     591       19831 :       P = shallowconcat(gen_2,P);
     592       19831 :       E = vecsmall_prepend(E, E[1]); /* add a copy of p=2 row */
     593       19831 :       i = 2; /* 2 generators at 2 */
     594       19831 :       break;
     595       14630 :     case 4:
     596       14630 :       i = 1; /* 1 generator at 2 */
     597       14630 :       break;
     598        7014 :     case 2: case 6:
     599        7014 :       P = vecsplice(P,1);
     600        7014 :       E = vecsplice(E,1); /* remove 2 */
     601        7014 :       i = 0; /* no generator at 2 */
     602        7014 :       break;
     603       32830 :     default:
     604       32830 :       i = 0; /* no generator at 2 */
     605       32830 :       break;
     606             :   }
     607       74305 :   l = lg(P);
     608       74305 :   cyc = cgetg(l,t_VEC);
     609       74305 :   gen = cgetg(l,t_VEC);
     610       74305 :   mod = cgetg(l,t_VEC);
     611             :   /* treat p=2 first */
     612       74305 :   if (i == 2)
     613             :   {
     614       19831 :     long v2 = E[1];
     615       19831 :     GEN q = int2n(v2);
     616       19831 :     gel(cyc,1) = gen_2;
     617       19831 :     gel(gen,1) = subiu(q,1); /* -1 */
     618       19831 :     gel(mod,1) = q;
     619       19831 :     gel(cyc,2) = int2n(v2-2);
     620       19831 :     gel(gen,2) = utoipos(5); /* Conrey normalization */
     621       19831 :     gel(mod,2) = q;
     622       19831 :     i0 = 3;
     623             :   }
     624       54474 :   else if (i == 1)
     625             :   {
     626       14630 :     gel(cyc,1) = gen_2;
     627       14630 :     gel(gen,1) = utoipos(3);
     628       14630 :     gel(mod,1) = utoipos(4);
     629       14630 :     i0 = 2;
     630             :   }
     631             :   else
     632       39844 :     i0 = 1;
     633             :   /* odd primes, fill remaining entries */
     634      187964 :   for (i = i0; i < l; i++)
     635             :   {
     636      113659 :     long e = E[i];
     637      113659 :     GEN p = gel(P,i), q = powiu(p, e-1), Q = mulii(p, q);
     638      113659 :     gel(cyc,i) = subii(Q, q); /* phi(p^e) */
     639      113659 :     gel(gen,i) = pgener_Zp(p);/* Conrey normalization, for e = 1 also */
     640      113659 :     gel(mod,i) = Q;
     641             :   }
     642             :   /* gen[i] has order cyc[i] and generates (Z/mod[i]Z)^* */
     643       74305 :   if (nbprimes > 1) /* lift generators to (Z/NZ)^*, = 1 mod N/mod[i] */
     644      195811 :     for (i=1; i<l; i++)
     645             :     {
     646      143353 :       GEN Q = gel(mod,i), g = gel(gen,i), qinv = Fp_inv(Q, diviiexact(N,Q));
     647      143353 :       g = addii(g, mulii(mulii(subsi(1,g),qinv),Q));
     648      143353 :       gel(gen,i) = modii(g, N);
     649             :     }
     650             : 
     651             :   /* cyc[i] > 1 and remain so in the loop, gen[i] = 1 mod (N/mod[i]) */
     652       74305 :   if (!flag)
     653             :   { /* update generators in place; about twice faster */
     654        7952 :     G = gen;
     655        8169 :     for (i=l-1; i>=2; i--)
     656             :     {
     657         217 :       GEN ci = gel(cyc,i), gi = gel(G,i);
     658             :       long j;
     659         518 :       for (j=i-1; j>=1; j--) /* we want cyc[i] | cyc[j] */
     660             :       {
     661         301 :         GEN cj = gel(cyc,j), gj, qj, v, d;
     662             : 
     663         301 :         d = bezout(ci,cj,NULL,&v); /* > 1 */
     664         455 :         if (absequalii(ci, d)) continue; /* ci | cj */
     665         189 :         if (absequalii(cj, d)) { /* cj | ci */
     666         154 :           swap(gel(G,j),gel(G,i));
     667         154 :           gi = gel(G,i);
     668         154 :           swap(gel(cyc,j),gel(cyc,i));
     669         154 :           ci = gel(cyc,i); continue;
     670             :         }
     671             : 
     672          35 :         qj = diviiexact(cj,d);
     673          35 :         gel(cyc,j) = mulii(ci,qj);
     674          35 :         gel(cyc,i) = d;
     675             : 
     676             :         /* [1,v*cj/d; 0,1]*[1,0;-1,1]*diag(cj,ci)*[ci/d,-v; cj/d,u]
     677             :          * = diag(lcm,gcd), with u ci + v cj = d */
     678          35 :         gj = gel(G,j);
     679             :         /* (gj, gi) *= [1,0; -1,1]^-1 */
     680          35 :         gj = Fp_mul(gj, gi, N); /* order ci*qj = lcm(ci,cj) */
     681             :         /* (gj,gi) *= [1,v*qj; 0,1]^-1 */
     682          35 :         togglesign_safe(&v);
     683          35 :         if (signe(v) < 0) v = modii(v,ci); /* >= 0 to avoid inversions */
     684          35 :         gel(G,i) = gi = Fp_mul(gi, Fp_pow(gj, mulii(qj, v), N), N);
     685          35 :         gel(G,j) = gj;
     686          35 :         ci = d; if (absequaliu(ci, 2)) break;
     687             :       }
     688             :     }
     689        7952 :     G = mkvec3(ZV_prod(cyc), cyc, FpV_to_mod(G,N));
     690             :   }
     691             :   else
     692             :   { /* keep matrices between generators, return an 'init' structure */
     693       66353 :     GEN D, U, Ui, fao = cgetg(l, t_VEC), lo = cgetg(l, t_VEC);
     694       66353 :     F = mkvec2(P, E);
     695       66353 :     D = ZV_snf_group(cyc,&U,&Ui);
     696      226135 :     for (i = 1; i < l; i++)
     697             :     {
     698      159782 :       GEN t = gen_0, p = gel(P,i), p_1 = subiu(p,1);
     699      159782 :       long e = E[i];
     700      159782 :       gel(fao,i) = get_arith_ZZM(p_1);
     701      159782 :       if (e >= 2 && !absequaliu(p,2))
     702             :       {
     703       12747 :         GEN q = gel(mod,i), g = Fp_pow(gel(gen,i),p_1,q);
     704       12747 :         if (e == 2)
     705       10374 :           t = Fp_inv(diviiexact(subiu(g,1), p), p);
     706             :         else
     707        2373 :           t = ginv(Qp_log(cvtop(g,p,e)));
     708             :       }
     709      159782 :       gel(lo,i) = t;
     710             :     }
     711       66353 :     G = cgetg(l, t_VEC);
     712      226135 :     for (i = 1; i < l; i++) gel(G,i) = FpV_factorback(gen, gel(Ui,i), N);
     713       66353 :     G = mkvec3(ZV_prod(D), D, G);
     714       66353 :     G = mkvec5(mkvec2(N,mkvec(gen_0)), G, F,
     715             :                mkvecn(6,mod,fao,Ui,gen,cyc,lo), U);
     716             :   }
     717       74305 :   return gerepilecopy(av, G);
     718             : }
     719             : GEN
     720        7903 : znstar(GEN N) { return znstar0(N, 0); }
     721             : 
     722             : /* g has order 2^(e-2), g,h = 1 (mod 4); return x s.t. g^x = h (mod 2^e) */
     723             : static GEN
     724      948934 : Zideallog_2k(GEN h, GEN g, long e, GEN pe)
     725             : {
     726      948934 :   GEN a = Fp_log(h, g, int2n(e-2), pe);
     727      948934 :   if (typ(a) != t_INT) return NULL;
     728      948934 :   return a;
     729             : }
     730             : 
     731             : /* ord = get_arith_ZZM(p-1), simplified form of znlog_rec: g is known
     732             :  * to be a primitive root mod p^e; lo = 1/log_p(g^(p-1)) */
     733             : static GEN
     734     1967308 : Zideallog_pk(GEN h, GEN g, GEN p, long e, GEN pe, GEN ord, GEN lo)
     735             : {
     736     1967308 :   GEN gp = (e == 1)? g: modii(g, p);
     737     1967308 :   GEN hp = (e == 1)? h: modii(h, p);
     738     1967308 :   GEN a = Fp_log(hp, gp, ord, p);
     739     1967308 :   if (typ(a) != t_INT) return NULL;
     740     1967301 :   if (e > 1)
     741             :   { /* find a s.t. g^a = h (mod p^e), p odd prime, e > 0, (h,p) = 1 */
     742             :     /* use p-adic log: O(log p + e) mul*/
     743       53172 :     GEN b, p_1 = gel(ord,1);
     744       53172 :     h = Fp_mul(h, Fp_pow(g, negi(a), pe), pe);
     745             :     /* g,h = 1 mod p; compute b s.t. h = g^b */
     746       53172 :     if (e == 2) /* simpler */
     747       45871 :       b = Fp_mul(diviiexact(subiu(h,1), p), lo, p);
     748             :     else
     749        7301 :       b = padic_to_Q(gmul(Qp_log(cvtop(h, p, e)), lo));
     750       53172 :     a = addii(a, mulii(p_1, b));
     751             :   }
     752     1967301 :   return a;
     753             : }
     754             : 
     755             : int
     756      885507 : znconrey_check(GEN cyc, GEN chi)
     757      885507 : { return typ(chi) == t_COL && lg(chi) == lg(cyc) && RgV_is_ZV(chi); }
     758             : 
     759             : int
     760      193200 : zncharcheck(GEN G, GEN chi)
     761             : {
     762      193200 :   switch(typ(chi))
     763             :   {
     764         875 :     case t_INT: return 1;
     765      190561 :     case t_COL: return znconrey_check(znstar_get_conreycyc(G), chi);
     766        1764 :     case t_VEC: return char_check(znstar_get_cyc(G), chi);
     767             :   }
     768           0 :   return 0;
     769             : }
     770             : 
     771             : GEN
     772      133035 : znconreyfromchar_normalized(GEN bid, GEN chi)
     773             : {
     774      133035 :   GEN nchi, U = znstar_get_U(bid);
     775      133035 :   long l = lg(chi);
     776      133035 :   if (l == 1) retmkvec2(gen_1,cgetg(1,t_VEC));
     777      132580 :   if (!RgV_is_ZV(chi) || lgcols(U) != l) pari_err_TYPE("lfunchiZ", chi);
     778      132573 :   nchi = char_normalize(chi, cyc_normalize(znstar_get_cyc(bid)));
     779      132573 :   gel(nchi,2) = ZV_ZM_mul(gel(nchi,2),U); return nchi;
     780             : }
     781             : 
     782             : GEN
     783      131117 : znconreyfromchar(GEN bid, GEN chi)
     784             : {
     785      131117 :   GEN nchi = znconreyfromchar_normalized(bid, chi);
     786      131110 :   GEN v = char_denormalize(znstar_get_conreycyc(bid), gel(nchi,1), gel(nchi,2));
     787      131110 :   settyp(v, t_COL); return v;
     788             : }
     789             : 
     790             : /* discrete log on canonical "primitive root" generators
     791             :  * Allow log(x) instead of x [usual discrete log on bid's generators] */
     792             : GEN
     793     2561223 : znconreylog(GEN bid, GEN x)
     794             : {
     795     2561223 :   pari_sp av = avma;
     796             :   GEN N, L, F, P,E, y, pe, fao, gen, lo, cycg;
     797             :   long i, l;
     798     2561223 :   if (!checkznstar_i(bid)) pari_err_TYPE("znconreylog", bid);
     799     2561223 :   N = znstar_get_N(bid);
     800     2561223 :   if (typ(N) != t_INT) pari_err_TYPE("znconreylog", N);
     801     2561216 :   if (abscmpiu(N, 2) <= 0) return cgetg(1, t_COL);
     802     2558808 :   cycg = znstar_get_conreycyc(bid);
     803     2558808 :   switch(typ(x))
     804             :   {
     805             :     GEN Ui;
     806     2536492 :     case t_INT:
     807     2536492 :       if (!signe(x)) pari_err_COPRIME("znconreylog", x, N);
     808     2536485 :       break;
     809          35 :     case t_COL: /* log_bid(x) */
     810          35 :       Ui = znstar_get_Ui(bid);
     811          35 :       if (!RgV_is_ZV(x) || lg(x) != lg(Ui)) pari_err_TYPE("znconreylog", x);
     812          35 :       return gerepileupto(av, vecmodii(ZM_ZC_mul(Ui,x), cycg));
     813       22281 :     case t_VEC:
     814       22281 :       return gerepilecopy(av, znconreyfromchar(bid, x));
     815           0 :     default: pari_err_TYPE("znconreylog", x);
     816             :   }
     817     2536485 :   F = znstar_get_faN(bid); /* factor(N) */
     818     2536485 :   P = gel(F, 1); /* prime divisors of N */
     819     2536485 :   E = gel(F, 2); /* exponents */
     820     2536485 :   L = gel(bid,4);
     821     2536485 :   pe = znstar_get_pe(bid);
     822     2536485 :   fao = gel(L,2);
     823     2536485 :   gen = znstar_get_conreygen(bid); /* local generators of (Z/p^k)^* */
     824     2536485 :   lo = gel(L,6); /* 1/log_p((g_i)^(p_i-1)) */
     825             : 
     826     2536485 :   l = lg(gen); i = 1;
     827     2536485 :   y = cgetg(l, t_COL);
     828     2536485 :   if (!mod2(N) && !mod2(x)) pari_err_COPRIME("znconreylog", x, N);
     829     2536471 :   if (absequaliu(gel(P,1), 2) && E[1] >= 2)
     830             :   {
     831     1253581 :     if (E[1] == 2)
     832      304647 :       gel(y,i++) = mod4(x) == 1? gen_0: gen_1;
     833             :     else
     834             :     {
     835      948934 :       GEN a, x2, q2 = gel(pe,1);
     836      948934 :       x2 = modii(x, q2);
     837      948934 :       if (mod4(x) == 1) /* 1 or 5 mod 8*/
     838      591962 :         gel(y,i++) = gen_0;
     839             :       else /* 3 or 7 */
     840      356972 :       { gel(y,i++) = gen_1; x2 = subii(q2, x2); }
     841             :       /* x2 = 5^x mod q */
     842      948934 :       a = Zideallog_2k(x2, gel(gen,i), E[1], q2);
     843      948934 :       if (!a) pari_err_COPRIME("znconreylog", x, N);
     844      948934 :       gel(y, i++) = a;
     845             :     }
     846             :   }
     847     4503772 :   while (i < l)
     848             :   {
     849     1967308 :     GEN p = gel(P,i), q = gel(pe,i), xpe = modii(x, q);
     850     1967308 :     GEN a = Zideallog_pk(xpe, gel(gen,i), p, E[i], q, gel(fao,i), gel(lo,i));
     851     1967308 :     if (!a) pari_err_COPRIME("znconreylog", x, N);
     852     1967301 :     gel(y, i++) = a;
     853             :   }
     854     2536464 :   return gerepilecopy(av, y);
     855             : }
     856             : GEN
     857        7217 : Zideallog(GEN bid, GEN x)
     858             : {
     859        7217 :   pari_sp av = avma;
     860        7217 :   GEN y = znconreylog(bid, x), U = znstar_get_U(bid);
     861        7189 :   return gerepileupto(av, ZM_ZC_mul(U, y));
     862             : }
     863             : GEN
     864         294 : znlog0(GEN h, GEN g, GEN o)
     865             : {
     866         294 :   if (typ(g) == t_VEC)
     867             :   {
     868             :     GEN N;
     869          56 :     if (o) pari_err_TYPE("znlog [with znstar]", o);
     870          56 :     if (!checkznstar_i(g)) pari_err_TYPE("znlog", g);
     871          56 :     N = znstar_get_N(g);
     872          56 :     h = Rg_to_Fp(h,N);
     873          49 :     return Zideallog(g, h);
     874             :   }
     875         238 :   return znlog(h, g, o);
     876             : }
     877             : 
     878             : GEN
     879      260764 : znconreyexp(GEN bid, GEN x)
     880             : {
     881      260764 :   pari_sp av = avma;
     882             :   long i, l;
     883             :   GEN N, pe, gen, cycg, v, vmod;
     884             :   int e2;
     885      260764 :   if (!checkznstar_i(bid)) pari_err_TYPE("znconreyexp", bid);
     886      260764 :   cycg = znstar_get_conreycyc(bid);
     887      260764 :   switch(typ(x))
     888             :   {
     889          21 :     case t_VEC:
     890          21 :       x = znconreylog(bid, x);
     891          21 :       break;
     892      260743 :     case t_COL:
     893      260743 :       if (RgV_is_ZV(x) && lg(x) == lg(cycg)) break;
     894           7 :     default: pari_err_TYPE("znconreyexp",x);
     895             :   }
     896      260757 :   pe = znstar_get_pe(bid);
     897      260757 :   gen = znstar_get_conreygen(bid); /* local generators of (Z/p^k)^* */
     898      260757 :   cycg = znstar_get_conreycyc(bid);
     899      260757 :   l = lg(x); v = cgetg(l, t_VEC);
     900      260757 :   N = znstar_get_N(bid);
     901      260757 :   e2 = !mod8(N); /* 2 generators at p = 2 */
     902      805658 :   for (i = 1; i < l; i++)
     903             :   {
     904             :     GEN q, g, m;
     905      544901 :     if (i == 1 && e2) { gel(v,1) = NULL; continue; }
     906      512617 :     q = gel(pe,i);
     907      512617 :     g = gel(gen,i);
     908      512617 :     m = modii(gel(x,i), gel(cycg,i));
     909      512617 :     m = Fp_pow(g, m, q);
     910      512617 :     if (i == 2 && e2 && signe(gel(x,1))) m = Fp_neg(m, q);
     911      512617 :     gel(v,i) = mkintmod(m, q);
     912             :   }
     913      260757 :   if (e2) v = vecsplice(v, 1);
     914      260757 :   v = chinese1_coprime_Z(v);
     915      260757 :   vmod = gel(v,1);
     916      260757 :   v = gel(v,2);
     917      260757 :   if (mpodd(v) || mpodd(N)) return gerepilecopy(av, v);
     918             :   /* handle N = 2 mod 4 */
     919         231 :   return gerepileuptoint(av, addii(v, vmod));
     920             : }
     921             : 
     922             : /* Return Dirichlet character \chi_q(m,.), where bid = znstar(q);
     923             :  * m is either a t_INT, or a t_COL [Conrey logarithm] */
     924             : GEN
     925       46767 : znconreychar(GEN bid, GEN m)
     926             : {
     927       46767 :   pari_sp av = avma;
     928             :   GEN c, d, nchi;
     929             : 
     930       46767 :   if (!checkznstar_i(bid)) pari_err_TYPE("znconreychar", bid);
     931       46760 :   switch(typ(m))
     932             :   {
     933       46760 :     case t_COL:
     934             :     case t_INT:
     935       46760 :       nchi = znconrey_normalized(bid,m); /* images of primroot gens */
     936       46753 :       break;
     937           0 :     default:
     938           0 :       pari_err_TYPE("znconreychar",m);
     939             :       return NULL;/*LCOV_EXCL_LINE*/
     940             :   }
     941       46753 :   d = gel(nchi,1);
     942       46753 :   c = ZV_ZM_mul(gel(nchi,2), znstar_get_Ui(bid)); /* images of bid gens */
     943       46753 :   return gerepilecopy(av, char_denormalize(znstar_get_cyc(bid),d,c));
     944             : }
     945             : 
     946             : /* chi a t_INT or Conrey log describing a character. Return conductor, as an
     947             :  * integer if primitive; as a t_VEC [N,factor(N)] if not. Set *pm=m to the
     948             :  * attached primitive character: chi(g_i) = m[i]/ord(g_i)
     949             :  * Caller should use znconreylog_normalize(BID, m), once BID(conductor) is
     950             :  * computed (wasteful to do it here since BID is shared by many characters) */
     951             : GEN
     952      716667 : znconreyconductor(GEN bid, GEN chi, GEN *pm)
     953             : {
     954      716667 :   pari_sp av = avma;
     955             :   GEN q, m, F, P, E;
     956             :   long i, j, l;
     957      716667 :   int e2, primitive = 1;
     958             : 
     959      716667 :   if (!checkznstar_i(bid)) pari_err_TYPE("znconreyconductor", bid);
     960      716667 :   if (typ(chi) == t_COL)
     961             :   {
     962      694946 :     if (!znconrey_check(znstar_get_conreycyc(bid), chi))
     963           0 :       pari_err_TYPE("znconreyconductor",chi);
     964             :   }
     965             :   else
     966       21721 :     chi = znconreylog(bid, chi);
     967      716660 :   l = lg(chi);
     968      716660 :   F = znstar_get_faN(bid);
     969      716660 :   P = gel(F,1);
     970      716660 :   E = gel(F,2);
     971      716660 :   if (l == 1)
     972             :   {
     973       95571 :     set_avma(av);
     974       95571 :     if (pm) *pm = cgetg(1,t_COL);
     975       95571 :     if (lg(P) == 1) return gen_1;
     976          14 :     retmkvec2(gen_1, trivial_fact());
     977             :   }
     978      621089 :   P = leafcopy(P);
     979      621089 :   E = leafcopy(E);
     980      621089 :   m = cgetg(l, t_COL);
     981      621089 :   e2 = (E[1] >= 3 && absequaliu(gel(P,1),2));
     982      621089 :   i = j = 1;
     983      621089 :   if (e2)
     984             :   { /* two generators at p=2 */
     985      285943 :     GEN a1 = gel(chi,1), a = gel(chi,2);
     986      285943 :     i = 3;
     987      285943 :     if (!signe(a))
     988             :     {
     989       97972 :       e2 =  primitive = 0;
     990       97972 :       if (signe(a1))
     991             :       { /* lose one generator */
     992       45493 :         E[1] = 2;
     993       45493 :         gel(m,1) = a1;
     994       45493 :         j = 2;
     995             :       }
     996             :       /* else lose both */
     997             :     }
     998             :     else
     999             :     {
    1000      187971 :       long v = Z_pvalrem(a, gen_2, &a);
    1001      187971 :       if (v) { E[1] -= v; E[2] = E[1]; primitive = 0; }
    1002      187971 :       gel(m,1) = a1;
    1003      187971 :       gel(m,2) = a;
    1004      187971 :       j = 3;
    1005             :     }
    1006             :   }
    1007      621089 :   l = lg(P);
    1008     1809458 :   for (; i < l; i++)
    1009             :   {
    1010     1188369 :     GEN p = gel(P,i), a = gel(chi,i);
    1011             :     /* image of g_i in Q/Z is a/cycg[i], cycg[i] = order(g_i) */
    1012     1188369 :     if (!signe(a)) primitive = 0;
    1013             :     else
    1014             :     {
    1015      928032 :       long v = Z_pvalrem(a, p, &a);
    1016      928032 :       E[j] = E[i]; if (v) { E[j] -= v; primitive = 0; }
    1017      928032 :       gel(P,j) = gel(P,i);
    1018      928032 :       gel(m,j) = a; j++;
    1019             :     }
    1020             :   }
    1021      621089 :   setlg(m,j);
    1022      621089 :   setlg(P,j);
    1023      621089 :   setlg(E,j);
    1024      621089 :   if (pm) *pm = m; /* attached primitive  character */
    1025      621089 :   if (primitive)
    1026             :   {
    1027      285334 :     q = znstar_get_N(bid);
    1028      285334 :     if (mod4(q) == 2) primitive = 0;
    1029             :   }
    1030      621089 :   if (!primitive)
    1031             :   {
    1032      336532 :     if (e2)
    1033             :     { /* remove duplicate p=2 row from factorization */
    1034      114744 :       P = vecsplice(P,1);
    1035      114744 :       E = vecsplice(E,1);
    1036             :     }
    1037      336532 :     E = zc_to_ZC(E);
    1038      336532 :     q = mkvec2(factorback2(P,E), mkmat2(P,E));
    1039             :   }
    1040      621089 :   return gc_all(av, pm? 2: 1, &q, pm);
    1041             : }
    1042             : 
    1043             : GEN
    1044        8358 : zncharinduce(GEN G, GEN chi, GEN N)
    1045             : {
    1046        8358 :   pari_sp av = avma;
    1047             :   GEN q, faq, P, E, Pq, Eq, CHI;
    1048             :   long i, j, l;
    1049             :   int e2;
    1050             : 
    1051        8358 :   if (!checkznstar_i(G)) pari_err_TYPE("zncharinduce", G);
    1052        8358 :   if (!zncharcheck(G, chi)) pari_err_TYPE("zncharinduce", chi);
    1053        8358 :   q = znstar_get_N(G);
    1054        8358 :   if (typ(chi) != t_COL) chi = znconreylog(G, chi);
    1055        8358 :   if (checkznstar_i(N))
    1056             :   {
    1057        8169 :     GEN faN = znstar_get_faN(N);
    1058        8169 :     P = gel(faN,1); l = lg(P);
    1059        8169 :     E = gel(faN,2);
    1060        8169 :     N = znstar_get_N(N);
    1061        8169 :     if (l > 2 && equalii(gel(P,1),gel(P,2)))
    1062             :     { /* remove duplicate 2 */
    1063        2569 :       l--;
    1064        2569 :       P = vecsplice(P,1);
    1065        2569 :       E = vecsplice(E,1);
    1066             :     }
    1067             :   }
    1068             :   else
    1069             :   {
    1070         189 :     GEN faN = check_arith_pos(N, "zncharinduce");
    1071         189 :     if (!faN) faN = Z_factor(N);
    1072             :     else
    1073           0 :       N = (typ(N) == t_VEC)? gel(N,1): factorback(faN);
    1074         189 :     P = gel(faN,1);
    1075         189 :     E = gel(faN,2);
    1076             :   }
    1077        8358 :   if (!dvdii(N,q)) pari_err_DOMAIN("zncharinduce", "N % q", "!=", gen_0, N);
    1078        8351 :   if (mod4(N) == 2)
    1079             :   { /* remove 2 */
    1080          77 :     if (lg(P) > 1 && absequaliu(gel(P,1), 2))
    1081             :     {
    1082          35 :       P = vecsplice(P,1);
    1083          35 :       E = vecsplice(E,1);
    1084             :     }
    1085          77 :     N = shifti(N,-1);
    1086             :   }
    1087        8351 :   l = lg(P);
    1088             :   /* q = N or q = 2N, N odd */
    1089        8351 :   if (cmpii(N,q) <= 0) return gerepilecopy(av, chi);
    1090             :   /* N > 1 => l > 1*/
    1091        8225 :   if (typ(E) != t_VECSMALL) E = ZV_to_zv(E);
    1092        8225 :   e2 = (E[1] >= 3 && absequaliu(gel(P,1),2)); /* 2 generators at 2 mod N */
    1093        8225 :   if (ZV_equal0(chi))
    1094             :   {
    1095        5327 :     set_avma(av);
    1096        5327 :     return equali1(N)? cgetg(1, t_COL): zerocol(l+e2 - 1);
    1097             :   }
    1098             : 
    1099        2898 :   faq = znstar_get_faN(G);
    1100        2898 :   Pq = gel(faq,1);
    1101        2898 :   Eq = gel(faq,2);
    1102        2898 :   CHI = cgetg(l+e2, t_COL);
    1103        2898 :   i = j = 1;
    1104        2898 :   if (e2)
    1105             :   {
    1106        1183 :     i = 2; j = 3;
    1107        1183 :     if (absequaliu(gel(Pq,1), 2))
    1108             :     {
    1109        1015 :       if (Eq[1] >= 3)
    1110             :       { /* 2 generators at 2 mod q */
    1111         560 :         gel(CHI,1) = gel(chi,1);
    1112         560 :         gel(CHI,2) = shifti(gel(chi,2), E[1]-Eq[1]);
    1113             :       }
    1114         455 :       else if (Eq[1] == 2)
    1115             :       { /* 1 generator at 2 mod q */
    1116         455 :         gel(CHI,1) = gel(chi,1);
    1117         455 :         gel(CHI,2) = gen_0;
    1118             :       }
    1119             :       else
    1120           0 :         gel(CHI,1) = gel(CHI,2) = gen_0;
    1121             :     }
    1122             :     else
    1123         168 :       gel(CHI,1) = gel(CHI,2) = gen_0;
    1124             :   }
    1125        7315 :   for (; i < l; i++,j++)
    1126             :   {
    1127        4417 :     GEN p = gel(P,i);
    1128        4417 :     long k = ZV_search(Pq, p);
    1129        4417 :     gel(CHI,j) = k? mulii(gel(chi,k), powiu(p, E[i]-Eq[k])): gen_0;
    1130             :   }
    1131        2898 :   return gerepilecopy(av, CHI);
    1132             : }
    1133             : 
    1134             : /* m a Conrey log [on the canonical primitive roots], cycg the primitive
    1135             :  * roots orders */
    1136             : GEN
    1137     2589762 : znconreylog_normalize(GEN G, GEN m)
    1138             : {
    1139     2589762 :   GEN cycg = znstar_get_conreycyc(G);
    1140             :   long i, l;
    1141     2589762 :   GEN d, M = cgetg_copy(m, &l);
    1142     2589762 :   if (typ(cycg) != t_VEC || lg(cycg) != l)
    1143           0 :     pari_err_TYPE("znconreylog_normalize",mkvec2(m,cycg));
    1144     6872922 :   for (i = 1; i < l; i++) gel(M,i) = gdiv(gel(m,i), gel(cycg,i));
    1145             :   /* m[i]: image of primroot generators g_i in Q/Z */
    1146     2589762 :   M = Q_remove_denom(M, &d);
    1147     2589762 :   return mkvec2(d? d: gen_1, M);
    1148             : }
    1149             : 
    1150             : /* return normalized character on Conrey generators attached to chi: Conrey
    1151             :  * label (t_INT), char on (SNF) G.gen* (t_VEC), or Conrey log (t_COL) */
    1152             : GEN
    1153     2577260 : znconrey_normalized(GEN G, GEN chi)
    1154             : {
    1155     2577260 :   switch(typ(chi))
    1156             :   {
    1157         420 :     case t_INT: /* Conrey label */
    1158         420 :       return znconreylog_normalize(G, znconreylog(G, chi));
    1159     2574922 :     case t_COL: /* Conrey log */
    1160     2574922 :       if (!RgV_is_ZV(chi)) break;
    1161     2574922 :       return znconreylog_normalize(G, chi);
    1162        1918 :     case t_VEC: /* char on G.gen */
    1163        1918 :       if (!RgV_is_ZV(chi)) break;
    1164        1918 :       return znconreyfromchar_normalized(G, chi);
    1165             :   }
    1166           0 :   pari_err_TYPE("znchareval",chi);
    1167             :   return NULL;/* LCOV_EXCL_LINE */
    1168             : }
    1169             : 
    1170             : /* return 1 iff chi(-1) = -1, and 0 otherwise */
    1171             : long
    1172      183610 : zncharisodd(GEN G, GEN chi)
    1173             : {
    1174             :   long i, l, s;
    1175             :   GEN N;
    1176      183610 :   if (!checkznstar_i(G)) pari_err_TYPE("zncharisodd", G);
    1177      183610 :   if (!zncharcheck(G, chi)) pari_err_TYPE("zncharisodd", chi);
    1178      183610 :   if (typ(chi) != t_COL) chi = znconreylog(G, chi);
    1179      183610 :   N = znstar_get_N(G);
    1180      183610 :   l = lg(chi);
    1181      183610 :   s = 0;
    1182      183610 :   if (!mod8(N))
    1183             :   {
    1184       91133 :     s = mpodd(gel(chi,1));
    1185       91133 :     i = 3;
    1186             :   }
    1187             :   else
    1188       92477 :     i = 1;
    1189      512267 :   for (; i < l; i++) s += mpodd(gel(chi,i));
    1190      183610 :   return odd(s);
    1191             : }
    1192             : 
    1193             : GEN
    1194         847 : znchartokronecker(GEN G, GEN chi, long flag)
    1195             : {
    1196         847 :   pari_sp av = avma;
    1197             :   long s;
    1198             :   GEN F, o;
    1199             : 
    1200         847 :   if (flag && flag != 1) pari_err_FLAG("znchartokronecker");
    1201         847 :   s = zncharisodd(G, chi)? -1: 1;
    1202         847 :   if (typ(chi) != t_COL) chi = znconreylog(G, chi);
    1203         847 :   o = zncharorder(G, chi);
    1204         847 :   if (abscmpiu(o,2) > 0) { set_avma(av); return gen_0; }
    1205         581 :   F = znconreyconductor(G, chi, NULL);
    1206         581 :   if (typ(F) == t_INT)
    1207             :   {
    1208         469 :     if (s < 0) F = negi(F);
    1209         469 :     return gerepileuptoint(av, F);
    1210             :   }
    1211         112 :   F = gel(F,1);
    1212         112 :   F = (s < 0)? negi(F): icopy(F);
    1213         112 :   if (!flag)
    1214             :   {
    1215          49 :     GEN MF = znstar_get_faN(G), P = gel(MF,1);
    1216          49 :     long i, l = lg(P);
    1217         140 :     for (i = 1; i < l; i++)
    1218             :     {
    1219          91 :       GEN p = gel(P,i);
    1220          91 :       if (!dvdii(F,p)) F = mulii(F,sqri(p));
    1221             :     }
    1222             :   }
    1223         112 :   return gerepileuptoint(av, F);
    1224             : }
    1225             : 
    1226             : /* (D/.) as a character mod N; assume |D| divides N and D = 0,1 mod 4*/
    1227             : GEN
    1228      303324 : znchar_quad(GEN G, GEN D)
    1229             : {
    1230      303324 :   GEN cyc = znstar_get_conreycyc(G);
    1231      303324 :   GEN gen = znstar_get_conreygen(G);
    1232      303324 :   long i, l = lg(cyc);
    1233      303324 :   GEN chi = cgetg(l, t_COL);
    1234     1351679 :   for (i = 1; i < l; i++)
    1235             :   {
    1236     1048355 :     long k = kronecker(D, gel(gen,i));
    1237     1048355 :     gel(chi,i) = (k==1)? gen_0: shifti(gel(cyc,i), -1);
    1238             :   }
    1239      303324 :   return chi;
    1240             : }
    1241             : 
    1242             : GEN
    1243        3283 : znchar(GEN D)
    1244             : {
    1245        3283 :   pari_sp av = avma;
    1246             :   GEN G, chi;
    1247        3283 :   switch(typ(D))
    1248             :   {
    1249        2506 :     case t_INT:
    1250        2506 :       if (!signe(D) || Mod4(D) > 1) pari_err_TYPE("znchar", D);
    1251        2485 :       G = znstar0(D,1);
    1252        2485 :       chi = mkvec2(G, znchar_quad(G,D));
    1253        2485 :       break;
    1254         707 :     case t_INTMOD:
    1255         707 :       G = znstar0(gel(D,1), 1);
    1256         707 :       chi = mkvec2(G, znconreylog(G, gel(D,2)));
    1257         707 :       break;
    1258          56 :     case t_VEC:
    1259          56 :       if (checkMF_i(D)) { chi = vecslice(MF_get_CHI(D),1,2); break; }
    1260          49 :       else if (checkmf_i(D)) { chi = vecslice(mf_get_CHI(D),1,2); break; }
    1261          42 :       if (lg(D) != 3) pari_err_TYPE("znchar", D);
    1262          35 :       G = gel(D,1);
    1263          35 :       if (!checkznstar_i(G)) pari_err_TYPE("znchar", D);
    1264          28 :       chi = gel(D,2);
    1265          28 :       if (typ(chi) == t_VEC && lg(chi) == 3 && is_vec_t(typ(gel(chi,2))))
    1266             :       { /* normalized character */
    1267           7 :         GEN n = gel(chi,1), chic = gel(chi,2);
    1268           7 :         GEN cyc = typ(chic)==t_VEC? znstar_get_cyc(G): znstar_get_conreycyc(G);
    1269           7 :         if (!char_check(cyc, chic)) pari_err_TYPE("znchar",D);
    1270           7 :         chi = char_denormalize(cyc, n, chic);
    1271             :       }
    1272          28 :       if (!zncharcheck(G, chi)) pari_err_TYPE("znchar", D);
    1273          21 :       chi = mkvec2(G,chi); break;
    1274          14 :     default:
    1275          14 :       pari_err_TYPE("znchar", D);
    1276             :       return NULL; /*LCOV_EXCL_LINE*/
    1277             :   }
    1278        3227 :   return gerepilecopy(av, chi);
    1279             : }
    1280             : 
    1281             : /* G a znstar, not stack clean */
    1282             : GEN
    1283     2513273 : znchareval(GEN G, GEN chi, GEN n, GEN z)
    1284             : {
    1285     2513273 :   GEN nchi, N = znstar_get_N(G);
    1286             :   /* avoid division by 0 */
    1287     2513273 :   if (typ(n) == t_FRAC && !equali1(gcdii(gel(n,2), N))) return not_coprime(z);
    1288     2513266 :   n = Rg_to_Fp(n, N);
    1289     2513266 :   if (!equali1(gcdii(n, N))) return not_coprime(z);
    1290             :   /* nchi: normalized character on Conrey generators */
    1291     2511432 :   nchi = znconrey_normalized(G, chi);
    1292     2511432 :   return chareval_i(nchi, znconreylog(G,n), z);
    1293             : }
    1294             : 
    1295             : /* G is a znstar, chi a Dirichlet character */
    1296             : GEN
    1297        1526 : zncharconj(GEN G, GEN chi)
    1298             : {
    1299        1526 :   switch(typ(chi))
    1300             :   {
    1301           7 :     case t_INT: chi = znconreylog(G, chi); /* fall through */
    1302         665 :     case t_COL: return charconj(znstar_get_conreycyc(G), chi);
    1303         861 :     case t_VEC: return charconj(znstar_get_cyc(G), chi);
    1304             :   }
    1305           0 :   pari_err_TYPE("zncharconj",chi);
    1306             :   return NULL; /*LCOV_EXCL_LINE*/
    1307             : }
    1308             : 
    1309             : /* G is a znstar, chi a Dirichlet character */
    1310             : GEN
    1311      377314 : zncharorder(GEN G,  GEN chi)
    1312             : {
    1313      377314 :   switch(typ(chi))
    1314             :   {
    1315          21 :     case t_INT: chi = znconreylog(G, chi); /*fall through*/
    1316      376138 :     case t_COL: return charorder(znstar_get_conreycyc(G), chi);
    1317        1176 :     case t_VEC: return charorder(znstar_get_cyc(G), chi);
    1318           0 :     default: pari_err_TYPE("zncharorder",chi);
    1319             :              return NULL; /* LCOV_EXCL_LINE */
    1320             :   }
    1321             : }
    1322             : 
    1323             : /* G is a znstar, chi a Dirichlet character */
    1324             : GEN
    1325          21 : zncharker(GEN G, GEN chi)
    1326             : {
    1327          21 :   if (typ(chi) != t_VEC) chi = znconreychar(G, chi);
    1328          21 :   return charker(znstar_get_cyc(G), chi);
    1329             : }
    1330             : 
    1331             : /* G is a znstar, 'a' is a Dirichlet character */
    1332             : GEN
    1333         210 : zncharpow(GEN G, GEN a, GEN n)
    1334             : {
    1335         210 :   switch(typ(a))
    1336             :   {
    1337          21 :     case t_INT: return Fp_pow(a, n, znstar_get_N(G));
    1338          21 :     case t_VEC: return charpow(znstar_get_cyc(G), a, n);
    1339         168 :     case t_COL: return charpow(znstar_get_conreycyc(G), a, n);
    1340           0 :     default: pari_err_TYPE("znchapow",a);
    1341             :              return NULL; /* LCOV_EXCL_LINE */
    1342             :   }
    1343             : }
    1344             : /* G is a znstar, 'a' and 'b' are Dirichlet character */
    1345             : GEN
    1346      302015 : zncharmul(GEN G, GEN a, GEN b)
    1347             : {
    1348      302015 :   long ta = typ(a), tb = typ(b);
    1349      302015 :   if (ta == tb) switch(ta)
    1350             :   {
    1351           7 :     case t_INT: return Fp_mul(a, b, znstar_get_N(G));
    1352           7 :     case t_VEC: return charmul(znstar_get_cyc(G), a, b);
    1353      301980 :     case t_COL: return charmul(znstar_get_conreycyc(G), a, b);
    1354           0 :     default: pari_err_TYPE("zncharmul",a);
    1355             :              return NULL; /* LCOV_EXCL_LINE */
    1356             :   }
    1357          21 :   if (ta != t_COL) a = znconreylog(G, a);
    1358          21 :   if (tb != t_COL) b = znconreylog(G, b);
    1359          21 :   return charmul(znstar_get_conreycyc(G), a, b);
    1360             : }
    1361             : 
    1362             : /* G is a znstar, 'a' and 'b' are Dirichlet character */
    1363             : GEN
    1364        5355 : znchardiv(GEN G, GEN a, GEN b)
    1365             : {
    1366        5355 :   long ta = typ(a), tb = typ(b);
    1367        5355 :   if (ta == tb) switch(ta)
    1368             :   {
    1369           7 :     case t_INT: return Fp_div(a, b, znstar_get_N(G));
    1370           7 :     case t_VEC: return chardiv(znstar_get_cyc(G), a, b);
    1371        5320 :     case t_COL: return chardiv(znstar_get_conreycyc(G), a, b);
    1372           0 :     default: pari_err_TYPE("znchardiv",a);
    1373             :              return NULL; /* LCOV_EXCL_LINE */
    1374             :   }
    1375          21 :   if (ta != t_COL) a = znconreylog(G, a);
    1376          21 :   if (tb != t_COL) b = znconreylog(G, b);
    1377          21 :   return chardiv(znstar_get_conreycyc(G), a, b);
    1378             : }
    1379             : 
    1380             : /* CHI mod N = \prod_p p^e; let CHI = \prod CHI_p, CHI_p mod p^e
    1381             :  * return \prod_{p | (Q,N)} CHI_p. E.g if Q = p, return chi_p */
    1382             : GEN
    1383         791 : znchardecompose(GEN G, GEN chi, GEN Q)
    1384             : {
    1385             :   GEN c, P, E, F;
    1386             :   long l, lP, i;
    1387             : 
    1388         791 :   if (!checkznstar_i(G)) pari_err_TYPE("znchardecompose", G);
    1389         791 :   if (typ(Q) != t_INT) pari_err_TYPE("znchardecompose", Q);
    1390         791 :   if (typ(chi) == t_COL)
    1391         560 :   { if (!zncharcheck(G, chi)) pari_err_TYPE("znchardecompose", chi); }
    1392             :   else
    1393         231 :     chi = znconreylog(G, chi);
    1394         791 :   l = lg(chi); if (l == 1) return cgetg(1, t_VEC);
    1395         784 :   F = znstar_get_faN(G);
    1396         784 :   c = zerocol(l-1);
    1397         784 :   P = gel(F,1); /* prime divisors of N */
    1398         784 :   lP = lg(P);
    1399         784 :   E = gel(F,2); /* exponents */
    1400        2471 :   for (i = 1; i < lP; i++)
    1401             :   {
    1402        1687 :     GEN p = gel(P,i);
    1403        1687 :     if (i == 1 && equaliu(p,2) && E[1] >= 3)
    1404             :     {
    1405         567 :       if (!mpodd(Q))
    1406             :       {
    1407         203 :         gel(c,1) = icopy(gel(chi,1));
    1408         203 :         gel(c,2) = icopy(gel(chi,2));
    1409             :       }
    1410         567 :       i = 2; /* skip P[2] = P[1] = 2 */
    1411             :     }
    1412             :     else
    1413        1120 :       if (dvdii(Q, p)) gel(c,i) = icopy(gel(chi,i));
    1414             :   }
    1415         784 :   return c;
    1416             : }
    1417             : 
    1418             : GEN
    1419       19873 : zncharconductor(GEN G, GEN chi)
    1420             : {
    1421       19873 :   pari_sp av = avma;
    1422       19873 :   GEN F = znconreyconductor(G, chi, NULL);
    1423       19873 :   if (typ(F) == t_INT) return F;
    1424       12705 :   return gerepilecopy(av, gel(F,1));
    1425             : }
    1426             : GEN
    1427        1274 : znchartoprimitive(GEN G, GEN chi)
    1428             : {
    1429        1274 :   pari_sp av = avma;
    1430        1274 :   GEN chi0, F = znconreyconductor(G, chi, &chi0);
    1431        1274 :   if (typ(F) == t_INT)
    1432        1015 :     chi = mkvec2(G,chi);
    1433             :   else
    1434         259 :     chi = mkvec2(znstar0(F,1), chi0);
    1435        1274 :   return gerepilecopy(av, chi);
    1436             : }

Generated by: LCOV version 1.13