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 "rmodulon.h"
#include "longrat.h"
#include "shortfl.h"
#include "modulop.h"
#include <string.h>
#include <float.h>
#include <coeffs/coeffs.h>
#include <coeffs/numbers.h>
#include <coeffs/mpr_complex.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)
 
number nlGetDenom (number &n, const coeffs r)
 
number nlGetNumerator (number &n, const coeffs r)
 
void nlCoeffWrite (const coeffs r, BOOLEAN details)
 
number nlChineseRemainder (number *x, number *q, int rl, const coeffs C)
 
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 r)
 
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 Q, const coeffs Zp)
 
void nlGMP (number &i, 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 src, const coeffs dst)
 
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

#define BYTES_PER_MP_LIMB   sizeof(mp_limb_t)

Definition at line 149 of file longrat.cc.

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

Definition at line 1647 of file longrat.cc.

#define LINLINE

Definition at line 26 of file longrat.cc.

#define LONG   int

Definition at line 108 of file longrat.cc.

#define LONGRAT_CC

Definition at line 136 of file longrat.cc.

#define MAX_NUM_SIZE   28

Definition at line 105 of file longrat.cc.

#define MP_SMALL   1

Definition at line 157 of file longrat.cc.

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

Definition at line 159 of file longrat.cc.

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

Definition at line 161 of file longrat.cc.

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

Definition at line 160 of file longrat.cc.

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

Definition at line 90 of file longrat.cc.

#define POW_2_28   (1L<<28)

Definition at line 106 of file longrat.cc.

#define POW_2_28_32   (1L<<28)

Definition at line 107 of file longrat.cc.

Function Documentation

number _nlAdd_aNoImm_OR_bNoImm ( number  a,
number  b 
)

Definition at line 1669 of file longrat.cc.

1670 {
1671  number u=ALLOC_RNUMBER();
1672 #if defined(LDEBUG)
1673  u->debug=123456;
1674 #endif
1675  mpz_init(u->z);
1676  if (SR_HDL(b) & SR_INT)
1677  {
1678  number x=a;
1679  a=b;
1680  b=x;
1681  }
1682  if (SR_HDL(a) & SR_INT)
1683  {
1684  switch (b->s)
1685  {
1686  case 0:
1687  case 1:/* a:short, b:1 */
1688  {
1689  mpz_t x;
1690  mpz_init(x);
1691  mpz_mul_si(x,b->n,SR_TO_INT(a));
1692  mpz_add(u->z,b->z,x);
1693  mpz_clear(x);
1694  if (mpz_cmp_ui(u->z,0L)==0)
1695  {
1696  mpz_clear(u->z);
1697  FREE_RNUMBER(u);
1698  return INT_TO_SR(0);
1699  }
1700  if (mpz_cmp(u->z,b->n)==0)
1701  {
1702  mpz_clear(u->z);
1703  FREE_RNUMBER(u);
1704  return INT_TO_SR(1);
1705  }
1706  mpz_init_set(u->n,b->n);
1707  if (GCD_NORM_COND(b,u)) { nlNormalize_Gcd(u); }
1708  else u->s = 0;
1709  break;
1710  }
1711  case 3:
1712  {
1713  if (((long)a)>0L)
1714  mpz_add_ui(u->z,b->z,SR_TO_INT(a));
1715  else
1716  mpz_sub_ui(u->z,b->z,-SR_TO_INT(a));
1717  u->s = 3;
1718  u=nlShort3(u);
1719  break;
1720  }
1721  }
1722  }
1723  else
1724  {
1725  switch (a->s)
1726  {
1727  case 0:
1728  case 1:
1729  {
1730  switch(b->s)
1731  {
1732  case 0:
1733  case 1:
1734  {
1735  mpz_t x;
1736  mpz_init(x);
1737 
1738  mpz_mul(x,b->z,a->n);
1739  mpz_mul(u->z,a->z,b->n);
1740  mpz_add(u->z,u->z,x);
1741  mpz_clear(x);
1742 
1743  if (mpz_cmp_ui(u->z,0L)==0)
1744  {
1745  mpz_clear(u->z);
1746  FREE_RNUMBER(u);
1747  return INT_TO_SR(0);
1748  }
1749  mpz_init(u->n);
1750  mpz_mul(u->n,a->n,b->n);
1751  if (mpz_cmp(u->z,u->n)==0)
1752  {
1753  mpz_clear(u->z);
1754  mpz_clear(u->n);
1755  FREE_RNUMBER(u);
1756  return INT_TO_SR(1);
1757  }
1758  if (GCD_NORM_COND(b,u)) { nlNormalize_Gcd(u); }
1759  else u->s = 0;
1760  break;
1761  }
1762  case 3: /* a:1 b:3 */
1763  {
1764  mpz_mul(u->z,b->z,a->n);
1765  mpz_add(u->z,u->z,a->z);
1766  if (mpz_cmp_ui(u->z,0L)==0)
1767  {
1768  mpz_clear(u->z);
1769  FREE_RNUMBER(u);
1770  return INT_TO_SR(0);
1771  }
1772  if (mpz_cmp(u->z,a->n)==0)
1773  {
1774  mpz_clear(u->z);
1775  FREE_RNUMBER(u);
1776  return INT_TO_SR(1);
1777  }
1778  mpz_init_set(u->n,a->n);
1779  if (GCD_NORM_COND(a,u)) { nlNormalize_Gcd(u); }
1780  else u->s = 0;
1781  break;
1782  }
1783  } /*switch (b->s) */
1784  break;
1785  }
1786  case 3:
1787  {
1788  switch(b->s)
1789  {
1790  case 0:
1791  case 1:/* a:3, b:1 */
1792  {
1793  mpz_mul(u->z,a->z,b->n);
1794  mpz_add(u->z,u->z,b->z);
1795  if (mpz_cmp_ui(u->z,0L)==0)
1796  {
1797  mpz_clear(u->z);
1798  FREE_RNUMBER(u);
1799  return INT_TO_SR(0);
1800  }
1801  if (mpz_cmp(u->z,b->n)==0)
1802  {
1803  mpz_clear(u->z);
1804  FREE_RNUMBER(u);
1805  return INT_TO_SR(1);
1806  }
1807  mpz_init_set(u->n,b->n);
1808  if (GCD_NORM_COND(b,u)) { nlNormalize_Gcd(u); }
1809  else u->s = 0;
1810  break;
1811  }
1812  case 3:
1813  {
1814  mpz_add(u->z,a->z,b->z);
1815  u->s = 3;
1816  u=nlShort3(u);
1817  break;
1818  }
1819  }
1820  break;
1821  }
1822  }
1823  }
1824  return u;
1825 }
void mpz_mul_si(mpz_ptr r, mpz_srcptr s, long int si)
Definition: longrat.cc:179
#define INT_TO_SR(INT)
Definition: longrat.h:66
const poly a
Definition: syzextra.cc:212
#define FREE_RNUMBER(x)
Definition: coeffs.h:85
static void nlNormalize_Gcd(number &x)
Definition: longrat.cc:1649
#define SR_TO_INT(SR)
Definition: longrat.h:67
static number nlShort3(number x)
Definition: longrat.cc:112
#define SR_INT
Definition: longrat.h:65
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
Variable x
Definition: cfModGcd.cc:4023
#define GCD_NORM_COND(OLD, NEW)
Definition: longrat.cc:1647
#define SR_HDL(A)
Definition: tgb.cc:35
const poly b
Definition: syzextra.cc:213
number _nlCopy_NoImm ( number  a)

Definition at line 1595 of file longrat.cc.

1596 {
1597  assume(!((SR_HDL(a) & SR_INT)||(a==NULL)));
1598  //nlTest(a, r);
1599  number b=ALLOC_RNUMBER();
1600 #if defined(LDEBUG)
1601  b->debug=123456;
1602 #endif
1603  switch (a->s)
1604  {
1605  case 0:
1606  case 1:
1607  mpz_init_set(b->n,a->n);
1608  case 3:
1609  mpz_init_set(b->z,a->z);
1610  break;
1611  }
1612  b->s = a->s;
1613  return b;
1614 }
const poly a
Definition: syzextra.cc:212
#define assume(x)
Definition: mod2.h:405
#define NULL
Definition: omList.c:10
#define SR_INT
Definition: longrat.h:65
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
#define SR_HDL(A)
Definition: tgb.cc:35
const poly b
Definition: syzextra.cc:213
void _nlDelete_NoImm ( number *  a)

Definition at line 1616 of file longrat.cc.

1617 {
1618  {
1619  switch ((*a)->s)
1620  {
1621  case 0:
1622  case 1:
1623  mpz_clear((*a)->n);
1624  case 3:
1625  mpz_clear((*a)->z);
1626 #ifdef LDEBUG
1627  (*a)->s=2;
1628 #endif
1629  }
1630  FREE_RNUMBER(*a); // omFreeBin((void *) *a, rnumber_bin);
1631  }
1632 }
const poly a
Definition: syzextra.cc:212
#define FREE_RNUMBER(x)
Definition: coeffs.h:85
BOOLEAN _nlEqual_aNoImm_OR_bNoImm ( number  a,
number  b 
)

Definition at line 1548 of file longrat.cc.

1549 {
1550  assume(! (SR_HDL(a) & SR_HDL(b) & SR_INT));
1551 // long - short
1552  BOOLEAN bo;
1553  if (SR_HDL(b) & SR_INT)
1554  {
1555  if (a->s!=0) return FALSE;
1556  number n=b; b=a; a=n;
1557  }
1558 // short - long
1559  if (SR_HDL(a) & SR_INT)
1560  {
1561  if (b->s!=0)
1562  return FALSE;
1563  if ((((long)a) > 0L) && (mpz_isNeg(b->z)))
1564  return FALSE;
1565  if ((((long)a) < 0L) && (!mpz_isNeg(b->z)))
1566  return FALSE;
1567  mpz_t bb;
1568  mpz_init_set(bb,b->n);
1569  mpz_mul_si(bb,bb,(long)SR_TO_INT(a));
1570  bo=(mpz_cmp(bb,b->z)==0);
1571  mpz_clear(bb);
1572  return bo;
1573  }
1574 // long - long
1575  if (((a->s==1) && (b->s==3))
1576  || ((b->s==1) && (a->s==3)))
1577  return FALSE;
1578  if (mpz_isNeg(a->z)&&(!mpz_isNeg(b->z)))
1579  return FALSE;
1580  if (mpz_isNeg(b->z)&&(!mpz_isNeg(a->z)))
1581  return FALSE;
1582  mpz_t aa;
1583  mpz_t bb;
1584  mpz_init_set(aa,a->z);
1585  mpz_init_set(bb,b->z);
1586  if (a->s<2) mpz_mul(bb,bb,a->n);
1587  if (b->s<2) mpz_mul(aa,aa,b->n);
1588  bo=(mpz_cmp(aa,bb)==0);
1589  mpz_clear(aa);
1590  mpz_clear(bb);
1591  return bo;
1592 }
void mpz_mul_si(mpz_ptr r, mpz_srcptr s, long int si)
Definition: longrat.cc:179
const poly a
Definition: syzextra.cc:212
#define FALSE
Definition: auxiliary.h:140
#define assume(x)
Definition: mod2.h:405
#define mpz_isNeg(A)
Definition: longrat.cc:159
#define SR_TO_INT(SR)
Definition: longrat.h:67
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
int BOOLEAN
Definition: auxiliary.h:131
const poly b
Definition: syzextra.cc:213
void _nlInpAdd_aNoImm_OR_bNoImm ( number &  a,
number  b 
)

Definition at line 1827 of file longrat.cc.

1828 {
1829  if (SR_HDL(b) & SR_INT)
1830  {
1831  switch (a->s)
1832  {
1833  case 0:
1834  case 1:/* b:short, a:1 */
1835  {
1836  mpz_t x;
1837  mpz_init(x);
1838  mpz_mul_si(x,a->n,SR_TO_INT(b));
1839  mpz_add(a->z,a->z,x);
1840  mpz_clear(x);
1841  nlNormalize_Gcd(a);
1842  break;
1843  }
1844  case 3:
1845  {
1846  if (((long)b)>0L)
1847  mpz_add_ui(a->z,a->z,SR_TO_INT(b));
1848  else
1849  mpz_sub_ui(a->z,a->z,-SR_TO_INT(b));
1850  a->s = 3;
1852  break;
1853  }
1854  }
1855  return;
1856  }
1857  else if (SR_HDL(a) & SR_INT)
1858  {
1859  number u=ALLOC_RNUMBER();
1860  #if defined(LDEBUG)
1861  u->debug=123456;
1862  #endif
1863  mpz_init(u->z);
1864  switch (b->s)
1865  {
1866  case 0:
1867  case 1:/* a:short, b:1 */
1868  {
1869  mpz_t x;
1870  mpz_init(x);
1871 
1872  mpz_mul_si(x,b->n,SR_TO_INT(a));
1873  mpz_add(u->z,b->z,x);
1874  mpz_clear(x);
1875  // result cannot be 0, if coeffs are normalized
1876  mpz_init_set(u->n,b->n);
1877  if (GCD_NORM_COND(b,u)) { nlNormalize_Gcd(u); }
1878  else { u->s = 0; u=nlShort1(u); }
1879  break;
1880  }
1881  case 3:
1882  {
1883  if (((long)a)>0L)
1884  mpz_add_ui(u->z,b->z,SR_TO_INT(a));
1885  else
1886  mpz_sub_ui(u->z,b->z,-SR_TO_INT(a));
1887  // result cannot be 0, if coeffs are normalized
1888  u->s = 3;
1889  u=nlShort3_noinline(u);
1890  break;
1891  }
1892  }
1893  a=u;
1894  }
1895  else
1896  {
1897  switch (a->s)
1898  {
1899  case 0:
1900  case 1:
1901  {
1902  switch(b->s)
1903  {
1904  case 0:
1905  case 1: /* a:1 b:1 */
1906  {
1907  mpz_t x;
1908  mpz_t y;
1909  mpz_init(x);
1910  mpz_init(y);
1911  mpz_mul(x,b->z,a->n);
1912  mpz_mul(y,a->z,b->n);
1913  mpz_add(a->z,x,y);
1914  mpz_clear(x);
1915  mpz_clear(y);
1916  mpz_mul(a->n,a->n,b->n);
1917  if (GCD_NORM_COND(b,a)) { nlNormalize_Gcd(a); }
1918  else { a->s = 0;a=nlShort1(a);}
1919  break;
1920  }
1921  case 3: /* a:1 b:3 */
1922  {
1923  mpz_t x;
1924  mpz_init(x);
1925  mpz_mul(x,b->z,a->n);
1926  mpz_add(a->z,a->z,x);
1927  mpz_clear(x);
1928  if (GCD_NORM_COND(b,a)) { nlNormalize_Gcd(a); }
1929  else { a->s = 0; a=nlShort1(a);}
1930  break;
1931  }
1932  } /*switch (b->s) */
1933  break;
1934  }
1935  case 3:
1936  {
1937  switch(b->s)
1938  {
1939  case 0:
1940  case 1:/* a:3, b:1 */
1941  {
1942  mpz_t x;
1943  mpz_init(x);
1944  mpz_mul(x,a->z,b->n);
1945  mpz_add(a->z,b->z,x);
1946  mpz_clear(x);
1947  mpz_init_set(a->n,b->n);
1948  if (GCD_NORM_COND(b,a)) { nlNormalize_Gcd(a); }
1949  else { a->s = 0; a=nlShort1(a);}
1950  break;
1951  }
1952  case 3:
1953  {
1954  mpz_add(a->z,a->z,b->z);
1955  a->s = 3;
1957  break;
1958  }
1959  }
1960  break;
1961  }
1962  }
1963  }
1964 }
const CanonicalForm int const CFList const Variable & y
Definition: facAbsFact.cc:57
void mpz_mul_si(mpz_ptr r, mpz_srcptr s, long int si)
Definition: longrat.cc:179
const poly a
Definition: syzextra.cc:212
number nlShort1(number x)
Definition: longrat.cc:1313
static void nlNormalize_Gcd(number &x)
Definition: longrat.cc:1649
number nlShort3_noinline(number x)
Definition: longrat.cc:172
#define SR_TO_INT(SR)
Definition: longrat.h:67
#define SR_INT
Definition: longrat.h:65
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
Variable x
Definition: cfModGcd.cc:4023
#define GCD_NORM_COND(OLD, NEW)
Definition: longrat.cc:1647
#define SR_HDL(A)
Definition: tgb.cc:35
const poly b
Definition: syzextra.cc:213
number _nlMult_aImm_bImm_rNoImm ( number  a,
number  b 
)

Definition at line 2177 of file longrat.cc.

2178 {
2179  number u=ALLOC_RNUMBER();
2180 #if defined(LDEBUG)
2181  u->debug=123456;
2182 #endif
2183  u->s=3;
2184  mpz_init_set_si(u->z,SR_TO_INT(a));
2185  mpz_mul_si(u->z,u->z,SR_TO_INT(b));
2186  return u;
2187 }
void mpz_mul_si(mpz_ptr r, mpz_srcptr s, long int si)
Definition: longrat.cc:179
const poly a
Definition: syzextra.cc:212
#define SR_TO_INT(SR)
Definition: longrat.h:67
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
const poly b
Definition: syzextra.cc:213
number _nlMult_aNoImm_OR_bNoImm ( number  a,
number  b 
)

Definition at line 2190 of file longrat.cc.

2191 {
2192  assume(! (SR_HDL(a) & SR_HDL(b) & SR_INT));
2193  number u=ALLOC_RNUMBER();
2194 #if defined(LDEBUG)
2195  u->debug=123456;
2196 #endif
2197  mpz_init(u->z);
2198  if (SR_HDL(b) & SR_INT)
2199  {
2200  number x=a;
2201  a=b;
2202  b=x;
2203  }
2204  if (SR_HDL(a) & SR_INT)
2205  {
2206  u->s=b->s;
2207  if (u->s==1) u->s=0;
2208  if (((long)a)>0L)
2209  {
2210  mpz_mul_ui(u->z,b->z,(unsigned long)SR_TO_INT(a));
2211  }
2212  else
2213  {
2214  if (a==INT_TO_SR(-1))
2215  {
2216  mpz_set(u->z,b->z);
2217  mpz_neg(u->z,u->z);
2218  u->s=b->s;
2219  }
2220  else
2221  {
2222  mpz_mul_ui(u->z,b->z,(unsigned long)-SR_TO_INT(a));
2223  mpz_neg(u->z,u->z);
2224  }
2225  }
2226  if (u->s<2)
2227  {
2228  if (mpz_cmp(u->z,b->n)==0)
2229  {
2230  mpz_clear(u->z);
2231  FREE_RNUMBER(u);
2232  return INT_TO_SR(1);
2233  }
2234  mpz_init_set(u->n,b->n);
2235  if (GCD_NORM_COND(b,u)) { nlNormalize_Gcd(u); }
2236  }
2237  else //u->s==3
2238  {
2239  u=nlShort3(u);
2240  }
2241  }
2242  else
2243  {
2244  mpz_mul(u->z,a->z,b->z);
2245  u->s = 0;
2246  if(a->s==3)
2247  {
2248  if(b->s==3)
2249  {
2250  u->s = 3;
2251  }
2252  else
2253  {
2254  if (mpz_cmp(u->z,b->n)==0)
2255  {
2256  mpz_clear(u->z);
2257  FREE_RNUMBER(u);
2258  return INT_TO_SR(1);
2259  }
2260  mpz_init_set(u->n,b->n);
2261  if (GCD_NORM_COND(b,u)) { nlNormalize_Gcd(u); }
2262  }
2263  }
2264  else
2265  {
2266  if(b->s==3)
2267  {
2268  if (mpz_cmp(u->z,a->n)==0)
2269  {
2270  mpz_clear(u->z);
2271  FREE_RNUMBER(u);
2272  return INT_TO_SR(1);
2273  }
2274  mpz_init_set(u->n,a->n);
2275  if (GCD_NORM_COND(a,u)) { nlNormalize_Gcd(u); }
2276  }
2277  else
2278  {
2279  mpz_init(u->n);
2280  mpz_mul(u->n,a->n,b->n);
2281  if (mpz_cmp(u->z,u->n)==0)
2282  {
2283  mpz_clear(u->z);
2284  mpz_clear(u->n);
2285  FREE_RNUMBER(u);
2286  return INT_TO_SR(1);
2287  }
2288  if (GCD_NORM_COND(a,u)) { nlNormalize_Gcd(u); }
2289  }
2290  }
2291  }
2292  return u;
2293 }
#define INT_TO_SR(INT)
Definition: longrat.h:66
const poly a
Definition: syzextra.cc:212
#define FREE_RNUMBER(x)
Definition: coeffs.h:85
#define assume(x)
Definition: mod2.h:405
static void nlNormalize_Gcd(number &x)
Definition: longrat.cc:1649
#define SR_TO_INT(SR)
Definition: longrat.h:67
static number nlShort3(number x)
Definition: longrat.cc:112
#define SR_INT
Definition: longrat.h:65
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
Variable x
Definition: cfModGcd.cc:4023
#define GCD_NORM_COND(OLD, NEW)
Definition: longrat.cc:1647
#define SR_HDL(A)
Definition: tgb.cc:35
const poly b
Definition: syzextra.cc:213
number _nlNeg_NoImm ( number  a)

Definition at line 1634 of file longrat.cc.

1635 {
1636  {
1637  mpz_neg(a->z,a->z);
1638  if (a->s==3)
1639  {
1640  a=nlShort3(a);
1641  }
1642  }
1643  return a;
1644 }
const poly a
Definition: syzextra.cc:212
static number nlShort3(number x)
Definition: longrat.cc:112
number _nlSub_aNoImm_OR_bNoImm ( number  a,
number  b 
)

Definition at line 1966 of file longrat.cc.

1967 {
1968  number u=ALLOC_RNUMBER();
1969 #if defined(LDEBUG)
1970  u->debug=123456;
1971 #endif
1972  mpz_init(u->z);
1973  if (SR_HDL(a) & SR_INT)
1974  {
1975  switch (b->s)
1976  {
1977  case 0:
1978  case 1:/* a:short, b:1 */
1979  {
1980  mpz_t x;
1981  mpz_init(x);
1982  mpz_mul_si(x,b->n,SR_TO_INT(a));
1983  mpz_sub(u->z,x,b->z);
1984  mpz_clear(x);
1985  if (mpz_cmp_ui(u->z,0L)==0)
1986  {
1987  mpz_clear(u->z);
1988  FREE_RNUMBER(u);
1989  return INT_TO_SR(0);
1990  }
1991  if (mpz_cmp(u->z,b->n)==0)
1992  {
1993  mpz_clear(u->z);
1994  FREE_RNUMBER(u);
1995  return INT_TO_SR(1);
1996  }
1997  mpz_init_set(u->n,b->n);
1998  if (GCD_NORM_COND(b,u)) { nlNormalize_Gcd(u); }
1999  else u->s = 0;
2000  break;
2001  }
2002  case 3:
2003  {
2004  if (((long)a)>0L)
2005  {
2006  mpz_sub_ui(u->z,b->z,SR_TO_INT(a));
2007  mpz_neg(u->z,u->z);
2008  }
2009  else
2010  {
2011  mpz_add_ui(u->z,b->z,-SR_TO_INT(a));
2012  mpz_neg(u->z,u->z);
2013  }
2014  u->s = 3;
2015  u=nlShort3(u);
2016  break;
2017  }
2018  }
2019  }
2020  else if (SR_HDL(b) & SR_INT)
2021  {
2022  switch (a->s)
2023  {
2024  case 0:
2025  case 1:/* b:short, a:1 */
2026  {
2027  mpz_t x;
2028  mpz_init(x);
2029  mpz_mul_si(x,a->n,SR_TO_INT(b));
2030  mpz_sub(u->z,a->z,x);
2031  mpz_clear(x);
2032  if (mpz_cmp_ui(u->z,0L)==0)
2033  {
2034  mpz_clear(u->z);
2035  FREE_RNUMBER(u);
2036  return INT_TO_SR(0);
2037  }
2038  if (mpz_cmp(u->z,a->n)==0)
2039  {
2040  mpz_clear(u->z);
2041  FREE_RNUMBER(u);
2042  return INT_TO_SR(1);
2043  }
2044  mpz_init_set(u->n,a->n);
2045  if (GCD_NORM_COND(a,u)) { nlNormalize_Gcd(u); }
2046  else u->s = 0;
2047  break;
2048  }
2049  case 3:
2050  {
2051  if (((long)b)>0L)
2052  {
2053  mpz_sub_ui(u->z,a->z,SR_TO_INT(b));
2054  }
2055  else
2056  {
2057  mpz_add_ui(u->z,a->z,-SR_TO_INT(b));
2058  }
2059  u->s = 3;
2060  u=nlShort3(u);
2061  break;
2062  }
2063  }
2064  }
2065  else
2066  {
2067  switch (a->s)
2068  {
2069  case 0:
2070  case 1:
2071  {
2072  switch(b->s)
2073  {
2074  case 0:
2075  case 1:
2076  {
2077  mpz_t x;
2078  mpz_t y;
2079  mpz_init(x);
2080  mpz_init(y);
2081  mpz_mul(x,b->z,a->n);
2082  mpz_mul(y,a->z,b->n);
2083  mpz_sub(u->z,y,x);
2084  mpz_clear(x);
2085  mpz_clear(y);
2086  if (mpz_cmp_ui(u->z,0L)==0)
2087  {
2088  mpz_clear(u->z);
2089  FREE_RNUMBER(u);
2090  return INT_TO_SR(0);
2091  }
2092  mpz_init(u->n);
2093  mpz_mul(u->n,a->n,b->n);
2094  if (mpz_cmp(u->z,u->n)==0)
2095  {
2096  mpz_clear(u->z);
2097  mpz_clear(u->n);
2098  FREE_RNUMBER(u);
2099  return INT_TO_SR(1);
2100  }
2101  if (GCD_NORM_COND(a,u)) { nlNormalize_Gcd(u); }
2102  else u->s = 0;
2103  break;
2104  }
2105  case 3: /* a:1, b:3 */
2106  {
2107  mpz_t x;
2108  mpz_init(x);
2109  mpz_mul(x,b->z,a->n);
2110  mpz_sub(u->z,a->z,x);
2111  mpz_clear(x);
2112  if (mpz_cmp_ui(u->z,0L)==0)
2113  {
2114  mpz_clear(u->z);
2115  FREE_RNUMBER(u);
2116  return INT_TO_SR(0);
2117  }
2118  if (mpz_cmp(u->z,a->n)==0)
2119  {
2120  mpz_clear(u->z);
2121  FREE_RNUMBER(u);
2122  return INT_TO_SR(1);
2123  }
2124  mpz_init_set(u->n,a->n);
2125  if (GCD_NORM_COND(a,u)) { nlNormalize_Gcd(u); }
2126  else u->s = 0;
2127  break;
2128  }
2129  }
2130  break;
2131  }
2132  case 3:
2133  {
2134  switch(b->s)
2135  {
2136  case 0:
2137  case 1: /* a:3, b:1 */
2138  {
2139  mpz_t x;
2140  mpz_init(x);
2141  mpz_mul(x,a->z,b->n);
2142  mpz_sub(u->z,x,b->z);
2143  mpz_clear(x);
2144  if (mpz_cmp_ui(u->z,0L)==0)
2145  {
2146  mpz_clear(u->z);
2147  FREE_RNUMBER(u);
2148  return INT_TO_SR(0);
2149  }
2150  if (mpz_cmp(u->z,b->n)==0)
2151  {
2152  mpz_clear(u->z);
2153  FREE_RNUMBER(u);
2154  return INT_TO_SR(1);
2155  }
2156  mpz_init_set(u->n,b->n);
2157  if (GCD_NORM_COND(b,u)) { nlNormalize_Gcd(u); }
2158  else u->s = 0;
2159  break;
2160  }
2161  case 3: /* a:3 , b:3 */
2162  {
2163  mpz_sub(u->z,a->z,b->z);
2164  u->s = 3;
2165  u=nlShort3(u);
2166  break;
2167  }
2168  }
2169  break;
2170  }
2171  }
2172  }
2173  return u;
2174 }
const CanonicalForm int const CFList const Variable & y
Definition: facAbsFact.cc:57
void mpz_mul_si(mpz_ptr r, mpz_srcptr s, long int si)
Definition: longrat.cc:179
#define INT_TO_SR(INT)
Definition: longrat.h:66
const poly a
Definition: syzextra.cc:212
#define FREE_RNUMBER(x)
Definition: coeffs.h:85
static void nlNormalize_Gcd(number &x)
Definition: longrat.cc:1649
#define SR_TO_INT(SR)
Definition: longrat.h:67
static number nlShort3(number x)
Definition: longrat.cc:112
#define SR_INT
Definition: longrat.h:65
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
Variable x
Definition: cfModGcd.cc:4023
#define GCD_NORM_COND(OLD, NEW)
Definition: longrat.cc:1647
#define SR_HDL(A)
Definition: tgb.cc:35
const poly b
Definition: syzextra.cc:213
static int int_extgcd ( int  a,
int  b,
int *  u,
int *  x,
int *  v,
int *  y 
)
static

Definition at line 1263 of file longrat.cc.

1264 {
1265  int q, r;
1266  if (a==0)
1267  {
1268  *u = 0;
1269  *v = 1;
1270  *x = -1;
1271  *y = 0;
1272  return b;
1273  }
1274  if (b==0)
1275  {
1276  *u = 1;
1277  *v = 0;
1278  *x = 0;
1279  *y = 1;
1280  return a;
1281  }
1282  *u=1;
1283  *v=0;
1284  *x=0;
1285  *y=1;
1286  do
1287  {
1288  q = a/b;
1289  r = a%b;
1290  assume (q*b+r == a);
1291  a = b;
1292  b = r;
1293 
1294  r = -(*v)*q+(*u);
1295  (*u) =(*v);
1296  (*v) = r;
1297 
1298  r = -(*y)*q+(*x);
1299  (*x) = (*y);
1300  (*y) = r;
1301  } while (b);
1302 
1303  return a;
1304 }
const CanonicalForm int const CFList const Variable & y
Definition: facAbsFact.cc:57
const poly a
Definition: syzextra.cc:212
const ring r
Definition: syzextra.cc:208
#define assume(x)
Definition: mod2.h:405
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
Variable x
Definition: cfModGcd.cc:4023
const poly b
Definition: syzextra.cc:213
void mpz_mul_si ( mpz_ptr  r,
mpz_srcptr  s,
long int  si 
)

Definition at line 179 of file longrat.cc.

180 {
181  if (si>=0)
182  mpz_mul_ui(r,s,si);
183  else
184  {
185  mpz_mul_ui(r,s,-si);
186  mpz_neg(r,r);
187  }
188 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
const ring r
Definition: syzextra.cc:208
LINLINE number nl_Copy ( number  a,
const coeffs  r 
)
LINLINE number nlAdd ( number  la,
number  li,
const coeffs  r 
)

Definition at line 2515 of file longrat.cc.

2516 {
2517  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
2518  {
2519  LONG r=SR_HDL(a)+SR_HDL(b)-1L;
2520  if ( ((r << 1) >> 1) == r )
2521  return (number)(long)r;
2522  else
2523  return nlRInit(SR_TO_INT(r));
2524  }
2525  number u = _nlAdd_aNoImm_OR_bNoImm(a, b);
2526  nlTest(u, R);
2527  return u;
2528 }
const poly a
Definition: syzextra.cc:212
number nlRInit(long i)
Definition: longrat.cc:2344
const ring R
Definition: DebugPrint.cc:36
#define SR_TO_INT(SR)
Definition: longrat.h:67
#define SR_INT
Definition: longrat.h:65
number _nlAdd_aNoImm_OR_bNoImm(number a, number b)
Definition: longrat.cc:1669
#define SR_HDL(A)
Definition: tgb.cc:35
const poly b
Definition: syzextra.cc:213
#define LONG
Definition: longrat.cc:108
#define nlTest(a, r)
Definition: longrat.cc:90
number nlBigInt ( number &  n)
number nlBigInt ( number &  i,
const coeffs  r 
)

Definition at line 637 of file longrat.cc.

638 {
639  nlTest(i, r);
640  nlNormalize(i,r);
641  if (SR_HDL(i) & SR_INT) return (i);
642  if (i->s==3)
643  {
644  return nlCopy(i,r);
645  }
646  number tmp=nlRInit(1);
647  mpz_tdiv_q(tmp->z,i->z,i->n);
648  tmp=nlShort3(tmp);
649  return tmp;
650 }
number nlRInit(long i)
Definition: longrat.cc:2344
int i
Definition: cfEzgcd.cc:123
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1334
static number nlShort3(number x)
Definition: longrat.cc:112
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
LINLINE number nlCopy(number a, const coeffs r)
Definition: longrat.cc:2467
#define nlTest(a, r)
Definition: longrat.cc:90
number nlChineseRemainder ( number *  x,
number *  q,
int  rl,
const coeffs  C 
)

Definition at line 2953 of file longrat.cc.

2954 {
2955  CFArray inv(rl);
2956  return nlChineseRemainderSym(x,q,rl,TRUE,inv,C);
2957 }
#define TRUE
Definition: auxiliary.h:144
number nlChineseRemainderSym(number *x, number *q, int rl, BOOLEAN sym, CFArray &inv_cache, const coeffs CF)
Definition: longrat.cc:2919
Variable x
Definition: cfModGcd.cc:4023
number nlChineseRemainderSym ( number *  x,
number *  q,
int  rl,
BOOLEAN  sym,
CFArray inv_cache,
const coeffs  CF 
)

Definition at line 2919 of file longrat.cc.

2921 {
2922  setCharacteristic( 0 ); // only in char 0
2923  Off(SW_RATIONAL);
2924  CFArray X(rl), Q(rl);
2925  int i;
2926  for(i=rl-1;i>=0;i--)
2927  {
2928  X[i]=CF->convSingNFactoryN(x[i],FALSE,CF); // may be larger MAX_INT
2929  Q[i]=CF->convSingNFactoryN(q[i],FALSE,CF); // may be larger MAX_INT
2930  }
2931  CanonicalForm xnew,qnew;
2932  if (n_SwitchChinRem)
2933  chineseRemainder(X,Q,xnew,qnew);
2934  else
2935  chineseRemainderCached(X,Q,xnew,qnew,inv_cache);
2936  number n=CF->convFactoryNSingN(xnew,CF);
2937  if (sym)
2938  {
2939  number p=CF->convFactoryNSingN(qnew,CF);
2940  number p2=nlIntDiv(p,nlInit(2, CF),CF);
2941  if (nlGreater(n,p2,CF))
2942  {
2943  number n2=nlSub(n,p,CF);
2944  nlDelete(&n,CF);
2945  n=n2;
2946  }
2947  nlDelete(&p2,CF);
2948  nlDelete(&p,CF);
2949  }
2950  nlNormalize(n,CF);
2951  return n;
2952 }
LINLINE number nlSub(number la, number li, const coeffs r)
Definition: longrat.cc:2581
void Off(int sw)
switches
#define FALSE
Definition: auxiliary.h:140
return P p
Definition: myNF.cc:203
int n_SwitchChinRem
Definition: longrat.cc:2918
number nlIntDiv(number a, number b, const coeffs r)
Definition: longrat.cc:786
factory&#39;s main class
Definition: canonicalform.h:75
#define Q
Definition: sirandom.c:25
void setCharacteristic(int c)
Definition: cf_char.cc:23
BOOLEAN nlGreater(number a, number b, const coeffs r)
Definition: longrat.cc:1165
static const int SW_RATIONAL
set to 1 for computations over Q
Definition: cf_defs.h:28
int i
Definition: cfEzgcd.cc:123
void chineseRemainderCached(CFArray &a, CFArray &n, CanonicalForm &xnew, CanonicalForm &prod, CFArray &inv)
Definition: cf_chinese.cc:264
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1334
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
LINLINE void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2480
Variable x
Definition: cfModGcd.cc:4023
LINLINE number nlInit(long i, const coeffs r)
Definition: longrat.cc:2420
END_NAMESPACE const void * p2
Definition: syzextra.cc:202
static void nlClearContent ( ICoeffsEnumerator numberCollectionEnumerator,
number &  c,
const coeffs  cf 
)
static

Definition at line 2959 of file longrat.cc.

2960 {
2961  assume(cf != NULL);
2962 
2963  numberCollectionEnumerator.Reset();
2964 
2965  if( !numberCollectionEnumerator.MoveNext() ) // empty zero polynomial?
2966  {
2967  c = nlInit(1, cf);
2968  return;
2969  }
2970 
2971  // all coeffs are given by integers!!!
2972 
2973  // part 1, find a small candidate for gcd
2974  number cand1,cand;
2975  int s1,s;
2976  s=2147483647; // max. int
2977 
2978  const BOOLEAN lc_is_pos=nlGreaterZero(numberCollectionEnumerator.Current(),cf);
2979 
2980  int normalcount = 0;
2981  do
2982  {
2983  number& n = numberCollectionEnumerator.Current();
2984  nlNormalize(n, cf); ++normalcount;
2985  cand1 = n;
2986 
2987  if (SR_HDL(cand1)&SR_INT) { cand=cand1; break; }
2988  assume(cand1->s==3); // all coeffs should be integers // ==0?!! after printing
2989  s1=mpz_size1(cand1->z);
2990  if (s>s1)
2991  {
2992  cand=cand1;
2993  s=s1;
2994  }
2995  } while (numberCollectionEnumerator.MoveNext() );
2996 
2997 // assume( nlGreaterZero(cand,cf) ); // cand may be a negative integer!
2998 
2999  cand=nlCopy(cand,cf);
3000  // part 2: compute gcd(cand,all coeffs)
3001 
3002  numberCollectionEnumerator.Reset();
3003 
3004  while (numberCollectionEnumerator.MoveNext() )
3005  {
3006  number& n = numberCollectionEnumerator.Current();
3007 
3008  if( (--normalcount) <= 0)
3009  nlNormalize(n, cf);
3010 
3011  nlInpGcd(cand, n, cf);
3012  assume( nlGreaterZero(cand,cf) );
3013 
3014  if(nlIsOne(cand,cf))
3015  {
3016  c = cand;
3017 
3018  if(!lc_is_pos)
3019  {
3020  // make the leading coeff positive
3021  c = nlNeg(c, cf);
3022  numberCollectionEnumerator.Reset();
3023 
3024  while (numberCollectionEnumerator.MoveNext() )
3025  {
3026  number& nn = numberCollectionEnumerator.Current();
3027  nn = nlNeg(nn, cf);
3028  }
3029  }
3030  return;
3031  }
3032  }
3033 
3034  // part3: all coeffs = all coeffs / cand
3035  if (!lc_is_pos)
3036  cand = nlNeg(cand,cf);
3037 
3038  c = cand;
3039  numberCollectionEnumerator.Reset();
3040 
3041  while (numberCollectionEnumerator.MoveNext() )
3042  {
3043  number& n = numberCollectionEnumerator.Current();
3044  number t=nlIntDiv(n, cand, cf); // simple integer exact division, no ratios to remain
3045  nlDelete(&n, cf);
3046  n = t;
3047  }
3048 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
BOOLEAN nlGreaterZero(number za, const coeffs r)
Definition: longrat.cc:1155
void nlInpGcd(number &a, number b, const coeffs r)
Definition: longrat.cc:2759
number nlIntDiv(number a, number b, const coeffs r)
Definition: longrat.cc:786
LINLINE BOOLEAN nlIsOne(number a, const coeffs r)
Definition: longrat.cc:2438
virtual void Reset()=0
Sets the enumerator to its initial position: -1, which is before the first element in the collection...
LINLINE number nlNeg(number za, const coeffs r)
Definition: longrat.cc:2496
#define assume(x)
Definition: mod2.h:405
virtual reference Current()=0
Gets the current element in the collection (read and write).
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1334
#define mpz_size1(A)
Definition: si_gmp.h:12
CanonicalForm cf
Definition: cfModGcd.cc:4024
#define NULL
Definition: omList.c:10
LINLINE void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2480
virtual bool MoveNext()=0
Advances the enumerator to the next element of the collection. returns true if the enumerator was suc...
#define SR_INT
Definition: longrat.h:65
LINLINE number nlInit(long i, const coeffs r)
Definition: longrat.cc:2420
#define SR_HDL(A)
Definition: tgb.cc:35
int BOOLEAN
Definition: auxiliary.h:131
LINLINE number nlCopy(number a, const coeffs r)
Definition: longrat.cc:2467
const CanonicalForm const CanonicalForm const CanonicalForm const CanonicalForm & cand
Definition: cfModGcd.cc:69
static void nlClearDenominators ( ICoeffsEnumerator numberCollectionEnumerator,
number &  c,
const coeffs  cf 
)
static

Definition at line 3050 of file longrat.cc.

3051 {
3052  assume(cf != NULL);
3053 
3054  numberCollectionEnumerator.Reset();
3055 
3056  if( !numberCollectionEnumerator.MoveNext() ) // empty zero polynomial?
3057  {
3058  c = nlInit(1, cf);
3059 // assume( n_GreaterZero(c, cf) );
3060  return;
3061  }
3062 
3063  // all coeffs are given by integers after returning from this routine
3064 
3065  // part 1, collect product of all denominators /gcds
3066  number cand;
3067  cand=ALLOC_RNUMBER();
3068 #if defined(LDEBUG)
3069  cand->debug=123456;
3070 #endif
3071  cand->s=3;
3072 
3073  int s=0;
3074 
3075  const BOOLEAN lc_is_pos=nlGreaterZero(numberCollectionEnumerator.Current(),cf);
3076 
3077  do
3078  {
3079  number& cand1 = numberCollectionEnumerator.Current();
3080 
3081  if (!(SR_HDL(cand1)&SR_INT))
3082  {
3083  nlNormalize(cand1, cf);
3084  if ((!(SR_HDL(cand1)&SR_INT)) // not a short int
3085  && (cand1->s==1)) // and is a normalised rational
3086  {
3087  if (s==0) // first denom, we meet
3088  {
3089  mpz_init_set(cand->z, cand1->n); // cand->z = cand1->n
3090  s=1;
3091  }
3092  else // we have already something
3093  {
3094  mpz_lcm(cand->z, cand->z, cand1->n);
3095  }
3096  }
3097  }
3098  }
3099  while (numberCollectionEnumerator.MoveNext() );
3100 
3101 
3102  if (s==0) // nothing to do, all coeffs are already integers
3103  {
3104 // mpz_clear(tmp);
3105  FREE_RNUMBER(cand);
3106  if (lc_is_pos)
3107  c=nlInit(1,cf);
3108  else
3109  {
3110  // make the leading coeff positive
3111  c=nlInit(-1,cf);
3112 
3113  // TODO: incorporate the following into the loop below?
3114  numberCollectionEnumerator.Reset();
3115  while (numberCollectionEnumerator.MoveNext() )
3116  {
3117  number& n = numberCollectionEnumerator.Current();
3118  n = nlNeg(n, cf);
3119  }
3120  }
3121 // assume( n_GreaterZero(c, cf) );
3122  return;
3123  }
3124 
3125  cand = nlShort3(cand);
3126 
3127  // part2: all coeffs = all coeffs * cand
3128  // make the lead coeff positive
3129  numberCollectionEnumerator.Reset();
3130 
3131  if (!lc_is_pos)
3132  cand = nlNeg(cand, cf);
3133 
3134  c = cand;
3135 
3136  while (numberCollectionEnumerator.MoveNext() )
3137  {
3138  number &n = numberCollectionEnumerator.Current();
3139  nlInpMult(n, cand, cf);
3140  }
3141 
3142 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
BOOLEAN nlGreaterZero(number za, const coeffs r)
Definition: longrat.cc:1155
#define FREE_RNUMBER(x)
Definition: coeffs.h:85
virtual void Reset()=0
Sets the enumerator to its initial position: -1, which is before the first element in the collection...
LINLINE number nlNeg(number za, const coeffs r)
Definition: longrat.cc:2496
#define assume(x)
Definition: mod2.h:405
LINLINE void nlInpMult(number &a, number b, const coeffs r)
Definition: longrat.cc:2599
virtual reference Current()=0
Gets the current element in the collection (read and write).
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1334
CanonicalForm cf
Definition: cfModGcd.cc:4024
#define NULL
Definition: omList.c:10
static number nlShort3(number x)
Definition: longrat.cc:112
virtual bool MoveNext()=0
Advances the enumerator to the next element of the collection. returns true if the enumerator was suc...
#define SR_INT
Definition: longrat.h:65
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
LINLINE number nlInit(long i, const coeffs r)
Definition: longrat.cc:2420
#define SR_HDL(A)
Definition: tgb.cc:35
int BOOLEAN
Definition: auxiliary.h:131
const CanonicalForm const CanonicalForm const CanonicalForm const CanonicalForm & cand
Definition: cfModGcd.cc:69
BOOLEAN nlCoeffIsEqual ( const coeffs  r,
n_coeffType  n,
void *  p 
)

Definition at line 3265 of file longrat.cc.

3266 {
3267  /* test, if r is an instance of nInitCoeffs(n,parameter) */
3268  /* if parameter is not needed */
3269  if (n==r->type)
3270  {
3271  if ((p==NULL)&&(r->cfDiv==nlDiv)) return TRUE;
3272  if ((p!=NULL)&&(r->cfDiv!=nlDiv)) return TRUE;
3273  }
3274  return FALSE;
3275 }
#define FALSE
Definition: auxiliary.h:140
return P p
Definition: myNF.cc:203
#define TRUE
Definition: auxiliary.h:144
number nlDiv(number a, number b, const coeffs r)
Definition: longrat.cc:992
#define NULL
Definition: omList.c:10
char* nlCoeffName ( const coeffs  r)

Definition at line 3144 of file longrat.cc.

3145 {
3146  if (r->cfDiv==nlDiv) return (char*)"QQ";
3147  else return (char*)"ZZ";
3148 }
number nlDiv(number a, number b, const coeffs r)
Definition: longrat.cc:992
static char* nlCoeffString ( const coeffs  r)
static

Definition at line 3150 of file longrat.cc.

3151 {
3152  //return omStrDup(nlCoeffName(r));
3153  if (r->cfDiv==nlDiv) return omStrDup("0");
3154  else return omStrDup("integer");
3155 }
number nlDiv(number a, number b, const coeffs r)
Definition: longrat.cc:992
#define omStrDup(s)
Definition: omAllocDecl.h:263
void nlCoeffWrite ( const coeffs  r,
BOOLEAN  details 
)

Definition at line 2910 of file longrat.cc.

2911 {
2912  if (r->is_field)
2913  PrintS("// characteristic : 0\n");
2914  else
2915  PrintS("// coeff. ring is : Integers\n");
2916 }
void PrintS(const char *s)
Definition: reporter.cc:294
static number nlConvFactoryNSingN ( const CanonicalForm  f,
const coeffs  r 
)
static

Definition at line 378 of file longrat.cc.

379 {
380  if (f.isImm())
381  {
382  return nlInit(f.intval(),r);
383  }
384  else
385  {
386  number z = ALLOC_RNUMBER();
387 #if defined(LDEBUG)
388  z->debug=123456;
389 #endif
390  gmp_numerator( f, z->z );
391  if ( f.den().isOne() )
392  {
393  z->s = 3;
394  z=nlShort3(z);
395  }
396  else
397  {
398  gmp_denominator( f, z->n );
399  z->s = 1;
400  }
401  return z;
402  }
403 }
long intval() const
conversion functions
CF_NO_INLINE bool isOne() const
CF_INLINE bool CanonicalForm::isOne, isZero () const.
Definition: cf_inline.cc:354
const ring r
Definition: syzextra.cc:208
CanonicalForm den() const
den() returns the denominator of CO if CO is a rational number, 1 (from the current domain!) otherwis...
void gmp_numerator(const CanonicalForm &f, mpz_ptr result)
Definition: singext.cc:20
bool isImm() const
static number nlShort3(number x)
Definition: longrat.cc:112
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
LINLINE number nlInit(long i, const coeffs r)
Definition: longrat.cc:2420
void gmp_denominator(const CanonicalForm &f, mpz_ptr result)
Definition: singext.cc:40
static CanonicalForm nlConvSingNFactoryN ( number  n,
const BOOLEAN  setChar,
const coeffs   
)
static

Definition at line 340 of file longrat.cc.

341 {
342  if (setChar) setCharacteristic( 0 );
343 
345  if ( SR_HDL(n) & SR_INT )
346  {
347  long nn=SR_TO_INT(n);
348  term = nn;
349  }
350  else
351  {
352  if ( n->s == 3 )
353  {
354  mpz_t dummy;
355  long lz=mpz_get_si(n->z);
356  if (mpz_cmp_si(n->z,lz)==0) term=lz;
357  else
358  {
359  mpz_init_set( dummy,n->z );
360  term = make_cf( dummy );
361  }
362  }
363  else
364  {
365  // assume s==0 or s==1
366  mpz_t num, den;
367  On(SW_RATIONAL);
368  mpz_init_set( num, n->z );
369  mpz_init_set( den, n->n );
370  term = make_cf( num, den, ( n->s != 1 ));
371  }
372  }
373  return term;
374 }
CanonicalForm num(const CanonicalForm &f)
Definition: int_poly.h:36
factory&#39;s main class
Definition: canonicalform.h:75
CanonicalForm make_cf(const mpz_ptr n)
Definition: singext.cc:67
void setCharacteristic(int c)
Definition: cf_char.cc:23
static const int SW_RATIONAL
set to 1 for computations over Q
Definition: cf_defs.h:28
void On(int sw)
switches
#define SR_TO_INT(SR)
Definition: longrat.h:67
CanonicalForm den(const CanonicalForm &f)
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
LINLINE number nlCopy ( number  a,
const coeffs  r 
)

Definition at line 2467 of file longrat.cc.

2468 {
2469  if ((SR_HDL(a) & SR_INT)||(a==NULL))
2470  {
2471  return a;
2472  }
2473  return _nlCopy_NoImm(a);
2474 }
const poly a
Definition: syzextra.cc:212
number _nlCopy_NoImm(number a)
Definition: longrat.cc:1595
#define NULL
Definition: omList.c:10
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
number nlCopyMap ( number  a,
const coeffs  src,
const coeffs  dst 
)

Definition at line 2298 of file longrat.cc.

2299 {
2300  if ((SR_HDL(a) & SR_INT)||(a==NULL))
2301  {
2302  return a;
2303  }
2304  return _nlCopy_NoImm(a);
2305 }
const poly a
Definition: syzextra.cc:212
number _nlCopy_NoImm(number a)
Definition: longrat.cc:1595
#define NULL
Definition: omList.c:10
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
BOOLEAN nlDBTest ( number  a,
const char *  f,
const int  l 
)
BOOLEAN nlDBTest ( number  a,
const char *  f,
int  l,
const coeffs  r 
)

Definition at line 248 of file longrat.cc.

249 {
250  if (a==NULL)
251  {
252  Print("!!longrat: NULL in %s:%d\n",f,l);
253  return FALSE;
254  }
255  //if ((int)a==1) Print("!! 0x1 as number ? %s %d\n",f,l);
256  if ((((long)a)&3L)==3L)
257  {
258  Print(" !!longrat:ptr(3) in %s:%d\n",f,l);
259  return FALSE;
260  }
261  if ((((long)a)&3L)==1L)
262  {
263  if (((((LONG)(long)a)<<1)>>1)!=((LONG)(long)a))
264  {
265  Print(" !!longrat:arith:%lx in %s:%d\n",(long)a, f,l);
266  return FALSE;
267  }
268  return TRUE;
269  }
270  /* TODO: If next line is active, then computations in algebraic field
271  extensions over Q will throw a lot of assume violations although
272  everything is computed correctly and no seg fault appears.
273  Maybe the test is not appropriate in this case. */
274  omCheckIf(omCheckAddrSize(a,sizeof(*a)), return FALSE);
275  if (a->debug!=123456)
276  {
277  Print("!!longrat:debug:%d in %s:%d\n",a->debug,f,l);
278  a->debug=123456;
279  return FALSE;
280  }
281  if ((a->s<0)||(a->s>4))
282  {
283  Print("!!longrat:s=%d in %s:%d\n",a->s,f,l);
284  return FALSE;
285  }
286  /* TODO: If next line is active, then computations in algebraic field
287  extensions over Q will throw a lot of assume violations although
288  everything is computed correctly and no seg fault appears.
289  Maybe the test is not appropriate in this case. */
290  //omCheckAddrSize(a->z[0]._mp_d,a->z[0]._mp_alloc*BYTES_PER_MP_LIMB);
291  if (a->z[0]._mp_alloc==0)
292  Print("!!longrat:z->alloc=0 in %s:%d\n",f,l);
293 
294  if (a->s<2)
295  {
296  if ((a->n[0]._mp_d[0]==0)&&(a->n[0]._mp_alloc<=1))
297  {
298  Print("!!longrat: n==0 in %s:%d\n",f,l);
299  return FALSE;
300  }
301  /* TODO: If next line is active, then computations in algebraic field
302  extensions over Q will throw a lot of assume violations although
303  everything is computed correctly and no seg fault appears.
304  Maybe the test is not appropriate in this case. */
305  //omCheckIf(omCheckAddrSize(a->n[0]._mp_d,a->n[0]._mp_alloc*BYTES_PER_MP_LIMB), return FALSE);
306  if (a->z[0]._mp_alloc==0)
307  Print("!!longrat:n->alloc=0 in %s:%d\n",f,l);
308  if ((mpz_size1(a->n) ==1) && (mpz_cmp_si(a->n,1L)==0))
309  {
310  Print("!!longrat:integer as rational in %s:%d\n",f,l);
311  mpz_clear(a->n); a->s=3;
312  return FALSE;
313  }
314  else if (mpz_isNeg(a->n))
315  {
316  Print("!!longrat:div. by negative in %s:%d\n",f,l);
317  mpz_neg(a->z,a->z);
318  mpz_neg(a->n,a->n);
319  return FALSE;
320  }
321  return TRUE;
322  }
323  //if (a->s==2)
324  //{
325  // Print("!!longrat:s=2 in %s:%d\n",f,l);
326  // return FALSE;
327  //}
328  if (mpz_size1(a->z)>MP_SMALL) return TRUE;
329  LONG ui=(LONG)mpz_get_si(a->z);
330  if ((((ui<<3)>>3)==ui)
331  && (mpz_cmp_si(a->z,(long)ui)==0))
332  {
333  Print("!!longrat:im int %d in %s:%d\n",ui,f,l);
334  return FALSE;
335  }
336  return TRUE;
337 }
#define omCheckAddrSize(addr, size)
Definition: omAllocDecl.h:327
const poly a
Definition: syzextra.cc:212
#define Print
Definition: emacs.cc:83
#define FALSE
Definition: auxiliary.h:140
#define omCheckIf(cond, test)
Definition: omAllocDecl.h:323
#define TRUE
Definition: auxiliary.h:144
#define MP_SMALL
Definition: longrat.cc:157
#define mpz_isNeg(A)
Definition: longrat.cc:159
FILE * f
Definition: checklibs.c:7
#define mpz_size1(A)
Definition: si_gmp.h:12
#define NULL
Definition: omList.c:10
#define LONG
Definition: longrat.cc:108
int l
Definition: cfEzgcd.cc:94
LINLINE void nlDelete ( number *  a,
const coeffs  r 
)

Definition at line 2480 of file longrat.cc.

2481 {
2482  if (*a!=NULL)
2483  {
2484  nlTest(*a, r);
2485  if ((SR_HDL(*a) & SR_INT)==0)
2486  {
2487  _nlDelete_NoImm(a);
2488  }
2489  *a=NULL;
2490  }
2491 }
const poly a
Definition: syzextra.cc:212
void _nlDelete_NoImm(number *a)
Definition: longrat.cc:1616
#define NULL
Definition: omList.c:10
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
#define nlTest(a, r)
Definition: longrat.cc:90
number nlDiv ( number  a,
number  b,
const coeffs  r 
)

Definition at line 992 of file longrat.cc.

993 {
994  if (nlIsZero(b,r))
995  {
996  WerrorS(nDivBy0);
997  return INT_TO_SR(0);
998  }
999  number u;
1000 // ---------- short / short ------------------------------------
1001  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
1002  {
1003  LONG i=SR_TO_INT(a);
1004  LONG j=SR_TO_INT(b);
1005  if (j==1L) return a;
1006  if ((i==-POW_2_28) && (j== -1L))
1007  {
1008  return nlRInit(POW_2_28);
1009  }
1010  LONG r=i%j;
1011  if (r==0)
1012  {
1013  return INT_TO_SR(i/j);
1014  }
1015  u=ALLOC_RNUMBER();
1016  u->s=0;
1017  #if defined(LDEBUG)
1018  u->debug=123456;
1019  #endif
1020  mpz_init_set_si(u->z,(long)i);
1021  mpz_init_set_si(u->n,(long)j);
1022  }
1023  else
1024  {
1025  u=ALLOC_RNUMBER();
1026  u->s=0;
1027  #if defined(LDEBUG)
1028  u->debug=123456;
1029  #endif
1030  mpz_init(u->z);
1031 // ---------- short / long ------------------------------------
1032  if (SR_HDL(a) & SR_INT)
1033  {
1034  // short a / (z/n) -> (a*n)/z
1035  if (b->s<2)
1036  {
1037  mpz_mul_si(u->z,b->n,SR_TO_INT(a));
1038  }
1039  else
1040  // short a / long z -> a/z
1041  {
1042  mpz_set_si(u->z,SR_TO_INT(a));
1043  }
1044  if (mpz_cmp(u->z,b->z)==0)
1045  {
1046  mpz_clear(u->z);
1047  FREE_RNUMBER(u);
1048  return INT_TO_SR(1);
1049  }
1050  mpz_init_set(u->n,b->z);
1051  }
1052 // ---------- long / short ------------------------------------
1053  else if (SR_HDL(b) & SR_INT)
1054  {
1055  mpz_set(u->z,a->z);
1056  // (z/n) / b -> z/(n*b)
1057  if (a->s<2)
1058  {
1059  mpz_init_set(u->n,a->n);
1060  if (((long)b)>0L)
1061  mpz_mul_ui(u->n,u->n,SR_TO_INT(b));
1062  else
1063  {
1064  mpz_mul_ui(u->n,u->n,-SR_TO_INT(b));
1065  mpz_neg(u->z,u->z);
1066  }
1067  }
1068  else
1069  // long z / short b -> z/b
1070  {
1071  //mpz_set(u->z,a->z);
1072  mpz_init_set_si(u->n,SR_TO_INT(b));
1073  }
1074  }
1075 // ---------- long / long ------------------------------------
1076  else
1077  {
1078  mpz_set(u->z,a->z);
1079  mpz_init_set(u->n,b->z);
1080  if (a->s<2) mpz_mul(u->n,u->n,a->n);
1081  if (b->s<2) mpz_mul(u->z,u->z,b->n);
1082  }
1083  }
1084  if (mpz_isNeg(u->n))
1085  {
1086  mpz_neg(u->z,u->z);
1087  mpz_neg(u->n,u->n);
1088  }
1089  if (mpz_cmp_si(u->n,1L)==0)
1090  {
1091  mpz_clear(u->n);
1092  u->s=3;
1093  u=nlShort3(u);
1094  }
1095  nlTest(u, r);
1096  return u;
1097 }
void mpz_mul_si(mpz_ptr r, mpz_srcptr s, long int si)
Definition: longrat.cc:179
#define INT_TO_SR(INT)
Definition: longrat.h:66
const poly a
Definition: syzextra.cc:212
#define POW_2_28
Definition: longrat.cc:106
number nlRInit(long i)
Definition: longrat.cc:2344
#define FREE_RNUMBER(x)
Definition: coeffs.h:85
void WerrorS(const char *s)
Definition: feFopen.cc:24
int j
Definition: myNF.cc:70
#define mpz_isNeg(A)
Definition: longrat.cc:159
const char *const nDivBy0
Definition: numbers.h:83
int i
Definition: cfEzgcd.cc:123
LINLINE BOOLEAN nlIsZero(number za, const coeffs r)
Definition: longrat.cc:2447
#define SR_TO_INT(SR)
Definition: longrat.h:67
static number nlShort3(number x)
Definition: longrat.cc:112
#define SR_INT
Definition: longrat.h:65
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
#define SR_HDL(A)
Definition: tgb.cc:35
const poly b
Definition: syzextra.cc:213
#define LONG
Definition: longrat.cc:108
#define nlTest(a, r)
Definition: longrat.cc:90
BOOLEAN nlDivBy ( number  a,
number  b,
const coeffs   
)

Definition at line 928 of file longrat.cc.

929 {
930  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
931  {
932  return ((SR_TO_INT(a) % SR_TO_INT(b))==0);
933  }
934  if (SR_HDL(b) & SR_INT)
935  {
936  return (mpz_divisible_ui_p(a->z,SR_TO_INT(b))!=0);
937  }
938  if (SR_HDL(a) & SR_INT) return FALSE;
939  return mpz_divisible_p(a->z, b->z) != 0;
940 }
const poly a
Definition: syzextra.cc:212
#define FALSE
Definition: auxiliary.h:140
#define SR_TO_INT(SR)
Definition: longrat.h:67
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
const poly b
Definition: syzextra.cc:213
int nlDivComp ( number  a,
number  b,
const coeffs  r 
)

Definition at line 942 of file longrat.cc.

943 {
944  if (nlDivBy(a, b, r))
945  {
946  if (nlDivBy(b, a, r)) return 2;
947  return -1;
948  }
949  if (nlDivBy(b, a, r)) return 1;
950  return 0;
951 }
const poly a
Definition: syzextra.cc:212
BOOLEAN nlDivBy(number a, number b, const coeffs)
Definition: longrat.cc:928
const poly b
Definition: syzextra.cc:213
LINLINE BOOLEAN nlEqual ( number  a,
number  b,
const coeffs  r 
)

Definition at line 2411 of file longrat.cc.

2412 {
2413  nlTest(a, r);
2414  nlTest(b, r);
2415 // short - short
2416  if (SR_HDL(a) & SR_HDL(b) & SR_INT) return a==b;
2417  return _nlEqual_aNoImm_OR_bNoImm(a, b);
2418 }
const poly a
Definition: syzextra.cc:212
BOOLEAN _nlEqual_aNoImm_OR_bNoImm(number a, number b)
Definition: longrat.cc:1548
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
const poly b
Definition: syzextra.cc:213
#define nlTest(a, r)
Definition: longrat.cc:90
number nlExactDiv ( number  a,
number  b,
const coeffs  r 
)

Definition at line 735 of file longrat.cc.

736 {
737  if (b==INT_TO_SR(0))
738  {
739  WerrorS(nDivBy0);
740  return INT_TO_SR(0);
741  }
742  if (a==INT_TO_SR(0))
743  return INT_TO_SR(0);
744  number u;
745  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
746  {
747  /* the small int -(1<<28) divided by -1 is the large int (1<<28) */
748  if ((a==INT_TO_SR(-(POW_2_28)))&&(b==INT_TO_SR(-1L)))
749  {
750  return nlRInit(POW_2_28);
751  }
752  long aa=SR_TO_INT(a);
753  long bb=SR_TO_INT(b);
754  return INT_TO_SR(aa/bb);
755  }
756  number bb=NULL;
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  mpz_divexact(u->z,a->z,b->z);
770  if (bb!=NULL)
771  {
772  mpz_clear(bb->z);
773 #if defined(LDEBUG)
774  bb->debug=654324;
775 #endif
776  FREE_RNUMBER(bb); // omFreeBin((void *)bb, rnumber_bin);
777  }
778  u=nlShort3(u);
779  nlTest(u, r);
780  return u;
781 }
#define INT_TO_SR(INT)
Definition: longrat.h:66
const poly a
Definition: syzextra.cc:212
#define POW_2_28
Definition: longrat.cc:106
number nlRInit(long i)
Definition: longrat.cc:2344
#define FREE_RNUMBER(x)
Definition: coeffs.h:85
void WerrorS(const char *s)
Definition: feFopen.cc:24
const char *const nDivBy0
Definition: numbers.h:83
#define SR_TO_INT(SR)
Definition: longrat.h:67
#define NULL
Definition: omList.c:10
static number nlShort3(number x)
Definition: longrat.cc:112
#define SR_INT
Definition: longrat.h:65
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
#define SR_HDL(A)
Definition: tgb.cc:35
const poly b
Definition: syzextra.cc:213
#define nlTest(a, r)
Definition: longrat.cc:90
number nlExtGcd ( number  a,
number  b,
number *  s,
number *  t,
const coeffs   
)

Definition at line 2861 of file longrat.cc.

2862 {
2863  mpz_ptr aa,bb;
2864  *s=ALLOC_RNUMBER();
2865  mpz_init((*s)->z); (*s)->s=3;
2866  (*t)=ALLOC_RNUMBER();
2867  mpz_init((*t)->z); (*t)->s=3;
2868  number g=ALLOC_RNUMBER();
2869  mpz_init(g->z); g->s=3;
2870  #ifdef LDEBUG
2871  g->debug=123456;
2872  (*s)->debug=123456;
2873  (*t)->debug=123456;
2874  #endif
2875  if (SR_HDL(a) & SR_INT)
2876  {
2877  aa=(mpz_ptr)omAlloc(sizeof(mpz_t));
2878  mpz_init_set_si(aa,SR_TO_INT(a));
2879  }
2880  else
2881  {
2882  aa=a->z;
2883  }
2884  if (SR_HDL(b) & SR_INT)
2885  {
2886  bb=(mpz_ptr)omAlloc(sizeof(mpz_t));
2887  mpz_init_set_si(bb,SR_TO_INT(b));
2888  }
2889  else
2890  {
2891  bb=b->z;
2892  }
2893  mpz_gcdext(g->z,(*s)->z,(*t)->z,aa,bb);
2894  g=nlShort3(g);
2895  (*s)=nlShort3((*s));
2896  (*t)=nlShort3((*t));
2897  if (SR_HDL(a) & SR_INT)
2898  {
2899  mpz_clear(aa);
2900  omFreeSize(aa, sizeof(mpz_t));
2901  }
2902  if (SR_HDL(b) & SR_INT)
2903  {
2904  mpz_clear(bb);
2905  omFreeSize(bb, sizeof(mpz_t));
2906  }
2907  return g;
2908 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
const poly a
Definition: syzextra.cc:212
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
g
Definition: cfModGcd.cc:4031
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define SR_TO_INT(SR)
Definition: longrat.h:67
static number nlShort3(number x)
Definition: longrat.cc:112
#define SR_INT
Definition: longrat.h:65
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
#define SR_HDL(A)
Definition: tgb.cc:35
const poly b
Definition: syzextra.cc:213
number nlFarey ( number  nN,
number  nP,
const coeffs  CF 
)

Definition at line 2792 of file longrat.cc.

2793 {
2794  mpz_t tmp; mpz_init(tmp);
2795  mpz_t A,B,C,D,E,N,P;
2796  if (SR_HDL(nN) & SR_INT) mpz_init_set_si(N,SR_TO_INT(nN));
2797  else mpz_init_set(N,nN->z);
2798  if (SR_HDL(nP) & SR_INT) mpz_init_set_si(P,SR_TO_INT(nP));
2799  else mpz_init_set(P,nP->z);
2800  assume(!mpz_isNeg(P));
2801  if (mpz_isNeg(N)) mpz_add(N,N,P);
2802  mpz_init_set_si(A,0L);
2803  mpz_init_set_ui(B,(unsigned long)1);
2804  mpz_init_set_si(C,0L);
2805  mpz_init(D);
2806  mpz_init_set(E,P);
2807  number z=INT_TO_SR(0);
2808  while(mpz_cmp_si(N,0L)!=0)
2809  {
2810  mpz_mul(tmp,N,N);
2811  mpz_add(tmp,tmp,tmp);
2812  if (mpz_cmp(tmp,P)<0)
2813  {
2814  if (mpz_isNeg(B))
2815  {
2816  mpz_neg(B,B);
2817  mpz_neg(N,N);
2818  }
2819  // check for gcd(N,B)==1
2820  mpz_gcd(tmp,N,B);
2821  if (mpz_cmp_ui(tmp,1)==0)
2822  {
2823  // return N/B
2824  z=ALLOC_RNUMBER();
2825  #ifdef LDEBUG
2826  z->debug=123456;
2827  #endif
2828  mpz_init_set(z->z,N);
2829  mpz_init_set(z->n,B);
2830  z->s = 0;
2831  nlNormalize(z,r);
2832  }
2833  else
2834  {
2835  // return nN (the input) instead of "fail"
2836  z=nlCopy(nN,r);
2837  }
2838  break;
2839  }
2840  //mpz_mod(D,E,N);
2841  //mpz_div(tmp,E,N);
2842  mpz_divmod(tmp,D,E,N);
2843  mpz_mul(tmp,tmp,B);
2844  mpz_sub(C,A,tmp);
2845  mpz_set(E,N);
2846  mpz_set(N,D);
2847  mpz_set(A,B);
2848  mpz_set(B,C);
2849  }
2850  mpz_clear(tmp);
2851  mpz_clear(A);
2852  mpz_clear(B);
2853  mpz_clear(C);
2854  mpz_clear(D);
2855  mpz_clear(E);
2856  mpz_clear(N);
2857  mpz_clear(P);
2858  return z;
2859 }
#define D(A)
Definition: gentable.cc:119
#define INT_TO_SR(INT)
Definition: longrat.h:66
const ring r
Definition: syzextra.cc:208
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:49
#define assume(x)
Definition: mod2.h:405
#define A
Definition: sirandom.c:23
#define mpz_isNeg(A)
Definition: longrat.cc:159
#define SR_TO_INT(SR)
Definition: longrat.h:67
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1334
REvaluation E(1, terms.length(), IntRandom(25))
b *CanonicalForm B
Definition: facBivar.cc:51
#define SR_INT
Definition: longrat.h:65
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
#define SR_HDL(A)
Definition: tgb.cc:35
kBucketDestroy & P
Definition: myNF.cc:191
LINLINE number nlCopy(number a, const coeffs r)
Definition: longrat.cc:2467
number nlGcd ( number  a,
number  b,
const coeffs  r 
)

Definition at line 1192 of file longrat.cc.

1193 {
1194  number result;
1195  nlTest(a, r);
1196  nlTest(b, r);
1197  //nlNormalize(a);
1198  //nlNormalize(b);
1199  if ((a==INT_TO_SR(1L))||(a==INT_TO_SR(-1L))
1200  || (b==INT_TO_SR(1L))||(b==INT_TO_SR(-1L)))
1201  return INT_TO_SR(1L);
1202  if (a==INT_TO_SR(0)) /* gcd(0,b) ->b */
1203  return nlCopy(b,r);
1204  if (b==INT_TO_SR(0)) /* gcd(a,0) -> a */
1205  return nlCopy(a,r);
1206  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
1207  {
1208  long i=SR_TO_INT(a);
1209  long j=SR_TO_INT(b);
1210  if((i==0L)||(j==0L))
1211  return INT_TO_SR(1);
1212  long l;
1213  i=ABS(i);
1214  j=ABS(j);
1215  do
1216  {
1217  l=i%j;
1218  i=j;
1219  j=l;
1220  } while (l!=0L);
1221  if (i==POW_2_28)
1222  result=nlRInit(POW_2_28);
1223  else
1224  result=INT_TO_SR(i);
1225  nlTest(result,r);
1226  return result;
1227  }
1228  if (((!(SR_HDL(a) & SR_INT))&&(a->s<2))
1229  || ((!(SR_HDL(b) & SR_INT))&&(b->s<2))) return INT_TO_SR(1);
1230  if (SR_HDL(a) & SR_INT)
1231  {
1232  LONG aa=ABS(SR_TO_INT(a));
1233  unsigned long t=mpz_gcd_ui(NULL,b->z,(long)aa);
1234  if (t==POW_2_28)
1235  result=nlRInit(POW_2_28);
1236  else
1237  result=INT_TO_SR(t);
1238  }
1239  else
1240  if (SR_HDL(b) & SR_INT)
1241  {
1242  LONG bb=ABS(SR_TO_INT(b));
1243  unsigned long t=mpz_gcd_ui(NULL,a->z,(long)bb);
1244  if (t==POW_2_28)
1245  result=nlRInit(POW_2_28);
1246  else
1247  result=INT_TO_SR(t);
1248  }
1249  else
1250  {
1251  result=ALLOC0_RNUMBER();
1252  result->s = 3;
1253  #ifdef LDEBUG
1254  result->debug=123456;
1255  #endif
1256  mpz_init(result->z);
1257  mpz_gcd(result->z,a->z,b->z);
1258  result=nlShort3(result);
1259  }
1260  nlTest(result, r);
1261  return result;
1262 }
#define INT_TO_SR(INT)
Definition: longrat.h:66
const poly a
Definition: syzextra.cc:212
#define POW_2_28
Definition: longrat.cc:106
number nlRInit(long i)
Definition: longrat.cc:2344
int j
Definition: myNF.cc:70
int i
Definition: cfEzgcd.cc:123
#define SR_TO_INT(SR)
Definition: longrat.h:67
#define NULL
Definition: omList.c:10
static number nlShort3(number x)
Definition: longrat.cc:112
#define ABS(x)
Definition: auxiliary.h:157
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
const poly b
Definition: syzextra.cc:213
LINLINE number nlCopy(number a, const coeffs r)
Definition: longrat.cc:2467
#define LONG
Definition: longrat.cc:108
int l
Definition: cfEzgcd.cc:94
return result
Definition: facAbsBiFact.cc:76
#define ALLOC0_RNUMBER()
Definition: coeffs.h:87
#define nlTest(a, r)
Definition: longrat.cc:90
number nlGetDenom ( number &  n,
const coeffs  r 
)

Definition at line 1488 of file longrat.cc.

1489 {
1490  if (!(SR_HDL(n) & SR_INT))
1491  {
1492  if (n->s==0)
1493  {
1494  nlNormalize(n,r);
1495  }
1496  if (!(SR_HDL(n) & SR_INT))
1497  {
1498  if (n->s!=3)
1499  {
1500  number u=ALLOC_RNUMBER();
1501  u->s=3;
1502 #if defined(LDEBUG)
1503  u->debug=123456;
1504 #endif
1505  mpz_init_set(u->z,n->n);
1506  u=nlShort3_noinline(u);
1507  return u;
1508  }
1509  }
1510  }
1511  return INT_TO_SR(1);
1512 }
#define INT_TO_SR(INT)
Definition: longrat.h:66
number nlShort3_noinline(number x)
Definition: longrat.cc:172
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1334
#define SR_INT
Definition: longrat.h:65
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
#define SR_HDL(A)
Definition: tgb.cc:35
number nlGetNumerator ( number &  n,
const coeffs  r 
)

Definition at line 1517 of file longrat.cc.

1518 {
1519  if (!(SR_HDL(n) & SR_INT))
1520  {
1521  if (n->s==0)
1522  {
1523  nlNormalize(n,r);
1524  }
1525  if (!(SR_HDL(n) & SR_INT))
1526  {
1527  number u=ALLOC_RNUMBER();
1528 #if defined(LDEBUG)
1529  u->debug=123456;
1530 #endif
1531  u->s=3;
1532  mpz_init_set(u->z,n->z);
1533  if (n->s!=3)
1534  {
1535  u=nlShort3_noinline(u);
1536  }
1537  return u;
1538  }
1539  }
1540  return n; // imm. int
1541 }
number nlShort3_noinline(number x)
Definition: longrat.cc:172
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1334
#define SR_INT
Definition: longrat.h:65
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
#define SR_HDL(A)
Definition: tgb.cc:35
number nlGetUnit ( number  n,
const coeffs  r 
)

Definition at line 953 of file longrat.cc.

954 {
955  return INT_TO_SR(1);
956 }
#define INT_TO_SR(INT)
Definition: longrat.h:66
void nlGMP ( number &  i,
number  n,
const coeffs  r 
)

Definition at line 1467 of file longrat.cc.

1468 {
1469  // Hier brauche ich einfach die GMP Zahl
1470  nlTest(i, r);
1471  nlNormalize(i, r);
1472  if (SR_HDL(i) & SR_INT)
1473  {
1474  mpz_set_si((mpz_ptr) n, SR_TO_INT(i));
1475  return;
1476  }
1477  if (i->s!=3)
1478  {
1479  WarnS("Omitted denominator during coefficient mapping !");
1480  }
1481  mpz_set((mpz_ptr) n, i->z);
1482 }
#define WarnS
Definition: emacs.cc:81
int i
Definition: cfEzgcd.cc:123
#define SR_TO_INT(SR)
Definition: longrat.h:67
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1334
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
#define nlTest(a, r)
Definition: longrat.cc:90
BOOLEAN nlGreater ( number  a,
number  b,
const coeffs  r 
)

Definition at line 1165 of file longrat.cc.

1166 {
1167  nlTest(a, r);
1168  nlTest(b, r);
1169  number re;
1170  BOOLEAN rr;
1171  re=nlSub(a,b,r);
1172  rr=(!nlIsZero(re,r)) && (nlGreaterZero(re,r));
1173  nlDelete(&re,r);
1174  return rr;
1175 }
LINLINE number nlSub(number la, number li, const coeffs r)
Definition: longrat.cc:2581
const poly a
Definition: syzextra.cc:212
BOOLEAN nlGreaterZero(number za, const coeffs r)
Definition: longrat.cc:1155
LINLINE BOOLEAN nlIsZero(number za, const coeffs r)
Definition: longrat.cc:2447
LINLINE void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2480
int BOOLEAN
Definition: auxiliary.h:131
const poly b
Definition: syzextra.cc:213
#define nlTest(a, r)
Definition: longrat.cc:90
BOOLEAN nlGreaterZero ( number  za,
const coeffs  r 
)

Definition at line 1155 of file longrat.cc.

1156 {
1157  nlTest(a, r);
1158  if (SR_HDL(a) & SR_INT) return SR_HDL(a)>1L /* represents number(0) */;
1159  return (!mpz_isNeg(a->z));
1160 }
const poly a
Definition: syzextra.cc:212
#define mpz_isNeg(A)
Definition: longrat.cc:159
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
#define nlTest(a, r)
Definition: longrat.cc:90
LINLINE number nlInit ( long  i,
const coeffs  r 
)

Definition at line 2420 of file longrat.cc.

2421 {
2422  number n;
2423  #if MAX_NUM_SIZE == 60
2424  if (((i << 3) >> 3) == i) n=INT_TO_SR(i);
2425  else n=nlRInit(i);
2426  #else
2427  LONG ii=(LONG)i;
2428  if ( ((((long)ii)==i) && ((ii << 3) >> 3) == ii )) n=INT_TO_SR(ii);
2429  else n=nlRInit(i);
2430  #endif
2431  nlTest(n, r);
2432  return n;
2433 }
#define INT_TO_SR(INT)
Definition: longrat.h:66
number nlRInit(long i)
Definition: longrat.cc:2344
int i
Definition: cfEzgcd.cc:123
#define LONG
Definition: longrat.cc:108
#define nlTest(a, r)
Definition: longrat.cc:90
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 2358 of file longrat.cc.

2359 {
2360  number z=ALLOC_RNUMBER();
2361 #if defined(LDEBUG)
2362  z->debug=123456;
2363 #endif
2364  mpz_init_set_si(z->z,(long)i);
2365  mpz_init_set_si(z->n,(long)j);
2366  z->s = 0;
2367  nlNormalize(z,r);
2368  return z;
2369 }
int j
Definition: myNF.cc:70
int i
Definition: cfEzgcd.cc:123
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1334
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
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 2371 of file longrat.cc.

2372 {
2373  number z=ALLOC_RNUMBER();
2374 #if defined(LDEBUG)
2375  z->debug=123456;
2376 #endif
2377  mpz_init_set(z->z,i);
2378  mpz_init_set(z->n,j);
2379  z->s = 0;
2380  nlNormalize(z,r);
2381  return z;
2382 }
int j
Definition: myNF.cc:70
int i
Definition: cfEzgcd.cc:123
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1334
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
BOOLEAN nlInitChar ( coeffs  r,
void *  p 
)

Definition at line 3301 of file longrat.cc.

3302 {
3303  r->is_domain=TRUE;
3304  r->rep=n_rep_gap_rat;
3305 
3306  //const int ch = (int)(long)(p);
3307 
3308  r->nCoeffIsEqual=nlCoeffIsEqual;
3309  //r->cfKillChar = ndKillChar; /* dummy */
3310  r->cfCoeffString=nlCoeffString;
3311  r->cfCoeffName=nlCoeffName;
3312 
3313  r->cfInitMPZ = nlInitMPZ;
3314  r->cfMPZ = nlMPZ;
3315 
3316  r->cfMult = nlMult;
3317  r->cfSub = nlSub;
3318  r->cfAdd = nlAdd;
3319  if (p==NULL) /* Q */
3320  {
3321  r->is_field=TRUE;
3322  r->cfDiv = nlDiv;
3323  //r->cfGcd = ndGcd_dummy;
3324  r->cfSubringGcd = nlGcd;
3325  }
3326  else /* Z: coeffs_BIGINT */
3327  {
3328  r->is_field=FALSE;
3329  r->cfDiv = nlIntDiv;
3330  r->cfIntMod= nlIntMod;
3331  r->cfGcd = nlGcd;
3332  r->cfDivBy=nlDivBy;
3333  r->cfDivComp = nlDivComp;
3334  r->cfIsUnit = nlIsUnit;
3335  r->cfGetUnit = nlGetUnit;
3336  r->cfQuot1 = nlQuot1;
3337  r->cfLcm = nlLcm;
3338  r->cfXExtGcd=nlXExtGcd;
3339  r->cfQuotRem=nlQuotRem;
3340  }
3341  r->cfExactDiv= nlExactDiv;
3342  r->cfInit = nlInit;
3343  r->cfSize = nlSize;
3344  r->cfInt = nlInt;
3345 
3346  r->cfChineseRemainder=nlChineseRemainderSym;
3347  r->cfFarey=nlFarey;
3348  r->cfInpNeg = nlNeg;
3349  r->cfInvers= nlInvers;
3350  r->cfCopy = nlCopy;
3351  r->cfRePart = nlCopy;
3352  //r->cfImPart = ndReturn0;
3353  r->cfWriteLong = nlWrite;
3354  r->cfRead = nlRead;
3355  r->cfNormalize=nlNormalize;
3356  r->cfGreater = nlGreater;
3357  r->cfEqual = nlEqual;
3358  r->cfIsZero = nlIsZero;
3359  r->cfIsOne = nlIsOne;
3360  r->cfIsMOne = nlIsMOne;
3361  r->cfGreaterZero = nlGreaterZero;
3362  r->cfPower = nlPower;
3363  r->cfGetDenom = nlGetDenom;
3364  r->cfGetNumerator = nlGetNumerator;
3365  r->cfExtGcd = nlExtGcd; // only for ring stuff and Z
3366  r->cfNormalizeHelper = nlNormalizeHelper;
3367  r->cfDelete= nlDelete;
3368  r->cfSetMap = nlSetMap;
3369  //r->cfName = ndName;
3370  r->cfInpMult=nlInpMult;
3371  r->cfInpAdd=nlInpAdd;
3372  r->cfCoeffWrite=nlCoeffWrite;
3373 
3374  r->cfClearContent = nlClearContent;
3375  r->cfClearDenominators = nlClearDenominators;
3376 
3377 #ifdef LDEBUG
3378  // debug stuff
3379  r->cfDBTest=nlDBTest;
3380 #endif
3381  r->convSingNFactoryN=nlConvSingNFactoryN;
3382  r->convFactoryNSingN=nlConvFactoryNSingN;
3383 
3384  r->cfRandom=nlRandom;
3385 
3386  // io via ssi
3387  r->cfWriteFd=nlWriteFd;
3388  r->cfReadFd=nlReadFd;
3389 
3390  // the variables: general stuff (required)
3391  r->nNULL = INT_TO_SR(0);
3392  //r->type = n_Q;
3393  r->ch = 0;
3394  r->has_simple_Alloc=FALSE;
3395  r->has_simple_Inverse=FALSE;
3396 
3397  // variables for this type of coeffs:
3398  // (none)
3399  return FALSE;
3400 }
number nlGetUnit(number n, const coeffs r)
Definition: longrat.cc:953
LINLINE number nlSub(number la, number li, const coeffs r)
Definition: longrat.cc:2581
static void nlClearDenominators(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs cf)
Definition: longrat.cc:3050
#define INT_TO_SR(INT)
Definition: longrat.h:66
BOOLEAN nlCoeffIsEqual(const coeffs r, n_coeffType n, void *p)
Definition: longrat.cc:3265
char * nlCoeffName(const coeffs r)
Definition: longrat.cc:3144
static number nlConvFactoryNSingN(const CanonicalForm f, const coeffs r)
Definition: longrat.cc:378
BOOLEAN nlGreaterZero(number za, const coeffs r)
Definition: longrat.cc:1155
#define FALSE
Definition: auxiliary.h:140
static void nlMPZ(mpz_t m, number &n, const coeffs r)
Definition: longrat.cc:2633
return P p
Definition: myNF.cc:203
number nlNormalizeHelper(number a, number b, const coeffs r)
Definition: longrat.cc:1378
LINLINE void nlInpAdd(number &a, number b, const coeffs r)
Definition: longrat.cc:2533
number nlGetDenom(number &n, const coeffs r)
Definition: longrat.cc:1488
void nlWrite(number a, const coeffs r)
Definition: longrat0.cc:116
int nlSize(number a, const coeffs)
Definition: longrat.cc:576
LINLINE number nlAdd(number la, number li, const coeffs r)
Definition: longrat.cc:2515
BOOLEAN nlIsMOne(number a, const coeffs r)
Definition: longrat.cc:1180
void nlCoeffWrite(const coeffs r, BOOLEAN details)
Definition: longrat.cc:2910
number nlIntDiv(number a, number b, const coeffs r)
Definition: longrat.cc:786
number nlGcd(number a, number b, const coeffs r)
Definition: longrat.cc:1192
#define TRUE
Definition: auxiliary.h:144
coeffs nlQuot1(number c, const coeffs r)
Definition: longrat.cc:958
const char * nlRead(const char *s, number *a, const coeffs r)
Definition: longrat0.cc:57
number nlIntMod(number a, number b, const coeffs r)
Definition: longrat.cc:867
BOOLEAN nlGreater(number a, number b, const coeffs r)
Definition: longrat.cc:1165
static number nlInitMPZ(mpz_t m, const coeffs)
Definition: longrat.cc:2642
LINLINE BOOLEAN nlIsOne(number a, const coeffs r)
Definition: longrat.cc:2438
static number nlLcm(number a, number b, const coeffs r)
Definition: longrat.cc:3277
LINLINE number nlNeg(number za, const coeffs r)
Definition: longrat.cc:2496
number nlXExtGcd(number a, number b, number *s, number *t, number *u, number *v, const coeffs r)
Definition: longrat.cc:2654
number nlDiv(number a, number b, const coeffs r)
Definition: longrat.cc:992
LINLINE number nlMult(number a, number b, const coeffs r)
Definition: longrat.cc:2551
number nlInvers(number a, const coeffs r)
Definition: longrat.cc:655
int nlDivComp(number a, number b, const coeffs r)
Definition: longrat.cc:942
LINLINE void nlInpMult(number &a, number b, const coeffs r)
Definition: longrat.cc:2599
static void nlWriteFd(number n, FILE *f, const coeffs)
Definition: longrat.cc:3157
LINLINE BOOLEAN nlEqual(number a, number b, const coeffs r)
Definition: longrat.cc:2411
void nlPower(number x, int exp, number *lu, const coeffs r)
Definition: longrat.cc:1102
number nlQuotRem(number a, number b, number *r, const coeffs R)
Definition: longrat.cc:2706
static number nlReadFd(s_buff f, const coeffs)
Definition: longrat.cc:3203
number nlExtGcd(number a, number b, number *s, number *t, const coeffs)
Definition: longrat.cc:2861
LINLINE BOOLEAN nlIsZero(number za, const coeffs r)
Definition: longrat.cc:2447
static void nlClearContent(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs cf)
Definition: longrat.cc:2959
static CanonicalForm nlConvSingNFactoryN(number n, const BOOLEAN setChar, const coeffs)
Definition: longrat.cc:340
(number), see longrat.h
Definition: coeffs.h:110
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1334
number nlChineseRemainderSym(number *x, number *q, int rl, BOOLEAN sym, CFArray &inv_cache, const coeffs CF)
Definition: longrat.cc:2919
#define NULL
Definition: omList.c:10
static number nlRandom(siRandProc p, number v2, number, const coeffs cf)
Definition: longrat.cc:3287
LINLINE void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2480
BOOLEAN nlDivBy(number a, number b, const coeffs)
Definition: longrat.cc:928
BOOLEAN nlIsUnit(number a, const coeffs)
Definition: longrat.cc:983
long nlInt(number &n, const coeffs r)
Definition: longrat.cc:605
nMapFunc nlSetMap(const coeffs src, const coeffs dst)
Definition: longrat.cc:2307
number nlExactDiv(number a, number b, const coeffs r)
Definition: longrat.cc:735
BOOLEAN nlDBTest(number a, const char *f, const int l)
LINLINE number nlInit(long i, const coeffs r)
Definition: longrat.cc:2420
static char * nlCoeffString(const coeffs r)
Definition: longrat.cc:3150
number nlGetNumerator(number &n, const coeffs r)
Definition: longrat.cc:1517
LINLINE number nlCopy(number a, const coeffs r)
Definition: longrat.cc:2467
number nlFarey(number nN, number nP, const coeffs CF)
Definition: longrat.cc:2792
static number nlInitMPZ ( mpz_t  m,
const coeffs   
)
static

Definition at line 2642 of file longrat.cc.

2643 {
2644  number z = ALLOC_RNUMBER();
2645  z->s = 3;
2646  #ifdef LDEBUG
2647  z->debug=123456;
2648  #endif
2649  mpz_init_set(z->z, m);
2650  z=nlShort3(z);
2651  return z;
2652 }
int m
Definition: cfEzgcd.cc:119
static number nlShort3(number x)
Definition: longrat.cc:112
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
LINLINE void nlInpAdd ( number &  a,
number  b,
const coeffs  r 
)

Definition at line 2533 of file longrat.cc.

2534 {
2535  // a=a+b
2536  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
2537  {
2538  LONG r=SR_HDL(a)+SR_HDL(b)-1L;
2539  if ( ((r << 1) >> 1) == r )
2540  a=(number)(long)r;
2541  else
2542  a=nlRInit(SR_TO_INT(r));
2543  }
2544  else
2545  {
2547  nlTest(a,r);
2548  }
2549 }
const poly a
Definition: syzextra.cc:212
number nlRInit(long i)
Definition: longrat.cc:2344
const ring r
Definition: syzextra.cc:208
void _nlInpAdd_aNoImm_OR_bNoImm(number &a, number b)
Definition: longrat.cc:1827
#define SR_TO_INT(SR)
Definition: longrat.h:67
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
const poly b
Definition: syzextra.cc:213
#define LONG
Definition: longrat.cc:108
#define nlTest(a, r)
Definition: longrat.cc:90
void nlInpGcd ( number &  a,
number  b,
const coeffs  r 
)

Definition at line 2759 of file longrat.cc.

2760 {
2761  if ((SR_HDL(b)|SR_HDL(a))&SR_INT)
2762  {
2763  number n=nlGcd(a,b,r);
2764  nlDelete(&a,r);
2765  a=n;
2766  }
2767  else
2768  {
2769  mpz_gcd(a->z,a->z,b->z);
2771  }
2772 }
const poly a
Definition: syzextra.cc:212
number nlGcd(number a, number b, const coeffs r)
Definition: longrat.cc:1192
number nlShort3_noinline(number x)
Definition: longrat.cc:172
LINLINE void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2480
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
const poly b
Definition: syzextra.cc:213
void nlInpIntDiv ( number &  a,
number  b,
const coeffs  r 
)

Definition at line 2774 of file longrat.cc.

2775 {
2776  if ((SR_HDL(b)|SR_HDL(a))&SR_INT)
2777  {
2778  number n=nlIntDiv(a,b, r);
2779  nlDelete(&a,r);
2780  a=n;
2781  }
2782  else
2783  {
2784  number rr=nlIntMod(a,b,r);
2785  if (SR_HDL(rr) & SR_INT) mpz_sub_ui(a->z,a->z,SR_TO_INT(rr));
2786  else mpz_sub(a->z,a->z,rr->z);
2787  mpz_divexact(a->z,a->z,b->z);
2789  }
2790 }
const poly a
Definition: syzextra.cc:212
number nlIntDiv(number a, number b, const coeffs r)
Definition: longrat.cc:786
number nlIntMod(number a, number b, const coeffs r)
Definition: longrat.cc:867
number nlShort3_noinline(number x)
Definition: longrat.cc:172
#define SR_TO_INT(SR)
Definition: longrat.h:67
LINLINE void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2480
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
const poly b
Definition: syzextra.cc:213
LINLINE void nlInpMult ( number &  a,
number  b,
const coeffs  r 
)

Definition at line 2599 of file longrat.cc.

2600 {
2601  number aa=a;
2602  if (((SR_HDL(b)|SR_HDL(aa))&SR_INT))
2603  {
2604  number n=nlMult(aa,b,r);
2605  nlDelete(&a,r);
2606  a=n;
2607  }
2608  else
2609  {
2610  mpz_mul(aa->z,a->z,b->z);
2611  if (aa->s==3)
2612  {
2613  if(b->s!=3)
2614  {
2615  mpz_init_set(a->n,b->n);
2616  a->s=0;
2617  }
2618  }
2619  else
2620  {
2621  if(b->s!=3)
2622  {
2623  mpz_mul(a->n,a->n,b->n);
2624  }
2625  a->s=0;
2626  }
2627  }
2628 }
const poly a
Definition: syzextra.cc:212
LINLINE number nlMult(number a, number b, const coeffs r)
Definition: longrat.cc:2551
LINLINE void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2480
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
const poly b
Definition: syzextra.cc:213
long nlInt ( number &  n,
const coeffs  r 
)

Definition at line 605 of file longrat.cc.

606 {
607  nlTest(i, r);
608  nlNormalize(i,r);
609  if (SR_HDL(i) & SR_INT)
610  {
611  return SR_TO_INT(i);
612  }
613  if (i->s==3)
614  {
615  if(mpz_size1(i->z)>MP_SMALL) return 0;
616  long ul=mpz_get_si(i->z);
617  if (mpz_cmp_si(i->z,ul)!=0) return 0;
618  return ul;
619  }
620  mpz_t tmp;
621  long ul;
622  mpz_init(tmp);
623  mpz_tdiv_q(tmp,i->z,i->n);
624  if(mpz_size1(tmp)>MP_SMALL) ul=0;
625  else
626  {
627  ul=mpz_get_si(tmp);
628  if (mpz_cmp_si(tmp,ul)!=0) ul=0;
629  }
630  mpz_clear(tmp);
631  return ul;
632 }
#define MP_SMALL
Definition: longrat.cc:157
int i
Definition: cfEzgcd.cc:123
#define SR_TO_INT(SR)
Definition: longrat.h:67
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1334
#define mpz_size1(A)
Definition: si_gmp.h:12
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
#define nlTest(a, r)
Definition: longrat.cc:90
number nlIntDiv ( number  a,
number  b,
const coeffs  r 
)

Definition at line 786 of file longrat.cc.

787 {
788  if (b==INT_TO_SR(0))
789  {
790  WerrorS(nDivBy0);
791  return INT_TO_SR(0);
792  }
793  if (a==INT_TO_SR(0))
794  return INT_TO_SR(0);
795  number u;
796  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
797  {
798  /* the small int -(1<<28) divided by -1 is the large int (1<<28) */
799  if ((a==INT_TO_SR(-(POW_2_28)))&&(b==INT_TO_SR(-1L)))
800  {
801  return nlRInit(POW_2_28);
802  }
803  LONG aa=SR_TO_INT(a);
804  LONG bb=SR_TO_INT(b);
805  LONG rr=aa%bb;
806  if (rr<0) rr+=ABS(bb);
807  LONG cc=(aa-rr)/bb;
808  return INT_TO_SR(cc);
809  }
810  number aa=NULL;
811  if (SR_HDL(a) & SR_INT)
812  {
813  /* the small int -(1<<28) divided by 2^28 is 1 */
814  if (a==INT_TO_SR(-(POW_2_28)))
815  {
816  if(mpz_cmp_si(b->z,(POW_2_28))==0)
817  {
818  return INT_TO_SR(-1);
819  }
820  }
821  aa=nlRInit(SR_TO_INT(a));
822  a=aa;
823  }
824  number bb=NULL;
825  if (SR_HDL(b) & SR_INT)
826  {
827  bb=nlRInit(SR_TO_INT(b));
828  b=bb;
829  }
830  u=ALLOC_RNUMBER();
831 #if defined(LDEBUG)
832  u->debug=123456;
833 #endif
834  assume(a->s==3);
835  assume(b->s==3);
836  mpz_init_set(u->z,a->z);
837  /* u=u/b */
838  u->s = 3;
839  number rr=nlIntMod(a,b,r);
840  if (SR_HDL(rr) & SR_INT) mpz_sub_ui(u->z,u->z,SR_TO_INT(rr));
841  else mpz_sub(u->z,u->z,rr->z);
842  mpz_divexact(u->z,u->z,b->z);
843  if (aa!=NULL)
844  {
845  mpz_clear(aa->z);
846 #if defined(LDEBUG)
847  aa->debug=654324;
848 #endif
849  FREE_RNUMBER(aa);
850  }
851  if (bb!=NULL)
852  {
853  mpz_clear(bb->z);
854 #if defined(LDEBUG)
855  bb->debug=654324;
856 #endif
857  FREE_RNUMBER(bb);
858  }
859  u=nlShort3(u);
860  nlTest(u,r);
861  return u;
862 }
#define INT_TO_SR(INT)
Definition: longrat.h:66
const poly a
Definition: syzextra.cc:212
#define POW_2_28
Definition: longrat.cc:106
number nlRInit(long i)
Definition: longrat.cc:2344
#define FREE_RNUMBER(x)
Definition: coeffs.h:85
void WerrorS(const char *s)
Definition: feFopen.cc:24
number nlIntMod(number a, number b, const coeffs r)
Definition: longrat.cc:867
#define assume(x)
Definition: mod2.h:405
const char *const nDivBy0
Definition: numbers.h:83
#define SR_TO_INT(SR)
Definition: longrat.h:67
#define NULL
Definition: omList.c:10
static number nlShort3(number x)
Definition: longrat.cc:112
#define ABS(x)
Definition: auxiliary.h:157
#define SR_INT
Definition: longrat.h:65
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
#define SR_HDL(A)
Definition: tgb.cc:35
const poly b
Definition: syzextra.cc:213
#define LONG
Definition: longrat.cc:108
#define nlTest(a, r)
Definition: longrat.cc:90
number nlIntMod ( number  a,
number  b,
const coeffs  r 
)

Definition at line 867 of file longrat.cc.

868 {
869  if (b==INT_TO_SR(0))
870  {
871  WerrorS(nDivBy0);
872  return INT_TO_SR(0);
873  }
874  if (a==INT_TO_SR(0))
875  return INT_TO_SR(0);
876  number u;
877  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
878  {
879  LONG aa=SR_TO_INT(a);
880  LONG bb=SR_TO_INT(b);
881  LONG c=aa % bb;
882  if (c<0) c+=ABS(bb);
883  return INT_TO_SR(c);
884  }
885  if (SR_HDL(a) & SR_INT)
886  {
887  LONG ai=SR_TO_INT(a);
888  mpz_t aa;
889  mpz_init_set_si(aa, ai);
890  u=ALLOC_RNUMBER();
891 #if defined(LDEBUG)
892  u->debug=123456;
893 #endif
894  u->s = 3;
895  mpz_init(u->z);
896  mpz_mod(u->z, aa, b->z);
897  mpz_clear(aa);
898  u=nlShort3(u);
899  nlTest(u,r);
900  return u;
901  }
902  number bb=NULL;
903  if (SR_HDL(b) & SR_INT)
904  {
905  bb=nlRInit(SR_TO_INT(b));
906  b=bb;
907  }
908  u=ALLOC_RNUMBER();
909 #if defined(LDEBUG)
910  u->debug=123456;
911 #endif
912  mpz_init(u->z);
913  u->s = 3;
914  mpz_mod(u->z, a->z, b->z);
915  if (bb!=NULL)
916  {
917  mpz_clear(bb->z);
918 #if defined(LDEBUG)
919  bb->debug=654324;
920 #endif
921  FREE_RNUMBER(bb);
922  }
923  u=nlShort3(u);
924  nlTest(u,r);
925  return u;
926 }
#define INT_TO_SR(INT)
Definition: longrat.h:66
const poly a
Definition: syzextra.cc:212
number nlRInit(long i)
Definition: longrat.cc:2344
#define FREE_RNUMBER(x)
Definition: coeffs.h:85
void WerrorS(const char *s)
Definition: feFopen.cc:24
const char *const nDivBy0
Definition: numbers.h:83
#define SR_TO_INT(SR)
Definition: longrat.h:67
#define NULL
Definition: omList.c:10
static number nlShort3(number x)
Definition: longrat.cc:112
#define ABS(x)
Definition: auxiliary.h:157
#define SR_INT
Definition: longrat.h:65
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
#define SR_HDL(A)
Definition: tgb.cc:35
const poly b
Definition: syzextra.cc:213
#define LONG
Definition: longrat.cc:108
#define nlTest(a, r)
Definition: longrat.cc:90
number nlInvers ( number  a,
const coeffs  r 
)

Definition at line 655 of file longrat.cc.

656 {
657  nlTest(a, r);
658  number n;
659  if (SR_HDL(a) & SR_INT)
660  {
661  if ((a==INT_TO_SR(1L)) || (a==INT_TO_SR(-1L)))
662  {
663  return a;
664  }
665  if (nlIsZero(a,r))
666  {
667  WerrorS(nDivBy0);
668  return INT_TO_SR(0);
669  }
670  n=ALLOC_RNUMBER();
671 #if defined(LDEBUG)
672  n->debug=123456;
673 #endif
674  n->s=1;
675  if (((long)a)>0L)
676  {
677  mpz_init_set_si(n->z,1L);
678  mpz_init_set_si(n->n,(long)SR_TO_INT(a));
679  }
680  else
681  {
682  mpz_init_set_si(n->z,-1L);
683  mpz_init_set_si(n->n,(long)-SR_TO_INT(a));
684  }
685  nlTest(n, r);
686  return n;
687  }
688  n=ALLOC_RNUMBER();
689 #if defined(LDEBUG)
690  n->debug=123456;
691 #endif
692  {
693  mpz_init_set(n->n,a->z);
694  switch (a->s)
695  {
696  case 0:
697  case 1:
698  n->s=a->s;
699  mpz_init_set(n->z,a->n);
700  if (mpz_isNeg(n->n)) /* && n->s<2*/
701  {
702  mpz_neg(n->z,n->z);
703  mpz_neg(n->n,n->n);
704  }
705  if (mpz_cmp_ui(n->n,1L)==0)
706  {
707  mpz_clear(n->n);
708  n->s=3;
709  n=nlShort3(n);
710  }
711  break;
712  case 3:
713  // i.e. |a| > 2^...
714  n->s=1;
715  if (mpz_isNeg(n->n)) /* && n->s<2*/
716  {
717  mpz_neg(n->n,n->n);
718  mpz_init_set_si(n->z,-1L);
719  }
720  else
721  {
722  mpz_init_set_si(n->z,1L);
723  }
724  break;
725  }
726  }
727  nlTest(n, r);
728  return n;
729 }
#define INT_TO_SR(INT)
Definition: longrat.h:66
const poly a
Definition: syzextra.cc:212
void WerrorS(const char *s)
Definition: feFopen.cc:24
#define mpz_isNeg(A)
Definition: longrat.cc:159
const char *const nDivBy0
Definition: numbers.h:83
LINLINE BOOLEAN nlIsZero(number za, const coeffs r)
Definition: longrat.cc:2447
#define SR_TO_INT(SR)
Definition: longrat.h:67
static number nlShort3(number x)
Definition: longrat.cc:112
#define SR_INT
Definition: longrat.h:65
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
#define SR_HDL(A)
Definition: tgb.cc:35
#define nlTest(a, r)
Definition: longrat.cc:90
BOOLEAN nlIsMOne ( number  a,
const coeffs  r 
)

Definition at line 1180 of file longrat.cc.

1181 {
1182 #ifdef LDEBUG
1183  if (a==NULL) return FALSE;
1184  nlTest(a, r);
1185 #endif
1186  return (a==INT_TO_SR(-1L));
1187 }
#define INT_TO_SR(INT)
Definition: longrat.h:66
const poly a
Definition: syzextra.cc:212
#define FALSE
Definition: auxiliary.h:140
#define NULL
Definition: omList.c:10
#define nlTest(a, r)
Definition: longrat.cc:90
LINLINE BOOLEAN nlIsOne ( number  a,
const coeffs  r 
)

Definition at line 2438 of file longrat.cc.

2439 {
2440 #ifdef LDEBUG
2441  if (a==NULL) return FALSE;
2442  nlTest(a, r);
2443 #endif
2444  return (a==INT_TO_SR(1));
2445 }
#define INT_TO_SR(INT)
Definition: longrat.h:66
const poly a
Definition: syzextra.cc:212
#define FALSE
Definition: auxiliary.h:140
#define NULL
Definition: omList.c:10
#define nlTest(a, r)
Definition: longrat.cc:90
BOOLEAN nlIsUnit ( number  a,
const coeffs   
)

Definition at line 983 of file longrat.cc.

984 {
985  return ((SR_HDL(a) & SR_INT) && (ABS(SR_TO_INT(a))==1));
986 }
const poly a
Definition: syzextra.cc:212
#define SR_TO_INT(SR)
Definition: longrat.h:67
#define ABS(x)
Definition: auxiliary.h:157
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
LINLINE BOOLEAN nlIsZero ( number  za,
const coeffs  r 
)

Definition at line 2447 of file longrat.cc.

2448 {
2449  #if 0
2450  if (a==INT_TO_SR(0)) return TRUE;
2451  if ((SR_HDL(a) & SR_INT)||(a==NULL)) return FALSE;
2452  if (mpz_cmp_si(a->z,0L)==0)
2453  {
2454  printf("gmp-0 in nlIsZero\n");
2455  dErrorBreak();
2456  return TRUE;
2457  }
2458  return FALSE;
2459  #else
2460  return (a==INT_TO_SR(0));
2461  #endif
2462 }
#define INT_TO_SR(INT)
Definition: longrat.h:66
const poly a
Definition: syzextra.cc:212
#define FALSE
Definition: auxiliary.h:140
#define TRUE
Definition: auxiliary.h:144
#define NULL
Definition: omList.c:10
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
void dErrorBreak()
Definition: dError.cc:141
static number nlLcm ( number  a,
number  b,
const coeffs  r 
)
static

Definition at line 3277 of file longrat.cc.

3278 {
3279  number g=nlGcd(a,b,r);
3280  number n1=nlMult(a,b,r);
3281  number n2=nlIntDiv(n1,g,r);
3282  nlDelete(&g,r);
3283  nlDelete(&n1,r);
3284  return n2;
3285 }
const poly a
Definition: syzextra.cc:212
number nlIntDiv(number a, number b, const coeffs r)
Definition: longrat.cc:786
number nlGcd(number a, number b, const coeffs r)
Definition: longrat.cc:1192
g
Definition: cfModGcd.cc:4031
LINLINE number nlMult(number a, number b, const coeffs r)
Definition: longrat.cc:2551
LINLINE void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2480
const poly b
Definition: syzextra.cc:213
number nlMapGMP ( number  from,
const coeffs  src,
const coeffs  dst 
)

Definition at line 208 of file longrat.cc.

209 {
210  number z=ALLOC_RNUMBER();
211 #if defined(LDEBUG)
212  z->debug=123456;
213 #endif
214  mpz_init_set(z->z,(mpz_ptr) from);
215  //mpz_init_set_ui(&z->n,1);
216  z->s = 3;
217  z=nlShort3(z);
218  return z;
219 }
static number nlShort3(number x)
Definition: longrat.cc:112
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
static number nlMapLongR ( number  from,
const coeffs  src,
const coeffs  dst 
)
static

Definition at line 435 of file longrat.cc.

436 {
437  assume( getCoeffType(src) == n_long_R );
438 
439  gmp_float *ff=(gmp_float*)from;
440  mpf_t *f=ff->_mpfp();
441  number res;
442  mpz_ptr dest,ndest;
443  int size, i,negative;
444  int e,al,bl;
445  mp_ptr qp,dd,nn;
446 
447  size = (*f)[0]._mp_size;
448  if (size == 0)
449  return INT_TO_SR(0);
450  if(size<0)
451  {
452  negative = 1;
453  size = -size;
454  }
455  else
456  negative = 0;
457 
458  qp = (*f)[0]._mp_d;
459  while(qp[0]==0)
460  {
461  qp++;
462  size--;
463  }
464 
465  e=(*f)[0]._mp_exp-size;
466  res = ALLOC_RNUMBER();
467 #if defined(LDEBUG)
468  res->debug=123456;
469 #endif
470  dest = res->z;
471 
472  if (e<0)
473  {
474  al = dest->_mp_size = size;
475  if (al<2) al = 2;
476  dd = (mp_ptr)omAlloc(sizeof(mp_limb_t)*al);
477  for (i=0;i<size;i++) dd[i] = qp[i];
478  bl = 1-e;
479  nn = (mp_ptr)omAlloc0(sizeof(mp_limb_t)*bl);
480  nn[bl-1] = 1;
481  ndest = res->n;
482  ndest->_mp_d = nn;
483  ndest->_mp_alloc = ndest->_mp_size = bl;
484  res->s = 0;
485  }
486  else
487  {
488  al = dest->_mp_size = size+e;
489  if (al<2) al = 2;
490  dd = (mp_ptr)omAlloc(sizeof(mp_limb_t)*al);
491  for (i=0;i<size;i++) dd[i+e] = qp[i];
492  for (i=0;i<e;i++) dd[i] = 0;
493  res->s = 3;
494  }
495 
496  dest->_mp_d = dd;
497  dest->_mp_alloc = al;
498  if (negative) mpz_neg(dest,dest);
499 
500  if (res->s==0)
501  nlNormalize(res,dst);
502  else if (mpz_size1(res->z)<=MP_SMALL)
503  {
504  // res is new, res->ref is 1
505  res=nlShort3(res);
506  }
507  nlTest(res, dst);
508  return res;
509 }
#define INT_TO_SR(INT)
Definition: longrat.h:66
mpf_t * _mpfp()
Definition: mpr_complex.h:134
bool negative(N n)
Definition: ValueTraits.h:119
#define omAlloc(size)
Definition: omAllocDecl.h:210
real floating point (GMP) numbers
Definition: coeffs.h:34
poly res
Definition: myNF.cc:322
#define MP_SMALL
Definition: longrat.cc:157
#define assume(x)
Definition: mod2.h:405
FILE * f
Definition: checklibs.c:7
int i
Definition: cfEzgcd.cc:123
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1334
#define mpz_size1(A)
Definition: si_gmp.h:12
static number nlShort3(number x)
Definition: longrat.cc:112
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
#define omAlloc0(size)
Definition: omAllocDecl.h:211
#define nlTest(a, r)
Definition: longrat.cc:90
number nlMapMachineInt ( number  from,
const coeffs  ,
const coeffs   
)

Definition at line 233 of file longrat.cc.

234 {
235  number z=ALLOC_RNUMBER();
236 #if defined(LDEBUG)
237  z->debug=123456;
238 #endif
239  mpz_init_set_ui(z->z,(unsigned long) from);
240  z->s = 3;
241  z=nlShort3(z);
242  return z;
243 }
static number nlShort3(number x)
Definition: longrat.cc:112
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
static number nlMapP ( number  from,
const coeffs  src,
const coeffs  dst 
)
static

Definition at line 191 of file longrat.cc.

192 {
193  assume( getCoeffType(src) == n_Zp );
194 
195  number to = nlInit(npInt(from,src), dst); // FIXME? TODO? // extern long npInt (number &n, const coeffs r);
196 
197  return to;
198 }
long npInt(number &n, const coeffs r)
Definition: modulop.cc:143
{p < 2^31}
Definition: coeffs.h:30
clock_t to
Definition: walk.cc:100
#define assume(x)
Definition: mod2.h:405
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
LINLINE number nlInit(long i, const coeffs r)
Definition: longrat.cc:2420
static number nlMapR ( number  from,
const coeffs  src,
const coeffs  dst 
)
static

Definition at line 405 of file longrat.cc.

406 {
407  assume( getCoeffType(src) == n_R );
408 
409  double f=nrFloat(from); // FIXME? TODO? // extern float nrFloat(number n);
410  if (f==0.0) return INT_TO_SR(0);
411  int f_sign=1;
412  if (f<0.0)
413  {
414  f_sign=-1;
415  f=-f;
416  }
417  int i=0;
418  mpz_t h1;
419  mpz_init_set_ui(h1,1);
420  while((FLT_RADIX*f) < DBL_MAX && i<DBL_MANT_DIG)
421  {
422  f*=FLT_RADIX;
423  mpz_mul_ui(h1,h1,FLT_RADIX);
424  i++;
425  }
426  number re=nlRInit(1);
427  mpz_set_d(re->z,f);
428  memcpy(&(re->n),&h1,sizeof(h1));
429  re->s=0; /* not normalized */
430  if(f_sign==-1) re=nlNeg(re,dst);
431  nlNormalize(re,dst);
432  return re;
433 }
#define INT_TO_SR(INT)
Definition: longrat.h:66
number nlRInit(long i)
Definition: longrat.cc:2344
single prescision (6,6) real numbers
Definition: coeffs.h:32
LINLINE number nlNeg(number za, const coeffs r)
Definition: longrat.cc:2496
float nrFloat(number n)
Converts a n_R number into a float. Needed by Maps.
Definition: shortfl.cc:78
#define assume(x)
Definition: mod2.h:405
FILE * f
Definition: checklibs.c:7
int i
Definition: cfEzgcd.cc:123
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1334
number nlMapZ ( number  from,
const coeffs  src,
const coeffs  dst 
)

Definition at line 221 of file longrat.cc.

222 {
223  if (SR_HDL(from) & SR_INT)
224  {
225  return from;
226  }
227  return nlMapGMP(from,src,dst);
228 }
#define SR_INT
Definition: longrat.h:65
number nlMapGMP(number from, const coeffs src, const coeffs dst)
Definition: longrat.cc:208
#define SR_HDL(A)
Definition: tgb.cc:35
number nlModP ( number  q,
const coeffs  Q,
const coeffs  Zp 
)

Definition at line 1425 of file longrat.cc.

1426 {
1427  const int p = n_GetChar(Zp);
1428  assume( p > 0 );
1429 
1430  const long P = p;
1431  assume( P > 0 );
1432 
1433  // embedded long within q => only long numerator has to be converted
1434  // to int (modulo char.)
1435  if (SR_HDL(q) & SR_INT)
1436  {
1437  long i = SR_TO_INT(q);
1438  return n_Init( i, Zp );
1439  }
1440 
1441  const unsigned long PP = p;
1442 
1443  // numerator modulo char. should fit into int
1444  number z = n_Init( static_cast<long>(mpz_fdiv_ui(q->z, PP)), Zp );
1445 
1446  // denominator != 1?
1447  if (q->s!=3)
1448  {
1449  // denominator modulo char. should fit into int
1450  number n = n_Init( static_cast<long>(mpz_fdiv_ui(q->n, PP)), Zp );
1451 
1452  number res = n_Div( z, n, Zp );
1453 
1454  n_Delete(&z, Zp);
1455  n_Delete(&n, Zp);
1456 
1457  return res;
1458  }
1459 
1460  return z;
1461 }
return P p
Definition: myNF.cc:203
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:539
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition: coeffs.h:445
poly res
Definition: myNF.cc:322
#define assume(x)
Definition: mod2.h:405
int i
Definition: cfEzgcd.cc:123
#define SR_TO_INT(SR)
Definition: longrat.h:67
static FORCE_INLINE number n_Div(number a, number b, const coeffs r)
return the quotient of &#39;a&#39; and &#39;b&#39;, i.e., a/b; raises an error if &#39;b&#39; is not invertible in r exceptio...
Definition: coeffs.h:616
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete &#39;p&#39;
Definition: coeffs.h:456
kBucketDestroy & P
Definition: myNF.cc:191
static void nlMPZ ( mpz_t  m,
number &  n,
const coeffs  r 
)
static

Definition at line 2633 of file longrat.cc.

2634 {
2635  nlTest(n, r);
2636  nlNormalize(n, r);
2637  if (SR_HDL(n) & SR_INT) mpz_init_set_si(m, SR_TO_INT(n)); /* n fits in an int */
2638  else mpz_init_set(m, (mpz_ptr)n->z);
2639 }
int m
Definition: cfEzgcd.cc:119
#define SR_TO_INT(SR)
Definition: longrat.h:67
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1334
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
#define nlTest(a, r)
Definition: longrat.cc:90
LINLINE number nlMult ( number  a,
number  b,
const coeffs  r 
)

Definition at line 2551 of file longrat.cc.

2552 {
2553  nlTest(a, R);
2554  nlTest(b, R);
2555  if (a==INT_TO_SR(0)) return INT_TO_SR(0);
2556  if (b==INT_TO_SR(0)) return INT_TO_SR(0);
2557  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
2558  {
2559  LONG r=(LONG)((unsigned LONG)(SR_HDL(a)-1L))*((unsigned LONG)(SR_HDL(b)>>1));
2560  if ((r/(SR_HDL(b)>>1))==(SR_HDL(a)-1L))
2561  {
2562  number u=((number) ((r>>1)+SR_INT));
2563  if (((((LONG)SR_HDL(u))<<1)>>1)==SR_HDL(u)) return (u);
2564  return nlRInit(SR_HDL(u)>>2);
2565  }
2566  number u = _nlMult_aImm_bImm_rNoImm(a, b);
2567  nlTest(u, R);
2568  return u;
2569 
2570  }
2571  number u = _nlMult_aNoImm_OR_bNoImm(a, b);
2572  nlTest(u, R);
2573  return u;
2574 
2575 }
#define INT_TO_SR(INT)
Definition: longrat.h:66
const poly a
Definition: syzextra.cc:212
number _nlMult_aNoImm_OR_bNoImm(number a, number b)
Definition: longrat.cc:2190
number nlRInit(long i)
Definition: longrat.cc:2344
const ring R
Definition: DebugPrint.cc:36
#define SR_INT
Definition: longrat.h:65
number _nlMult_aImm_bImm_rNoImm(number a, number b)
Definition: longrat.cc:2177
#define SR_HDL(A)
Definition: tgb.cc:35
const poly b
Definition: syzextra.cc:213
#define LONG
Definition: longrat.cc:108
#define nlTest(a, r)
Definition: longrat.cc:90
LINLINE number nlNeg ( number  za,
const coeffs  r 
)

Definition at line 2496 of file longrat.cc.

2497 {
2498  nlTest(a, R);
2499  if(SR_HDL(a) &SR_INT)
2500  {
2501  LONG r=SR_TO_INT(a);
2502  if (r==(-(POW_2_28))) a=nlRInit(POW_2_28);
2503  else a=INT_TO_SR(-r);
2504  return a;
2505  }
2506  a = _nlNeg_NoImm(a);
2507  nlTest(a, R);
2508  return a;
2509 
2510 }
#define INT_TO_SR(INT)
Definition: longrat.h:66
const poly a
Definition: syzextra.cc:212
#define POW_2_28
Definition: longrat.cc:106
number nlRInit(long i)
Definition: longrat.cc:2344
const ring R
Definition: DebugPrint.cc:36
#define SR_TO_INT(SR)
Definition: longrat.h:67
number _nlNeg_NoImm(number a)
Definition: longrat.cc:1634
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
#define LONG
Definition: longrat.cc:108
#define nlTest(a, r)
Definition: longrat.cc:90
void nlNormalize ( number &  x,
const coeffs  r 
)

Definition at line 1334 of file longrat.cc.

1335 {
1336  if ((SR_HDL(x) & SR_INT) ||(x==NULL))
1337  return;
1338  if (x->s==3)
1339  {
1341  nlTest(x,r);
1342  return;
1343  }
1344  else if (x->s==0)
1345  {
1346  if (mpz_cmp_si(x->n,1L)==0)
1347  {
1348  mpz_clear(x->n);
1349  x->s=3;
1350  x=nlShort3(x);
1351  }
1352  else
1353  {
1354  mpz_t gcd;
1355  mpz_init(gcd);
1356  mpz_gcd(gcd,x->z,x->n);
1357  x->s=1;
1358  if (mpz_cmp_si(gcd,1L)!=0)
1359  {
1360  mpz_divexact(x->z,x->z,gcd);
1361  mpz_divexact(x->n,x->n,gcd);
1362  if (mpz_cmp_si(x->n,1L)==0)
1363  {
1364  mpz_clear(x->n);
1365  x->s=3;
1367  }
1368  }
1369  mpz_clear(gcd);
1370  }
1371  }
1372  nlTest(x, r);
1373 }
number nlShort3_noinline(number x)
Definition: longrat.cc:172
#define NULL
Definition: omList.c:10
static number nlShort3(number x)
Definition: longrat.cc:112
int gcd(int a, int b)
Definition: walkSupport.cc:839
#define SR_INT
Definition: longrat.h:65
Variable x
Definition: cfModGcd.cc:4023
#define SR_HDL(A)
Definition: tgb.cc:35
#define nlTest(a, r)
Definition: longrat.cc:90
static void nlNormalize_Gcd ( number &  x)
static

Definition at line 1649 of file longrat.cc.

1650 {
1651  mpz_t gcd;
1652  mpz_init(gcd);
1653  mpz_gcd(gcd,x->z,x->n);
1654  x->s=1;
1655  if (mpz_cmp_si(gcd,1L)!=0)
1656  {
1657  mpz_divexact(x->z,x->z,gcd);
1658  mpz_divexact(x->n,x->n,gcd);
1659  if (mpz_cmp_si(x->n,1L)==0)
1660  {
1661  mpz_clear(x->n);
1662  x->s=3;
1664  }
1665  }
1666  mpz_clear(gcd);
1667 }
number nlShort3_noinline(number x)
Definition: longrat.cc:172
int gcd(int a, int b)
Definition: walkSupport.cc:839
Variable x
Definition: cfModGcd.cc:4023
number nlNormalizeHelper ( number  a,
number  b,
const coeffs  r 
)

Definition at line 1378 of file longrat.cc.

1379 {
1380  number result;
1381  nlTest(a, r);
1382  nlTest(b, r);
1383  if ((SR_HDL(b) & SR_INT)
1384  || (b->s==3))
1385  {
1386  // b is 1/(b->n) => b->n is 1 => result is a
1387  return nlCopy(a,r);
1388  }
1389  result=ALLOC_RNUMBER();
1390 #if defined(LDEBUG)
1391  result->debug=123456;
1392 #endif
1393  result->s=3;
1394  mpz_t gcd;
1395  mpz_init(gcd);
1396  mpz_init(result->z);
1397  if (SR_HDL(a) & SR_INT)
1398  mpz_gcd_ui(gcd,b->n,ABS(SR_TO_INT(a)));
1399  else
1400  mpz_gcd(gcd,a->z,b->n);
1401  if (mpz_cmp_si(gcd,1L)!=0)
1402  {
1403  mpz_t bt;
1404  mpz_init_set(bt,b->n);
1405  mpz_divexact(bt,bt,gcd);
1406  if (SR_HDL(a) & SR_INT)
1407  mpz_mul_si(result->z,bt,SR_TO_INT(a));
1408  else
1409  mpz_mul(result->z,bt,a->z);
1410  mpz_clear(bt);
1411  }
1412  else
1413  if (SR_HDL(a) & SR_INT)
1414  mpz_mul_si(result->z,b->n,SR_TO_INT(a));
1415  else
1416  mpz_mul(result->z,b->n,a->z);
1417  mpz_clear(gcd);
1418  result=nlShort3(result);
1419  nlTest(result, r);
1420  return result;
1421 }
void mpz_mul_si(mpz_ptr r, mpz_srcptr s, long int si)
Definition: longrat.cc:179
const poly a
Definition: syzextra.cc:212
#define SR_TO_INT(SR)
Definition: longrat.h:67
static number nlShort3(number x)
Definition: longrat.cc:112
#define ABS(x)
Definition: auxiliary.h:157
int gcd(int a, int b)
Definition: walkSupport.cc:839
#define SR_INT
Definition: longrat.h:65
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
#define SR_HDL(A)
Definition: tgb.cc:35
const poly b
Definition: syzextra.cc:213
LINLINE number nlCopy(number a, const coeffs r)
Definition: longrat.cc:2467
return result
Definition: facAbsBiFact.cc:76
#define nlTest(a, r)
Definition: longrat.cc:90
void nlPower ( number  x,
int  exp,
number *  lu,
const coeffs  r 
)

Definition at line 1102 of file longrat.cc.

1103 {
1104  *u = INT_TO_SR(0); // 0^e, e!=0
1105  if (exp==0)
1106  *u= INT_TO_SR(1);
1107  else if (!nlIsZero(x,r))
1108  {
1109  nlTest(x, r);
1110  number aa=NULL;
1111  if (SR_HDL(x) & SR_INT)
1112  {
1113  aa=nlRInit(SR_TO_INT(x));
1114  x=aa;
1115  }
1116  else if (x->s==0)
1117  nlNormalize(x,r);
1118  *u=ALLOC_RNUMBER();
1119 #if defined(LDEBUG)
1120  (*u)->debug=123456;
1121 #endif
1122  mpz_init((*u)->z);
1123  mpz_pow_ui((*u)->z,x->z,(unsigned long)exp);
1124  if (x->s<2)
1125  {
1126  if (mpz_cmp_si(x->n,1L)==0)
1127  {
1128  x->s=3;
1129  mpz_clear(x->n);
1130  }
1131  else
1132  {
1133  mpz_init((*u)->n);
1134  mpz_pow_ui((*u)->n,x->n,(unsigned long)exp);
1135  }
1136  }
1137  (*u)->s = x->s;
1138  if ((*u)->s==3) *u=nlShort3(*u);
1139  if (aa!=NULL)
1140  {
1141  mpz_clear(aa->z);
1142  FREE_RNUMBER(aa);
1143  }
1144  }
1145 #ifdef LDEBUG
1146  if (exp<0) Print("nlPower: neg. exp. %d\n",exp);
1147  nlTest(*u, r);
1148 #endif
1149 }
#define INT_TO_SR(INT)
Definition: longrat.h:66
#define Print
Definition: emacs.cc:83
number nlRInit(long i)
Definition: longrat.cc:2344
#define FREE_RNUMBER(x)
Definition: coeffs.h:85
LINLINE BOOLEAN nlIsZero(number za, const coeffs r)
Definition: longrat.cc:2447
#define SR_TO_INT(SR)
Definition: longrat.h:67
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1334
#define NULL
Definition: omList.c:10
static number nlShort3(number x)
Definition: longrat.cc:112
#define SR_INT
Definition: longrat.h:65
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
Variable x
Definition: cfModGcd.cc:4023
p exp[i]
Definition: DebugPrint.cc:39
#define SR_HDL(A)
Definition: tgb.cc:35
#define nlTest(a, r)
Definition: longrat.cc:90
coeffs nlQuot1 ( number  c,
const coeffs  r 
)

Definition at line 958 of file longrat.cc.

959 {
960  long ch = r->cfInt(c, r);
961  int p=IsPrime(ch);
962  coeffs rr=NULL;
963  if (((long)p)==ch)
964  {
965  rr = nInitChar(n_Zp,(void*)ch);
966  }
967  #ifdef HAVE_RINGS
968  else
969  {
970  mpz_ptr dummy;
971  dummy = (mpz_ptr) omAlloc(sizeof(mpz_t));
972  mpz_init_set_ui(dummy, ch);
973  ZnmInfo info;
974  info.base = dummy;
975  info.exp = (unsigned long) 1;
976  rr = nInitChar(n_Zn, (void*)&info);
977  }
978  #endif
979  return(rr);
980 }
mpz_ptr base
Definition: rmodulon.h:18
only used if HAVE_RINGS is defined: ?
Definition: coeffs.h:43
return P p
Definition: myNF.cc:203
{p < 2^31}
Definition: coeffs.h:30
#define omAlloc(size)
Definition: omAllocDecl.h:210
The main handler for Singular numbers which are suitable for Singular polynomials.
const ExtensionInfo & info
< [in] sqrfree poly
unsigned long exp
Definition: rmodulon.h:18
int IsPrime(int p)
Definition: prime.cc:61
#define NULL
Definition: omList.c:10
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:327
number nlQuotRem ( number  a,
number  b,
number *  r,
const coeffs  R 
)

Definition at line 2706 of file longrat.cc.

2707 {
2708  assume(SR_TO_INT(b)!=0);
2709  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
2710  {
2711  if (r!=NULL)
2712  *r = INT_TO_SR(SR_TO_INT(a) % SR_TO_INT(b));
2713  return INT_TO_SR(SR_TO_INT(a)/SR_TO_INT(b));
2714  }
2715  else if (SR_HDL(a) & SR_INT)
2716  {
2717  // -2^xx / 2^xx
2718  if ((a==INT_TO_SR(-(POW_2_28)))&&(b==INT_TO_SR(-1L)))
2719  {
2720  if (r!=NULL) *r=INT_TO_SR(0);
2721  return nlRInit(POW_2_28);
2722  }
2723  //a is small, b is not, so q=0, r=a
2724  if (r!=NULL)
2725  *r = a;
2726  return INT_TO_SR(0);
2727  }
2728  else if (SR_HDL(b) & SR_INT)
2729  {
2730  unsigned long rr;
2731  mpz_t qq;
2732  mpz_init(qq);
2733  mpz_t rrr;
2734  mpz_init(rrr);
2735  rr = mpz_divmod_ui(qq, rrr, a->z, (unsigned long)ABS(SR_TO_INT(b)));
2736  mpz_clear(rrr);
2737 
2738  if (r!=NULL)
2739  *r = INT_TO_SR(rr);
2740  if (SR_TO_INT(b)<0)
2741  {
2742  mpz_mul_si(qq, qq, -1);
2743  }
2744  return nlInitMPZ(qq,R);
2745  }
2746  mpz_t qq,rr;
2747  mpz_init(qq);
2748  mpz_init(rr);
2749  mpz_divmod(qq, rr, a->z, b->z);
2750  if (r!=NULL)
2751  *r = nlInitMPZ(rr,R);
2752  else
2753  {
2754  mpz_clear(rr);
2755  }
2756  return nlInitMPZ(qq,R);
2757 }
void mpz_mul_si(mpz_ptr r, mpz_srcptr s, long int si)
Definition: longrat.cc:179
#define INT_TO_SR(INT)
Definition: longrat.h:66
const poly a
Definition: syzextra.cc:212
#define POW_2_28
Definition: longrat.cc:106
number nlRInit(long i)
Definition: longrat.cc:2344
static number nlInitMPZ(mpz_t m, const coeffs)
Definition: longrat.cc:2642
const ring r
Definition: syzextra.cc:208
#define assume(x)
Definition: mod2.h:405
#define SR_TO_INT(SR)
Definition: longrat.h:67
#define NULL
Definition: omList.c:10
#define ABS(x)
Definition: auxiliary.h:157
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
const poly b
Definition: syzextra.cc:213
static number nlRandom ( siRandProc  p,
number  v2,
number  ,
const coeffs  cf 
)
static

Definition at line 3287 of file longrat.cc.

3288 {
3289  number a=nlInit(p(),cf);
3290  if (v2!=NULL)
3291  {
3292  number b=nlInit(p(),cf);
3293  number c=nlDiv(a,b,cf);
3294  nlDelete(&b,cf);
3295  nlDelete(&a,cf);
3296  a=c;
3297  }
3298  return a;
3299 }
const poly a
Definition: syzextra.cc:212
return P p
Definition: myNF.cc:203
number nlDiv(number a, number b, const coeffs r)
Definition: longrat.cc:992
#define NULL
Definition: omList.c:10
LINLINE void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2480
LINLINE number nlInit(long i, const coeffs r)
Definition: longrat.cc:2420
const poly b
Definition: syzextra.cc:213
const char* nlRead ( const char *  s,
number *  a,
const coeffs  r 
)

Definition at line 57 of file longrat0.cc.

58 {
59  if (*s<'0' || *s>'9')
60  {
61  *a = INT_TO_SR(1); /* nlInit(1) */
62  return s;
63  }
64  *a=(number)ALLOC_RNUMBER();
65  {
66  (*a)->s = 3;
67 #if defined(LDEBUG)
68  (*a)->debug=123456;
69 #endif
70  mpz_ptr z=(*a)->z;
71  mpz_ptr n=(*a)->n;
72  mpz_init(z);
73  s = nlEatLong((char *)s, z);
74  if (*s == '/')
75  {
76  mpz_init(n);
77  (*a)->s = 0;
78  s++;
79  s = nlEatLong((char *)s, n);
80  if (mpz_cmp_si(n,0L)==0)
81  {
83  mpz_clear(n);
84  (*a)->s = 3;
85  }
86  else if (mpz_cmp_si(n,1L)==0)
87  {
88  mpz_clear(n);
89  (*a)->s=3;
90  }
91  }
92  if (mpz_cmp_si(z,0L)==0)
93  {
94  mpz_clear(z);
95  FREE_RNUMBER(*a);
96  *a=INT_TO_SR(0);
97  }
98  else if ((*a)->s==3)
99  {
100  number nlShort3_noinline(number x);
101  *a=nlShort3_noinline(*a);
102  }
103  else
104  {
105  number aa=*a;
106  nlNormalize(aa,r); // FIXME? TODO? // extern void nlNormalize(number &x, const coeffs r);
107  *a=aa;
108  }
109  }
110  return s;
111 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
#define INT_TO_SR(INT)
Definition: longrat.h:66
const poly a
Definition: syzextra.cc:212
#define FREE_RNUMBER(x)
Definition: coeffs.h:85
void WerrorS(const char *s)
Definition: feFopen.cc:24
const char *const nDivBy0
Definition: numbers.h:83
number nlShort3_noinline(number x)
Definition: longrat.cc:172
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1334
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
Variable x
Definition: cfModGcd.cc:4023
static const char * nlEatLong(char *s, mpz_ptr i)
Definition: longrat0.cc:35
static number nlReadFd ( s_buff  f,
const coeffs   
)
static

Definition at line 3203 of file longrat.cc.

3204 {
3205  int sub_type=-1;
3206  sub_type=s_readint(f);
3207  switch(sub_type)
3208  {
3209  case 0:
3210  case 1:
3211  {// read mpz_t, mpz_t
3212  number n=nlRInit(0);
3213  mpz_init(n->n);
3214  s_readmpz(f,n->z);
3215  s_readmpz(f,n->n);
3216  n->s=sub_type;
3217  return n;
3218  }
3219 
3220  case 3:
3221  {// read mpz_t
3222  number n=nlRInit(0);
3223  s_readmpz(f,n->z);
3224  n->s=3; /*sub_type*/
3225  #if SIZEOF_LONG == 8
3226  n=nlShort3(n);
3227  #endif
3228  return n;
3229  }
3230  case 4:
3231  {
3232  LONG dd=s_readlong(f);
3233  //#if SIZEOF_LONG == 8
3234  return INT_TO_SR(dd);
3235  //#else
3236  //return nlInit(dd,NULL);
3237  //#endif
3238  }
3239  case 5:
3240  case 6:
3241  {// read raw mpz_t, mpz_t
3242  number n=nlRInit(0);
3243  mpz_init(n->n);
3244  s_readmpz_base (f,n->z, SSI_BASE);
3245  s_readmpz_base (f,n->n, SSI_BASE);
3246  n->s=sub_type-5;
3247  return n;
3248  }
3249  case 8:
3250  {// read raw mpz_t
3251  number n=nlRInit(0);
3252  s_readmpz_base (f,n->z, SSI_BASE);
3253  n->s=sub_type=3; /*subtype-5*/
3254  #if SIZEOF_LONG == 8
3255  n=nlShort3(n);
3256  #endif
3257  return n;
3258  }
3259 
3260  default: Werror("error in reading number: invalid subtype %d",sub_type);
3261  return NULL;
3262  }
3263  return NULL;
3264 }
#define INT_TO_SR(INT)
Definition: longrat.h:66
number nlRInit(long i)
Definition: longrat.cc:2344
void s_readmpz_base(s_buff F, mpz_ptr a, int base)
Definition: s_buff.cc:217
void s_readmpz(s_buff F, mpz_t a)
Definition: s_buff.cc:192
int s_readint(s_buff F)
Definition: s_buff.cc:120
#define SSI_BASE
Definition: auxiliary.h:177
FILE * f
Definition: checklibs.c:7
#define NULL
Definition: omList.c:10
static number nlShort3(number x)
Definition: longrat.cc:112
long s_readlong(s_buff F)
Definition: s_buff.cc:148
void Werror(const char *fmt,...)
Definition: reporter.cc:199
#define LONG
Definition: longrat.cc:108
number nlRInit ( long  i)

Definition at line 2344 of file longrat.cc.

2345 {
2346  number z=ALLOC_RNUMBER();
2347 #if defined(LDEBUG)
2348  z->debug=123456;
2349 #endif
2350  mpz_init_set_si(z->z,i);
2351  z->s = 3;
2352  return z;
2353 }
int i
Definition: cfEzgcd.cc:123
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
nMapFunc nlSetMap ( const coeffs  src,
const coeffs  dst 
)

Definition at line 2307 of file longrat.cc.

2308 {
2309  if (src->rep==n_rep_gap_rat) /*Q, coeffs_BIGINT */
2310  {
2311  return ndCopyMap;
2312  }
2313  if ((src->rep==n_rep_int) && nCoeff_is_Zp(src))
2314  {
2315  return nlMapP;
2316  }
2317  if ((src->rep==n_rep_float) && nCoeff_is_R(src))
2318  {
2319  return nlMapR;
2320  }
2321  if ((src->rep==n_rep_gmp_float) && nCoeff_is_long_R(src))
2322  {
2323  return nlMapLongR; /* long R -> Q */
2324  }
2325 #ifdef HAVE_RINGS
2326  if (src->rep==n_rep_gmp) // nCoeff_is_Ring_Z(src) || nCoeff_is_Ring_PtoM(src) || nCoeff_is_Ring_ModN(src))
2327  {
2328  return nlMapGMP;
2329  }
2330  if (src->rep==n_rep_gap_gmp)
2331  {
2332  return nlMapZ;
2333  }
2334  if ((src->rep==n_rep_int) && nCoeff_is_Ring_2toM(src))
2335  {
2336  return nlMapMachineInt;
2337  }
2338 #endif
2339  return NULL;
2340 }
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition: coeffs.h:823
number ndCopyMap(number a, const coeffs aRing, const coeffs r)
Definition: numbers.cc:239
static FORCE_INLINE BOOLEAN nCoeff_is_long_R(const coeffs r)
Definition: coeffs.h:894
static FORCE_INLINE BOOLEAN nCoeff_is_R(const coeffs r)
Definition: coeffs.h:839
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_2toM(const coeffs r)
Definition: coeffs.h:746
(), see rinteger.h, new impl.
Definition: coeffs.h:111
number nlMapZ(number from, const coeffs src, const coeffs dst)
Definition: longrat.cc:221
static number nlMapP(number from, const coeffs src, const coeffs dst)
Definition: longrat.cc:191
static number nlMapLongR(number from, const coeffs src, const coeffs dst)
Definition: longrat.cc:435
(mpz_ptr), see rmodulon,h
Definition: coeffs.h:114
(number), see longrat.h
Definition: coeffs.h:110
#define NULL
Definition: omList.c:10
(gmp_float), see
Definition: coeffs.h:116
number nlMapGMP(number from, const coeffs src, const coeffs dst)
Definition: longrat.cc:208
(int), see modulop.h
Definition: coeffs.h:109
number nlMapMachineInt(number from, const coeffs, const coeffs)
Definition: longrat.cc:233
static number nlMapR(number from, const coeffs src, const coeffs dst)
Definition: longrat.cc:405
(float), see shortfl.h
Definition: coeffs.h:115
number nlShort1 ( number  x)

Definition at line 1313 of file longrat.cc.

1314 {
1315  assume(x->s<2);
1316  if (mpz_cmp_ui(x->z,0L)==0)
1317  {
1318  _nlDelete_NoImm(&x);
1319  return INT_TO_SR(0);
1320  }
1321  if (x->s<2)
1322  {
1323  if (mpz_cmp(x->z,x->n)==0)
1324  {
1325  _nlDelete_NoImm(&x);
1326  return INT_TO_SR(1);
1327  }
1328  }
1329  return x;
1330 }
#define INT_TO_SR(INT)
Definition: longrat.h:66
#define assume(x)
Definition: mod2.h:405
void _nlDelete_NoImm(number *a)
Definition: longrat.cc:1616
Variable x
Definition: cfModGcd.cc:4023
static number nlShort3 ( number  x)
inlinestatic

Definition at line 112 of file longrat.cc.

113 {
114  assume(x->s==3);
115  if (mpz_cmp_ui(x->z,0L)==0)
116  {
117  mpz_clear(x->z);
118  FREE_RNUMBER(x);
119  return INT_TO_SR(0);
120  }
121  if (mpz_size1(x->z)<=MP_SMALL)
122  {
123  LONG ui=mpz_get_si(x->z);
124  if ((((ui<<3)>>3)==ui)
125  && (mpz_cmp_si(x->z,(long)ui)==0))
126  {
127  mpz_clear(x->z);
128  FREE_RNUMBER(x);
129  return INT_TO_SR(ui);
130  }
131  }
132  return x;
133 }
#define INT_TO_SR(INT)
Definition: longrat.h:66
#define FREE_RNUMBER(x)
Definition: coeffs.h:85
#define MP_SMALL
Definition: longrat.cc:157
#define assume(x)
Definition: mod2.h:405
#define mpz_size1(A)
Definition: si_gmp.h:12
Variable x
Definition: cfModGcd.cc:4023
#define LONG
Definition: longrat.cc:108
number nlShort3_noinline ( number  x)

Definition at line 172 of file longrat.cc.

173 {
174  return nlShort3(x);
175 }
static number nlShort3(number x)
Definition: longrat.cc:112
Variable x
Definition: cfModGcd.cc:4023
int nlSize ( number  a,
const coeffs   
)

Definition at line 576 of file longrat.cc.

577 {
578  if (a==INT_TO_SR(0))
579  return 0; /* rational 0*/
580  if (SR_HDL(a) & SR_INT)
581  return 1; /* immediate int */
582  int s=a->z[0]._mp_alloc;
583 // while ((s>0) &&(a->z._mp_d[s]==0L)) s--;
584 //#if SIZEOF_LONG == 8
585 // if (a->z._mp_d[s] < (unsigned long)0x100000000L) s=s*2-1;
586 // else s *=2;
587 //#endif
588 // s++;
589  if (a->s<2)
590  {
591  int d=a->n[0]._mp_alloc;
592 // while ((d>0) && (a->n._mp_d[d]==0L)) d--;
593 //#if SIZEOF_LONG == 8
594 // if (a->n._mp_d[d] < (unsigned long)0x100000000L) d=d*2-1;
595 // else d *=2;
596 //#endif
597  s+=d;
598  }
599  return s;
600 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
#define INT_TO_SR(INT)
Definition: longrat.h:66
const poly a
Definition: syzextra.cc:212
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
LINLINE number nlSub ( number  la,
number  li,
const coeffs  r 
)

Definition at line 2581 of file longrat.cc.

2582 {
2583  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
2584  {
2585  LONG r=SR_HDL(a)-SR_HDL(b)+1;
2586  if ( ((r << 1) >> 1) == r )
2587  {
2588  return (number)(long)r;
2589  }
2590  else
2591  return nlRInit(SR_TO_INT(r));
2592  }
2593  number u = _nlSub_aNoImm_OR_bNoImm(a, b);
2594  nlTest(u, r);
2595  return u;
2596 
2597 }
const poly a
Definition: syzextra.cc:212
number nlRInit(long i)
Definition: longrat.cc:2344
#define SR_TO_INT(SR)
Definition: longrat.h:67
#define SR_INT
Definition: longrat.h:65
number _nlSub_aNoImm_OR_bNoImm(number a, number b)
Definition: longrat.cc:1966
#define SR_HDL(A)
Definition: tgb.cc:35
const poly b
Definition: syzextra.cc:213
#define LONG
Definition: longrat.cc:108
#define nlTest(a, r)
Definition: longrat.cc:90
void nlWrite ( number  a,
const coeffs  r 
)

Definition at line 116 of file longrat0.cc.

117 {
118  char *s,*z;
119  if (SR_HDL(a) & SR_INT)
120  {
121  StringAppend("%ld",SR_TO_INT(a));
122  }
123  else if (a==NULL)
124  {
125  StringAppendS("o");
126  }
127  else
128  {
129  if (a->s==0)
130  {
131  nlNormalize(a,r); // FIXME? TODO? // extern void nlNormalize(number &x, const coeffs r);
132  nlWrite(a,r);
133  return;
134  }
135  int l=mpz_sizeinbase(a->z,10);
136  if (a->s<2) l=si_max(l,(int)mpz_sizeinbase(a->n,10));
137  l+=2;
138  s=(char*)omAlloc(l);
139  z=mpz_get_str(s,10,a->z);
140  StringAppendS(z);
141  if (a->s!=3)
142  {
143  StringAppendS("/");
144  z=mpz_get_str(s,10,a->n);
145  StringAppendS(z);
146  }
147  omFreeSize((void *)s,l);
148  }
149 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
const poly a
Definition: syzextra.cc:212
void nlWrite(number a, const coeffs r)
Definition: longrat0.cc:116
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define SR_HDL(A)
Definition: longrat0.cc:26
#define omAlloc(size)
Definition: omAllocDecl.h:210
void StringAppendS(const char *st)
Definition: reporter.cc:107
static int si_max(const int a, const int b)
Definition: auxiliary.h:166
#define StringAppend
Definition: emacs.cc:82
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1334
#define NULL
Definition: omList.c:10
#define SR_TO_INT(SR)
Definition: longrat0.cc:29
#define SR_INT
Definition: longrat.h:65
int l
Definition: cfEzgcd.cc:94
static void nlWriteFd ( number  n,
FILE *  f,
const coeffs   
)
static

Definition at line 3157 of file longrat.cc.

3158 {
3159  if(SR_HDL(n) & SR_INT)
3160  {
3161  #if SIZEOF_LONG == 4
3162  fprintf(f,"4 %ld ",SR_TO_INT(n));
3163  #else
3164  long nn=SR_TO_INT(n);
3165  if ((nn<POW_2_28_32)&&(nn>= -POW_2_28_32))
3166  {
3167  int nnn=(int)nn;
3168  fprintf(f,"4 %d ",nnn);
3169  }
3170  else
3171  {
3172  mpz_t tmp;
3173  mpz_init_set_si(tmp,nn);
3174  fputs("8 ",f);
3175  mpz_out_str (f,SSI_BASE, tmp);
3176  fputc(' ',f);
3177  mpz_clear(tmp);
3178  }
3179  #endif
3180  }
3181  else if (n->s<2)
3182  {
3183  //gmp_fprintf(f,"%d %Zd %Zd ",n->s,n->z,n->n);
3184  fprintf(f,"%d ",n->s+5);
3185  mpz_out_str (f,SSI_BASE, n->z);
3186  fputc(' ',f);
3187  mpz_out_str (f,SSI_BASE, n->n);
3188  fputc(' ',f);
3189 
3190  //if (d->f_debug!=NULL) gmp_fprintf(d->f_debug,"number: s=%d gmp/gmp \"%Zd %Zd\" ",n->s,n->z,n->n);
3191  }
3192  else /*n->s==3*/
3193  {
3194  //gmp_fprintf(d->f_write,"3 %Zd ",n->z);
3195  fputs("8 ",f);
3196  mpz_out_str (f,SSI_BASE, n->z);
3197  fputc(' ',f);
3198 
3199  //if (d->f_debug!=NULL) gmp_fprintf(d->f_debug,"number: gmp \"%Zd\" ",n->z);
3200  }
3201 }
#define POW_2_28_32
Definition: longrat.cc:107
#define SSI_BASE
Definition: auxiliary.h:177
FILE * f
Definition: checklibs.c:7
#define SR_TO_INT(SR)
Definition: longrat.h:67
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
number nlXExtGcd ( number  a,
number  b,
number *  s,
number *  t,
number *  u,
number *  v,
const coeffs  r 
)

Definition at line 2654 of file longrat.cc.

2655 {
2656  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
2657  {
2658  int uu, vv, x, y;
2659  int g = int_extgcd(SR_TO_INT(a), SR_TO_INT(b), &uu, &vv, &x, &y);
2660  *s = INT_TO_SR(uu);
2661  *t = INT_TO_SR(vv);
2662  *u = INT_TO_SR(x);
2663  *v = INT_TO_SR(y);
2664  return INT_TO_SR(g);
2665  }
2666  else
2667  {
2668  mpz_t aa, bb;
2669  if (SR_HDL(a) & SR_INT)
2670  {
2671  mpz_init_set_si(aa, SR_TO_INT(a));
2672  }
2673  else
2674  {
2675  mpz_init_set(aa, a->z);
2676  }
2677  if (SR_HDL(b) & SR_INT)
2678  {
2679  mpz_init_set_si(bb, SR_TO_INT(b));
2680  }
2681  else
2682  {
2683  mpz_init_set(bb, b->z);
2684  }
2685  mpz_t erg; mpz_t bs; mpz_t bt;
2686  mpz_init(erg);
2687  mpz_init(bs);
2688  mpz_init(bt);
2689 
2690  mpz_gcdext(erg, bs, bt, aa, bb);
2691 
2692  mpz_div(aa, aa, erg);
2693  *u=nlInitMPZ(bb,r);
2694  *u=nlNeg(*u,r);
2695  *v=nlInitMPZ(aa,r);
2696 
2697  mpz_clear(aa);
2698  mpz_clear(bb);
2699 
2700  *s = nlInitMPZ(bs,r);
2701  *t = nlInitMPZ(bt,r);
2702  return nlInitMPZ(erg,r);
2703  }
2704 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
const CanonicalForm int const CFList const Variable & y
Definition: facAbsFact.cc:57
#define INT_TO_SR(INT)
Definition: longrat.h:66
const poly a
Definition: syzextra.cc:212
static int int_extgcd(int a, int b, int *u, int *x, int *v, int *y)
Definition: longrat.cc:1263
g
Definition: cfModGcd.cc:4031
static number nlInitMPZ(mpz_t m, const coeffs)
Definition: longrat.cc:2642
LINLINE number nlNeg(number za, const coeffs r)
Definition: longrat.cc:2496
#define SR_TO_INT(SR)
Definition: longrat.h:67
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
#define SR_INT
Definition: longrat.h:65
Variable x
Definition: cfModGcd.cc:4023
#define SR_HDL(A)
Definition: tgb.cc:35
const poly b
Definition: syzextra.cc:213

Variable Documentation

int n_SwitchChinRem =0

Definition at line 2918 of file longrat.cc.