bridge/class-master/depend/pari/src/basemath/elliptic.c
/* Given J an ideal in HNF coprime to 3 and z algebraic integer,
 * return b algebraic integer such that z + 3b in  J */
Given J an ideal in HNF coprime to 3 and z algebraic integer,
return b algebraic integer such that z + 3b in  J
Given J an ideal in HNF coprime to 3 and z algebraic integer return b algebraic integer such that z + 3b in J
static GEN
approx_mod3(GEN J, GEN z)
{
  GEN b = z;
  long i;
  if (typ(b) == t_INT)
  {
    long s = smodis(b,3);
    if (s)
    {
      GEN Jz = gcoeff(J,1,1);
      if (smodis(Jz, 3) == s)
        b = subii(b, Jz);
      else
        b = addii(b, Jz);
    }
    return diviiexact(b, stoi(-3));
  }
  for (i = lg(J)-1; i >= 1; i--)
  {
    long s = smodis(gel(b,i), 3);
    if (!s) continue;
    if (smodis(gcoeff(J,i,i), 3) == s)
      b = ZC_sub(b, gel(J,i));
    else
      b = ZC_add(b, gel(J,i));
  }
  return ZC_Z_divexact(b, stoi(-3));
}
static GEN approx_mod3 ( GEN J , GEN z ) { GEN b = z ; long i ; if ( typ ( b ) == t_INT ) { long s = smodis ( b , 3 ) ; if ( s ) { GEN Jz = gcoeff ( J , 1 , 1 ) ; if ( smodis ( Jz , 3 ) == s ) b = subii ( b , Jz ) ; else b = addii ( b , Jz ) ; } return diviiexact ( b , stoi ( -3 ) ) ; } for ( i = lg ( J ) - 1 ; i >= 1 ; i -- ) { long s = smodis ( gel ( b , i ) , 3 ) ; if ( ! s ) continue ; if ( smodis ( gcoeff ( J , i , i ) , 3 ) == s ) b = ZC_sub ( b , gel ( J , i ) ) ; else b = ZC_add ( b , gel ( J , i ) ) ; } return ZC_Z_divexact ( b , stoi ( -3 ) ) ; }
Given J an ideal in HNF coprime to 3 and z algebraic integer,
 return b algebraic integer such that z + 3b in  J
Given J an ideal in HNF coprime to 3 and z algebraic integer return b algebraic integer such that z + 3b in J