My Project  debian-1:4.1.1-p2+ds-4
Macros | Functions | Variables
longrat.cc File Reference
#include "misc/auxiliary.h"
#include "omalloc/omalloc.h"
#include "factory/factory.h"
#include "misc/sirandom.h"
#include "misc/prime.h"
#include "reporter/reporter.h"
#include "coeffs/coeffs.h"
#include "coeffs/numbers.h"
#include "coeffs/rmodulon.h"
#include "coeffs/longrat.h"
#include "coeffs/shortfl.h"
#include "coeffs/modulop.h"
#include "coeffs/mpr_complex.h"
#include <string.h>
#include <float.h>

Go to the source code of this file.

Macros

#define LINLINE
 
#define nlTest(a, r)   nlDBTest(a,__FILE__,__LINE__, r)
 
#define MAX_NUM_SIZE   28
 
#define POW_2_28   (1L<<28)
 
#define POW_2_28_32   (1L<<28)
 
#define LONG   int
 
#define LONGRAT_CC
 
#define BYTES_PER_MP_LIMB   sizeof(mp_limb_t)
 
#define MP_SMALL   1
 
#define mpz_isNeg(A)   ((A)->_mp_size<0)
 
#define mpz_limb_size(A)   ((A)->_mp_size)
 
#define mpz_limb_d(A)   ((A)->_mp_d)
 
#define GCD_NORM_COND(OLD, NEW)   (mpz_size1(NEW->z)>mpz_size1(OLD->z))
 

Functions

LINLINE BOOLEAN nlEqual (number a, number b, const coeffs r)
 
LINLINE number nlInit (long i, const coeffs r)
 
LINLINE BOOLEAN nlIsOne (number a, const coeffs r)
 
LINLINE BOOLEAN nlIsZero (number za, const coeffs r)
 
LINLINE number nlCopy (number a, const coeffs r)
 
LINLINE number nl_Copy (number a, const coeffs r)
 
LINLINE void nlDelete (number *a, const coeffs r)
 
LINLINE number nlNeg (number za, const coeffs r)
 
LINLINE number nlAdd (number la, number li, const coeffs r)
 
LINLINE number nlSub (number la, number li, const coeffs r)
 
LINLINE number nlMult (number a, number b, const coeffs r)
 
LINLINE void nlInpAdd (number &a, number b, const coeffs r)
 
LINLINE void nlInpMult (number &a, number b, const coeffs r)
 
number nlRInit (long i)
 
void nlNormalize (number &x, const coeffs r)
 
number nlGcd (number a, number b, const coeffs r)
 
number nlExtGcd (number a, number b, number *s, number *t, const coeffs)
 
number nlNormalizeHelper (number a, number b, const coeffs r)
 
BOOLEAN nlGreater (number a, number b, const coeffs r)
 
BOOLEAN nlIsMOne (number a, const coeffs r)
 
long nlInt (number &n, const coeffs r)
 
number nlBigInt (number &n)
 
number nlMapGMP (number from, const coeffs src, const coeffs dst)
 
BOOLEAN nlGreaterZero (number za, const coeffs r)
 
number nlInvers (number a, const coeffs r)
 
number nlDiv (number a, number b, const coeffs r)
 
number nlExactDiv (number a, number b, const coeffs r)
 
number nlIntDiv (number a, number b, const coeffs r)
 
number nlIntMod (number a, number b, const coeffs r)
 
void nlPower (number x, int exp, number *lu, const coeffs r)
 
const char * nlRead (const char *s, number *a, const coeffs r)
 
void nlWrite (number a, const coeffs r)
 
void nlCoeffWrite (const coeffs r, BOOLEAN details)
 
number nlFarey (number nN, number nP, const coeffs CF)
 
BOOLEAN nlDBTest (number a, const char *f, const int l)
 
nMapFunc nlSetMap (const coeffs src, const coeffs dst)
 
void nlInpIntDiv (number &a, number b, const coeffs r)
 
BOOLEAN nlDBTest (number a, const char *f, int l, const coeffs r)
 
static number nlShort3 (number x)
 
void _nlDelete_NoImm (number *a)
 
number nlShort3_noinline (number x)
 
void mpz_mul_si (mpz_ptr r, mpz_srcptr s, long int si)
 
static number nlMapP (number from, const coeffs src, const coeffs dst)
 
static number nlMapLongR (number from, const coeffs src, const coeffs dst)
 
static number nlMapR (number from, const coeffs src, const coeffs dst)
 
number nlMapZ (number from, const coeffs src, const coeffs dst)
 
number nlMapMachineInt (number from, const coeffs, const coeffs)
 
static CanonicalForm nlConvSingNFactoryN (number n, const BOOLEAN setChar, const coeffs)
 
static number nlConvFactoryNSingN (const CanonicalForm f, const coeffs r)
 
int nlSize (number a, const coeffs)
 
number nlBigInt (number &i, const coeffs r)
 
BOOLEAN nlDivBy (number a, number b, const coeffs)
 
int nlDivComp (number a, number b, const coeffs r)
 
number nlGetUnit (number n, const coeffs cf)
 
coeffs nlQuot1 (number c, const coeffs r)
 
BOOLEAN nlIsUnit (number a, const coeffs)
 
static int int_extgcd (int a, int b, int *u, int *x, int *v, int *y)
 
number nlShort1 (number x)
 
number nlModP (number q, const coeffs, const coeffs Zp)
 
void nlGMP (number &i, mpz_t n, const coeffs r)
 
number nlGetDenom (number &n, const coeffs r)
 
number nlGetNumerator (number &n, const coeffs r)
 
BOOLEAN _nlEqual_aNoImm_OR_bNoImm (number a, number b)
 
number _nlCopy_NoImm (number a)
 
number _nlNeg_NoImm (number a)
 
static void nlNormalize_Gcd (number &x)
 
number _nlAdd_aNoImm_OR_bNoImm (number a, number b)
 
void _nlInpAdd_aNoImm_OR_bNoImm (number &a, number b)
 
number _nlSub_aNoImm_OR_bNoImm (number a, number b)
 
number _nlMult_aImm_bImm_rNoImm (number a, number b)
 
number _nlMult_aNoImm_OR_bNoImm (number a, number b)
 
number nlCopyMap (number a, const coeffs, const coeffs)
 
number nlInit2 (int i, int j, const coeffs r)
 create a rational i/j (implicitly) over Q NOTE: make sure to use correct Q in debug mode More...
 
number nlInit2gmp (mpz_t i, mpz_t j, const coeffs r)
 create a rational i/j (implicitly) over Q NOTE: make sure to use correct Q in debug mode More...
 
static void nlMPZ (mpz_t m, number &n, const coeffs r)
 
static number nlInitMPZ (mpz_t m, const coeffs)
 
number nlXExtGcd (number a, number b, number *s, number *t, number *u, number *v, const coeffs r)
 
number nlQuotRem (number a, number b, number *r, const coeffs R)
 
void nlInpGcd (number &a, number b, const coeffs r)
 
number nlChineseRemainderSym (number *x, number *q, int rl, BOOLEAN sym, CFArray &inv_cache, const coeffs CF)
 
static void nlClearContent (ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs cf)
 
static void nlClearDenominators (ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs cf)
 
char * nlCoeffName (const coeffs r)
 
static char * nlCoeffString (const coeffs r)
 
static void nlWriteFd (number n, FILE *f, const coeffs)
 
static number nlReadFd (s_buff f, const coeffs)
 
BOOLEAN nlCoeffIsEqual (const coeffs r, n_coeffType n, void *p)
 
static number nlLcm (number a, number b, const coeffs r)
 
static number nlRandom (siRandProc p, number v2, number, const coeffs cf)
 
BOOLEAN nlInitChar (coeffs r, void *p)
 

Variables

int n_SwitchChinRem =0
 

Macro Definition Documentation

◆ BYTES_PER_MP_LIMB

#define BYTES_PER_MP_LIMB   sizeof(mp_limb_t)

Definition at line 141 of file longrat.cc.

◆ GCD_NORM_COND

#define GCD_NORM_COND (   OLD,
  NEW 
)    (mpz_size1(NEW->z)>mpz_size1(OLD->z))

Definition at line 1655 of file longrat.cc.

◆ LINLINE

#define LINLINE

Definition at line 31 of file longrat.cc.

◆ LONG

#define LONG   int

Definition at line 110 of file longrat.cc.

◆ LONGRAT_CC

#define LONGRAT_CC

Definition at line 138 of file longrat.cc.

◆ MAX_NUM_SIZE

#define MAX_NUM_SIZE   28

Definition at line 107 of file longrat.cc.

◆ MP_SMALL

#define MP_SMALL   1

Definition at line 149 of file longrat.cc.

◆ mpz_isNeg

#define mpz_isNeg (   A)    ((A)->_mp_size<0)

Definition at line 151 of file longrat.cc.

◆ mpz_limb_d

#define mpz_limb_d (   A)    ((A)->_mp_d)

Definition at line 153 of file longrat.cc.

◆ mpz_limb_size

#define mpz_limb_size (   A)    ((A)->_mp_size)

Definition at line 152 of file longrat.cc.

◆ nlTest

#define nlTest (   a,
 
)    nlDBTest(a,__FILE__,__LINE__, r)

Definition at line 92 of file longrat.cc.

◆ POW_2_28

#define POW_2_28   (1L<<28)

Definition at line 108 of file longrat.cc.

◆ POW_2_28_32

#define POW_2_28_32   (1L<<28)

Definition at line 109 of file longrat.cc.

Function Documentation

◆ _nlAdd_aNoImm_OR_bNoImm()

number _nlAdd_aNoImm_OR_bNoImm ( number  a,
number  b 
)

Definition at line 1677 of file longrat.cc.

1681 {
1682  number u=ALLOC_RNUMBER();
1683 #if defined(LDEBUG)
1684  u->debug=123456;
1685 #endif
1686  mpz_init(u->z);
1687  if (SR_HDL(b) & SR_INT)
1688  {
1689  number x=a;
1690  a=b;
1691  b=x;
1692  }
1693  if (SR_HDL(a) & SR_INT)
1694  {
1695  switch (b->s)
1696  {
1697  case 0:
1698  case 1:/* a:short, b:1 */
1699  {
1700  mpz_t x;
1701  mpz_init(x);
1702  mpz_mul_si(x,b->n,SR_TO_INT(a));
1703  mpz_add(u->z,b->z,x);
1704  mpz_clear(x);
1705  if (mpz_sgn1(u->z)==0)
1706  {
1707  mpz_clear(u->z);
1708  FREE_RNUMBER(u);
1709  return INT_TO_SR(0);
1710  }
1711  if (mpz_cmp(u->z,b->n)==0)
1712  {
1713  mpz_clear(u->z);
1714  FREE_RNUMBER(u);
1715  return INT_TO_SR(1);
1716  }
1717  mpz_init_set(u->n,b->n);
1718  u->s = 0;
1719  if (GCD_NORM_COND(b,u)) { nlNormalize_Gcd(u); }
1720  break;
1721  }
1722  case 3:
1723  {
1724  if (((long)a)>0L)
1725  mpz_add_ui(u->z,b->z,SR_TO_INT(a));
1726  else
1727  mpz_sub_ui(u->z,b->z,-SR_TO_INT(a));
1728  u->s = 3;
1729  u=nlShort3(u);
1730  break;
1731  }
1732  }
1733  }
1734  else
1735  {
1736  switch (a->s)
1737  {
1738  case 0:
1739  case 1:
1740  {
1741  switch(b->s)
1742  {
1743  case 0:
1744  case 1:
1745  {
1746  mpz_t x;
1747  mpz_init(x);
1748 
1749  mpz_mul(x,b->z,a->n);
1750  mpz_mul(u->z,a->z,b->n);
1751  mpz_add(u->z,u->z,x);
1752  mpz_clear(x);
1753 
1754  if (mpz_sgn1(u->z)==0)
1755  {
1756  mpz_clear(u->z);
1757  FREE_RNUMBER(u);
1758  return INT_TO_SR(0);
1759  }
1760  mpz_init(u->n);
1761  mpz_mul(u->n,a->n,b->n);
1762  if (mpz_cmp(u->z,u->n)==0)
1763  {
1764  mpz_clear(u->z);
1765  mpz_clear(u->n);
1766  FREE_RNUMBER(u);
1767  return INT_TO_SR(1);
1768  }
1769  u->s = 0;
1770  if (GCD_NORM_COND(b,u)) { nlNormalize_Gcd(u); }
1771  break;
1772  }
1773  case 3: /* a:1 b:3 */
1774  {
1775  mpz_mul(u->z,b->z,a->n);
1776  mpz_add(u->z,u->z,a->z);
1777  if (mpz_sgn1(u->z)==0)
1778  {
1779  mpz_clear(u->z);
1780  FREE_RNUMBER(u);
1781  return INT_TO_SR(0);
1782  }
1783  if (mpz_cmp(u->z,a->n)==0)
1784  {
1785  mpz_clear(u->z);
1786  FREE_RNUMBER(u);
1787  return INT_TO_SR(1);
1788  }
1789  mpz_init_set(u->n,a->n);
1790  u->s = 0;
1791  if (GCD_NORM_COND(a,u)) { nlNormalize_Gcd(u); }
1792  break;
1793  }
1794  } /*switch (b->s) */
1795  break;
1796  }
1797  case 3:
1798  {
1799  switch(b->s)
1800  {
1801  case 0:
1802  case 1:/* a:3, b:1 */
1803  {
1804  mpz_mul(u->z,a->z,b->n);
1805  mpz_add(u->z,u->z,b->z);
1806  if (mpz_sgn1(u->z)==0)
1807  {
1808  mpz_clear(u->z);
1809  FREE_RNUMBER(u);
1810  return INT_TO_SR(0);
1811  }
1812  if (mpz_cmp(u->z,b->n)==0)
1813  {
1814  mpz_clear(u->z);
1815  FREE_RNUMBER(u);
1816  return INT_TO_SR(1);
1817  }
1818  mpz_init_set(u->n,b->n);
1819  u->s = 0;
1820  if (GCD_NORM_COND(b,u)) { nlNormalize_Gcd(u); }
1821  break;
1822  }
1823  case 3:
1824  {
1825  mpz_add(u->z,a->z,b->z);
1826  u->s = 3;
1827  u=nlShort3(u);
1828  break;
1829  }
1830  }
1831  break;
1832  }
1833  }

◆ _nlCopy_NoImm()

number _nlCopy_NoImm ( number  a)

Definition at line 1603 of file longrat.cc.

1607 {
1608  assume(!((SR_HDL(a) & SR_INT)||(a==NULL)));
1609  //nlTest(a, r);
1610  number b=ALLOC_RNUMBER();
1611 #if defined(LDEBUG)
1612  b->debug=123456;
1613 #endif
1614  switch (a->s)
1615  {
1616  case 0:
1617  case 1:
1618  mpz_init_set(b->n,a->n);
1619  case 3:
1620  mpz_init_set(b->z,a->z);
1621  break;
1622  }

◆ _nlDelete_NoImm()

void _nlDelete_NoImm ( number *  a)

Definition at line 1624 of file longrat.cc.

1628 {
1629  {
1630  switch ((*a)->s)
1631  {
1632  case 0:
1633  case 1:
1634  mpz_clear((*a)->n);
1635  case 3:
1636  mpz_clear((*a)->z);
1637 #ifdef LDEBUG
1638  (*a)->s=2;
1639 #endif
1640  }

◆ _nlEqual_aNoImm_OR_bNoImm()

BOOLEAN _nlEqual_aNoImm_OR_bNoImm ( number  a,
number  b 
)

Definition at line 1556 of file longrat.cc.

1560 {
1561  assume(! (SR_HDL(a) & SR_HDL(b) & SR_INT));
1562 // long - short
1563  BOOLEAN bo;
1564  if (SR_HDL(b) & SR_INT)
1565  {
1566  if (a->s!=0) return FALSE;
1567  number n=b; b=a; a=n;
1568  }
1569 // short - long
1570  if (SR_HDL(a) & SR_INT)
1571  {
1572  if (b->s!=0)
1573  return FALSE;
1574  if ((((long)a) > 0L) && (mpz_isNeg(b->z)))
1575  return FALSE;
1576  if ((((long)a) < 0L) && (!mpz_isNeg(b->z)))
1577  return FALSE;
1578  mpz_t bb;
1579  mpz_init(bb);
1580  mpz_mul_si(bb,b->n,(long)SR_TO_INT(a));
1581  bo=(mpz_cmp(bb,b->z)==0);
1582  mpz_clear(bb);
1583  return bo;
1584  }
1585 // long - long
1586  if (((a->s==1) && (b->s==3))
1587  || ((b->s==1) && (a->s==3)))
1588  return FALSE;
1589  if (mpz_isNeg(a->z)&&(!mpz_isNeg(b->z)))
1590  return FALSE;
1591  if (mpz_isNeg(b->z)&&(!mpz_isNeg(a->z)))
1592  return FALSE;
1593  mpz_t aa;
1594  mpz_t bb;
1595  mpz_init_set(aa,a->z);
1596  mpz_init_set(bb,b->z);
1597  if (a->s<2) mpz_mul(bb,bb,a->n);
1598  if (b->s<2) mpz_mul(aa,aa,b->n);
1599  bo=(mpz_cmp(aa,bb)==0);
1600  mpz_clear(aa);

◆ _nlInpAdd_aNoImm_OR_bNoImm()

void _nlInpAdd_aNoImm_OR_bNoImm ( number &  a,
number  b 
)

Definition at line 1835 of file longrat.cc.

1839 {
1840  if (SR_HDL(b) & SR_INT)
1841  {
1842  switch (a->s)
1843  {
1844  case 0:
1845  case 1:/* b:short, a:1 */
1846  {
1847  mpz_t x;
1848  mpz_init(x);
1849  mpz_mul_si(x,a->n,SR_TO_INT(b));
1850  mpz_add(a->z,a->z,x);
1851  mpz_clear(x);
1852  nlNormalize_Gcd(a);
1853  break;
1854  }
1855  case 3:
1856  {
1857  if (((long)b)>0L)
1858  mpz_add_ui(a->z,a->z,SR_TO_INT(b));
1859  else
1860  mpz_sub_ui(a->z,a->z,-SR_TO_INT(b));
1861  a->s = 3;
1862  a=nlShort3_noinline(a);
1863  break;
1864  }
1865  }
1866  return;
1867  }
1868  else if (SR_HDL(a) & SR_INT)
1869  {
1870  number u=ALLOC_RNUMBER();
1871  #if defined(LDEBUG)
1872  u->debug=123456;
1873  #endif
1874  mpz_init(u->z);
1875  switch (b->s)
1876  {
1877  case 0:
1878  case 1:/* a:short, b:1 */
1879  {
1880  mpz_t x;
1881  mpz_init(x);
1882 
1883  mpz_mul_si(x,b->n,SR_TO_INT(a));
1884  mpz_add(u->z,b->z,x);
1885  mpz_clear(x);
1886  // result cannot be 0, if coeffs are normalized
1887  mpz_init_set(u->n,b->n);
1888  u->s=0;
1889  if (GCD_NORM_COND(b,u)) { nlNormalize_Gcd(u); }
1890  else { u=nlShort1(u); }
1891  break;
1892  }
1893  case 3:
1894  {
1895  if (((long)a)>0L)
1896  mpz_add_ui(u->z,b->z,SR_TO_INT(a));
1897  else
1898  mpz_sub_ui(u->z,b->z,-SR_TO_INT(a));
1899  // result cannot be 0, if coeffs are normalized
1900  u->s = 3;
1901  u=nlShort3_noinline(u);
1902  break;
1903  }
1904  }
1905  a=u;
1906  }
1907  else
1908  {
1909  switch (a->s)
1910  {
1911  case 0:
1912  case 1:
1913  {
1914  switch(b->s)
1915  {
1916  case 0:
1917  case 1: /* a:1 b:1 */
1918  {
1919  mpz_t x;
1920  mpz_t y;
1921  mpz_init(x);
1922  mpz_init(y);
1923  mpz_mul(x,b->z,a->n);
1924  mpz_mul(y,a->z,b->n);
1925  mpz_add(a->z,x,y);
1926  mpz_clear(x);
1927  mpz_clear(y);
1928  mpz_mul(a->n,a->n,b->n);
1929  a->s=0;
1930  if (GCD_NORM_COND(b,a)) { nlNormalize_Gcd(a); }
1931  else { a=nlShort1(a);}
1932  break;
1933  }
1934  case 3: /* a:1 b:3 */
1935  {
1936  mpz_t x;
1937  mpz_init(x);
1938  mpz_mul(x,b->z,a->n);
1939  mpz_add(a->z,a->z,x);
1940  mpz_clear(x);
1941  a->s=0;
1942  if (GCD_NORM_COND(b,a)) { nlNormalize_Gcd(a); }
1943  else { a=nlShort1(a);}
1944  break;
1945  }
1946  } /*switch (b->s) */
1947  break;
1948  }
1949  case 3:
1950  {
1951  switch(b->s)
1952  {
1953  case 0:
1954  case 1:/* a:3, b:1 */
1955  {
1956  mpz_t x;
1957  mpz_init(x);
1958  mpz_mul(x,a->z,b->n);
1959  mpz_add(a->z,b->z,x);
1960  mpz_clear(x);
1961  mpz_init_set(a->n,b->n);
1962  a->s=0;
1963  if (GCD_NORM_COND(b,a)) { nlNormalize_Gcd(a); }
1964  else { a=nlShort1(a);}
1965  break;
1966  }
1967  case 3:
1968  {
1969  mpz_add(a->z,a->z,b->z);
1970  a->s = 3;
1971  a=nlShort3_noinline(a);
1972  break;
1973  }
1974  }
1975  break;
1976  }

◆ _nlMult_aImm_bImm_rNoImm()

number _nlMult_aImm_bImm_rNoImm ( number  a,
number  b 
)

Definition at line 2189 of file longrat.cc.

2193 {
2194  number u=ALLOC_RNUMBER();
2195 #if defined(LDEBUG)
2196  u->debug=123456;
2197 #endif
2198  u->s=3;
2199  mpz_init_set_si(u->z,SR_TO_INT(a));

◆ _nlMult_aNoImm_OR_bNoImm()

number _nlMult_aNoImm_OR_bNoImm ( number  a,
number  b 
)

Definition at line 2202 of file longrat.cc.

2206 {
2207  assume(! (SR_HDL(a) & SR_HDL(b) & SR_INT));
2208  number u=ALLOC_RNUMBER();
2209 #if defined(LDEBUG)
2210  u->debug=123456;
2211 #endif
2212  mpz_init(u->z);
2213  if (SR_HDL(b) & SR_INT)
2214  {
2215  number x=a;
2216  a=b;
2217  b=x;
2218  }
2219  if (SR_HDL(a) & SR_INT)
2220  {
2221  u->s=b->s;
2222  if (u->s==1) u->s=0;
2223  if (((long)a)>0L)
2224  {
2225  mpz_mul_ui(u->z,b->z,(unsigned long)SR_TO_INT(a));
2226  }
2227  else
2228  {
2229  if (a==INT_TO_SR(-1))
2230  {
2231  mpz_set(u->z,b->z);
2232  mpz_neg(u->z,u->z);
2233  u->s=b->s;
2234  }
2235  else
2236  {
2237  mpz_mul_ui(u->z,b->z,(unsigned long)-SR_TO_INT(a));
2238  mpz_neg(u->z,u->z);
2239  }
2240  }
2241  if (u->s<2)
2242  {
2243  if (mpz_cmp(u->z,b->n)==0)
2244  {
2245  mpz_clear(u->z);
2246  FREE_RNUMBER(u);
2247  return INT_TO_SR(1);
2248  }
2249  mpz_init_set(u->n,b->n);
2250  if (GCD_NORM_COND(b,u)) { nlNormalize_Gcd(u); }
2251  }
2252  else //u->s==3
2253  {
2254  u=nlShort3(u);
2255  }
2256  }
2257  else
2258  {
2259  mpz_mul(u->z,a->z,b->z);
2260  u->s = 0;
2261  if(a->s==3)
2262  {
2263  if(b->s==3)
2264  {
2265  u->s = 3;
2266  }
2267  else
2268  {
2269  if (mpz_cmp(u->z,b->n)==0)
2270  {
2271  mpz_clear(u->z);
2272  FREE_RNUMBER(u);
2273  return INT_TO_SR(1);
2274  }
2275  mpz_init_set(u->n,b->n);
2276  if (GCD_NORM_COND(b,u)) { nlNormalize_Gcd(u); }
2277  }
2278  }
2279  else
2280  {
2281  if(b->s==3)
2282  {
2283  if (mpz_cmp(u->z,a->n)==0)
2284  {
2285  mpz_clear(u->z);
2286  FREE_RNUMBER(u);
2287  return INT_TO_SR(1);
2288  }
2289  mpz_init_set(u->n,a->n);
2290  if (GCD_NORM_COND(a,u)) { nlNormalize_Gcd(u); }
2291  }
2292  else
2293  {
2294  mpz_init(u->n);
2295  mpz_mul(u->n,a->n,b->n);
2296  if (mpz_cmp(u->z,u->n)==0)
2297  {
2298  mpz_clear(u->z);
2299  mpz_clear(u->n);
2300  FREE_RNUMBER(u);
2301  return INT_TO_SR(1);
2302  }
2303  if (GCD_NORM_COND(a,u)) { nlNormalize_Gcd(u); }
2304  }
2305  }

◆ _nlNeg_NoImm()

number _nlNeg_NoImm ( number  a)

Definition at line 1642 of file longrat.cc.

1646 {
1647  {
1648  mpz_neg(a->z,a->z);
1649  if (a->s==3)
1650  {
1651  a=nlShort3(a);
1652  }

◆ _nlSub_aNoImm_OR_bNoImm()

number _nlSub_aNoImm_OR_bNoImm ( number  a,
number  b 
)

Definition at line 1978 of file longrat.cc.

1982 {
1983  number u=ALLOC_RNUMBER();
1984 #if defined(LDEBUG)
1985  u->debug=123456;
1986 #endif
1987  mpz_init(u->z);
1988  if (SR_HDL(a) & SR_INT)
1989  {
1990  switch (b->s)
1991  {
1992  case 0:
1993  case 1:/* a:short, b:1 */
1994  {
1995  mpz_t x;
1996  mpz_init(x);
1997  mpz_mul_si(x,b->n,SR_TO_INT(a));
1998  mpz_sub(u->z,x,b->z);
1999  mpz_clear(x);
2000  if (mpz_sgn1(u->z)==0)
2001  {
2002  mpz_clear(u->z);
2003  FREE_RNUMBER(u);
2004  return INT_TO_SR(0);
2005  }
2006  if (mpz_cmp(u->z,b->n)==0)
2007  {
2008  mpz_clear(u->z);
2009  FREE_RNUMBER(u);
2010  return INT_TO_SR(1);
2011  }
2012  mpz_init_set(u->n,b->n);
2013  u->s=0;
2014  if (GCD_NORM_COND(b,u)) { nlNormalize_Gcd(u); }
2015  break;
2016  }
2017  case 3:
2018  {
2019  if (((long)a)>0L)
2020  {
2021  mpz_sub_ui(u->z,b->z,SR_TO_INT(a));
2022  mpz_neg(u->z,u->z);
2023  }
2024  else
2025  {
2026  mpz_add_ui(u->z,b->z,-SR_TO_INT(a));
2027  mpz_neg(u->z,u->z);
2028  }
2029  u->s = 3;
2030  u=nlShort3(u);
2031  break;
2032  }
2033  }
2034  }
2035  else if (SR_HDL(b) & SR_INT)
2036  {
2037  switch (a->s)
2038  {
2039  case 0:
2040  case 1:/* b:short, a:1 */
2041  {
2042  mpz_t x;
2043  mpz_init(x);
2044  mpz_mul_si(x,a->n,SR_TO_INT(b));
2045  mpz_sub(u->z,a->z,x);
2046  mpz_clear(x);
2047  if (mpz_sgn1(u->z)==0)
2048  {
2049  mpz_clear(u->z);
2050  FREE_RNUMBER(u);
2051  return INT_TO_SR(0);
2052  }
2053  if (mpz_cmp(u->z,a->n)==0)
2054  {
2055  mpz_clear(u->z);
2056  FREE_RNUMBER(u);
2057  return INT_TO_SR(1);
2058  }
2059  mpz_init_set(u->n,a->n);
2060  u->s=0;
2061  if (GCD_NORM_COND(a,u)) { nlNormalize_Gcd(u); }
2062  break;
2063  }
2064  case 3:
2065  {
2066  if (((long)b)>0L)
2067  {
2068  mpz_sub_ui(u->z,a->z,SR_TO_INT(b));
2069  }
2070  else
2071  {
2072  mpz_add_ui(u->z,a->z,-SR_TO_INT(b));
2073  }
2074  u->s = 3;
2075  u=nlShort3(u);
2076  break;
2077  }
2078  }
2079  }
2080  else
2081  {
2082  switch (a->s)
2083  {
2084  case 0:
2085  case 1:
2086  {
2087  switch(b->s)
2088  {
2089  case 0:
2090  case 1:
2091  {
2092  mpz_t x;
2093  mpz_t y;
2094  mpz_init(x);
2095  mpz_init(y);
2096  mpz_mul(x,b->z,a->n);
2097  mpz_mul(y,a->z,b->n);
2098  mpz_sub(u->z,y,x);
2099  mpz_clear(x);
2100  mpz_clear(y);
2101  if (mpz_sgn1(u->z)==0)
2102  {
2103  mpz_clear(u->z);
2104  FREE_RNUMBER(u);
2105  return INT_TO_SR(0);
2106  }
2107  mpz_init(u->n);
2108  mpz_mul(u->n,a->n,b->n);
2109  if (mpz_cmp(u->z,u->n)==0)
2110  {
2111  mpz_clear(u->z);
2112  mpz_clear(u->n);
2113  FREE_RNUMBER(u);
2114  return INT_TO_SR(1);
2115  }
2116  u->s=0;
2117  if (GCD_NORM_COND(a,u)) { nlNormalize_Gcd(u); }
2118  break;
2119  }
2120  case 3: /* a:1, b:3 */
2121  {
2122  mpz_t x;
2123  mpz_init(x);
2124  mpz_mul(x,b->z,a->n);
2125  mpz_sub(u->z,a->z,x);
2126  mpz_clear(x);
2127  if (mpz_sgn1(u->z)==0)
2128  {
2129  mpz_clear(u->z);
2130  FREE_RNUMBER(u);
2131  return INT_TO_SR(0);
2132  }
2133  if (mpz_cmp(u->z,a->n)==0)
2134  {
2135  mpz_clear(u->z);
2136  FREE_RNUMBER(u);
2137  return INT_TO_SR(1);
2138  }
2139  mpz_init_set(u->n,a->n);
2140  u->s=0;
2141  if (GCD_NORM_COND(a,u)) { nlNormalize_Gcd(u); }
2142  break;
2143  }
2144  }
2145  break;
2146  }
2147  case 3:
2148  {
2149  switch(b->s)
2150  {
2151  case 0:
2152  case 1: /* a:3, b:1 */
2153  {
2154  mpz_t x;
2155  mpz_init(x);
2156  mpz_mul(x,a->z,b->n);
2157  mpz_sub(u->z,x,b->z);
2158  mpz_clear(x);
2159  if (mpz_sgn1(u->z)==0)
2160  {
2161  mpz_clear(u->z);
2162  FREE_RNUMBER(u);
2163  return INT_TO_SR(0);
2164  }
2165  if (mpz_cmp(u->z,b->n)==0)
2166  {
2167  mpz_clear(u->z);
2168  FREE_RNUMBER(u);
2169  return INT_TO_SR(1);
2170  }
2171  mpz_init_set(u->n,b->n);
2172  u->s=0;
2173  if (GCD_NORM_COND(b,u)) { nlNormalize_Gcd(u); }
2174  break;
2175  }
2176  case 3: /* a:3 , b:3 */
2177  {
2178  mpz_sub(u->z,a->z,b->z);
2179  u->s = 3;
2180  u=nlShort3(u);
2181  break;
2182  }
2183  }
2184  break;
2185  }
2186  }

◆ int_extgcd()

static int int_extgcd ( int  a,
int  b,
int *  u,
int *  x,
int *  v,
int *  y 
)
static

Definition at line 1272 of file longrat.cc.

1275 {
1276  int q, r;
1277  if (a==0)
1278  {
1279  *u = 0;
1280  *v = 1;
1281  *x = -1;
1282  *y = 0;
1283  return b;
1284  }
1285  if (b==0)
1286  {
1287  *u = 1;
1288  *v = 0;
1289  *x = 0;
1290  *y = 1;
1291  return a;
1292  }
1293  *u=1;
1294  *v=0;
1295  *x=0;
1296  *y=1;
1297  do
1298  {
1299  q = a/b;
1300  r = a%b;
1301  assume (q*b+r == a);
1302  a = b;
1303  b = r;
1304 
1305  r = -(*v)*q+(*u);
1306  (*u) =(*v);
1307  (*v) = r;
1308 
1309  r = -(*y)*q+(*x);
1310  (*x) = (*y);
1311  (*y) = r;
1312  } while (b);
1313 

◆ mpz_mul_si()

void mpz_mul_si ( mpz_ptr  r,
mpz_srcptr  s,
long int  si 
)

Definition at line 170 of file longrat.cc.

173 {
174  if (si>=0)
175  mpz_mul_ui(r,s,si);
176  else
177  {
178  mpz_mul_ui(r,s,-si);
179  mpz_neg(r,r);

◆ nl_Copy()

LINLINE number nl_Copy ( number  a,
const coeffs  r 
)

◆ nlAdd()

LINLINE number nlAdd ( number  la,
number  li,
const coeffs  r 
)

Definition at line 2526 of file longrat.cc.

2531 {
2532  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
2533  {
2534  LONG r=SR_HDL(a)+SR_HDL(b)-1L;
2535  if ( ((r << 1) >> 1) == r )
2536  return (number)(long)r;
2537  else
2538  return nlRInit(SR_TO_INT(r));
2539  }

◆ nlBigInt() [1/2]

number nlBigInt ( number &  i,
const coeffs  r 
)

Definition at line 629 of file longrat.cc.

632 {
633  nlTest(i, r);
634  nlNormalize(i,r);
635  if (SR_HDL(i) & SR_INT) return (i);
636  if (i->s==3)
637  {
638  return nlCopy(i,r);
639  }
640  number tmp=nlRInit(1);
641  mpz_tdiv_q(tmp->z,i->z,i->n);
642  tmp=nlShort3(tmp);

◆ nlBigInt() [2/2]

number nlBigInt ( number &  n)

◆ nlChineseRemainderSym()

number nlChineseRemainderSym ( number *  x,
number *  q,
int  rl,
BOOLEAN  sym,
CFArray inv_cache,
const coeffs  CF 
)

Definition at line 2932 of file longrat.cc.

2938 {
2939  setCharacteristic( 0 ); // only in char 0
2940  Off(SW_RATIONAL);
2941  CFArray X(rl), Q(rl);
2942  int i;
2943  for(i=rl-1;i>=0;i--)
2944  {
2945  X[i]=CF->convSingNFactoryN(x[i],FALSE,CF); // may be larger MAX_INT
2946  Q[i]=CF->convSingNFactoryN(q[i],FALSE,CF); // may be larger MAX_INT
2947  }
2948  CanonicalForm xnew,qnew;
2949  if (n_SwitchChinRem)
2950  chineseRemainder(X,Q,xnew,qnew);
2951  else
2952  chineseRemainderCached(X,Q,xnew,qnew,inv_cache);
2953  number n=CF->convFactoryNSingN(xnew,CF);
2954  if (sym)
2955  {
2956  number p=CF->convFactoryNSingN(qnew,CF);
2957  number p2;
2958  if (getCoeffType(CF) == n_Q) p2=nlIntDiv(p,nlInit(2, CF),CF);
2959  else p2=CF->cfDiv(p,CF->cfInit(2, CF),CF);
2960  if (CF->cfGreater(n,p2,CF))
2961  {
2962  number n2=CF->cfSub(n,p,CF);
2963  CF->cfDelete(&n,CF);
2964  n=n2;
2965  }
2966  CF->cfDelete(&p2,CF);
2967  CF->cfDelete(&p,CF);

◆ nlClearContent()

static void nlClearContent ( ICoeffsEnumerator numberCollectionEnumerator,
number &  c,
const coeffs  cf 
)
static

Definition at line 2976 of file longrat.cc.

2981 {
2982  assume(cf != NULL);
2983 
2984  numberCollectionEnumerator.Reset();
2985 
2986  if( !numberCollectionEnumerator.MoveNext() ) // empty zero polynomial?
2987  {
2988  c = nlInit(1, cf);
2989  return;
2990  }
2991 
2992  // all coeffs are given by integers!!!
2993 
2994  // part 1, find a small candidate for gcd
2995  number cand1,cand;
2996  int s1,s;
2997  s=2147483647; // max. int
2998 
2999  const BOOLEAN lc_is_pos=nlGreaterZero(numberCollectionEnumerator.Current(),cf);
3000 
3001  int normalcount = 0;
3002  do
3003  {
3004  number& n = numberCollectionEnumerator.Current();
3005  nlNormalize(n, cf); ++normalcount;
3006  cand1 = n;
3007 
3008  if (SR_HDL(cand1)&SR_INT) { cand=cand1; break; }
3009  assume(cand1->s==3); // all coeffs should be integers // ==0?!! after printing
3010  s1=mpz_size1(cand1->z);
3011  if (s>s1)
3012  {
3013  cand=cand1;
3014  s=s1;
3015  }
3016  } while (numberCollectionEnumerator.MoveNext() );
3017 
3018 // assume( nlGreaterZero(cand,cf) ); // cand may be a negative integer!
3019 
3020  cand=nlCopy(cand,cf);
3021  // part 2: compute gcd(cand,all coeffs)
3022 
3023  numberCollectionEnumerator.Reset();
3024 
3025  while (numberCollectionEnumerator.MoveNext() )
3026  {
3027  number& n = numberCollectionEnumerator.Current();
3028 
3029  if( (--normalcount) <= 0)
3030  nlNormalize(n, cf);
3031 
3032  nlInpGcd(cand, n, cf);
3034 
3035  if(nlIsOne(cand,cf))
3036  {
3037  c = cand;
3038 
3039  if(!lc_is_pos)
3040  {
3041  // make the leading coeff positive
3042  c = nlNeg(c, cf);
3043  numberCollectionEnumerator.Reset();
3044 
3045  while (numberCollectionEnumerator.MoveNext() )
3046  {
3047  number& nn = numberCollectionEnumerator.Current();
3048  nn = nlNeg(nn, cf);
3049  }
3050  }
3051  return;
3052  }
3053  }
3054 
3055  // part3: all coeffs = all coeffs / cand
3056  if (!lc_is_pos)
3057  cand = nlNeg(cand,cf);
3058 
3059  c = cand;
3060  numberCollectionEnumerator.Reset();
3061 
3062  while (numberCollectionEnumerator.MoveNext() )
3063  {
3064  number& n = numberCollectionEnumerator.Current();
3065  number t=nlIntDiv(n, cand, cf); // simple integer exact division, no ratios to remain

◆ nlClearDenominators()

static void nlClearDenominators ( ICoeffsEnumerator numberCollectionEnumerator,
number &  c,
const coeffs  cf 
)
static

Definition at line 3067 of file longrat.cc.

3072 {
3073  assume(cf != NULL);
3074 
3075  numberCollectionEnumerator.Reset();
3076 
3077  if( !numberCollectionEnumerator.MoveNext() ) // empty zero polynomial?
3078  {
3079  c = nlInit(1, cf);
3080 // assume( n_GreaterZero(c, cf) );
3081  return;
3082  }
3083 
3084  // all coeffs are given by integers after returning from this routine
3085 
3086  // part 1, collect product of all denominators /gcds
3087  number cand;
3088  cand=ALLOC_RNUMBER();
3089 #if defined(LDEBUG)
3090  cand->debug=123456;
3091 #endif
3092  cand->s=3;
3093 
3094  int s=0;
3095 
3096  const BOOLEAN lc_is_pos=nlGreaterZero(numberCollectionEnumerator.Current(),cf);
3097 
3098  do
3099  {
3100  number& cand1 = numberCollectionEnumerator.Current();
3101 
3102  if (!(SR_HDL(cand1)&SR_INT))
3103  {
3104  nlNormalize(cand1, cf);
3105  if ((!(SR_HDL(cand1)&SR_INT)) // not a short int
3106  && (cand1->s==1)) // and is a normalised rational
3107  {
3108  if (s==0) // first denom, we meet
3109  {
3110  mpz_init_set(cand->z, cand1->n); // cand->z = cand1->n
3111  s=1;
3112  }
3113  else // we have already something
3114  {
3115  mpz_lcm(cand->z, cand->z, cand1->n);
3116  }
3117  }
3118  }
3119  }
3120  while (numberCollectionEnumerator.MoveNext() );
3121 
3122 
3123  if (s==0) // nothing to do, all coeffs are already integers
3124  {
3125 // mpz_clear(tmp);
3126  FREE_RNUMBER(cand);
3127  if (lc_is_pos)
3128  c=nlInit(1,cf);
3129  else
3130  {
3131  // make the leading coeff positive
3132  c=nlInit(-1,cf);
3133 
3134  // TODO: incorporate the following into the loop below?
3135  numberCollectionEnumerator.Reset();
3136  while (numberCollectionEnumerator.MoveNext() )
3137  {
3138  number& n = numberCollectionEnumerator.Current();
3139  n = nlNeg(n, cf);
3140  }
3141  }
3142 // assume( n_GreaterZero(c, cf) );
3143  return;
3144  }
3145 
3146  cand = nlShort3(cand);
3147 
3148  // part2: all coeffs = all coeffs * cand
3149  // make the lead coeff positive
3150  numberCollectionEnumerator.Reset();
3151 
3152  if (!lc_is_pos)
3153  cand = nlNeg(cand, cf);
3154 
3155  c = cand;
3156 
3157  while (numberCollectionEnumerator.MoveNext() )
3158  {
3159  number &n = numberCollectionEnumerator.Current();

◆ nlCoeffIsEqual()

BOOLEAN nlCoeffIsEqual ( const coeffs  r,
n_coeffType  n,
void *  p 
)

Definition at line 3282 of file longrat.cc.

3287 {
3288  /* test, if r is an instance of nInitCoeffs(n,parameter) */
3289  /* if parameter is not needed */
3290  if (n==r->type)
3291  {
3292  if ((p==NULL)&&(r->cfDiv==nlDiv)) return TRUE;

◆ nlCoeffName()

char* nlCoeffName ( const coeffs  r)

Definition at line 3161 of file longrat.cc.

3166 {

◆ nlCoeffString()

static char* nlCoeffString ( const coeffs  r)
static

Definition at line 3167 of file longrat.cc.

3172 {

◆ nlCoeffWrite()

void nlCoeffWrite ( const coeffs  r,
BOOLEAN  details 
)

Definition at line 2923 of file longrat.cc.

2928 {
2929  if (r->is_field)

◆ nlConvFactoryNSingN()

static number nlConvFactoryNSingN ( const CanonicalForm  f,
const coeffs  r 
)
static

Definition at line 368 of file longrat.cc.

371 {
372  if (f.isImm())
373  {
374  return nlInit(f.intval(),r);
375  }
376  else
377  {
378  number z = ALLOC_RNUMBER();
379 #if defined(LDEBUG)
380  z->debug=123456;
381 #endif
382  gmp_numerator( f, z->z );
383  if ( f.den().isOne() )
384  {
385  z->s = 3;
386  z=nlShort3(z);
387  }
388  else
389  {
390  gmp_denominator( f, z->n );
391  z->s = 1;
392  }
393  return z;

◆ nlConvSingNFactoryN()

static CanonicalForm nlConvSingNFactoryN ( number  n,
const BOOLEAN  setChar,
const  coeffs 
)
static

Definition at line 330 of file longrat.cc.

333 {
334  if (setChar) setCharacteristic( 0 );
335 
337  if ( SR_HDL(n) & SR_INT )
338  {
339  long nn=SR_TO_INT(n);
340  term = nn;
341  }
342  else
343  {
344  if ( n->s == 3 )
345  {
346  mpz_t dummy;
347  long lz=mpz_get_si(n->z);
348  if (mpz_cmp_si(n->z,lz)==0) term=lz;
349  else
350  {
351  mpz_init_set( dummy,n->z );
352  term = make_cf( dummy );
353  }
354  }
355  else
356  {
357  // assume s==0 or s==1
358  mpz_t num, den;
359  On(SW_RATIONAL);
360  mpz_init_set( num, n->z );
361  mpz_init_set( den, n->n );
362  term = make_cf( num, den, ( n->s != 1 ));
363  }
364  }

◆ nlCopy()

LINLINE number nlCopy ( number  a,
const coeffs  r 
)

Definition at line 2478 of file longrat.cc.

2483 {
2484  if ((SR_HDL(a) & SR_INT)||(a==NULL))
2485  {

◆ nlCopyMap()

number nlCopyMap ( number  a,
const  coeffs,
const  coeffs 
)

Definition at line 2310 of file longrat.cc.

2314 {
2315  if ((SR_HDL(a) & SR_INT)||(a==NULL))
2316  {
2317  return a;

◆ nlDBTest() [1/2]

BOOLEAN nlDBTest ( number  a,
const char *  f,
const int  l 
)

◆ nlDBTest() [2/2]

BOOLEAN nlDBTest ( number  a,
const char *  f,
int  l,
const coeffs  r 
)

Definition at line 238 of file longrat.cc.

241 {
242  if (a==NULL)
243  {
244  Print("!!longrat: NULL in %s:%d\n",f,l);
245  return FALSE;
246  }
247  //if ((int)a==1) Print("!! 0x1 as number ? %s %d\n",f,l);
248  if ((((long)a)&3L)==3L)
249  {
250  Print(" !!longrat:ptr(3) in %s:%d\n",f,l);
251  return FALSE;
252  }
253  if ((((long)a)&3L)==1L)
254  {
255  if (((((LONG)(long)a)<<1)>>1)!=((LONG)(long)a))
256  {
257  Print(" !!longrat:arith:%lx in %s:%d\n",(long)a, f,l);
258  return FALSE;
259  }
260  return TRUE;
261  }
262  /* TODO: If next line is active, then computations in algebraic field
263  extensions over Q will throw a lot of assume violations although
264  everything is computed correctly and no seg fault appears.
265  Maybe the test is not appropriate in this case. */
266  omCheckIf(omCheckAddrSize(a,sizeof(*a)), return FALSE);
267  if (a->debug!=123456)
268  {
269  Print("!!longrat:debug:%d in %s:%d\n",a->debug,f,l);
270  a->debug=123456;
271  return FALSE;
272  }
273  if ((a->s<0)||(a->s>4))
274  {
275  Print("!!longrat:s=%d in %s:%d\n",a->s,f,l);
276  return FALSE;
277  }
278  /* TODO: If next line is active, then computations in algebraic field
279  extensions over Q will throw a lot of assume violations although
280  everything is computed correctly and no seg fault appears.
281  Maybe the test is not appropriate in this case. */
282  //omCheckAddrSize(a->z[0]._mp_d,a->z[0]._mp_alloc*BYTES_PER_MP_LIMB);
283  if (a->z[0]._mp_alloc==0)
284  Print("!!longrat:z->alloc=0 in %s:%d\n",f,l);
285 
286  if (a->s<2)
287  {
288  if ((a->n[0]._mp_d[0]==0)&&(a->n[0]._mp_alloc<=1))
289  {
290  Print("!!longrat: n==0 in %s:%d\n",f,l);
291  return FALSE;
292  }
293  /* TODO: If next line is active, then computations in algebraic field
294  extensions over Q will throw a lot of assume violations although
295  everything is computed correctly and no seg fault appears.
296  Maybe the test is not appropriate in this case. */
297  //omCheckIf(omCheckAddrSize(a->n[0]._mp_d,a->n[0]._mp_alloc*BYTES_PER_MP_LIMB), return FALSE);
298  if (a->z[0]._mp_alloc==0)
299  Print("!!longrat:n->alloc=0 in %s:%d\n",f,l);
300  if ((mpz_size1(a->n) ==1) && (mpz_cmp_si(a->n,1L)==0))
301  {
302  Print("!!longrat:integer as rational in %s:%d\n",f,l);
303  mpz_clear(a->n); a->s=3;
304  return FALSE;
305  }
306  else if (mpz_isNeg(a->n))
307  {
308  Print("!!longrat:div. by negative in %s:%d\n",f,l);
309  mpz_neg(a->z,a->z);
310  mpz_neg(a->n,a->n);
311  return FALSE;
312  }
313  return TRUE;
314  }
315  //if (a->s==2)
316  //{
317  // Print("!!longrat:s=2 in %s:%d\n",f,l);
318  // return FALSE;
319  //}
320  if (mpz_size1(a->z)>MP_SMALL) return TRUE;
321  LONG ui=(LONG)mpz_get_si(a->z);
322  if ((((ui<<3)>>3)==ui)
323  && (mpz_cmp_si(a->z,(long)ui)==0))
324  {
325  Print("!!longrat:im int %d in %s:%d\n",ui,f,l);
326  return FALSE;
327  }

◆ nlDelete()

LINLINE void nlDelete ( number *  a,
const coeffs  r 
)

Definition at line 2491 of file longrat.cc.

2496 {
2497  if (*a!=NULL)
2498  {
2499  nlTest(*a, r);
2500  if ((SR_HDL(*a) & SR_INT)==0)
2501  {
2502  _nlDelete_NoImm(a);

◆ nlDiv()

number nlDiv ( number  a,
number  b,
const coeffs  r 
)

Definition at line 1001 of file longrat.cc.

1001  := a / b
1002 */
1003 number nlDiv (number a, number b, const coeffs r)
1004 {
1005  if (nlIsZero(b,r))
1006  {
1007  WerrorS(nDivBy0);
1008  return INT_TO_SR(0);
1009  }
1010  number u;
1011 // ---------- short / short ------------------------------------
1012  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
1013  {
1014  LONG i=SR_TO_INT(a);
1015  LONG j=SR_TO_INT(b);
1016  if (j==1L) return a;
1017  if ((i==-POW_2_28) && (j== -1L))
1018  {
1019  return nlRInit(POW_2_28);
1020  }
1021  LONG r=i%j;
1022  if (r==0)
1023  {
1024  return INT_TO_SR(i/j);
1025  }
1026  u=ALLOC_RNUMBER();
1027  u->s=0;
1028  #if defined(LDEBUG)
1029  u->debug=123456;
1030  #endif
1031  mpz_init_set_si(u->z,(long)i);
1032  mpz_init_set_si(u->n,(long)j);
1033  }
1034  else
1035  {
1036  u=ALLOC_RNUMBER();
1037  u->s=0;
1038  #if defined(LDEBUG)
1039  u->debug=123456;
1040  #endif
1041  mpz_init(u->z);
1042 // ---------- short / long ------------------------------------
1043  if (SR_HDL(a) & SR_INT)
1044  {
1045  // short a / (z/n) -> (a*n)/z
1046  if (b->s<2)
1047  {
1048  mpz_mul_si(u->z,b->n,SR_TO_INT(a));
1049  }
1050  else
1051  // short a / long z -> a/z
1052  {
1053  mpz_set_si(u->z,SR_TO_INT(a));
1054  }
1055  if (mpz_cmp(u->z,b->z)==0)
1056  {
1057  mpz_clear(u->z);
1058  FREE_RNUMBER(u);
1059  return INT_TO_SR(1);
1060  }
1061  mpz_init_set(u->n,b->z);
1062  }
1063 // ---------- long / short ------------------------------------
1064  else if (SR_HDL(b) & SR_INT)
1065  {
1066  mpz_set(u->z,a->z);
1067  // (z/n) / b -> z/(n*b)
1068  if (a->s<2)
1069  {
1070  mpz_init_set(u->n,a->n);
1071  if (((long)b)>0L)
1072  mpz_mul_ui(u->n,u->n,SR_TO_INT(b));
1073  else
1074  {
1075  mpz_mul_ui(u->n,u->n,-SR_TO_INT(b));
1076  mpz_neg(u->z,u->z);
1077  }
1078  }
1079  else
1080  // long z / short b -> z/b
1081  {
1082  //mpz_set(u->z,a->z);
1083  mpz_init_set_si(u->n,SR_TO_INT(b));
1084  }
1085  }
1086 // ---------- long / long ------------------------------------
1087  else
1088  {
1089  mpz_set(u->z,a->z);
1090  mpz_init_set(u->n,b->z);
1091  if (a->s<2) mpz_mul(u->n,u->n,a->n);
1092  if (b->s<2) mpz_mul(u->z,u->z,b->n);
1093  }
1094  }
1095  if (mpz_isNeg(u->n))
1096  {
1097  mpz_neg(u->z,u->z);
1098  mpz_neg(u->n,u->n);
1099  }
1100  if (mpz_cmp_si(u->n,1L)==0)
1101  {
1102  mpz_clear(u->n);
1103  u->s=3;
1104  u=nlShort3(u);
1105  }
1106  nlTest(u, r);

◆ nlDivBy()

BOOLEAN nlDivBy ( number  a,
number  b,
const  coeffs 
)

Definition at line 936 of file longrat.cc.

939 {
940  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
941  {
942  return ((SR_TO_INT(a) % SR_TO_INT(b))==0);
943  }
944  if (SR_HDL(b) & SR_INT)
945  {
946  return (mpz_divisible_ui_p(a->z,SR_TO_INT(b))!=0);
947  }
948  if (SR_HDL(a) & SR_INT) return FALSE;

◆ nlDivComp()

int nlDivComp ( number  a,
number  b,
const coeffs  r 
)

Definition at line 950 of file longrat.cc.

953 {
954  if (nlDivBy(a, b, r))
955  {
956  if (nlDivBy(b, a, r)) return 2;
957  return -1;
958  }
959  if (nlDivBy(b, a, r)) return 1;

◆ nlEqual()

LINLINE BOOLEAN nlEqual ( number  a,
number  b,
const coeffs  r 
)

Definition at line 2422 of file longrat.cc.

2427 {
2428  nlTest(a, r);
2429  nlTest(b, r);

◆ nlExactDiv()

number nlExactDiv ( number  a,
number  b,
const coeffs  r 
)

Definition at line 727 of file longrat.cc.

727  := a / b in Z, if b | a (else undefined)
728 */
729 number nlExactDiv(number a, number b, const coeffs r)
730 {
731  if (b==INT_TO_SR(0))
732  {
733  WerrorS(nDivBy0);
734  return INT_TO_SR(0);
735  }
736  if (a==INT_TO_SR(0))
737  return INT_TO_SR(0);
738  number u;
739  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
740  {
741  /* the small int -(1<<28) divided by -1 is the large int (1<<28) */
742  if ((a==INT_TO_SR(-(POW_2_28)))&&(b==INT_TO_SR(-1L)))
743  {
744  return nlRInit(POW_2_28);
745  }
746  long aa=SR_TO_INT(a);
747  long bb=SR_TO_INT(b);
748  return INT_TO_SR(aa/bb);
749  }
750  number aa=NULL;
751  number bb=NULL;
752  if (SR_HDL(a) & SR_INT)
753  {
754  aa=nlRInit(SR_TO_INT(a));
755  a=aa;
756  }
757  if (SR_HDL(b) & SR_INT)
758  {
759  bb=nlRInit(SR_TO_INT(b));
760  b=bb;
761  }
762  u=ALLOC_RNUMBER();
763 #if defined(LDEBUG)
764  u->debug=123456;
765 #endif
766  mpz_init(u->z);
767  /* u=a/b */
768  u->s = 3;
769  assume(a->s==3);
770  assume(b->s==3);
771  mpz_divexact(u->z,a->z,b->z);
772  if (aa!=NULL)
773  {
774  mpz_clear(aa->z);
775 #if defined(LDEBUG)
776  aa->debug=654324;
777 #endif
778  FREE_RNUMBER(aa); // omFreeBin((void *)aa, rnumber_bin);
779  }
780  if (bb!=NULL)
781  {
782  mpz_clear(bb->z);
783 #if defined(LDEBUG)
784  bb->debug=654324;
785 #endif
786  FREE_RNUMBER(bb); // omFreeBin((void *)bb, rnumber_bin);
787  }
788  u=nlShort3(u);
789  nlTest(u, r);

◆ nlExtGcd()

number nlExtGcd ( number  a,
number  b,
number *  s,
number *  t,
const  coeffs 
)

Definition at line 2874 of file longrat.cc.

2879 {
2880  mpz_ptr aa,bb;
2881  *s=ALLOC_RNUMBER();
2882  mpz_init((*s)->z); (*s)->s=3;
2883  (*t)=ALLOC_RNUMBER();
2884  mpz_init((*t)->z); (*t)->s=3;
2885  number g=ALLOC_RNUMBER();
2886  mpz_init(g->z); g->s=3;
2887  #ifdef LDEBUG
2888  g->debug=123456;
2889  (*s)->debug=123456;
2890  (*t)->debug=123456;
2891  #endif
2892  if (SR_HDL(a) & SR_INT)
2893  {
2894  aa=(mpz_ptr)omAlloc(sizeof(mpz_t));
2895  mpz_init_set_si(aa,SR_TO_INT(a));
2896  }
2897  else
2898  {
2899  aa=a->z;
2900  }
2901  if (SR_HDL(b) & SR_INT)
2902  {
2903  bb=(mpz_ptr)omAlloc(sizeof(mpz_t));
2904  mpz_init_set_si(bb,SR_TO_INT(b));
2905  }
2906  else
2907  {
2908  bb=b->z;
2909  }
2910  mpz_gcdext(g->z,(*s)->z,(*t)->z,aa,bb);
2911  g=nlShort3(g);
2912  (*s)=nlShort3((*s));
2913  (*t)=nlShort3((*t));
2914  if (SR_HDL(a) & SR_INT)
2915  {
2916  mpz_clear(aa);
2917  omFreeSize(aa, sizeof(mpz_t));
2918  }
2919  if (SR_HDL(b) & SR_INT)
2920  {
2921  mpz_clear(bb);

◆ nlFarey()

number nlFarey ( number  nN,
number  nP,
const coeffs  CF 
)

Definition at line 2803 of file longrat.cc.

2808 {
2809  mpz_t A,B,C,D,E,N,P,tmp;
2810  if (SR_HDL(nP) & SR_INT) mpz_init_set_si(P,SR_TO_INT(nP));
2811  else mpz_init_set(P,nP->z);
2812  const mp_bitcnt_t bits=2*(mpz_size1(P)+1)*GMP_LIMB_BITS;
2813  mpz_init2(N,bits);
2814  if (SR_HDL(nN) & SR_INT) mpz_set_si(N,SR_TO_INT(nN));
2815  else mpz_set(N,nN->z);
2816  assume(!mpz_isNeg(P));
2817  if (mpz_isNeg(N)) mpz_add(N,N,P);
2818  mpz_init2(A,bits); mpz_set_ui(A,0L);
2819  mpz_init2(B,bits); mpz_set_ui(B,1L);
2820  mpz_init2(C,bits); mpz_set_ui(C,0L);
2821  mpz_init2(D,bits);
2822  mpz_init2(E,bits); mpz_set(E,P);
2823  mpz_init2(tmp,bits);
2824  number z=INT_TO_SR(0);
2825  while(mpz_sgn1(N)!=0)
2826  {
2827  mpz_mul(tmp,N,N);
2828  mpz_add(tmp,tmp,tmp);
2829  if (mpz_cmp(tmp,P)<0)
2830  {
2831  if (mpz_isNeg(B))
2832  {
2833  mpz_neg(B,B);
2834  mpz_neg(N,N);
2835  }
2836  // check for gcd(N,B)==1
2837  mpz_gcd(tmp,N,B);
2838  if (mpz_cmp_ui(tmp,1)==0)
2839  {
2840  // return N/B
2841  z=ALLOC_RNUMBER();
2842  #ifdef LDEBUG
2843  z->debug=123456;
2844  #endif
2845  mpz_init_set(z->z,N);
2846  mpz_init_set(z->n,B);
2847  z->s = 0;
2848  nlNormalize(z,r);
2849  }
2850  else
2851  {
2852  // return nN (the input) instead of "fail"
2853  z=nlCopy(nN,r);
2854  }
2855  break;
2856  }
2857  //mpz_mod(D,E,N);
2858  //mpz_div(tmp,E,N);
2859  mpz_divmod(tmp,D,E,N);
2860  mpz_mul(tmp,tmp,B);
2861  mpz_sub(C,A,tmp);
2862  mpz_set(E,N);
2863  mpz_set(N,D);
2864  mpz_set(A,B);
2865  mpz_set(B,C);
2866  }
2867  mpz_clear(tmp);
2868  mpz_clear(A);
2869  mpz_clear(B);
2870  mpz_clear(C);
2871  mpz_clear(D);
2872  mpz_clear(E);

◆ nlGcd()

number nlGcd ( number  a,
number  b,
const coeffs  r 
)

Definition at line 1201 of file longrat.cc.

1204 {
1205  number result;
1206  nlTest(a, r);
1207  nlTest(b, r);
1208  //nlNormalize(a);
1209  //nlNormalize(b);
1210  if ((a==INT_TO_SR(1L))||(a==INT_TO_SR(-1L))
1211  || (b==INT_TO_SR(1L))||(b==INT_TO_SR(-1L)))
1212  return INT_TO_SR(1L);
1213  if (a==INT_TO_SR(0)) /* gcd(0,b) ->b */
1214  return nlCopy(b,r);
1215  if (b==INT_TO_SR(0)) /* gcd(a,0) -> a */
1216  return nlCopy(a,r);
1217  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
1218  {
1219  long i=SR_TO_INT(a);
1220  long j=SR_TO_INT(b);
1221  if((i==0L)||(j==0L))
1222  return INT_TO_SR(1);
1223  long l;
1224  i=ABS(i);
1225  j=ABS(j);
1226  do
1227  {
1228  l=i%j;
1229  i=j;
1230  j=l;
1231  } while (l!=0L);
1232  if (i==POW_2_28)
1234  else
1235  result=INT_TO_SR(i);
1236  nlTest(result,r);
1237  return result;
1238  }
1239  if (((!(SR_HDL(a) & SR_INT))&&(a->s<2))
1240  || ((!(SR_HDL(b) & SR_INT))&&(b->s<2))) return INT_TO_SR(1);
1241  if (SR_HDL(a) & SR_INT)
1242  {
1243  LONG aa=ABS(SR_TO_INT(a));
1244  unsigned long t=mpz_gcd_ui(NULL,b->z,(long)aa);
1245  if (t==POW_2_28)
1247  else
1248  result=INT_TO_SR(t);
1249  }
1250  else
1251  if (SR_HDL(b) & SR_INT)
1252  {
1253  LONG bb=ABS(SR_TO_INT(b));
1254  unsigned long t=mpz_gcd_ui(NULL,a->z,(long)bb);
1255  if (t==POW_2_28)
1257  else
1258  result=INT_TO_SR(t);
1259  }
1260  else
1261  {
1263  result->s = 3;
1264  #ifdef LDEBUG
1265  result->debug=123456;
1266  #endif
1267  mpz_init(result->z);
1268  mpz_gcd(result->z,a->z,b->z);
1270  }
1271  nlTest(result, r);

◆ nlGetDenom()

number nlGetDenom ( number &  n,
const coeffs  r 
)

Definition at line 1497 of file longrat.cc.

1500 {
1501  if (!(SR_HDL(n) & SR_INT))
1502  {
1503  if (n->s==0)
1504  {
1505  nlNormalize(n,r);
1506  }
1507  if (!(SR_HDL(n) & SR_INT))
1508  {
1509  if (n->s!=3)
1510  {
1511  number u=ALLOC_RNUMBER();
1512  u->s=3;
1513 #if defined(LDEBUG)
1514  u->debug=123456;
1515 #endif
1516  mpz_init_set(u->z,n->n);
1517  u=nlShort3_noinline(u);
1518  return u;
1519  }
1520  }
1521  }

◆ nlGetNumerator()

number nlGetNumerator ( number &  n,
const coeffs  r 
)

Definition at line 1526 of file longrat.cc.

1529 {
1530  if (!(SR_HDL(n) & SR_INT))
1531  {
1532  if (n->s==0)
1533  {
1534  nlNormalize(n,r);
1535  }
1536  if (!(SR_HDL(n) & SR_INT))
1537  {
1538  number u=ALLOC_RNUMBER();
1539 #if defined(LDEBUG)
1540  u->debug=123456;
1541 #endif
1542  u->s=3;
1543  mpz_init_set(u->z,n->z);
1544  if (n->s!=3)
1545  {
1546  u=nlShort3_noinline(u);
1547  }
1548  return u;
1549  }
1550  }

◆ nlGetUnit()

number nlGetUnit ( number  n,
const coeffs  cf 
)

Definition at line 961 of file longrat.cc.

964 {
965  if (nlGreaterZero(n,cf)) return INT_TO_SR(1);

◆ nlGMP()

void nlGMP ( number &  i,
mpz_t  n,
const coeffs  r 
)

Definition at line 1476 of file longrat.cc.

1479 {
1480  // Hier brauche ich einfach die GMP Zahl
1481  nlTest(i, r);
1482  nlNormalize(i, r);
1483  if (SR_HDL(i) & SR_INT)
1484  {
1485  mpz_set_si(n, SR_TO_INT(i));
1486  return;
1487  }
1488  if (i->s!=3)
1489  {
1490  WarnS("Omitted denominator during coefficient mapping !");
1491  }

◆ nlGreater()

BOOLEAN nlGreater ( number  a,
number  b,
const coeffs  r 
)

Definition at line 1174 of file longrat.cc.

1177 {
1178  nlTest(a, r);
1179  nlTest(b, r);
1180  number re;
1181  BOOLEAN rr;
1182  re=nlSub(a,b,r);
1183  rr=(!nlIsZero(re,r)) && (nlGreaterZero(re,r));
1184  nlDelete(&re,r);

◆ nlGreaterZero()

BOOLEAN nlGreaterZero ( number  za,
const coeffs  r 
)

Definition at line 1164 of file longrat.cc.

1167 {
1168  nlTest(a, r);
1169  if (SR_HDL(a) & SR_INT) return SR_HDL(a)>1L /* represents number(0) */;

◆ nlInit()

LINLINE number nlInit ( long  i,
const coeffs  r 
)

Definition at line 2431 of file longrat.cc.

2436 {
2437  number n;
2438  #if MAX_NUM_SIZE == 60
2439  if (((i << 3) >> 3) == i) n=INT_TO_SR(i);
2440  else n=nlRInit(i);
2441  #else
2442  LONG ii=(LONG)i;
2443  if ( ((((long)ii)==i) && ((ii << 3) >> 3) == ii )) n=INT_TO_SR(ii);
2444  else n=nlRInit(i);

◆ nlInit2()

number nlInit2 ( int  i,
int  j,
const coeffs  r 
)

create a rational i/j (implicitly) over Q NOTE: make sure to use correct Q in debug mode

Definition at line 2370 of file longrat.cc.

2374 {
2375  number z=ALLOC_RNUMBER();
2376 #if defined(LDEBUG)
2377  z->debug=123456;
2378 #endif
2379  mpz_init_set_si(z->z,(long)i);
2380  mpz_init_set_si(z->n,(long)j);
2381  z->s = 0;

◆ nlInit2gmp()

number nlInit2gmp ( mpz_t  i,
mpz_t  j,
const coeffs  r 
)

create a rational i/j (implicitly) over Q NOTE: make sure to use correct Q in debug mode

Definition at line 2383 of file longrat.cc.

2387 {
2388  number z=ALLOC_RNUMBER();
2389 #if defined(LDEBUG)
2390  z->debug=123456;
2391 #endif
2392  mpz_init_set(z->z,i);
2393  mpz_init_set(z->n,j);
2394  z->s = 0;

◆ nlInitChar()

BOOLEAN nlInitChar ( coeffs  r,
void *  p 
)

Definition at line 3318 of file longrat.cc.

3323 {
3324  r->is_domain=TRUE;
3325  r->rep=n_rep_gap_rat;
3326 
3327  r->nCoeffIsEqual=nlCoeffIsEqual;
3328  //r->cfKillChar = ndKillChar; /* dummy */
3329  r->cfCoeffString=nlCoeffString;
3330  r->cfCoeffName=nlCoeffName;
3331 
3332  r->cfInitMPZ = nlInitMPZ;
3333  r->cfMPZ = nlMPZ;
3334 
3335  r->cfMult = nlMult;
3336  r->cfSub = nlSub;
3337  r->cfAdd = nlAdd;
3338  r->cfExactDiv= nlExactDiv;
3339  if (p==NULL) /* Q */
3340  {
3341  r->is_field=TRUE;
3342  r->cfDiv = nlDiv;
3343  //r->cfGcd = ndGcd_dummy;
3344  r->cfSubringGcd = nlGcd;
3345  }
3346  else /* Z: coeffs_BIGINT */
3347  {
3348  r->is_field=FALSE;
3349  r->cfDiv = nlIntDiv;
3350  r->cfIntMod= nlIntMod;
3351  r->cfGcd = nlGcd;
3352  r->cfDivBy=nlDivBy;
3353  r->cfDivComp = nlDivComp;
3354  r->cfIsUnit = nlIsUnit;
3355  r->cfGetUnit = nlGetUnit;
3356  r->cfQuot1 = nlQuot1;
3357  r->cfLcm = nlLcm;
3358  r->cfXExtGcd=nlXExtGcd;
3359  r->cfQuotRem=nlQuotRem;
3360  }
3361  r->cfInit = nlInit;
3362  r->cfSize = nlSize;
3363  r->cfInt = nlInt;
3364 
3365  r->cfChineseRemainder=nlChineseRemainderSym;
3366  r->cfFarey=nlFarey;
3367  r->cfInpNeg = nlNeg;
3368  r->cfInvers= nlInvers;
3369  r->cfCopy = nlCopy;
3370  r->cfRePart = nlCopy;
3371  //r->cfImPart = ndReturn0;
3372  r->cfWriteLong = nlWrite;
3373  r->cfRead = nlRead;
3374  r->cfNormalize=nlNormalize;
3375  r->cfGreater = nlGreater;
3376  r->cfEqual = nlEqual;
3377  r->cfIsZero = nlIsZero;
3378  r->cfIsOne = nlIsOne;
3379  r->cfIsMOne = nlIsMOne;
3380  r->cfGreaterZero = nlGreaterZero;
3381  r->cfPower = nlPower;
3382  r->cfGetDenom = nlGetDenom;
3383  r->cfGetNumerator = nlGetNumerator;
3384  r->cfExtGcd = nlExtGcd; // only for ring stuff and Z
3385  r->cfNormalizeHelper = nlNormalizeHelper;
3386  r->cfDelete= nlDelete;
3387  r->cfSetMap = nlSetMap;
3388  //r->cfName = ndName;
3389  r->cfInpMult=nlInpMult;
3390  r->cfInpAdd=nlInpAdd;
3391  r->cfCoeffWrite=nlCoeffWrite;
3392 
3393  r->cfClearContent = nlClearContent;
3394  r->cfClearDenominators = nlClearDenominators;
3395 
3396 #ifdef LDEBUG
3397  // debug stuff
3398  r->cfDBTest=nlDBTest;
3399 #endif
3400  r->convSingNFactoryN=nlConvSingNFactoryN;
3401  r->convFactoryNSingN=nlConvFactoryNSingN;
3402 
3403  r->cfRandom=nlRandom;
3404 
3405  // io via ssi
3406  r->cfWriteFd=nlWriteFd;
3407  r->cfReadFd=nlReadFd;
3408 
3409  //r->type = n_Q;
3410  r->ch = 0;
3411  r->has_simple_Alloc=FALSE;
3412  r->has_simple_Inverse=FALSE;
3413 

◆ nlInitMPZ()

static number nlInitMPZ ( mpz_t  m,
const  coeffs 
)
static

Definition at line 2653 of file longrat.cc.

2658 {
2659  number z = ALLOC_RNUMBER();
2660  z->s = 3;
2661  #ifdef LDEBUG
2662  z->debug=123456;
2663  #endif

◆ nlInpAdd()

LINLINE void nlInpAdd ( number &  a,
number  b,
const coeffs  r 
)

Definition at line 2544 of file longrat.cc.

2549 {
2550  // a=a+b
2551  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
2552  {
2553  LONG r=SR_HDL(a)+SR_HDL(b)-1L;
2554  if ( ((r << 1) >> 1) == r )
2555  a=(number)(long)r;
2556  else
2557  a=nlRInit(SR_TO_INT(r));
2558  }
2559  else
2560  {

◆ nlInpGcd()

void nlInpGcd ( number &  a,
number  b,
const coeffs  r 
)

Definition at line 2770 of file longrat.cc.

2775 {
2776  if ((SR_HDL(b)|SR_HDL(a))&SR_INT)
2777  {
2778  number n=nlGcd(a,b,r);
2779  nlDelete(&a,r);
2780  a=n;
2781  }
2782  else
2783  {

◆ nlInpIntDiv()

void nlInpIntDiv ( number &  a,
number  b,
const coeffs  r 
)

Definition at line 2785 of file longrat.cc.

2790 {
2791  if ((SR_HDL(b)|SR_HDL(a))&SR_INT)
2792  {
2793  number n=nlIntDiv(a,b, r);
2794  nlDelete(&a,r);
2795  a=n;
2796  }
2797  else
2798  {
2799  number rr=nlIntMod(a,b,r);
2800  if (SR_HDL(rr) & SR_INT) mpz_sub_ui(a->z,a->z,SR_TO_INT(rr));
2801  else mpz_sub(a->z,a->z,rr->z);

◆ nlInpMult()

LINLINE void nlInpMult ( number &  a,
number  b,
const coeffs  r 
)

Definition at line 2610 of file longrat.cc.

2615 {
2616  number aa=a;
2617  if (((SR_HDL(b)|SR_HDL(aa))&SR_INT))
2618  {
2619  number n=nlMult(aa,b,r);
2620  nlDelete(&a,r);
2621  a=n;
2622  }
2623  else
2624  {
2625  mpz_mul(aa->z,a->z,b->z);
2626  if (aa->s==3)
2627  {
2628  if(b->s!=3)
2629  {
2630  mpz_init_set(a->n,b->n);
2631  a->s=0;
2632  }
2633  }
2634  else
2635  {
2636  if(b->s!=3)
2637  {
2638  mpz_mul(a->n,a->n,b->n);
2639  }

◆ nlInt()

long nlInt ( number &  n,
const coeffs  r 
)

Definition at line 597 of file longrat.cc.

600 {
601  nlTest(i, r);
602  nlNormalize(i,r);
603  if (SR_HDL(i) & SR_INT)
604  {
605  return SR_TO_INT(i);
606  }
607  if (i->s==3)
608  {
609  if(mpz_size1(i->z)>MP_SMALL) return 0;
610  long ul=mpz_get_si(i->z);
611  if (mpz_cmp_si(i->z,ul)!=0) return 0;
612  return ul;
613  }
614  mpz_t tmp;
615  long ul;
616  mpz_init(tmp);
617  mpz_tdiv_q(tmp,i->z,i->n);
618  if(mpz_size1(tmp)>MP_SMALL) ul=0;
619  else
620  {
621  ul=mpz_get_si(tmp);
622  if (mpz_cmp_si(tmp,ul)!=0) ul=0;
623  }
624  mpz_clear(tmp);

◆ nlIntDiv()

number nlIntDiv ( number  a,
number  b,
const coeffs  r 
)

Definition at line 794 of file longrat.cc.

794  := a / b in Z
795 */
796 number nlIntDiv (number a, number b, const coeffs r)
797 {
798  if (b==INT_TO_SR(0))
799  {
800  WerrorS(nDivBy0);
801  return INT_TO_SR(0);
802  }
803  if (a==INT_TO_SR(0))
804  return INT_TO_SR(0);
805  number u;
806  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
807  {
808  /* the small int -(1<<28) divided by -1 is the large int (1<<28) */
809  if ((a==INT_TO_SR(-(POW_2_28)))&&(b==INT_TO_SR(-1L)))
810  {
811  return nlRInit(POW_2_28);
812  }
813  LONG aa=SR_TO_INT(a);
814  LONG bb=SR_TO_INT(b);
815  LONG rr=aa%bb;
816  if (rr<0) rr+=ABS(bb);
817  LONG cc=(aa-rr)/bb;
818  return INT_TO_SR(cc);
819  }
820  number aa=NULL;
821  if (SR_HDL(a) & SR_INT)
822  {
823  /* the small int -(1<<28) divided by 2^28 is 1 */
824  if (a==INT_TO_SR(-(POW_2_28)))
825  {
826  if(mpz_cmp_si(b->z,(POW_2_28))==0)
827  {
828  return INT_TO_SR(-1);
829  }
830  }
831  aa=nlRInit(SR_TO_INT(a));
832  a=aa;
833  }
834  number bb=NULL;
835  if (SR_HDL(b) & SR_INT)
836  {
837  bb=nlRInit(SR_TO_INT(b));
838  b=bb;
839  }
840  u=ALLOC_RNUMBER();
841 #if defined(LDEBUG)
842  u->debug=123456;
843 #endif
844  assume(a->s==3);
845  assume(b->s==3);
846  mpz_init_set(u->z,a->z);
847  /* u=u/b */
848  u->s = 3;
849  number rr=nlIntMod(a,b,r);
850  if (SR_HDL(rr) & SR_INT) mpz_sub_ui(u->z,u->z,SR_TO_INT(rr));
851  else mpz_sub(u->z,u->z,rr->z);
852  mpz_divexact(u->z,u->z,b->z);
853  if (aa!=NULL)
854  {
855  mpz_clear(aa->z);
856 #if defined(LDEBUG)
857  aa->debug=654324;
858 #endif
859  FREE_RNUMBER(aa);
860  }
861  if (bb!=NULL)
862  {
863  mpz_clear(bb->z);
864 #if defined(LDEBUG)
865  bb->debug=654324;
866 #endif
867  FREE_RNUMBER(bb);
868  }
869  u=nlShort3(u);
870  nlTest(u,r);

◆ nlIntMod()

number nlIntMod ( number  a,
number  b,
const coeffs  r 
)

Definition at line 875 of file longrat.cc.

875  := a mod b in Z, u>=0
876 */
877 number nlIntMod (number a, number b, const coeffs r)
878 {
879  if (b==INT_TO_SR(0))
880  {
881  WerrorS(nDivBy0);
882  return INT_TO_SR(0);
883  }
884  if (a==INT_TO_SR(0))
885  return INT_TO_SR(0);
886  number u;
887  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
888  {
889  LONG aa=SR_TO_INT(a);
890  LONG bb=SR_TO_INT(b);
891  LONG c=aa % bb;
892  if (c<0) c+=ABS(bb);
893  return INT_TO_SR(c);
894  }
895  if (SR_HDL(a) & SR_INT)
896  {
897  LONG ai=SR_TO_INT(a);
898  mpz_t aa;
899  mpz_init_set_si(aa, ai);
900  u=ALLOC_RNUMBER();
901 #if defined(LDEBUG)
902  u->debug=123456;
903 #endif
904  u->s = 3;
905  mpz_init(u->z);
906  mpz_mod(u->z, aa, b->z);
907  mpz_clear(aa);
908  u=nlShort3(u);
909  nlTest(u,r);
910  return u;
911  }
912  number bb=NULL;
913  if (SR_HDL(b) & SR_INT)
914  {
915  bb=nlRInit(SR_TO_INT(b));
916  b=bb;
917  }
918  u=ALLOC_RNUMBER();
919 #if defined(LDEBUG)
920  u->debug=123456;
921 #endif
922  mpz_init(u->z);
923  u->s = 3;
924  mpz_mod(u->z, a->z, b->z);
925  if (bb!=NULL)
926  {
927  mpz_clear(bb->z);
928 #if defined(LDEBUG)
929  bb->debug=654324;
930 #endif
931  FREE_RNUMBER(bb);
932  }
933  u=nlShort3(u);
934  nlTest(u,r);

◆ nlInvers()

number nlInvers ( number  a,
const coeffs  r 
)

Definition at line 647 of file longrat.cc.

650 {
651  nlTest(a, r);
652  number n;
653  if (SR_HDL(a) & SR_INT)
654  {
655  if ((a==INT_TO_SR(1L)) || (a==INT_TO_SR(-1L)))
656  {
657  return a;
658  }
659  if (nlIsZero(a,r))
660  {
661  WerrorS(nDivBy0);
662  return INT_TO_SR(0);
663  }
664  n=ALLOC_RNUMBER();
665 #if defined(LDEBUG)
666  n->debug=123456;
667 #endif
668  n->s=1;
669  if (((long)a)>0L)
670  {
671  mpz_init_set_ui(n->z,1L);
672  mpz_init_set_si(n->n,(long)SR_TO_INT(a));
673  }
674  else
675  {
676  mpz_init_set_si(n->z,-1L);
677  mpz_init_set_si(n->n,(long)-SR_TO_INT(a));
678  }
679  nlTest(n, r);
680  return n;
681  }
682  n=ALLOC_RNUMBER();
683 #if defined(LDEBUG)
684  n->debug=123456;
685 #endif
686  {
687  mpz_init_set(n->n,a->z);
688  switch (a->s)
689  {
690  case 0:
691  case 1:
692  n->s=a->s;
693  mpz_init_set(n->z,a->n);
694  if (mpz_isNeg(n->n)) /* && n->s<2*/
695  {
696  mpz_neg(n->z,n->z);
697  mpz_neg(n->n,n->n);
698  }
699  if (mpz_cmp_ui(n->n,1L)==0)
700  {
701  mpz_clear(n->n);
702  n->s=3;
703  n=nlShort3(n);
704  }
705  break;
706  case 3:
707  // i.e. |a| > 2^...
708  n->s=1;
709  if (mpz_isNeg(n->n)) /* && n->s<2*/
710  {
711  mpz_neg(n->n,n->n);
712  mpz_init_set_si(n->z,-1L);
713  }
714  else
715  {
716  mpz_init_set_ui(n->z,1L);
717  }
718  break;
719  }
720  }
721  nlTest(n, r);

◆ nlIsMOne()

BOOLEAN nlIsMOne ( number  a,
const coeffs  r 
)

Definition at line 1189 of file longrat.cc.

1192 {
1193 #ifdef LDEBUG
1194  if (a==NULL) return FALSE;
1195  nlTest(a, r);
1196 #endif

◆ nlIsOne()

LINLINE BOOLEAN nlIsOne ( number  a,
const coeffs  r 
)

Definition at line 2449 of file longrat.cc.

2454 {
2455 #ifdef LDEBUG
2456  if (a==NULL) return FALSE;

◆ nlIsUnit()

BOOLEAN nlIsUnit ( number  a,
const  coeffs 
)

Definition at line 992 of file longrat.cc.

995 {

◆ nlIsZero()

LINLINE BOOLEAN nlIsZero ( number  za,
const coeffs  r 
)

Definition at line 2458 of file longrat.cc.

2463 {
2464  #if 0
2465  if (a==INT_TO_SR(0)) return TRUE;
2466  if ((SR_HDL(a) & SR_INT)||(a==NULL)) return FALSE;
2467  if (mpz_cmp_si(a->z,0L)==0)
2468  {
2469  printf("gmp-0 in nlIsZero\n");
2470  dErrorBreak();
2471  return TRUE;
2472  }
2473  return FALSE;

◆ nlLcm()

static number nlLcm ( number  a,
number  b,
const coeffs  r 
)
static

Definition at line 3294 of file longrat.cc.

3299 {
3300  number g=nlGcd(a,b,r);
3301  number n1=nlMult(a,b,r);
3302  number n2=nlIntDiv(n1,g,r);

◆ nlMapGMP()

number nlMapGMP ( number  from,
const coeffs  src,
const coeffs  dst 
)

Definition at line 199 of file longrat.cc.

202 {
203  number z=ALLOC_RNUMBER();
204 #if defined(LDEBUG)
205  z->debug=123456;
206 #endif
207  mpz_init_set(z->z,(mpz_ptr) from);
208  z->s = 3;
209  z=nlShort3(z);

◆ nlMapLongR()

static number nlMapLongR ( number  from,
const coeffs  src,
const coeffs  dst 
)
static

Definition at line 425 of file longrat.cc.

428 {
429  assume( getCoeffType(src) == n_long_R );
430 
431  gmp_float *ff=(gmp_float*)from;
432  mpf_t *f=ff->_mpfp();
433  number res;
434  mpz_ptr dest,ndest;
435  int size, i,negative;
436  int e,al,bl;
437  mp_ptr qp,dd,nn;
438 
439  size = (*f)[0]._mp_size;
440  if (size == 0)
441  return INT_TO_SR(0);
442  if(size<0)
443  {
444  negative = 1;
445  size = -size;
446  }
447  else
448  negative = 0;
449 
450  qp = (*f)[0]._mp_d;
451  while(qp[0]==0)
452  {
453  qp++;
454  size--;
455  }
456 
457  e=(*f)[0]._mp_exp-size;
458  res = ALLOC_RNUMBER();
459 #if defined(LDEBUG)
460  res->debug=123456;
461 #endif
462  dest = res->z;
463 
464  void* (*allocfunc) (size_t);
465  mp_get_memory_functions (&allocfunc,NULL, NULL);
466  if (e<0)
467  {
468  al = dest->_mp_size = size;
469  if (al<2) al = 2;
470  dd = (mp_ptr)allocfunc(sizeof(mp_limb_t)*al);
471  for (i=0;i<size;i++) dd[i] = qp[i];
472  bl = 1-e;
473  nn = (mp_ptr)allocfunc(sizeof(mp_limb_t)*bl);
474  nn[bl-1] = 1;
475  ndest = res->n;
476  ndest->_mp_d = nn;
477  ndest->_mp_alloc = ndest->_mp_size = bl;
478  res->s = 0;
479  }
480  else
481  {
482  al = dest->_mp_size = size+e;
483  if (al<2) al = 2;
484  dd = (mp_ptr)allocfunc(sizeof(mp_limb_t)*al);
485  for (i=0;i<size;i++) dd[i+e] = qp[i];
486  for (i=0;i<e;i++) dd[i] = 0;
487  res->s = 3;
488  }
489 
490  dest->_mp_d = dd;
491  dest->_mp_alloc = al;
492  if (negative) mpz_neg(dest,dest);
493 
494  if (res->s==0)
495  nlNormalize(res,dst);
496  else if (mpz_size1(res->z)<=MP_SMALL)
497  {
498  // res is new, res->ref is 1
499  res=nlShort3(res);
500  }
501  nlTest(res, dst);

◆ nlMapMachineInt()

number nlMapMachineInt ( number  from,
const  coeffs,
const  coeffs 
)

Definition at line 223 of file longrat.cc.

226 {
227  number z=ALLOC_RNUMBER();
228 #if defined(LDEBUG)
229  z->debug=123456;
230 #endif
231  mpz_init_set_ui(z->z,(unsigned long) from);
232  z->s = 3;
233  z=nlShort3(z);

◆ nlMapP()

static number nlMapP ( number  from,
const coeffs  src,
const coeffs  dst 
)
static

Definition at line 182 of file longrat.cc.

185 {
186  assume( getCoeffType(src) == n_Zp );
187 
188  number to = nlInit(npInt(from,src), dst); // FIXME? TODO? // extern long npInt (number &n, const coeffs r);
189 

◆ nlMapR()

static number nlMapR ( number  from,
const coeffs  src,
const coeffs  dst 
)
static

Definition at line 395 of file longrat.cc.

398 {
399  assume( getCoeffType(src) == n_R );
400 
401  double f=nrFloat(from); // FIXME? TODO? // extern float nrFloat(number n);
402  if (f==0.0) return INT_TO_SR(0);
403  int f_sign=1;
404  if (f<0.0)
405  {
406  f_sign=-1;
407  f=-f;
408  }
409  int i=0;
410  mpz_t h1;
411  mpz_init_set_ui(h1,1);
412  while((FLT_RADIX*f) < DBL_MAX && i<DBL_MANT_DIG)
413  {
414  f*=FLT_RADIX;
415  mpz_mul_ui(h1,h1,FLT_RADIX);
416  i++;
417  }
418  number re=nlRInit(1);
419  mpz_set_d(re->z,f);
420  memcpy(&(re->n),&h1,sizeof(h1));
421  re->s=0; /* not normalized */
422  if(f_sign==-1) re=nlNeg(re,dst);
423  nlNormalize(re,dst);

◆ nlMapZ()

number nlMapZ ( number  from,
const coeffs  src,
const coeffs  dst 
)

Definition at line 211 of file longrat.cc.

214 {
215  if (SR_HDL(from) & SR_INT)
216  {
217  return from;
218  }

◆ nlModP()

number nlModP ( number  q,
const  coeffs,
const coeffs  Zp 
)

Definition at line 1434 of file longrat.cc.

1437 {
1438  const int p = n_GetChar(Zp);
1439  assume( p > 0 );
1440 
1441  const long P = p;
1442  assume( P > 0 );
1443 
1444  // embedded long within q => only long numerator has to be converted
1445  // to int (modulo char.)
1446  if (SR_HDL(q) & SR_INT)
1447  {
1448  long i = SR_TO_INT(q);
1449  return n_Init( i, Zp );
1450  }
1451 
1452  const unsigned long PP = p;
1453 
1454  // numerator modulo char. should fit into int
1455  number z = n_Init( static_cast<long>(mpz_fdiv_ui(q->z, PP)), Zp );
1456 
1457  // denominator != 1?
1458  if (q->s!=3)
1459  {
1460  // denominator modulo char. should fit into int
1461  number n = n_Init( static_cast<long>(mpz_fdiv_ui(q->n, PP)), Zp );
1462 
1463  number res = n_Div( z, n, Zp );
1464 
1465  n_Delete(&z, Zp);
1466  n_Delete(&n, Zp);
1467 
1468  return res;
1469  }
1470 

◆ nlMPZ()

static void nlMPZ ( mpz_t  m,
number &  n,
const coeffs  r 
)
static

Definition at line 2644 of file longrat.cc.

2649 {
2650  nlTest(n, r);

◆ nlMult()

LINLINE number nlMult ( number  a,
number  b,
const coeffs  r 
)

Definition at line 2562 of file longrat.cc.

2567 {
2568  nlTest(a, R);
2569  nlTest(b, R);
2570  if (a==INT_TO_SR(0)) return INT_TO_SR(0);
2571  if (b==INT_TO_SR(0)) return INT_TO_SR(0);
2572  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
2573  {
2574  LONG r=(LONG)((unsigned LONG)(SR_HDL(a)-1L))*((unsigned LONG)(SR_HDL(b)>>1));
2575  if ((r/(SR_HDL(b)>>1))==(SR_HDL(a)-1L))
2576  {
2577  number u=((number) ((r>>1)+SR_INT));
2578  if (((((LONG)SR_HDL(u))<<1)>>1)==SR_HDL(u)) return (u);
2579  return nlRInit(SR_HDL(u)>>2);
2580  }
2581  number u = _nlMult_aImm_bImm_rNoImm(a, b);
2582  nlTest(u, R);
2583  return u;
2584 
2585  }
2586  number u = _nlMult_aNoImm_OR_bNoImm(a, b);

◆ nlNeg()

LINLINE number nlNeg ( number  za,
const coeffs  r 
)

Definition at line 2507 of file longrat.cc.

2512 {
2513  nlTest(a, R);
2514  if(SR_HDL(a) &SR_INT)
2515  {
2516  LONG r=SR_TO_INT(a);
2517  if (r==(-(POW_2_28))) a=nlRInit(POW_2_28);
2518  else a=INT_TO_SR(-r);
2519  return a;
2520  }
2521  a = _nlNeg_NoImm(a);

◆ nlNormalize()

void nlNormalize ( number &  x,
const coeffs  r 
)

Definition at line 1343 of file longrat.cc.

1346 {
1347  if ((SR_HDL(x) & SR_INT) ||(x==NULL))
1348  return;
1349  if (x->s==3)
1350  {
1352  nlTest(x,r);
1353  return;
1354  }
1355  else if (x->s==0)
1356  {
1357  if (mpz_cmp_si(x->n,1L)==0)
1358  {
1359  mpz_clear(x->n);
1360  x->s=3;
1361  x=nlShort3(x);
1362  }
1363  else
1364  {
1365  mpz_t gcd;
1366  mpz_init(gcd);
1367  mpz_gcd(gcd,x->z,x->n);
1368  x->s=1;
1369  if (mpz_cmp_si(gcd,1L)!=0)
1370  {
1371  mpz_divexact(x->z,x->z,gcd);
1372  mpz_divexact(x->n,x->n,gcd);
1373  if (mpz_cmp_si(x->n,1L)==0)
1374  {
1375  mpz_clear(x->n);
1376  x->s=3;
1378  }
1379  }
1380  mpz_clear(gcd);
1381  }
1382  }

◆ nlNormalize_Gcd()

static void nlNormalize_Gcd ( number &  x)
static

Definition at line 1657 of file longrat.cc.

1661 {
1662  mpz_t gcd;
1663  mpz_init(gcd);
1664  mpz_gcd(gcd,x->z,x->n);
1665  x->s=1;
1666  if (mpz_cmp_si(gcd,1L)!=0)
1667  {
1668  mpz_divexact(x->z,x->z,gcd);
1669  mpz_divexact(x->n,x->n,gcd);
1670  if (mpz_cmp_si(x->n,1L)==0)
1671  {
1672  mpz_clear(x->n);
1673  x->s=3;
1675  }

◆ nlNormalizeHelper()

number nlNormalizeHelper ( number  a,
number  b,
const coeffs  r 
)

Definition at line 1387 of file longrat.cc.

1390 {
1391  number result;
1392  nlTest(a, r);
1393  nlTest(b, r);
1394  if ((SR_HDL(b) & SR_INT)
1395  || (b->s==3))
1396  {
1397  // b is 1/(b->n) => b->n is 1 => result is a
1398  return nlCopy(a,r);
1399  }
1401 #if defined(LDEBUG)
1402  result->debug=123456;
1403 #endif
1404  result->s=3;
1405  mpz_t gcd;
1406  mpz_init(gcd);
1407  mpz_init(result->z);
1408  if (SR_HDL(a) & SR_INT)
1409  mpz_gcd_ui(gcd,b->n,ABS(SR_TO_INT(a)));
1410  else
1411  mpz_gcd(gcd,a->z,b->n);
1412  if (mpz_cmp_si(gcd,1L)!=0)
1413  {
1414  mpz_t bt;
1415  mpz_init(bt);
1416  mpz_divexact(bt,b->n,gcd);
1417  if (SR_HDL(a) & SR_INT)
1418  mpz_mul_si(result->z,bt,SR_TO_INT(a));
1419  else
1420  mpz_mul(result->z,bt,a->z);
1421  mpz_clear(bt);
1422  }
1423  else
1424  if (SR_HDL(a) & SR_INT)
1425  mpz_mul_si(result->z,b->n,SR_TO_INT(a));
1426  else
1427  mpz_mul(result->z,b->n,a->z);
1428  mpz_clear(gcd);
1430  nlTest(result, r);

◆ nlPower()

void nlPower ( number  x,
int  exp,
number *  lu,
const coeffs  r 
)

Definition at line 1111 of file longrat.cc.

1111  := x ^ exp
1112 */
1113 void nlPower (number x,int exp,number * u, const coeffs r)
1114 {
1115  *u = INT_TO_SR(0); // 0^e, e!=0
1116  if (exp==0)
1117  *u= INT_TO_SR(1);
1118  else if (!nlIsZero(x,r))
1119  {
1120  nlTest(x, r);
1121  number aa=NULL;
1122  if (SR_HDL(x) & SR_INT)
1123  {
1124  aa=nlRInit(SR_TO_INT(x));
1125  x=aa;
1126  }
1127  else if (x->s==0)
1128  nlNormalize(x,r);
1129  *u=ALLOC_RNUMBER();
1130 #if defined(LDEBUG)
1131  (*u)->debug=123456;
1132 #endif
1133  mpz_init((*u)->z);
1134  mpz_pow_ui((*u)->z,x->z,(unsigned long)exp);
1135  if (x->s<2)
1136  {
1137  if (mpz_cmp_si(x->n,1L)==0)
1138  {
1139  x->s=3;
1140  mpz_clear(x->n);
1141  }
1142  else
1143  {
1144  mpz_init((*u)->n);
1145  mpz_pow_ui((*u)->n,x->n,(unsigned long)exp);
1146  }
1147  }
1148  (*u)->s = x->s;
1149  if ((*u)->s==3) *u=nlShort3(*u);
1150  if (aa!=NULL)
1151  {
1152  mpz_clear(aa->z);
1153  FREE_RNUMBER(aa);
1154  }
1155  }
1156 #ifdef LDEBUG
1157  if (exp<0) Print("nlPower: neg. exp. %d\n",exp);
1158  nlTest(*u, r);

◆ nlQuot1()

coeffs nlQuot1 ( number  c,
const coeffs  r 
)

Definition at line 967 of file longrat.cc.

970 {
971  long ch = r->cfInt(c, r);
972  int p=IsPrime(ch);
973  coeffs rr=NULL;
974  if (((long)p)==ch)
975  {
976  rr = nInitChar(n_Zp,(void*)ch);
977  }
978  #ifdef HAVE_RINGS
979  else
980  {
981  mpz_t dummy;
982  mpz_init_set_ui(dummy, ch);
983  ZnmInfo info;
984  info.base = dummy;
985  info.exp = (unsigned long) 1;
986  rr = nInitChar(n_Zn, (void*)&info);
987  mpz_clear(dummy);
988  }
989  #endif

◆ nlQuotRem()

number nlQuotRem ( number  a,
number  b,
number *  r,
const coeffs  R 
)

Definition at line 2717 of file longrat.cc.

2722 {
2723  assume(SR_TO_INT(b)!=0);
2724  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
2725  {
2726  if (r!=NULL)
2727  *r = INT_TO_SR(SR_TO_INT(a) % SR_TO_INT(b));
2728  return INT_TO_SR(SR_TO_INT(a)/SR_TO_INT(b));
2729  }
2730  else if (SR_HDL(a) & SR_INT)
2731  {
2732  // -2^xx / 2^xx
2733  if ((a==INT_TO_SR(-(POW_2_28)))&&(b==INT_TO_SR(-1L)))
2734  {
2735  if (r!=NULL) *r=INT_TO_SR(0);
2736  return nlRInit(POW_2_28);
2737  }
2738  //a is small, b is not, so q=0, r=a
2739  if (r!=NULL)
2740  *r = a;
2741  return INT_TO_SR(0);
2742  }
2743  else if (SR_HDL(b) & SR_INT)
2744  {
2745  unsigned long rr;
2746  mpz_t qq;
2747  mpz_init(qq);
2748  mpz_t rrr;
2749  mpz_init(rrr);
2750  rr = mpz_divmod_ui(qq, rrr, a->z, (unsigned long)ABS(SR_TO_INT(b)));
2751  mpz_clear(rrr);
2752 
2753  if (r!=NULL)
2754  *r = INT_TO_SR(rr);
2755  if (SR_TO_INT(b)<0)
2756  {
2757  mpz_neg(qq, qq);
2758  }
2759  return nlInitMPZ(qq,R);
2760  }
2761  mpz_t qq,rr;
2762  mpz_init(qq);
2763  mpz_init(rr);
2764  mpz_divmod(qq, rr, a->z, b->z);
2765  if (r!=NULL)
2766  *r = nlInitMPZ(rr,R);
2767  else
2768  {

◆ nlRandom()

static number nlRandom ( siRandProc  p,
number  v2,
number  ,
const coeffs  cf 
)
static

Definition at line 3304 of file longrat.cc.

3309 {
3310  number a=nlInit(p(),cf);
3311  if (v2!=NULL)
3312  {
3313  number b=nlInit(p(),cf);
3314  number c=nlDiv(a,b,cf);
3315  nlDelete(&b,cf);
3316  nlDelete(&a,cf);

◆ nlRead()

const char* nlRead ( const char *  s,
number *  a,
const coeffs  r 
)

Definition at line 53 of file longrat0.cc.

55 {
56  if (*s<'0' || *s>'9')
57  {
58  *a = INT_TO_SR(1); /* nlInit(1) */
59  return s;
60  }
61  *a=(number)ALLOC_RNUMBER();
62  {
63  (*a)->s = 3;
64 #if defined(LDEBUG)
65  (*a)->debug=123456;
66 #endif
67  mpz_ptr z=(*a)->z;
68  mpz_ptr n=(*a)->n;
69  mpz_init(z);
70  s = nlEatLong((char *)s, z);
71  if (*s == '/')
72  {
73  mpz_init(n);
74  (*a)->s = 0;
75  s++;
76  s = nlEatLong((char *)s, n);
77  if (mpz_cmp_si(n,0L)==0)
78  {
80  mpz_clear(n);
81  (*a)->s = 3;
82  }
83  else if (mpz_cmp_si(n,1L)==0)
84  {
85  mpz_clear(n);
86  (*a)->s=3;
87  }
88  }
89  if (mpz_cmp_si(z,0L)==0)
90  {
91  mpz_clear(z);
92  FREE_RNUMBER(*a);
93  *a=INT_TO_SR(0);
94  }
95  else if ((*a)->s==3)
96  {
97  number nlShort3_noinline(number x);
98  *a=nlShort3_noinline(*a);
99  }
100  else
101  {
102  number aa=*a;
103  nlNormalize(aa,r); // FIXME? TODO? // extern void nlNormalize(number &x, const coeffs r);
104  *a=aa;
105  }
106  }
107  return s;

◆ nlReadFd()

static number nlReadFd ( s_buff  f,
const  coeffs 
)
static

Definition at line 3220 of file longrat.cc.

3225 {
3226  int sub_type=-1;
3227  sub_type=s_readint(f);
3228  switch(sub_type)
3229  {
3230  case 0:
3231  case 1:
3232  {// read mpz_t, mpz_t
3233  number n=nlRInit(0);
3234  mpz_init(n->n);
3235  s_readmpz(f,n->z);
3236  s_readmpz(f,n->n);
3237  n->s=sub_type;
3238  return n;
3239  }
3240 
3241  case 3:
3242  {// read mpz_t
3243  number n=nlRInit(0);
3244  s_readmpz(f,n->z);
3245  n->s=3; /*sub_type*/
3246  #if SIZEOF_LONG == 8
3247  n=nlShort3(n);
3248  #endif
3249  return n;
3250  }
3251  case 4:
3252  {
3253  LONG dd=s_readlong(f);
3254  //#if SIZEOF_LONG == 8
3255  return INT_TO_SR(dd);
3256  //#else
3257  //return nlInit(dd,NULL);
3258  //#endif
3259  }
3260  case 5:
3261  case 6:
3262  {// read raw mpz_t, mpz_t
3263  number n=nlRInit(0);
3264  mpz_init(n->n);
3265  s_readmpz_base (f,n->z, SSI_BASE);
3266  s_readmpz_base (f,n->n, SSI_BASE);
3267  n->s=sub_type-5;
3268  return n;
3269  }
3270  case 8:
3271  {// read raw mpz_t
3272  number n=nlRInit(0);
3273  s_readmpz_base (f,n->z, SSI_BASE);
3274  n->s=sub_type=3; /*subtype-5*/
3275  #if SIZEOF_LONG == 8
3276  n=nlShort3(n);
3277  #endif
3278  return n;
3279  }
3280 
3281  default: Werror("error in reading number: invalid subtype %d",sub_type);

◆ nlRInit()

number nlRInit ( long  i)

Definition at line 2356 of file longrat.cc.

2360 {
2361  number z=ALLOC_RNUMBER();
2362 #if defined(LDEBUG)
2363  z->debug=123456;
2364 #endif
2365  mpz_init_set_si(z->z,i);

◆ nlSetMap()

nMapFunc nlSetMap ( const coeffs  src,
const coeffs  dst 
)

Definition at line 2319 of file longrat.cc.

2323 {
2324  if (src->rep==n_rep_gap_rat) /*Q, coeffs_BIGINT */
2325  {
2326  return ndCopyMap;
2327  }
2328  if ((src->rep==n_rep_int) && nCoeff_is_Zp(src))
2329  {
2330  return nlMapP;
2331  }
2332  if ((src->rep==n_rep_float) && nCoeff_is_R(src))
2333  {
2334  return nlMapR;
2335  }
2336  if ((src->rep==n_rep_gmp_float) && nCoeff_is_long_R(src))
2337  {
2338  return nlMapLongR; /* long R -> Q */
2339  }
2340 #ifdef HAVE_RINGS
2341  if (src->rep==n_rep_gmp) // nCoeff_is_Ring_Z(src) || nCoeff_is_Ring_PtoM(src) || nCoeff_is_Ring_ModN(src))
2342  {
2343  return nlMapGMP;
2344  }
2345  if (src->rep==n_rep_gap_gmp)
2346  {
2347  return nlMapZ;
2348  }
2349  if ((src->rep==n_rep_int) && nCoeff_is_Ring_2toM(src))
2350  {
2351  return nlMapMachineInt;
2352  }

◆ nlShort1()

number nlShort1 ( number  x)

Definition at line 1322 of file longrat.cc.

1325 {
1326  assume(x->s<2);
1327  if (mpz_sgn1(x->z)==0)
1328  {
1329  _nlDelete_NoImm(&x);
1330  return INT_TO_SR(0);
1331  }
1332  if (x->s<2)
1333  {
1334  if (mpz_cmp(x->z,x->n)==0)
1335  {
1336  _nlDelete_NoImm(&x);
1337  return INT_TO_SR(1);
1338  }
1339  }

◆ nlShort3()

static number nlShort3 ( number  x)
inlinestatic

Definition at line 114 of file longrat.cc.

116 {
117  assume(x->s==3);
118  if (mpz_sgn1(x->z)==0)
119  {
120  mpz_clear(x->z);
121  FREE_RNUMBER(x);
122  return INT_TO_SR(0);
123  }
124  if (mpz_size1(x->z)<=MP_SMALL)
125  {
126  LONG ui=mpz_get_si(x->z);
127  if ((((ui<<3)>>3)==ui)
128  && (mpz_cmp_si(x->z,(long)ui)==0))
129  {
130  mpz_clear(x->z);
131  FREE_RNUMBER(x);
132  return INT_TO_SR(ui);
133  }
134  }
135  return x;

◆ nlShort3_noinline()

number nlShort3_noinline ( number  x)

Definition at line 163 of file longrat.cc.

166 {

◆ nlSize()

int nlSize ( number  a,
const  coeffs 
)

Definition at line 568 of file longrat.cc.

571 {
572  if (a==INT_TO_SR(0))
573  return 0; /* rational 0*/
574  if (SR_HDL(a) & SR_INT)
575  return 1; /* immediate int */
576  int s=a->z[0]._mp_alloc;
577 // while ((s>0) &&(a->z._mp_d[s]==0L)) s--;
578 //#if SIZEOF_LONG == 8
579 // if (a->z._mp_d[s] < (unsigned long)0x100000000L) s=s*2-1;
580 // else s *=2;
581 //#endif
582 // s++;
583  if (a->s<2)
584  {
585  int d=a->n[0]._mp_alloc;
586 // while ((d>0) && (a->n._mp_d[d]==0L)) d--;
587 //#if SIZEOF_LONG == 8
588 // if (a->n._mp_d[d] < (unsigned long)0x100000000L) d=d*2-1;
589 // else d *=2;
590 //#endif
591  s+=d;
592  }

◆ nlSub()

LINLINE number nlSub ( number  la,
number  li,
const coeffs  r 
)

Definition at line 2592 of file longrat.cc.

2597 {
2598  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
2599  {
2600  LONG r=SR_HDL(a)-SR_HDL(b)+1;
2601  if ( ((r << 1) >> 1) == r )
2602  {
2603  return (number)(long)r;
2604  }
2605  else
2606  return nlRInit(SR_TO_INT(r));
2607  }
2608  number u = _nlSub_aNoImm_OR_bNoImm(a, b);

◆ nlWrite()

void nlWrite ( number  a,
const coeffs  r 
)

Definition at line 112 of file longrat0.cc.

114 {
115  char *s,*z;
116  if (SR_HDL(a) & SR_INT)
117  {
118  StringAppend("%ld",SR_TO_INT(a));
119  }
120  else if (a==NULL)
121  {
122  StringAppendS("o");
123  }
124  else
125  {
126  int l=mpz_sizeinbase(a->z,10);
127  if (a->s<2) l=si_max(l,(int)mpz_sizeinbase(a->n,10));
128  l+=2;
129  s=(char*)omAlloc(l);
130  z=mpz_get_str(s,10,a->z);
131  StringAppendS(z);
132  if (a->s!=3)
133  {
134  StringAppendS("/");
135  z=mpz_get_str(s,10,a->n);
136  StringAppendS(z);
137  }
138  omFreeSize((void *)s,l);
139  }

◆ nlWriteFd()

static void nlWriteFd ( number  n,
FILE *  f,
const  coeffs 
)
static

Definition at line 3174 of file longrat.cc.

3179 {
3180  if(SR_HDL(n) & SR_INT)
3181  {
3182  #if SIZEOF_LONG == 4
3183  fprintf(f,"4 %ld ",SR_TO_INT(n));
3184  #else
3185  long nn=SR_TO_INT(n);
3186  if ((nn<POW_2_28_32)&&(nn>= -POW_2_28_32))
3187  {
3188  int nnn=(int)nn;
3189  fprintf(f,"4 %d ",nnn);
3190  }
3191  else
3192  {
3193  mpz_t tmp;
3194  mpz_init_set_si(tmp,nn);
3195  fputs("8 ",f);
3196  mpz_out_str (f,SSI_BASE, tmp);
3197  fputc(' ',f);
3198  mpz_clear(tmp);
3199  }
3200  #endif
3201  }
3202  else if (n->s<2)
3203  {
3204  //gmp_fprintf(f,"%d %Zd %Zd ",n->s,n->z,n->n);
3205  fprintf(f,"%d ",n->s+5);
3206  mpz_out_str (f,SSI_BASE, n->z);
3207  fputc(' ',f);
3208  mpz_out_str (f,SSI_BASE, n->n);
3209  fputc(' ',f);
3210 
3211  //if (d->f_debug!=NULL) gmp_fprintf(d->f_debug,"number: s=%d gmp/gmp \"%Zd %Zd\" ",n->s,n->z,n->n);
3212  }
3213  else /*n->s==3*/
3214  {
3215  //gmp_fprintf(d->f_write,"3 %Zd ",n->z);
3216  fputs("8 ",f);
3217  mpz_out_str (f,SSI_BASE, n->z);
3218  fputc(' ',f);

◆ nlXExtGcd()

number nlXExtGcd ( number  a,
number  b,
number *  s,
number *  t,
number *  u,
number *  v,
const coeffs  r 
)

Definition at line 2665 of file longrat.cc.

2670 {
2671  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
2672  {
2673  int uu, vv, x, y;
2674  int g = int_extgcd(SR_TO_INT(a), SR_TO_INT(b), &uu, &vv, &x, &y);
2675  *s = INT_TO_SR(uu);
2676  *t = INT_TO_SR(vv);
2677  *u = INT_TO_SR(x);
2678  *v = INT_TO_SR(y);
2679  return INT_TO_SR(g);
2680  }
2681  else
2682  {
2683  mpz_t aa, bb;
2684  if (SR_HDL(a) & SR_INT)
2685  {
2686  mpz_init_set_si(aa, SR_TO_INT(a));
2687  }
2688  else
2689  {
2690  mpz_init_set(aa, a->z);
2691  }
2692  if (SR_HDL(b) & SR_INT)
2693  {
2694  mpz_init_set_si(bb, SR_TO_INT(b));
2695  }
2696  else
2697  {
2698  mpz_init_set(bb, b->z);
2699  }
2700  mpz_t erg; mpz_t bs; mpz_t bt;
2701  mpz_init(erg);
2702  mpz_init(bs);
2703  mpz_init(bt);
2704 
2705  mpz_gcdext(erg, bs, bt, aa, bb);
2706 
2707  mpz_div(aa, aa, erg);
2708  *u=nlInitMPZ(bb,r);
2709  *u=nlNeg(*u,r);
2710  *v=nlInitMPZ(aa,r);
2711 
2712  mpz_clear(aa);
2713  mpz_clear(bb);
2714 
2715  *s = nlInitMPZ(bs,r);

Variable Documentation

◆ n_SwitchChinRem

int n_SwitchChinRem =0

Definition at line 2931 of file longrat.cc.

getCoeffType
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
nlLcm
static number nlLcm(number a, number b, const coeffs r)
Definition: longrat.cc:3294
n_rep_gap_rat
(number), see longrat.h
Definition: coeffs.h:111
FALSE
#define FALSE
Definition: auxiliary.h:94
nlEatLong
const char * nlEatLong(char *s, mpz_ptr i)
Definition: longrat0.cc:31
n_rep_gmp
(mpz_ptr), see rmodulon,h
Definition: coeffs.h:115
omCheckAddrSize
#define omCheckAddrSize(addr, size)
Definition: omAllocDecl.h:325
n_Zn
only used if HAVE_RINGS is defined
Definition: coeffs.h:44
nlIsUnit
BOOLEAN nlIsUnit(number a, const coeffs)
Definition: longrat.cc:992
LONG
#define LONG
Definition: longrat.cc:110
nlIsZero
LINLINE BOOLEAN nlIsZero(number za, const coeffs r)
Definition: longrat.cc:2458
SW_RATIONAL
static const int SW_RATIONAL
set to 1 for computations over Q
Definition: cf_defs.h:28
ALLOC_RNUMBER
#define ALLOC_RNUMBER()
Definition: coeffs.h:87
nCoeff_is_Zp
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition: coeffs.h:830
StringAppendS
void StringAppendS(const char *st)
Definition: reporter.cc:106
nlQuot1
coeffs nlQuot1(number c, const coeffs r)
Definition: longrat.cc:967
IsPrime
int IsPrime(int p)
Definition: prime.cc:61
POW_2_28
#define POW_2_28
Definition: longrat.cc:108
j
int j
Definition: facHensel.cc:105
f
FILE * f
Definition: checklibs.c:9
nCoeff_is_R
static FORCE_INLINE BOOLEAN nCoeff_is_R(const coeffs r)
Definition: coeffs.h:849
IAccessor::Current
virtual reference Current()=0
Gets the current element in the collection (read and write).
nlInpMult
LINLINE void nlInpMult(number &a, number b, const coeffs r)
Definition: longrat.cc:2610
nCoeff_is_Ring_2toM
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_2toM(const coeffs r)
Definition: coeffs.h:746
nlWriteFd
static void nlWriteFd(number n, FILE *f, const coeffs)
Definition: longrat.cc:3174
x
Variable x
Definition: cfModGcd.cc:4023
dErrorBreak
void dErrorBreak()
Definition: dError.cc:139
nlSetMap
nMapFunc nlSetMap(const coeffs src, const coeffs dst)
Definition: longrat.cc:2319
nlInt
long nlInt(number &n, const coeffs r)
Definition: longrat.cc:597
y
const CanonicalForm int const CFList const Variable & y
Definition: facAbsFact.cc:57
nlMapZ
number nlMapZ(number from, const coeffs src, const coeffs dst)
Definition: longrat.cc:211
s_readint
int s_readint(s_buff F)
Definition: s_buff.cc:110
nlExtGcd
number nlExtGcd(number a, number b, number *s, number *t, const coeffs)
Definition: longrat.cc:2874
result
return result
Definition: facAbsBiFact.cc:76
n_GetChar
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition: coeffs.h:444
nlIsOne
LINLINE BOOLEAN nlIsOne(number a, const coeffs r)
Definition: longrat.cc:2449
nlChineseRemainderSym
number nlChineseRemainderSym(number *x, number *q, int rl, BOOLEAN sym, CFArray &inv_cache, const coeffs CF)
Definition: longrat.cc:2932
mpz_sgn1
#define mpz_sgn1(A)
Definition: si_gmp.h:13
nlCopy
LINLINE number nlCopy(number a, const coeffs r)
Definition: longrat.cc:2478
_nlMult_aNoImm_OR_bNoImm
number _nlMult_aNoImm_OR_bNoImm(number a, number b)
Definition: longrat.cc:2202
CxxTest::negative
bool negative(N n)
Definition: ValueTraits.h:119
nlIsMOne
BOOLEAN nlIsMOne(number a, const coeffs r)
Definition: longrat.cc:1189
nlCoeffName
char * nlCoeffName(const coeffs r)
Definition: longrat.cc:3161
num
CanonicalForm num(const CanonicalForm &f)
Definition: canonicalform.h:330
nlCoeffWrite
void nlCoeffWrite(const coeffs r, BOOLEAN details)
Definition: longrat.cc:2923
_nlDelete_NoImm
void _nlDelete_NoImm(number *a)
Definition: longrat.cc:1624
nlMapR
static number nlMapR(number from, const coeffs src, const coeffs dst)
Definition: longrat.cc:395
cf
CanonicalForm cf
Definition: cfModGcd.cc:4024
n_rep_float
(float), see shortfl.h
Definition: coeffs.h:116
g
g
Definition: cfModGcd.cc:4031
nlDivComp
int nlDivComp(number a, number b, const coeffs r)
Definition: longrat.cc:950
nrFloat
SI_FLOAT nrFloat(number n)
Converts a n_R number into a float. Needed by Maps.
Definition: shortfl.cc:56
ndCopyMap
number ndCopyMap(number a, const coeffs aRing, const coeffs r)
Definition: numbers.cc:251
n_Delete
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:455
mod
CF_NO_INLINE CanonicalForm mod(const CanonicalForm &, const CanonicalForm &)
Definition: cf_inline.cc:564
E
REvaluation E(1, terms.length(), IntRandom(25))
nInitChar
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:349
n_Q
rational (GMP) numbers
Definition: coeffs.h:30
nlDivBy
BOOLEAN nlDivBy(number a, number b, const coeffs)
Definition: longrat.cc:936
nlMapMachineInt
number nlMapMachineInt(number from, const coeffs, const coeffs)
Definition: longrat.cc:223
make_cf
CanonicalForm make_cf(const mpz_ptr n)
Definition: singext.cc:66
nlShort1
number nlShort1(number x)
Definition: longrat.cc:1322
N
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:48
SSI_BASE
#define SSI_BASE
Definition: auxiliary.h:149
n_rep_int
(int), see modulop.h
Definition: coeffs.h:110
nlInpAdd
LINLINE void nlInpAdd(number &a, number b, const coeffs r)
Definition: longrat.cc:2544
_nlSub_aNoImm_OR_bNoImm
number _nlSub_aNoImm_OR_bNoImm(number a, number b)
Definition: longrat.cc:1978
ABS
static int ABS(int v)
Definition: auxiliary.h:110
nlInit
LINLINE number nlInit(long i, const coeffs r)
Definition: longrat.cc:2431
b
CanonicalForm b
Definition: cfModGcd.cc:4044
nlSub
LINLINE number nlSub(number la, number li, const coeffs r)
Definition: longrat.cc:2592
s_readmpz
void s_readmpz(s_buff F, mpz_t a)
Definition: s_buff.cc:182
gmp_float::_mpfp
mpf_t * _mpfp()
Definition: mpr_complex.h:133
CanonicalForm
factory's main class
Definition: canonicalform.h:77
nlDBTest
BOOLEAN nlDBTest(number a, const char *f, const int l)
n_long_R
real floating point (GMP) numbers
Definition: coeffs.h:33
term
Definition: int_poly.h:33
nlTest
#define nlTest(a, r)
Definition: longrat.cc:92
IBaseEnumerator::Reset
virtual void Reset()=0
Sets the enumerator to its initial position: -1, which is before the first element in the collection.
nlSize
int nlSize(number a, const coeffs)
Definition: longrat.cc:568
nlEqual
LINLINE BOOLEAN nlEqual(number a, number b, const coeffs r)
Definition: longrat.cc:2422
nlRandom
static number nlRandom(siRandProc p, number v2, number, const coeffs cf)
Definition: longrat.cc:3304
nlPower
void nlPower(number x, int exp, number *lu, const coeffs r)
Definition: longrat.cc:1111
nlClearContent
static void nlClearContent(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs cf)
Definition: longrat.cc:2976
TRUE
#define TRUE
Definition: auxiliary.h:98
i
int i
Definition: cfEzgcd.cc:125
Array
Definition: ftmpl_array.h:17
res
CanonicalForm res
Definition: facAbsFact.cc:64
int_extgcd
static int int_extgcd(int a, int b, int *u, int *x, int *v, int *y)
Definition: longrat.cc:1272
nDivBy0
const char *const nDivBy0
Definition: numbers.h:88
SR_TO_INT
#define SR_TO_INT(SR)
Definition: longrat0.cc:25
omFreeSize
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:258
BOOLEAN
int BOOLEAN
Definition: auxiliary.h:85
nlClearDenominators
static void nlClearDenominators(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs cf)
Definition: longrat.cc:3067
nlWrite
void nlWrite(number a, const coeffs r)
Definition: longrat0.cc:112
nlXExtGcd
number nlXExtGcd(number a, number b, number *s, number *t, number *u, number *v, const coeffs r)
Definition: longrat.cc:2665
mpz_isNeg
#define mpz_isNeg(A)
Definition: longrat.cc:151
nlGetUnit
number nlGetUnit(number n, const coeffs cf)
Definition: longrat.cc:961
nlNormalizeHelper
number nlNormalizeHelper(number a, number b, const coeffs r)
Definition: longrat.cc:1387
D
#define D(A)
Definition: gentable.cc:128
nlConvFactoryNSingN
static number nlConvFactoryNSingN(const CanonicalForm f, const coeffs r)
Definition: longrat.cc:368
nlNormalize_Gcd
static void nlNormalize_Gcd(number &x)
Definition: longrat.cc:1657
setCharacteristic
void setCharacteristic(int c)
Definition: cf_char.cc:23
size
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
nlMPZ
static void nlMPZ(mpz_t m, number &n, const coeffs r)
Definition: longrat.cc:2644
nlGcd
number nlGcd(number a, number b, const coeffs r)
Definition: longrat.cc:1201
coeffs
nlConvSingNFactoryN
static CanonicalForm nlConvSingNFactoryN(number n, const BOOLEAN setChar, const coeffs)
Definition: longrat.cc:330
nlInitMPZ
static number nlInitMPZ(mpz_t m, const coeffs)
Definition: longrat.cc:2653
nlNormalize
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1343
nCoeff_is_long_R
static FORCE_INLINE BOOLEAN nCoeff_is_long_R(const coeffs r)
Definition: coeffs.h:904
chineseRemainderCached
void chineseRemainderCached(CFArray &a, CFArray &n, CanonicalForm &xnew, CanonicalForm &prod, CFArray &inv)
Definition: cf_chinese.cc:265
nlGetNumerator
number nlGetNumerator(number &n, const coeffs r)
Definition: longrat.cc:1526
chineseRemainder
void chineseRemainder(const CanonicalForm &x1, const CanonicalForm &q1, const CanonicalForm &x2, const CanonicalForm &q2, CanonicalForm &xnew, CanonicalForm &qnew)
void chineseRemainder ( const CanonicalForm & x1, const CanonicalForm & q1, const CanonicalForm & x2,...
Definition: cf_chinese.cc:52
omAlloc
#define omAlloc(size)
Definition: omAllocDecl.h:208
FREE_RNUMBER
#define FREE_RNUMBER(x)
Definition: coeffs.h:86
nlGetDenom
number nlGetDenom(number &n, const coeffs r)
Definition: longrat.cc:1497
SR_HDL
#define SR_HDL(A)
Definition: longrat0.cc:22
n_Init
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition: coeffs.h:538
s_readlong
long s_readlong(s_buff F)
Definition: s_buff.cc:138
MP_SMALL
#define MP_SMALL
Definition: longrat.cc:149
nlQuotRem
number nlQuotRem(number a, number b, number *r, const coeffs R)
Definition: longrat.cc:2717
den
CanonicalForm den(const CanonicalForm &f)
Definition: canonicalform.h:333
ALLOC0_RNUMBER
#define ALLOC0_RNUMBER()
Definition: coeffs.h:88
nlGreaterZero
BOOLEAN nlGreaterZero(number za, const coeffs r)
Definition: longrat.cc:1164
nlIntMod
number nlIntMod(number a, number b, const coeffs r)
Definition: longrat.cc:875
nlMapGMP
number nlMapGMP(number from, const coeffs src, const coeffs dst)
Definition: longrat.cc:199
Off
void Off(int sw)
switches
Definition: canonicalform.cc:1905
_nlMult_aImm_bImm_rNoImm
number _nlMult_aImm_bImm_rNoImm(number a, number b)
Definition: longrat.cc:2189
SR_INT
#define SR_INT
Definition: longrat.h:67
n_R
single prescision (6,6) real numbers
Definition: coeffs.h:31
exp
gmp_float exp(const gmp_float &a)
Definition: mpr_complex.cc:357
SR_TO_INT
#define SR_TO_INT(SR)
Definition: longrat.h:69
npInt
long npInt(number &n, const coeffs r)
Definition: modulop.cc:127
cand
const CanonicalForm const CanonicalForm const CanonicalForm const CanonicalForm & cand
Definition: cfModGcd.cc:69
nlInpGcd
void nlInpGcd(number &a, number b, const coeffs r)
Definition: longrat.cc:2770
mpz_mul_si
void mpz_mul_si(mpz_ptr r, mpz_srcptr s, long int si)
Definition: longrat.cc:170
nlDiv
number nlDiv(number a, number b, const coeffs r)
Definition: longrat.cc:1001
IBaseEnumerator::MoveNext
virtual bool MoveNext()=0
Advances the enumerator to the next element of the collection. returns true if the enumerator was suc...
n_Zp
\F{p < 2^31}
Definition: coeffs.h:29
si_max
static int si_max(const int a, const int b)
Definition: auxiliary.h:138
n_rep_gmp_float
(gmp_float), see
Definition: coeffs.h:117
nlAdd
LINLINE number nlAdd(number la, number li, const coeffs r)
Definition: longrat.cc:2526
Print
#define Print
Definition: emacs.cc:79
B
b *CanonicalForm B
Definition: facBivar.cc:52
POW_2_28_32
#define POW_2_28_32
Definition: longrat.cc:109
mpz_size1
#define mpz_size1(A)
Definition: si_gmp.h:12
Werror
void Werror(const char *fmt,...)
Definition: reporter.cc:188
nlReadFd
static number nlReadFd(s_buff f, const coeffs)
Definition: longrat.cc:3220
nlInvers
number nlInvers(number a, const coeffs r)
Definition: longrat.cc:647
WerrorS
void WerrorS(const char *s)
Definition: feFopen.cc:24
nlShort3
static number nlShort3(number x)
Definition: longrat.cc:114
nlFarey
number nlFarey(number nN, number nP, const coeffs CF)
Definition: longrat.cc:2803
SR_HDL
#define SR_HDL(A)
Definition: tgb.cc:35
omCheckIf
#define omCheckIf(cond, test)
Definition: omAllocDecl.h:321
WarnS
#define WarnS
Definition: emacs.cc:77
assume
#define assume(x)
Definition: mod2.h:384
NULL
#define NULL
Definition: omList.c:9
nlRead
const char * nlRead(const char *s, number *a, const coeffs r)
Definition: longrat0.cc:53
nlMapP
static number nlMapP(number from, const coeffs src, const coeffs dst)
Definition: longrat.cc:182
l
int l
Definition: cfEzgcd.cc:93
R
#define R
Definition: sirandom.c:26
nlIntDiv
number nlIntDiv(number a, number b, const coeffs r)
Definition: longrat.cc:794
gmp_denominator
void gmp_denominator(const CanonicalForm &f, mpz_ptr result)
Definition: singext.cc:40
gmp_numerator
void gmp_numerator(const CanonicalForm &f, mpz_ptr result)
Definition: singext.cc:20
gcd
int gcd(int a, int b)
Definition: walkSupport.cc:836
nlShort3_noinline
number nlShort3_noinline(number x)
Definition: longrat.cc:163
StringAppend
#define StringAppend
Definition: emacs.cc:78
v
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
nlMult
LINLINE number nlMult(number a, number b, const coeffs r)
Definition: longrat.cc:2562
nlRInit
number nlRInit(long i)
Definition: longrat.cc:2356
p
int p
Definition: cfModGcd.cc:4019
nlNeg
LINLINE number nlNeg(number za, const coeffs r)
Definition: longrat.cc:2507
ZnmInfo
Definition: rmodulon.h:17
s
const CanonicalForm int s
Definition: facAbsFact.cc:55
n_Div
static FORCE_INLINE number n_Div(number a, number b, const coeffs r)
return the quotient of 'a' and 'b', i.e., a/b; raises an error if 'b' is not invertible in r exceptio...
Definition: coeffs.h:615
s_readmpz_base
void s_readmpz_base(s_buff F, mpz_ptr a, int base)
Definition: s_buff.cc:207
Q
#define Q
Definition: sirandom.c:25
INT_TO_SR
#define INT_TO_SR(INT)
Definition: longrat.h:68
nlDelete
LINLINE void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2491
nlMapLongR
static number nlMapLongR(number from, const coeffs src, const coeffs dst)
Definition: longrat.cc:425
_nlNeg_NoImm
number _nlNeg_NoImm(number a)
Definition: longrat.cc:1642
A
#define A
Definition: sirandom.c:23
n_SwitchChinRem
int n_SwitchChinRem
Definition: longrat.cc:2931
info
const ExtensionInfo & info
< [in] sqrfree poly
Definition: facFqFactorize.h:38
nlExactDiv
number nlExactDiv(number a, number b, const coeffs r)
Definition: longrat.cc:727
gmp_float
Definition: mpr_complex.h:30
nlCoeffIsEqual
BOOLEAN nlCoeffIsEqual(const coeffs r, n_coeffType n, void *p)
Definition: longrat.cc:3282
On
void On(int sw)
switches
Definition: canonicalform.cc:1898
GCD_NORM_COND
#define GCD_NORM_COND(OLD, NEW)
Definition: longrat.cc:1655
nlGreater
BOOLEAN nlGreater(number a, number b, const coeffs r)
Definition: longrat.cc:1174
nlCoeffString
static char * nlCoeffString(const coeffs r)
Definition: longrat.cc:3167
n_rep_gap_gmp
(), see rinteger.h, new impl.
Definition: coeffs.h:112