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 MPZ_DIV(A, B, C)   mpz_tdiv_q((A),(B),(C))
 
#define MPZ_EXACTDIV(A, B, C)   mpz_divexact((A),(B),(C))
 
#define SSI_BASE   16
 

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, 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)
 
BOOLEAN nlDBTest (number a, const char *f, const int l, 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)
 
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)
 
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)
 
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 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_DIV (   A,
  B,
 
)    mpz_tdiv_q((A),(B),(C))

Definition at line 162 of file longrat.cc.

#define MPZ_EXACTDIV (   A,
  B,
 
)    mpz_divexact((A),(B),(C))

Definition at line 163 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.

#define SSI_BASE   16

Definition at line 2992 of file longrat.cc.

Function Documentation

number _nlAdd_aNoImm_OR_bNoImm ( number  a,
number  b 
)

Definition at line 1589 of file longrat.cc.

1590 {
1591  number u=ALLOC_RNUMBER();
1592 #if defined(LDEBUG)
1593  u->debug=123456;
1594 #endif
1595  mpz_init(u->z);
1596  if (SR_HDL(b) & SR_INT)
1597  {
1598  number x=a;
1599  a=b;
1600  b=x;
1601  }
1602  if (SR_HDL(a) & SR_INT)
1603  {
1604  switch (b->s)
1605  {
1606  case 0:
1607  case 1:/* a:short, b:1 */
1608  {
1609  mpz_t x;
1610  mpz_init(x);
1611  mpz_mul_si(x,b->n,SR_TO_INT(a));
1612  mpz_add(u->z,b->z,x);
1613  mpz_clear(x);
1614  if (mpz_cmp_ui(u->z,(long)0)==0)
1615  {
1616  mpz_clear(u->z);
1617  FREE_RNUMBER(u);
1618  return INT_TO_SR(0);
1619  }
1620  if (mpz_cmp(u->z,b->n)==0)
1621  {
1622  mpz_clear(u->z);
1623  FREE_RNUMBER(u);
1624  return INT_TO_SR(1);
1625  }
1626  mpz_init_set(u->n,b->n);
1627  u->s = 0;
1628  break;
1629  }
1630  case 3:
1631  {
1632  if ((long)a>0L)
1633  mpz_add_ui(u->z,b->z,SR_TO_INT(a));
1634  else
1635  mpz_sub_ui(u->z,b->z,-SR_TO_INT(a));
1636  if (mpz_cmp_ui(u->z,(long)0)==0)
1637  {
1638  mpz_clear(u->z);
1639  FREE_RNUMBER(u);
1640  return INT_TO_SR(0);
1641  }
1642  u->s = 3;
1643  u=nlShort3(u);
1644  break;
1645  }
1646  }
1647  }
1648  else
1649  {
1650  switch (a->s)
1651  {
1652  case 0:
1653  case 1:
1654  {
1655  switch(b->s)
1656  {
1657  case 0:
1658  case 1:
1659  {
1660  mpz_t x;
1661  mpz_init(x);
1662 
1663  mpz_mul(x,b->z,a->n);
1664  mpz_mul(u->z,a->z,b->n);
1665  mpz_add(u->z,u->z,x);
1666  mpz_clear(x);
1667 
1668  if (mpz_cmp_ui(u->z,(long)0)==0)
1669  {
1670  mpz_clear(u->z);
1671  FREE_RNUMBER(u);
1672  return INT_TO_SR(0);
1673  }
1674  mpz_init(u->n);
1675  mpz_mul(u->n,a->n,b->n);
1676  if (mpz_cmp(u->z,u->n)==0)
1677  {
1678  mpz_clear(u->z);
1679  mpz_clear(u->n);
1680  FREE_RNUMBER(u);
1681  return INT_TO_SR(1);
1682  }
1683  u->s = 0;
1684  break;
1685  }
1686  case 3: /* a:1 b:3 */
1687  {
1688  mpz_mul(u->z,b->z,a->n);
1689  mpz_add(u->z,u->z,a->z);
1690  if (mpz_cmp_ui(u->z,(long)0)==0)
1691  {
1692  mpz_clear(u->z);
1693  FREE_RNUMBER(u);
1694  return INT_TO_SR(0);
1695  }
1696  if (mpz_cmp(u->z,a->n)==0)
1697  {
1698  mpz_clear(u->z);
1699  FREE_RNUMBER(u);
1700  return INT_TO_SR(1);
1701  }
1702  mpz_init_set(u->n,a->n);
1703  u->s = 0;
1704  break;
1705  }
1706  } /*switch (b->s) */
1707  break;
1708  }
1709  case 3:
1710  {
1711  switch(b->s)
1712  {
1713  case 0:
1714  case 1:/* a:3, b:1 */
1715  {
1716  mpz_mul(u->z,a->z,b->n);
1717  mpz_add(u->z,u->z,b->z);
1718  if (mpz_cmp_ui(u->z,(long)0)==0)
1719  {
1720  mpz_clear(u->z);
1721  FREE_RNUMBER(u);
1722  return INT_TO_SR(0);
1723  }
1724  if (mpz_cmp(u->z,b->n)==0)
1725  {
1726  mpz_clear(u->z);
1727  FREE_RNUMBER(u);
1728  return INT_TO_SR(1);
1729  }
1730  mpz_init_set(u->n,b->n);
1731  u->s = 0;
1732  break;
1733  }
1734  case 3:
1735  {
1736  mpz_add(u->z,a->z,b->z);
1737  if (mpz_cmp_ui(u->z,(long)0)==0)
1738  {
1739  mpz_clear(u->z);
1740  FREE_RNUMBER(u);
1741  return INT_TO_SR(0);
1742  }
1743  u->s = 3;
1744  u=nlShort3(u);
1745  break;
1746  }
1747  }
1748  break;
1749  }
1750  }
1751  }
1752  return u;
1753 }
void mpz_mul_si(mpz_ptr r, mpz_srcptr s, long int si)
Definition: longrat.cc:181
#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 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 SR_HDL(A)
Definition: tgb.cc:35
const poly b
Definition: syzextra.cc:213
number _nlCopy_NoImm ( number  a)

Definition at line 1538 of file longrat.cc.

1539 {
1540  assume(!((SR_HDL(a) & SR_INT)||(a==NULL)));
1541  //nlTest(a, r);
1542  number b=ALLOC_RNUMBER();
1543 #if defined(LDEBUG)
1544  b->debug=123456;
1545 #endif
1546  switch (a->s)
1547  {
1548  case 0:
1549  case 1:
1550  mpz_init_set(b->n,a->n);
1551  case 3:
1552  mpz_init_set(b->z,a->z);
1553  break;
1554  }
1555  b->s = a->s;
1556  return b;
1557 }
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 1559 of file longrat.cc.

1560 {
1561  {
1562  switch ((*a)->s)
1563  {
1564  case 0:
1565  case 1:
1566  mpz_clear((*a)->n);
1567  case 3:
1568  mpz_clear((*a)->z);
1569 #ifdef LDEBUG
1570  (*a)->s=2;
1571 #endif
1572  }
1573  FREE_RNUMBER(*a); // omFreeBin((void *) *a, rnumber_bin);
1574  }
1575 }
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 1491 of file longrat.cc.

1492 {
1493  assume(! (SR_HDL(a) & SR_HDL(b) & SR_INT));
1494 // long - short
1495  BOOLEAN bo;
1496  if (SR_HDL(b) & SR_INT)
1497  {
1498  if (a->s!=0) return FALSE;
1499  number n=b; b=a; a=n;
1500  }
1501 // short - long
1502  if (SR_HDL(a) & SR_INT)
1503  {
1504  if (b->s!=0)
1505  return FALSE;
1506  if (((long)a > 0L) && (mpz_isNeg(b->z)))
1507  return FALSE;
1508  if (((long)a < 0L) && (!mpz_isNeg(b->z)))
1509  return FALSE;
1510  mpz_t bb;
1511  mpz_init_set(bb,b->n);
1512  mpz_mul_si(bb,bb,(long)SR_TO_INT(a));
1513  bo=(mpz_cmp(bb,b->z)==0);
1514  mpz_clear(bb);
1515  return bo;
1516  }
1517 // long - long
1518  if (((a->s==1) && (b->s==3))
1519  || ((b->s==1) && (a->s==3)))
1520  return FALSE;
1521  if (mpz_isNeg(a->z)&&(!mpz_isNeg(b->z)))
1522  return FALSE;
1523  if (mpz_isNeg(b->z)&&(!mpz_isNeg(a->z)))
1524  return FALSE;
1525  mpz_t aa;
1526  mpz_t bb;
1527  mpz_init_set(aa,a->z);
1528  mpz_init_set(bb,b->z);
1529  if (a->s<2) mpz_mul(bb,bb,a->n);
1530  if (b->s<2) mpz_mul(aa,aa,b->n);
1531  bo=(mpz_cmp(aa,bb)==0);
1532  mpz_clear(aa);
1533  mpz_clear(bb);
1534  return bo;
1535 }
void mpz_mul_si(mpz_ptr r, mpz_srcptr s, long int si)
Definition: longrat.cc:181
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 1755 of file longrat.cc.

1756 {
1757  if (SR_HDL(b) & SR_INT)
1758  {
1759  switch (a->s)
1760  {
1761  case 0:
1762  case 1:/* b:short, a:1 */
1763  {
1764  mpz_t x;
1765  mpz_init(x);
1766  mpz_mul_si(x,a->n,SR_TO_INT(b));
1767  mpz_add(a->z,a->z,x);
1768  mpz_clear(x);
1769  a->s = 0;
1770  a=nlShort1(a);
1771  break;
1772  }
1773  case 3:
1774  {
1775  if ((long)b>0L)
1776  mpz_add_ui(a->z,a->z,SR_TO_INT(b));
1777  else
1778  mpz_sub_ui(a->z,a->z,-SR_TO_INT(b));
1779  a->s = 3;
1781  break;
1782  }
1783  }
1784  return;
1785  }
1786  else if (SR_HDL(a) & SR_INT)
1787  {
1788  number u=ALLOC_RNUMBER();
1789  #if defined(LDEBUG)
1790  u->debug=123456;
1791  #endif
1792  mpz_init(u->z);
1793  switch (b->s)
1794  {
1795  case 0:
1796  case 1:/* a:short, b:1 */
1797  {
1798  mpz_t x;
1799  mpz_init(x);
1800 
1801  mpz_mul_si(x,b->n,SR_TO_INT(a));
1802  mpz_add(u->z,b->z,x);
1803  mpz_clear(x);
1804  // result cannot be 0, if coeffs are normalized
1805  mpz_init_set(u->n,b->n);
1806  u->s = 0;
1807  u=nlShort1(u);
1808  break;
1809  }
1810  case 3:
1811  {
1812  if ((long)a>0L)
1813  mpz_add_ui(u->z,b->z,SR_TO_INT(a));
1814  else
1815  mpz_sub_ui(u->z,b->z,-SR_TO_INT(a));
1816  // result cannot be 0, if coeffs are normalized
1817  u->s = 3;
1818  u=nlShort3_noinline(u);
1819  break;
1820  }
1821  }
1822  a=u;
1823  }
1824  else
1825  {
1826  switch (a->s)
1827  {
1828  case 0:
1829  case 1:
1830  {
1831  switch(b->s)
1832  {
1833  case 0:
1834  case 1: /* a:1 b:1 */
1835  {
1836  mpz_t x;
1837  mpz_t y;
1838  mpz_init(x);
1839  mpz_init(y);
1840  mpz_mul(x,b->z,a->n);
1841  mpz_mul(y,a->z,b->n);
1842  mpz_add(a->z,x,y);
1843  mpz_clear(x);
1844  mpz_clear(y);
1845  mpz_mul(a->n,a->n,b->n);
1846  a->s = 0;
1847  break;
1848  }
1849  case 3: /* a:1 b:3 */
1850  {
1851  mpz_t x;
1852  mpz_init(x);
1853  mpz_mul(x,b->z,a->n);
1854  mpz_add(a->z,a->z,x);
1855  mpz_clear(x);
1856  a->s = 0;
1857  break;
1858  }
1859  } /*switch (b->s) */
1860  a=nlShort1(a);
1861  break;
1862  }
1863  case 3:
1864  {
1865  switch(b->s)
1866  {
1867  case 0:
1868  case 1:/* a:3, b:1 */
1869  {
1870  mpz_t x;
1871  mpz_init(x);
1872  mpz_mul(x,a->z,b->n);
1873  mpz_add(a->z,b->z,x);
1874  mpz_clear(x);
1875  mpz_init_set(a->n,b->n);
1876  a->s = 0;
1877  a=nlShort1(a);
1878  break;
1879  }
1880  case 3:
1881  {
1882  mpz_add(a->z,a->z,b->z);
1883  a->s = 3;
1885  break;
1886  }
1887  }
1888  break;
1889  }
1890  }
1891  }
1892 }
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:181
const poly a
Definition: syzextra.cc:212
number nlShort1(number x)
Definition: longrat.cc:1256
number nlShort3_noinline(number x)
Definition: longrat.cc:174
#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 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 2118 of file longrat.cc.

2119 {
2120  number u=ALLOC_RNUMBER();
2121 #if defined(LDEBUG)
2122  u->debug=123456;
2123 #endif
2124  u->s=3;
2125  mpz_init_set_si(u->z,SR_TO_INT(a));
2126  mpz_mul_si(u->z,u->z,SR_TO_INT(b));
2127  return u;
2128 }
void mpz_mul_si(mpz_ptr r, mpz_srcptr s, long int si)
Definition: longrat.cc:181
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 2131 of file longrat.cc.

2132 {
2133  assume(! (SR_HDL(a) & SR_HDL(b) & SR_INT));
2134  number u=ALLOC_RNUMBER();
2135 #if defined(LDEBUG)
2136  u->debug=123456;
2137 #endif
2138  mpz_init(u->z);
2139  if (SR_HDL(b) & SR_INT)
2140  {
2141  number x=a;
2142  a=b;
2143  b=x;
2144  }
2145  if (SR_HDL(a) & SR_INT)
2146  {
2147  u->s=b->s;
2148  if (u->s==1) u->s=0;
2149  if ((long)a>0L)
2150  {
2151  mpz_mul_ui(u->z,b->z,(unsigned long)SR_TO_INT(a));
2152  }
2153  else
2154  {
2155  if (a==INT_TO_SR(-1))
2156  {
2157  mpz_set(u->z,b->z);
2158  mpz_neg(u->z,u->z);
2159  u->s=b->s;
2160  }
2161  else
2162  {
2163  mpz_mul_ui(u->z,b->z,(unsigned long)-SR_TO_INT(a));
2164  mpz_neg(u->z,u->z);
2165  }
2166  }
2167  if (u->s<2)
2168  {
2169  if (mpz_cmp(u->z,b->n)==0)
2170  {
2171  mpz_clear(u->z);
2172  FREE_RNUMBER(u);
2173  return INT_TO_SR(1);
2174  }
2175  mpz_init_set(u->n,b->n);
2176  }
2177  else //u->s==3
2178  {
2179  u=nlShort3(u);
2180  }
2181  }
2182  else
2183  {
2184  mpz_mul(u->z,a->z,b->z);
2185  u->s = 0;
2186  if(a->s==3)
2187  {
2188  if(b->s==3)
2189  {
2190  u->s = 3;
2191  }
2192  else
2193  {
2194  if (mpz_cmp(u->z,b->n)==0)
2195  {
2196  mpz_clear(u->z);
2197  FREE_RNUMBER(u);
2198  return INT_TO_SR(1);
2199  }
2200  mpz_init_set(u->n,b->n);
2201  }
2202  }
2203  else
2204  {
2205  if(b->s==3)
2206  {
2207  if (mpz_cmp(u->z,a->n)==0)
2208  {
2209  mpz_clear(u->z);
2210  FREE_RNUMBER(u);
2211  return INT_TO_SR(1);
2212  }
2213  mpz_init_set(u->n,a->n);
2214  }
2215  else
2216  {
2217  mpz_init(u->n);
2218  mpz_mul(u->n,a->n,b->n);
2219  if (mpz_cmp(u->z,u->n)==0)
2220  {
2221  mpz_clear(u->z);
2222  mpz_clear(u->n);
2223  FREE_RNUMBER(u);
2224  return INT_TO_SR(1);
2225  }
2226  }
2227  }
2228  }
2229  return u;
2230 }
#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
#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 SR_HDL(A)
Definition: tgb.cc:35
const poly b
Definition: syzextra.cc:213
number _nlNeg_NoImm ( number  a)

Definition at line 1577 of file longrat.cc.

1578 {
1579  {
1580  mpz_neg(a->z,a->z);
1581  if (a->s==3)
1582  {
1583  a=nlShort3(a);
1584  }
1585  }
1586  return a;
1587 }
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 1894 of file longrat.cc.

1895 {
1896  number u=ALLOC_RNUMBER();
1897 #if defined(LDEBUG)
1898  u->debug=123456;
1899 #endif
1900  mpz_init(u->z);
1901  if (SR_HDL(a) & SR_INT)
1902  {
1903  switch (b->s)
1904  {
1905  case 0:
1906  case 1:/* a:short, b:1 */
1907  {
1908  mpz_t x;
1909  mpz_init(x);
1910  mpz_mul_si(x,b->n,SR_TO_INT(a));
1911  mpz_sub(u->z,x,b->z);
1912  mpz_clear(x);
1913  if (mpz_cmp_ui(u->z,(long)0)==0)
1914  {
1915  mpz_clear(u->z);
1916  FREE_RNUMBER(u);
1917  return INT_TO_SR(0);
1918  }
1919  if (mpz_cmp(u->z,b->n)==0)
1920  {
1921  mpz_clear(u->z);
1922  FREE_RNUMBER(u);
1923  return INT_TO_SR(1);
1924  }
1925  mpz_init_set(u->n,b->n);
1926  u->s = 0;
1927  break;
1928  }
1929  case 3:
1930  {
1931  if ((long)a>0L)
1932  {
1933  mpz_sub_ui(u->z,b->z,SR_TO_INT(a));
1934  mpz_neg(u->z,u->z);
1935  }
1936  else
1937  {
1938  mpz_add_ui(u->z,b->z,-SR_TO_INT(a));
1939  mpz_neg(u->z,u->z);
1940  }
1941  if (mpz_cmp_ui(u->z,(long)0)==0)
1942  {
1943  mpz_clear(u->z);
1944  FREE_RNUMBER(u);
1945  return INT_TO_SR(0);
1946  }
1947  u->s = 3;
1948  u=nlShort3(u);
1949  break;
1950  }
1951  }
1952  }
1953  else if (SR_HDL(b) & SR_INT)
1954  {
1955  switch (a->s)
1956  {
1957  case 0:
1958  case 1:/* b:short, a:1 */
1959  {
1960  mpz_t x;
1961  mpz_init(x);
1962  mpz_mul_si(x,a->n,SR_TO_INT(b));
1963  mpz_sub(u->z,a->z,x);
1964  mpz_clear(x);
1965  if (mpz_cmp_ui(u->z,(long)0)==0)
1966  {
1967  mpz_clear(u->z);
1968  FREE_RNUMBER(u);
1969  return INT_TO_SR(0);
1970  }
1971  if (mpz_cmp(u->z,a->n)==0)
1972  {
1973  mpz_clear(u->z);
1974  FREE_RNUMBER(u);
1975  return INT_TO_SR(1);
1976  }
1977  mpz_init_set(u->n,a->n);
1978  u->s = 0;
1979  break;
1980  }
1981  case 3:
1982  {
1983  if ((long)b>0L)
1984  {
1985  mpz_sub_ui(u->z,a->z,SR_TO_INT(b));
1986  }
1987  else
1988  {
1989  mpz_add_ui(u->z,a->z,-SR_TO_INT(b));
1990  }
1991  if (mpz_cmp_ui(u->z,(long)0)==0)
1992  {
1993  mpz_clear(u->z);
1994  FREE_RNUMBER(u);
1995  return INT_TO_SR(0);
1996  }
1997  u->s = 3;
1998  u=nlShort3(u);
1999  break;
2000  }
2001  }
2002  }
2003  else
2004  {
2005  switch (a->s)
2006  {
2007  case 0:
2008  case 1:
2009  {
2010  switch(b->s)
2011  {
2012  case 0:
2013  case 1:
2014  {
2015  mpz_t x;
2016  mpz_t y;
2017  mpz_init(x);
2018  mpz_init(y);
2019  mpz_mul(x,b->z,a->n);
2020  mpz_mul(y,a->z,b->n);
2021  mpz_sub(u->z,y,x);
2022  mpz_clear(x);
2023  mpz_clear(y);
2024  if (mpz_cmp_ui(u->z,(long)0)==0)
2025  {
2026  mpz_clear(u->z);
2027  FREE_RNUMBER(u);
2028  return INT_TO_SR(0);
2029  }
2030  mpz_init(u->n);
2031  mpz_mul(u->n,a->n,b->n);
2032  if (mpz_cmp(u->z,u->n)==0)
2033  {
2034  mpz_clear(u->z);
2035  mpz_clear(u->n);
2036  FREE_RNUMBER(u);
2037  return INT_TO_SR(1);
2038  }
2039  u->s = 0;
2040  break;
2041  }
2042  case 3: /* a:1, b:3 */
2043  {
2044  mpz_t x;
2045  mpz_init(x);
2046  mpz_mul(x,b->z,a->n);
2047  mpz_sub(u->z,a->z,x);
2048  mpz_clear(x);
2049  if (mpz_cmp_ui(u->z,(long)0)==0)
2050  {
2051  mpz_clear(u->z);
2052  FREE_RNUMBER(u);
2053  return INT_TO_SR(0);
2054  }
2055  if (mpz_cmp(u->z,a->n)==0)
2056  {
2057  mpz_clear(u->z);
2058  FREE_RNUMBER(u);
2059  return INT_TO_SR(1);
2060  }
2061  mpz_init_set(u->n,a->n);
2062  u->s = 0;
2063  break;
2064  }
2065  }
2066  break;
2067  }
2068  case 3:
2069  {
2070  switch(b->s)
2071  {
2072  case 0:
2073  case 1: /* a:3, b:1 */
2074  {
2075  mpz_t x;
2076  mpz_init(x);
2077  mpz_mul(x,a->z,b->n);
2078  mpz_sub(u->z,x,b->z);
2079  mpz_clear(x);
2080  if (mpz_cmp_ui(u->z,(long)0)==0)
2081  {
2082  mpz_clear(u->z);
2083  FREE_RNUMBER(u);
2084  return INT_TO_SR(0);
2085  }
2086  if (mpz_cmp(u->z,b->n)==0)
2087  {
2088  mpz_clear(u->z);
2089  FREE_RNUMBER(u);
2090  return INT_TO_SR(1);
2091  }
2092  mpz_init_set(u->n,b->n);
2093  u->s = 0;
2094  break;
2095  }
2096  case 3: /* a:3 , b:3 */
2097  {
2098  mpz_sub(u->z,a->z,b->z);
2099  if (mpz_cmp_ui(u->z,(long)0)==0)
2100  {
2101  mpz_clear(u->z);
2102  FREE_RNUMBER(u);
2103  return INT_TO_SR(0);
2104  }
2105  u->s = 3;
2106  u=nlShort3(u);
2107  break;
2108  }
2109  }
2110  break;
2111  }
2112  }
2113  }
2114  return u;
2115 }
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:181
#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 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 SR_HDL(A)
Definition: tgb.cc:35
const poly b
Definition: syzextra.cc:213
void mpz_mul_si ( mpz_ptr  r,
mpz_srcptr  s,
long int  si 
)

Definition at line 181 of file longrat.cc.

182 {
183  if (si>=0)
184  mpz_mul_ui(r,s,si);
185  else
186  {
187  mpz_mul_ui(r,s,-si);
188  mpz_neg(r,r);
189  }
190 }
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 2452 of file longrat.cc.

2453 {
2454  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
2455  {
2456  LONG r=SR_HDL(a)+SR_HDL(b)-1L;
2457  if ( ((r << 1) >> 1) == r )
2458  return (number)(long)r;
2459  else
2460  return nlRInit(SR_TO_INT(r));
2461  }
2462  number u = _nlAdd_aNoImm_OR_bNoImm(a, b);
2463  nlTest(u, R);
2464  return u;
2465 }
const poly a
Definition: syzextra.cc:212
number nlRInit(long i)
Definition: longrat.cc:2281
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:1589
#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 638 of file longrat.cc.

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

Definition at line 2788 of file longrat.cc.

2789 {
2790  CFArray inv(rl);
2791  return nlChineseRemainderSym(x,q,rl,TRUE,inv,C);
2792 }
#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:2754
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 2754 of file longrat.cc.

2756 {
2757  setCharacteristic( 0 ); // only in char 0
2758  Off(SW_RATIONAL);
2759  CFArray X(rl), Q(rl);
2760  int i;
2761  for(i=rl-1;i>=0;i--)
2762  {
2763  X[i]=CF->convSingNFactoryN(x[i],FALSE,CF); // may be larger MAX_INT
2764  Q[i]=CF->convSingNFactoryN(q[i],FALSE,CF); // may be larger MAX_INT
2765  }
2766  CanonicalForm xnew,qnew;
2767  if (n_SwitchChinRem)
2768  chineseRemainder(X,Q,xnew,qnew);
2769  else
2770  chineseRemainderCached(X,Q,xnew,qnew,inv_cache);
2771  number n=CF->convFactoryNSingN(xnew,CF);
2772  if (sym)
2773  {
2774  number p=CF->convFactoryNSingN(qnew,CF);
2775  number p2=nlIntDiv(p,nlInit(2, CF),CF);
2776  if (nlGreater(n,p2,CF))
2777  {
2778  number n2=nlSub(n,p,CF);
2779  nlDelete(&n,CF);
2780  n=n2;
2781  }
2782  nlDelete(&p2,CF);
2783  nlDelete(&p,CF);
2784  }
2785  nlNormalize(n,CF);
2786  return n;
2787 }
LINLINE number nlSub(number la, number li, const coeffs r)
Definition: longrat.cc:2518
void Off(int sw)
switches
#define FALSE
Definition: auxiliary.h:140
return P p
Definition: myNF.cc:203
int n_SwitchChinRem
Definition: longrat.cc:2753
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:1151
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:1277
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:2417
Variable x
Definition: cfModGcd.cc:4023
LINLINE number nlInit(long i, const coeffs r)
Definition: longrat.cc:2357
END_NAMESPACE const void * p2
Definition: syzextra.cc:202
static void nlClearContent ( ICoeffsEnumerator numberCollectionEnumerator,
number &  c,
const coeffs  cf 
)
static

Definition at line 2794 of file longrat.cc.

2795 {
2796  assume(cf != NULL);
2797 
2798  numberCollectionEnumerator.Reset();
2799 
2800  if( !numberCollectionEnumerator.MoveNext() ) // empty zero polynomial?
2801  {
2802  c = nlInit(1, cf);
2803  return;
2804  }
2805 
2806  // all coeffs are given by integers!!!
2807 
2808  // part 1, find a small candidate for gcd
2809  number cand1,cand;
2810  int s1,s;
2811  s=2147483647; // max. int
2812 
2813  const BOOLEAN lc_is_pos=nlGreaterZero(numberCollectionEnumerator.Current(),cf);
2814 
2815  int normalcount = 0;
2816  do
2817  {
2818  number& n = numberCollectionEnumerator.Current();
2819  nlNormalize(n, cf); ++normalcount;
2820  cand1 = n;
2821 
2822  if (SR_HDL(cand1)&SR_INT) { cand=cand1; break; }
2823  assume(cand1->s==3); // all coeffs should be integers // ==0?!! after printing
2824  s1=mpz_size1(cand1->z);
2825  if (s>s1)
2826  {
2827  cand=cand1;
2828  s=s1;
2829  }
2830  } while (numberCollectionEnumerator.MoveNext() );
2831 
2832 // assume( nlGreaterZero(cand,cf) ); // cand may be a negative integer!
2833 
2834  cand=nlCopy(cand,cf);
2835  // part 2: compute gcd(cand,all coeffs)
2836 
2837  numberCollectionEnumerator.Reset();
2838 
2839  while (numberCollectionEnumerator.MoveNext() )
2840  {
2841  number& n = numberCollectionEnumerator.Current();
2842 
2843  if( (--normalcount) <= 0)
2844  nlNormalize(n, cf);
2845 
2846  nlInpGcd(cand, n, cf);
2847  assume( nlGreaterZero(cand,cf) );
2848 
2849  if(nlIsOne(cand,cf))
2850  {
2851  c = cand;
2852 
2853  if(!lc_is_pos)
2854  {
2855  // make the leading coeff positive
2856  c = nlNeg(c, cf);
2857  numberCollectionEnumerator.Reset();
2858 
2859  while (numberCollectionEnumerator.MoveNext() )
2860  {
2861  number& nn = numberCollectionEnumerator.Current();
2862  nn = nlNeg(nn, cf);
2863  }
2864  }
2865  return;
2866  }
2867  }
2868 
2869  // part3: all coeffs = all coeffs / cand
2870  if (!lc_is_pos)
2871  cand = nlNeg(cand,cf);
2872 
2873  c = cand;
2874  numberCollectionEnumerator.Reset();
2875 
2876  while (numberCollectionEnumerator.MoveNext() )
2877  {
2878  number& n = numberCollectionEnumerator.Current();
2879  number t=nlIntDiv(n, cand, cf); // simple integer exact division, no ratios to remain
2880  nlDelete(&n, cf);
2881  n = t;
2882  }
2883 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
BOOLEAN nlGreaterZero(number za, const coeffs r)
Definition: longrat.cc:1141
void nlInpGcd(number &a, number b, const coeffs r)
Definition: longrat.cc:2588
number nlIntDiv(number a, number b, const coeffs r)
Definition: longrat.cc:786
LINLINE BOOLEAN nlIsOne(number a, const coeffs r)
Definition: longrat.cc:2375
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:2433
#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:1277
#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:2417
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:2357
#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:2404
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 2885 of file longrat.cc.

2886 {
2887  assume(cf != NULL);
2888 
2889  numberCollectionEnumerator.Reset();
2890 
2891  if( !numberCollectionEnumerator.MoveNext() ) // empty zero polynomial?
2892  {
2893  c = nlInit(1, cf);
2894 // assume( n_GreaterZero(c, cf) );
2895  return;
2896  }
2897 
2898  // all coeffs are given by integers after returning from this routine
2899 
2900  // part 1, collect product of all denominators /gcds
2901  number cand;
2902  cand=ALLOC_RNUMBER();
2903 #if defined(LDEBUG)
2904  cand->debug=123456;
2905 #endif
2906  cand->s=3;
2907 
2908  int s=0;
2909 
2910  const BOOLEAN lc_is_pos=nlGreaterZero(numberCollectionEnumerator.Current(),cf);
2911 
2912  do
2913  {
2914  number& cand1 = numberCollectionEnumerator.Current();
2915 
2916  if (!(SR_HDL(cand1)&SR_INT))
2917  {
2918  nlNormalize(cand1, cf);
2919  if ((!(SR_HDL(cand1)&SR_INT)) // not a short int
2920  && (cand1->s==1)) // and is a normalised rational
2921  {
2922  if (s==0) // first denom, we meet
2923  {
2924  mpz_init_set(cand->z, cand1->n); // cand->z = cand1->n
2925  s=1;
2926  }
2927  else // we have already something
2928  {
2929  mpz_lcm(cand->z, cand->z, cand1->n);
2930  }
2931  }
2932  }
2933  }
2934  while (numberCollectionEnumerator.MoveNext() );
2935 
2936 
2937  if (s==0) // nothing to do, all coeffs are already integers
2938  {
2939 // mpz_clear(tmp);
2940  FREE_RNUMBER(cand);
2941  if (lc_is_pos)
2942  c=nlInit(1,cf);
2943  else
2944  {
2945  // make the leading coeff positive
2946  c=nlInit(-1,cf);
2947 
2948  // TODO: incorporate the following into the loop below?
2949  numberCollectionEnumerator.Reset();
2950  while (numberCollectionEnumerator.MoveNext() )
2951  {
2952  number& n = numberCollectionEnumerator.Current();
2953  n = nlNeg(n, cf);
2954  }
2955  }
2956 // assume( n_GreaterZero(c, cf) );
2957  return;
2958  }
2959 
2960  cand = nlShort3(cand);
2961 
2962  // part2: all coeffs = all coeffs * cand
2963  // make the lead coeff positive
2964  numberCollectionEnumerator.Reset();
2965 
2966  if (!lc_is_pos)
2967  cand = nlNeg(cand, cf);
2968 
2969  c = cand;
2970 
2971  while (numberCollectionEnumerator.MoveNext() )
2972  {
2973  number &n = numberCollectionEnumerator.Current();
2974  nlInpMult(n, cand, cf);
2975  }
2976 
2977 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
BOOLEAN nlGreaterZero(number za, const coeffs r)
Definition: longrat.cc:1141
#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:2433
#define assume(x)
Definition: mod2.h:405
LINLINE void nlInpMult(number &a, number b, const coeffs r)
Definition: longrat.cc:2536
virtual reference Current()=0
Gets the current element in the collection (read and write).
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1277
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:2357
#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 3102 of file longrat.cc.

3103 {
3104  /* test, if r is an instance of nInitCoeffs(n,parameter) */
3105  /* if parameter is not needed */
3106  if (n==r->type)
3107  {
3108  if ((p==NULL)&&(r->cfDiv==nlDiv)) return TRUE;
3109  if ((p!=NULL)&&(r->cfDiv!=nlDiv)) return TRUE;
3110  }
3111  return FALSE;
3112 }
#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:978
#define NULL
Definition: omList.c:10
char* nlCoeffName ( const coeffs  r)

Definition at line 2979 of file longrat.cc.

2980 {
2981  if (r->cfDiv==nlDiv) return (char*)"QQ";
2982  else return (char*)"ZZ";
2983 }
number nlDiv(number a, number b, const coeffs r)
Definition: longrat.cc:978
static char* nlCoeffString ( const coeffs  r)
static

Definition at line 2985 of file longrat.cc.

2986 {
2987  //return omStrDup(nlCoeffName(r));
2988  if (r->cfDiv==nlDiv) return omStrDup("0");
2989  else return omStrDup("integer");
2990 }
number nlDiv(number a, number b, const coeffs r)
Definition: longrat.cc:978
#define omStrDup(s)
Definition: omAllocDecl.h:263
void nlCoeffWrite ( const coeffs  r,
BOOLEAN  details 
)

Definition at line 2745 of file longrat.cc.

2746 {
2747  if (r->is_field)
2748  PrintS("// characteristic : 0\n");
2749  else
2750  PrintS("// coeff. ring is : Integers\n");
2751 }
void PrintS(const char *s)
Definition: reporter.cc:294
static number nlConvFactoryNSingN ( const CanonicalForm  f,
const coeffs  r 
)
static

Definition at line 380 of file longrat.cc.

381 {
382  if (f.isImm())
383  {
384  return nlInit(f.intval(),r);
385  }
386  else
387  {
388  number z = ALLOC_RNUMBER(); //Q!? // (number)omAllocBin(rnumber_bin);
389 #if defined(LDEBUG)
390  z->debug=123456;
391 #endif
392  gmp_numerator( f, z->z );
393  if ( f.den().isOne() )
394  z->s = 3;
395  else
396  {
397  gmp_denominator( f, z->n );
398  z->s = 0;
399  }
400  nlNormalize(z,r);
401  return z;
402  }
403 }
void gmp_numerator(const CanonicalForm &f, mpz_ptr result)
Definition: singext.cc:20
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 nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1277
bool isImm() const
void gmp_denominator(const CanonicalForm &f, mpz_ptr result)
Definition: singext.cc:40
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
LINLINE number nlInit(long i, const coeffs r)
Definition: longrat.cc:2357
static CanonicalForm nlConvSingNFactoryN ( number  n,
const BOOLEAN  setChar,
const coeffs   
)
static

Definition at line 342 of file longrat.cc.

343 {
344  if (setChar) setCharacteristic( 0 );
345 
347  if ( SR_HDL(n) & SR_INT )
348  {
349  long nn=SR_TO_INT(n);
350  term = nn;
351  }
352  else
353  {
354  if ( n->s == 3 )
355  {
356  mpz_t dummy;
357  long lz=mpz_get_si(n->z);
358  if (mpz_cmp_si(n->z,lz)==0) term=lz;
359  else
360  {
361  mpz_init_set( dummy,n->z );
362  term = make_cf( dummy );
363  }
364  }
365  else
366  {
367  // assume s==0 or s==1
368  mpz_t num, den;
369  On(SW_RATIONAL);
370  mpz_init_set( num, n->z );
371  mpz_init_set( den, n->n );
372  term = make_cf( num, den, ( n->s != 1 ));
373  }
374  }
375  return term;
376 }
CanonicalForm num(const CanonicalForm &f)
Definition: int_poly.h:36
factory&#39;s main class
Definition: canonicalform.h:75
void setCharacteristic(int c)
Definition: cf_char.cc:23
CanonicalForm make_cf(const mpz_ptr n)
Definition: singext.cc:67
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 2404 of file longrat.cc.

2405 {
2406  if ((SR_HDL(a) & SR_INT)||(a==NULL))
2407  {
2408  return a;
2409  }
2410  return _nlCopy_NoImm(a);
2411 }
const poly a
Definition: syzextra.cc:212
number _nlCopy_NoImm(number a)
Definition: longrat.cc:1538
#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 2235 of file longrat.cc.

2236 {
2237  if ((SR_HDL(a) & SR_INT)||(a==NULL))
2238  {
2239  return a;
2240  }
2241  return _nlCopy_NoImm(a);
2242 }
const poly a
Definition: syzextra.cc:212
number _nlCopy_NoImm(number a)
Definition: longrat.cc:1538
#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,
char *  f,
int  l,
const coeffs  r 
)
BOOLEAN nlDBTest ( number  a,
const char *  f,
const int  l,
const coeffs   
)

Definition at line 250 of file longrat.cc.

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

2418 {
2419  if (*a!=NULL)
2420  {
2421  nlTest(*a, r);
2422  if ((SR_HDL(*a) & SR_INT)==0)
2423  {
2424  _nlDelete_NoImm(a);
2425  }
2426  *a=NULL;
2427  }
2428 }
const poly a
Definition: syzextra.cc:212
void _nlDelete_NoImm(number *a)
Definition: longrat.cc:1559
#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 978 of file longrat.cc.

979 {
980  if (nlIsZero(b,r))
981  {
982  WerrorS(nDivBy0);
983  return INT_TO_SR(0);
984  }
985  number u;
986 // ---------- short / short ------------------------------------
987  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
988  {
989  LONG i=SR_TO_INT(a);
990  LONG j=SR_TO_INT(b);
991  if (j==1L) return a;
992  if ((i==-POW_2_28) && (j== -1L))
993  {
994  return nlRInit(POW_2_28);
995  }
996  LONG r=i%j;
997  if (r==0)
998  {
999  return INT_TO_SR(i/j);
1000  }
1001  u=ALLOC_RNUMBER();
1002  u->s=0;
1003  #if defined(LDEBUG)
1004  u->debug=123456;
1005  #endif
1006  mpz_init_set_si(u->z,(long)i);
1007  mpz_init_set_si(u->n,(long)j);
1008  }
1009  else
1010  {
1011  u=ALLOC_RNUMBER();
1012  u->s=0;
1013  #if defined(LDEBUG)
1014  u->debug=123456;
1015  #endif
1016  mpz_init(u->z);
1017 // ---------- short / long ------------------------------------
1018  if (SR_HDL(a) & SR_INT)
1019  {
1020  // short a / (z/n) -> (a*n)/z
1021  if (b->s<2)
1022  {
1023  mpz_mul_si(u->z,b->n,SR_TO_INT(a));
1024  }
1025  else
1026  // short a / long z -> a/z
1027  {
1028  mpz_set_si(u->z,SR_TO_INT(a));
1029  }
1030  if (mpz_cmp(u->z,b->z)==0)
1031  {
1032  mpz_clear(u->z);
1033  FREE_RNUMBER(u);
1034  return INT_TO_SR(1);
1035  }
1036  mpz_init_set(u->n,b->z);
1037  }
1038 // ---------- long / short ------------------------------------
1039  else if (SR_HDL(b) & SR_INT)
1040  {
1041  mpz_set(u->z,a->z);
1042  // (z/n) / b -> z/(n*b)
1043  if (a->s<2)
1044  {
1045  mpz_init_set(u->n,a->n);
1046  if ((long)b>0L)
1047  mpz_mul_ui(u->n,u->n,SR_TO_INT(b));
1048  else
1049  {
1050  mpz_mul_ui(u->n,u->n,-SR_TO_INT(b));
1051  mpz_neg(u->z,u->z);
1052  }
1053  }
1054  else
1055  // long z / short b -> z/b
1056  {
1057  //mpz_set(u->z,a->z);
1058  mpz_init_set_si(u->n,SR_TO_INT(b));
1059  }
1060  }
1061 // ---------- long / long ------------------------------------
1062  else
1063  {
1064  mpz_set(u->z,a->z);
1065  mpz_init_set(u->n,b->z);
1066  if (a->s<2) mpz_mul(u->n,u->n,a->n);
1067  if (b->s<2) mpz_mul(u->z,u->z,b->n);
1068  }
1069  }
1070  if (mpz_isNeg(u->n))
1071  {
1072  mpz_neg(u->z,u->z);
1073  mpz_neg(u->n,u->n);
1074  }
1075  if (mpz_cmp_si(u->n,(long)1)==0)
1076  {
1077  mpz_clear(u->n);
1078  u->s=3;
1079  u=nlShort3(u);
1080  }
1081  nlTest(u, r);
1082  return u;
1083 }
void mpz_mul_si(mpz_ptr r, mpz_srcptr s, long int si)
Definition: longrat.cc:181
#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:2281
#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:2384
#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 911 of file longrat.cc.

912 {
913  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
914  {
915  return ((SR_TO_INT(a) % SR_TO_INT(b))==0);
916  }
917  if (SR_HDL(b) & SR_INT)
918  {
919  return (mpz_divisible_ui_p(a->z,SR_TO_INT(b))!=0);
920  }
921  if (SR_HDL(a) & SR_INT) return FALSE;
922  return mpz_divisible_p(a->z, b->z) != 0;
923 }
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 925 of file longrat.cc.

926 {
927  if (nlDivBy(a, b, r))
928  {
929  if (nlDivBy(b, a, r)) return 2;
930  return -1;
931  }
932  if (nlDivBy(b, a, r)) return 1;
933  return 0;
934 }
const poly a
Definition: syzextra.cc:212
BOOLEAN nlDivBy(number a, number b, const coeffs)
Definition: longrat.cc:911
const poly b
Definition: syzextra.cc:213
LINLINE BOOLEAN nlEqual ( number  a,
number  b,
const coeffs  r 
)

Definition at line 2348 of file longrat.cc.

2349 {
2350  nlTest(a, r);
2351  nlTest(b, r);
2352 // short - short
2353  if (SR_HDL(a) & SR_HDL(b) & SR_INT) return a==b;
2354  return _nlEqual_aNoImm_OR_bNoImm(a, b);
2355 }
const poly a
Definition: syzextra.cc:212
BOOLEAN _nlEqual_aNoImm_OR_bNoImm(number a, number b)
Definition: longrat.cc:1491
#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_EXACTDIV(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 MPZ_EXACTDIV(A, B, C)
Definition: longrat.cc:163
#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:2281
#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 2711 of file longrat.cc.

2712 {
2713  mpz_t aa,bb;
2714  *s=ALLOC_RNUMBER();
2715  mpz_init((*s)->z); (*s)->s=3;
2716  (*t)=ALLOC_RNUMBER();
2717  mpz_init((*t)->z); (*t)->s=3;
2718  number g=ALLOC_RNUMBER();
2719  mpz_init(g->z); g->s=3;
2720  if (SR_HDL(a) & SR_INT)
2721  {
2722  mpz_init_set_si(aa,SR_TO_INT(a));
2723  }
2724  else
2725  {
2726  mpz_init_set(aa,a->z);
2727  }
2728  if (SR_HDL(b) & SR_INT)
2729  {
2730  mpz_init_set_si(bb,SR_TO_INT(b));
2731  }
2732  else
2733  {
2734  mpz_init_set(bb,b->z);
2735  }
2736  mpz_gcdext(g->z,(*s)->z,(*t)->z,aa,bb);
2737  mpz_clear(aa);
2738  mpz_clear(bb);
2739  (*s)=nlShort3((*s));
2740  (*t)=nlShort3((*t));
2741  g=nlShort3(g);
2742  return g;
2743 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
const poly a
Definition: syzextra.cc:212
g
Definition: cfModGcd.cc:4031
#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 2642 of file longrat.cc.

2643 {
2644  mpz_t tmp; mpz_init(tmp);
2645  mpz_t A,B,C,D,E,N,P;
2646  if (SR_HDL(nN) & SR_INT) mpz_init_set_si(N,SR_TO_INT(nN));
2647  else mpz_init_set(N,nN->z);
2648  if (SR_HDL(nP) & SR_INT) mpz_init_set_si(P,SR_TO_INT(nP));
2649  else mpz_init_set(P,nP->z);
2650  assume(!mpz_isNeg(P));
2651  if (mpz_isNeg(N)) mpz_add(N,N,P);
2652  mpz_init_set_si(A,(long)0);
2653  mpz_init_set_ui(B,(unsigned long)1);
2654  mpz_init_set_si(C,(long)0);
2655  mpz_init(D);
2656  mpz_init_set(E,P);
2657  number z=INT_TO_SR(0);
2658  while(mpz_cmp_si(N,(long)0)!=0)
2659  {
2660  mpz_mul(tmp,N,N);
2661  mpz_add(tmp,tmp,tmp);
2662  if (mpz_cmp(tmp,P)<0)
2663  {
2664  if (mpz_isNeg(B))
2665  {
2666  mpz_neg(B,B);
2667  mpz_neg(N,N);
2668  }
2669  // check for gcd(N,B)==1
2670  mpz_gcd(tmp,N,B);
2671  if (mpz_cmp_ui(tmp,1)==0)
2672  {
2673  // return N/B
2674  z=ALLOC_RNUMBER();
2675  #ifdef LDEBUG
2676  z->debug=123456;
2677  #endif
2678  mpz_init_set(z->z,N);
2679  mpz_init_set(z->n,B);
2680  z->s = 0;
2681  nlNormalize(z,r);
2682  }
2683  else
2684  {
2685  // return nN (the input) instead of "fail"
2686  z=nlCopy(nN,r);
2687  }
2688  break;
2689  }
2690  //mpz_mod(D,E,N);
2691  //mpz_div(tmp,E,N);
2692  mpz_divmod(tmp,D,E,N);
2693  mpz_mul(tmp,tmp,B);
2694  mpz_sub(C,A,tmp);
2695  mpz_set(E,N);
2696  mpz_set(N,D);
2697  mpz_set(A,B);
2698  mpz_set(B,C);
2699  }
2700  mpz_clear(tmp);
2701  mpz_clear(A);
2702  mpz_clear(B);
2703  mpz_clear(C);
2704  mpz_clear(D);
2705  mpz_clear(E);
2706  mpz_clear(N);
2707  mpz_clear(P);
2708  return z;
2709 }
#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:1277
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:2404
number nlGcd ( number  a,
number  b,
const coeffs  r 
)

Definition at line 1178 of file longrat.cc.

1179 {
1180  number result;
1181  nlTest(a, r);
1182  nlTest(b, r);
1183  //nlNormalize(a);
1184  //nlNormalize(b);
1185  if ((a==INT_TO_SR(1L))||(a==INT_TO_SR(-1L))
1186  || (b==INT_TO_SR(1L))||(b==INT_TO_SR(-1L)))
1187  return INT_TO_SR(1L);
1188  if (a==INT_TO_SR(0)) /* gcd(0,b) ->b */
1189  return nlCopy(b,r);
1190  if (b==INT_TO_SR(0)) /* gcd(a,0) -> a */
1191  return nlCopy(a,r);
1192  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
1193  {
1194  long i=SR_TO_INT(a);
1195  long j=SR_TO_INT(b);
1196  if((i==0L)||(j==0L))
1197  return INT_TO_SR(1);
1198  long l;
1199  i=ABS(i);
1200  j=ABS(j);
1201  do
1202  {
1203  l=i%j;
1204  i=j;
1205  j=l;
1206  } while (l!=0L);
1207  if (i==POW_2_28)
1208  result=nlRInit(POW_2_28);
1209  else
1210  result=INT_TO_SR(i);
1211  nlTest(result,r);
1212  return result;
1213  }
1214  if (((!(SR_HDL(a) & SR_INT))&&(a->s<2))
1215  || ((!(SR_HDL(b) & SR_INT))&&(b->s<2))) return INT_TO_SR(1);
1216  if (SR_HDL(a) & SR_INT)
1217  {
1218  LONG aa=ABS(SR_TO_INT(a));
1219  unsigned long t=mpz_gcd_ui(NULL,b->z,(long)aa);
1220  if (t==POW_2_28)
1221  result=nlRInit(POW_2_28);
1222  else
1223  result=INT_TO_SR(t);
1224  }
1225  else
1226  if (SR_HDL(b) & SR_INT)
1227  {
1228  LONG bb=ABS(SR_TO_INT(b));
1229  unsigned long t=mpz_gcd_ui(NULL,a->z,(long)bb);
1230  if (t==POW_2_28)
1231  result=nlRInit(POW_2_28);
1232  else
1233  result=INT_TO_SR(t);
1234  }
1235  else
1236  {
1237  result=ALLOC0_RNUMBER();
1238  mpz_init(result->z);
1239  mpz_gcd(result->z,a->z,b->z);
1240  result->s = 3;
1241  #ifdef LDEBUG
1242  result->debug=123456;
1243  #endif
1244  result=nlShort3(result);
1245  }
1246  nlTest(result, r);
1247  return result;
1248 }
#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:2281
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:2404
#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 1431 of file longrat.cc.

1432 {
1433  if (!(SR_HDL(n) & SR_INT))
1434  {
1435  if (n->s==0)
1436  {
1437  nlNormalize(n,r);
1438  }
1439  if (!(SR_HDL(n) & SR_INT))
1440  {
1441  if (n->s!=3)
1442  {
1443  number u=ALLOC_RNUMBER();
1444  u->s=3;
1445 #if defined(LDEBUG)
1446  u->debug=123456;
1447 #endif
1448  mpz_init_set(u->z,n->n);
1449  u=nlShort3_noinline(u);
1450  return u;
1451  }
1452  }
1453  }
1454  return INT_TO_SR(1);
1455 }
#define INT_TO_SR(INT)
Definition: longrat.h:66
number nlShort3_noinline(number x)
Definition: longrat.cc:174
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1277
#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 1460 of file longrat.cc.

1461 {
1462  if (!(SR_HDL(n) & SR_INT))
1463  {
1464  if (n->s==0)
1465  {
1466  nlNormalize(n,r);
1467  }
1468  if (!(SR_HDL(n) & SR_INT))
1469  {
1470  number u=ALLOC_RNUMBER();
1471 #if defined(LDEBUG)
1472  u->debug=123456;
1473 #endif
1474  u->s=3;
1475  mpz_init_set(u->z,n->z);
1476  if (n->s!=3)
1477  {
1478  u=nlShort3_noinline(u);
1479  }
1480  return u;
1481  }
1482  }
1483  return n; // imm. int
1484 }
number nlShort3_noinline(number x)
Definition: longrat.cc:174
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1277
#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 936 of file longrat.cc.

937 {
938  if (nlGreaterZero(n, r))
939  return INT_TO_SR(1);
940  else
941  return INT_TO_SR(-1);
942 }
#define INT_TO_SR(INT)
Definition: longrat.h:66
BOOLEAN nlGreaterZero(number za, const coeffs r)
Definition: longrat.cc:1141
void nlGMP ( number &  i,
number  n,
const coeffs  r 
)

Definition at line 1410 of file longrat.cc.

1411 {
1412  // Hier brauche ich einfach die GMP Zahl
1413  nlTest(i, r);
1414  nlNormalize(i, r);
1415  if (SR_HDL(i) & SR_INT)
1416  {
1417  mpz_set_si((mpz_ptr) n, SR_TO_INT(i));
1418  return;
1419  }
1420  if (i->s!=3)
1421  {
1422  WarnS("Omitted denominator during coefficient mapping !");
1423  }
1424  mpz_set((mpz_ptr) n, i->z);
1425 }
#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:1277
#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 1151 of file longrat.cc.

1152 {
1153  nlTest(a, r);
1154  nlTest(b, r);
1155  number re;
1156  BOOLEAN rr;
1157  re=nlSub(a,b,r);
1158  rr=(!nlIsZero(re,r)) && (nlGreaterZero(re,r));
1159  nlDelete(&re,r);
1160  return rr;
1161 }
LINLINE number nlSub(number la, number li, const coeffs r)
Definition: longrat.cc:2518
const poly a
Definition: syzextra.cc:212
BOOLEAN nlGreaterZero(number za, const coeffs r)
Definition: longrat.cc:1141
LINLINE BOOLEAN nlIsZero(number za, const coeffs r)
Definition: longrat.cc:2384
LINLINE void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2417
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 1141 of file longrat.cc.

1142 {
1143  nlTest(a, r);
1144  if (SR_HDL(a) & SR_INT) return SR_HDL(a)>1L /* represents number(0) */;
1145  return (!mpz_isNeg(a->z));
1146 }
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 2357 of file longrat.cc.

2358 {
2359  number n;
2360  #if MAX_NUM_SIZE == 60
2361  if (((i << 3) >> 3) == i) n=INT_TO_SR(i);
2362  else n=nlRInit(i);
2363  #else
2364  LONG ii=(LONG)i;
2365  if ( (((long)ii==i) && ((ii << 3) >> 3) == ii )) n=INT_TO_SR(ii);
2366  else n=nlRInit(i);
2367  #endif
2368  nlTest(n, r);
2369  return n;
2370 }
#define INT_TO_SR(INT)
Definition: longrat.h:66
number nlRInit(long i)
Definition: longrat.cc:2281
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 2295 of file longrat.cc.

2296 {
2297  number z=ALLOC_RNUMBER();
2298 #if defined(LDEBUG)
2299  z->debug=123456;
2300 #endif
2301  mpz_init_set_si(z->z,(long)i);
2302  mpz_init_set_si(z->n,(long)j);
2303  z->s = 0;
2304  nlNormalize(z,r);
2305  return z;
2306 }
int j
Definition: myNF.cc:70
int i
Definition: cfEzgcd.cc:123
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1277
#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 2308 of file longrat.cc.

2309 {
2310  number z=ALLOC_RNUMBER();
2311 #if defined(LDEBUG)
2312  z->debug=123456;
2313 #endif
2314  mpz_init_set(z->z,i);
2315  mpz_init_set(z->n,j);
2316  z->s = 0;
2317  nlNormalize(z,r);
2318  return z;
2319 }
int j
Definition: myNF.cc:70
int i
Definition: cfEzgcd.cc:123
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1277
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
BOOLEAN nlInitChar ( coeffs  r,
void *  p 
)

Definition at line 3138 of file longrat.cc.

3139 {
3140  r->is_domain=TRUE;
3141  r->rep=n_rep_gap_rat;
3142 
3143  //const int ch = (int)(long)(p);
3144 
3145  r->nCoeffIsEqual=nlCoeffIsEqual;
3146  //r->cfKillChar = ndKillChar; /* dummy */
3147  r->cfCoeffString=nlCoeffString;
3148  r->cfCoeffName=nlCoeffName;
3149 
3150  r->cfInitMPZ = nlInitMPZ;
3151  r->cfMPZ = nlMPZ;
3152 
3153  r->cfMult = nlMult;
3154  r->cfSub = nlSub;
3155  r->cfAdd = nlAdd;
3156  if (p==NULL) /* Q */
3157  {
3158  r->is_field=TRUE;
3159  r->cfDiv = nlDiv;
3160  //r->cfGcd = ndGcd_dummy;
3161  r->cfSubringGcd = nlGcd;
3162  }
3163  else /* Z: coeffs_BIGINT */
3164  {
3165  r->is_field=FALSE;
3166  r->cfDiv = nlIntDiv;
3167  r->cfIntMod= nlIntMod;
3168  r->cfGcd = nlGcd;
3169  r->cfDivBy=nlDivBy;
3170  r->cfDivComp = nlDivComp;
3171  r->cfIsUnit = nlIsUnit;
3172  r->cfGetUnit = nlGetUnit;
3173  r->cfQuot1 = nlQuot1;
3174  r->cfLcm = nlLcm;
3175  }
3176  r->cfExactDiv= nlExactDiv;
3177  r->cfInit = nlInit;
3178  r->cfSize = nlSize;
3179  r->cfInt = nlInt;
3180 
3181  r->cfChineseRemainder=nlChineseRemainderSym;
3182  r->cfFarey=nlFarey;
3183  r->cfInpNeg = nlNeg;
3184  r->cfInvers= nlInvers;
3185  r->cfCopy = nlCopy;
3186  r->cfRePart = nlCopy;
3187  //r->cfImPart = ndReturn0;
3188  r->cfWriteLong = nlWrite;
3189  r->cfRead = nlRead;
3190  r->cfNormalize=nlNormalize;
3191  r->cfGreater = nlGreater;
3192  r->cfEqual = nlEqual;
3193  r->cfIsZero = nlIsZero;
3194  r->cfIsOne = nlIsOne;
3195  r->cfIsMOne = nlIsMOne;
3196  r->cfGreaterZero = nlGreaterZero;
3197  r->cfPower = nlPower;
3198  r->cfGetDenom = nlGetDenom;
3199  r->cfGetNumerator = nlGetNumerator;
3200  r->cfExtGcd = nlExtGcd; // only for ring stuff and Z
3201  r->cfNormalizeHelper = nlNormalizeHelper;
3202  r->cfDelete= nlDelete;
3203  r->cfSetMap = nlSetMap;
3204  //r->cfName = ndName;
3205  r->cfInpMult=nlInpMult;
3206  r->cfInpAdd=nlInpAdd;
3207  r->cfCoeffWrite=nlCoeffWrite;
3208 
3209  r->cfClearContent = nlClearContent;
3210  r->cfClearDenominators = nlClearDenominators;
3211 
3212 #ifdef LDEBUG
3213  // debug stuff
3214  r->cfDBTest=nlDBTest;
3215 #endif
3216  r->convSingNFactoryN=nlConvSingNFactoryN;
3217  r->convFactoryNSingN=nlConvFactoryNSingN;
3218 
3219  r->cfRandom=nlRandom;
3220 
3221  // io via ssi
3222  r->cfWriteFd=nlWriteFd;
3223  r->cfReadFd=nlReadFd;
3224 
3225  // the variables: general stuff (required)
3226  r->nNULL = INT_TO_SR(0);
3227  //r->type = n_Q;
3228  r->ch = 0;
3229  r->has_simple_Alloc=FALSE;
3230  r->has_simple_Inverse=FALSE;
3231 
3232  // variables for this type of coeffs:
3233  // (none)
3234  return FALSE;
3235 }
number nlGetUnit(number n, const coeffs r)
Definition: longrat.cc:936
LINLINE number nlSub(number la, number li, const coeffs r)
Definition: longrat.cc:2518
static void nlClearDenominators(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs cf)
Definition: longrat.cc:2885
#define INT_TO_SR(INT)
Definition: longrat.h:66
BOOLEAN nlCoeffIsEqual(const coeffs r, n_coeffType n, void *p)
Definition: longrat.cc:3102
char * nlCoeffName(const coeffs r)
Definition: longrat.cc:2979
static number nlConvFactoryNSingN(const CanonicalForm f, const coeffs r)
Definition: longrat.cc:380
BOOLEAN nlGreaterZero(number za, const coeffs r)
Definition: longrat.cc:1141
#define FALSE
Definition: auxiliary.h:140
static void nlMPZ(mpz_t m, number &n, const coeffs r)
Definition: longrat.cc:2570
return P p
Definition: myNF.cc:203
number nlNormalizeHelper(number a, number b, const coeffs r)
Definition: longrat.cc:1321
LINLINE void nlInpAdd(number &a, number b, const coeffs r)
Definition: longrat.cc:2470
number nlGetDenom(number &n, const coeffs r)
Definition: longrat.cc:1431
void nlWrite(number a, const coeffs r)
Definition: longrat0.cc:117
int nlSize(number a, const coeffs)
Definition: longrat.cc:577
LINLINE number nlAdd(number la, number li, const coeffs r)
Definition: longrat.cc:2452
BOOLEAN nlIsMOne(number a, const coeffs r)
Definition: longrat.cc:1166
void nlCoeffWrite(const coeffs r, BOOLEAN details)
Definition: longrat.cc:2745
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:1178
#define TRUE
Definition: auxiliary.h:144
coeffs nlQuot1(number c, const coeffs r)
Definition: longrat.cc:944
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:852
BOOLEAN nlGreater(number a, number b, const coeffs r)
Definition: longrat.cc:1151
static number nlInitMPZ(mpz_t m, const coeffs)
Definition: longrat.cc:2579
LINLINE BOOLEAN nlIsOne(number a, const coeffs r)
Definition: longrat.cc:2375
static number nlLcm(number a, number b, const coeffs r)
Definition: longrat.cc:3114
LINLINE number nlNeg(number za, const coeffs r)
Definition: longrat.cc:2433
number nlDiv(number a, number b, const coeffs r)
Definition: longrat.cc:978
LINLINE number nlMult(number a, number b, const coeffs r)
Definition: longrat.cc:2488
number nlInvers(number a, const coeffs r)
Definition: longrat.cc:656
int nlDivComp(number a, number b, const coeffs r)
Definition: longrat.cc:925
LINLINE void nlInpMult(number &a, number b, const coeffs r)
Definition: longrat.cc:2536
static void nlWriteFd(number n, FILE *f, const coeffs)
Definition: longrat.cc:2994
LINLINE BOOLEAN nlEqual(number a, number b, const coeffs r)
Definition: longrat.cc:2348
void nlPower(number x, int exp, number *lu, const coeffs r)
Definition: longrat.cc:1088
static number nlReadFd(s_buff f, const coeffs)
Definition: longrat.cc:3040
number nlExtGcd(number a, number b, number *s, number *t, const coeffs)
Definition: longrat.cc:2711
LINLINE BOOLEAN nlIsZero(number za, const coeffs r)
Definition: longrat.cc:2384
static void nlClearContent(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs cf)
Definition: longrat.cc:2794
static CanonicalForm nlConvSingNFactoryN(number n, const BOOLEAN setChar, const coeffs)
Definition: longrat.cc:342
(number), see longrat.h
Definition: coeffs.h:110
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1277
number nlChineseRemainderSym(number *x, number *q, int rl, BOOLEAN sym, CFArray &inv_cache, const coeffs CF)
Definition: longrat.cc:2754
#define NULL
Definition: omList.c:10
static number nlRandom(siRandProc p, number v2, number, const coeffs cf)
Definition: longrat.cc:3124
LINLINE void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2417
BOOLEAN nlDivBy(number a, number b, const coeffs)
Definition: longrat.cc:911
BOOLEAN nlIsUnit(number a, const coeffs)
Definition: longrat.cc:969
long nlInt(number &n, const coeffs r)
Definition: longrat.cc:606
nMapFunc nlSetMap(const coeffs src, const coeffs dst)
Definition: longrat.cc:2244
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:2357
static char * nlCoeffString(const coeffs r)
Definition: longrat.cc:2985
number nlGetNumerator(number &n, const coeffs r)
Definition: longrat.cc:1460
LINLINE number nlCopy(number a, const coeffs r)
Definition: longrat.cc:2404
number nlFarey(number nN, number nP, const coeffs CF)
Definition: longrat.cc:2642
static number nlInitMPZ ( mpz_t  m,
const coeffs   
)
static

Definition at line 2579 of file longrat.cc.

2580 {
2581  number z = ALLOC_RNUMBER();
2582  mpz_init_set(z->z, m);
2583  z->s = 3;
2584  return z;
2585 }
int m
Definition: cfEzgcd.cc:119
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
LINLINE void nlInpAdd ( number &  a,
number  b,
const coeffs  r 
)

Definition at line 2470 of file longrat.cc.

2471 {
2472  // a=a+b
2473  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
2474  {
2475  LONG r=SR_HDL(a)+SR_HDL(b)-1L;
2476  if ( ((r << 1) >> 1) == r )
2477  a=(number)(long)r;
2478  else
2479  a=nlRInit(SR_TO_INT(r));
2480  }
2481  else
2482  {
2484  nlTest(a,r);
2485  }
2486 }
const poly a
Definition: syzextra.cc:212
number nlRInit(long i)
Definition: longrat.cc:2281
const ring r
Definition: syzextra.cc:208
void _nlInpAdd_aNoImm_OR_bNoImm(number &a, number b)
Definition: longrat.cc:1755
#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 2588 of file longrat.cc.

2589 {
2590  if ((SR_HDL(b)|SR_HDL(a))&SR_INT)
2591  {
2592  number n=nlGcd(a,b,r);
2593  nlDelete(&a,r);
2594  a=n;
2595  }
2596  else
2597  {
2598  mpz_gcd(a->z,a->z,b->z);
2600  }
2601 }
const poly a
Definition: syzextra.cc:212
number nlGcd(number a, number b, const coeffs r)
Definition: longrat.cc:1178
number nlShort3_noinline(number x)
Definition: longrat.cc:174
LINLINE void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2417
#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 2603 of file longrat.cc.

2604 {
2605  if ((SR_HDL(b)|SR_HDL(a))&SR_INT)
2606  {
2607  number n=nlIntDiv(a,b, r);
2608  nlDelete(&a,r);
2609  a=n;
2610  }
2611  else
2612  {
2613  if (mpz_isNeg(a->z))
2614  {
2615  if (mpz_isNeg(b->z))
2616  {
2617  mpz_add(a->z,a->z,b->z);
2618  }
2619  else
2620  {
2621  mpz_sub(a->z,a->z,b->z);
2622  }
2623  mpz_add_ui(a->z,a->z,1);
2624  }
2625  else
2626  {
2627  if (mpz_isNeg(b->z))
2628  {
2629  mpz_sub(a->z,a->z,b->z);
2630  }
2631  else
2632  {
2633  mpz_add(a->z,a->z,b->z);
2634  }
2635  mpz_sub_ui(a->z,a->z,1);
2636  }
2637  MPZ_DIV(a->z,a->z,b->z);
2639  }
2640 }
const poly a
Definition: syzextra.cc:212
number nlIntDiv(number a, number b, const coeffs r)
Definition: longrat.cc:786
#define mpz_isNeg(A)
Definition: longrat.cc:159
number nlShort3_noinline(number x)
Definition: longrat.cc:174
LINLINE void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2417
#define SR_INT
Definition: longrat.h:65
#define MPZ_DIV(A, B, C)
Definition: longrat.cc:162
#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 2536 of file longrat.cc.

2537 {
2538  number aa=a;
2539  if (((SR_HDL(b)|SR_HDL(aa))&SR_INT))
2540  {
2541  number n=nlMult(aa,b,r);
2542  nlDelete(&a,r);
2543  a=n;
2544  }
2545  else
2546  {
2547  mpz_mul(aa->z,a->z,b->z);
2548  if (aa->s==3)
2549  {
2550  if(b->s!=3)
2551  {
2552  mpz_init_set(a->n,b->n);
2553  a->s=0;
2554  }
2555  }
2556  else
2557  {
2558  if(b->s!=3)
2559  {
2560  mpz_mul(a->n,a->n,b->n);
2561  }
2562  a->s=0;
2563  }
2564  }
2565 }
const poly a
Definition: syzextra.cc:212
LINLINE number nlMult(number a, number b, const coeffs r)
Definition: longrat.cc:2488
LINLINE void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2417
#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 606 of file longrat.cc.

607 {
608  nlTest(i, r);
609  nlNormalize(i,r);
610  if (SR_HDL(i) & SR_INT)
611  {
612  return SR_TO_INT(i);
613  }
614  if (i->s==3)
615  {
616  if(mpz_size1(i->z)>MP_SMALL) return 0;
617  long ul=mpz_get_si(i->z);
618  if (mpz_cmp_si(i->z,ul)!=0) return 0;
619  return ul;
620  }
621  mpz_t tmp;
622  long ul;
623  mpz_init(tmp);
624  MPZ_DIV(tmp,i->z,i->n);
625  if(mpz_size1(tmp)>MP_SMALL) ul=0;
626  else
627  {
628  ul=mpz_get_si(tmp);
629  if (mpz_cmp_si(tmp,ul)!=0) ul=0;
630  }
631  mpz_clear(tmp);
632  return ul;
633 }
#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:1277
#define mpz_size1(A)
Definition: si_gmp.h:12
#define SR_INT
Definition: longrat.h:65
#define MPZ_DIV(A, B, C)
Definition: longrat.cc:162
#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  return INT_TO_SR(aa/bb);
806  }
807  if (SR_HDL(a) & SR_INT)
808  {
809  /* the small int -(1<<28) divided by 2^28 is 1 */
810  if (a==INT_TO_SR(-(POW_2_28)))
811  {
812  if(mpz_cmp_si(b->z,(POW_2_28))==0)
813  {
814  return INT_TO_SR(-1);
815  }
816  }
817  /* a is a small and b is a large int: -> 0 */
818  return INT_TO_SR(0);
819  }
820  number bb=NULL;
821  if (SR_HDL(b) & SR_INT)
822  {
823  bb=nlRInit(SR_TO_INT(b));
824  b=bb;
825  }
826  u=ALLOC_RNUMBER();
827 #if defined(LDEBUG)
828  u->debug=123456;
829 #endif
830  assume(a->s==3);
831  assume(b->s==3);
832  mpz_init_set(u->z,a->z);
833  /* u=u/b */
834  u->s = 3;
835  MPZ_DIV(u->z,u->z,b->z);
836  if (bb!=NULL)
837  {
838  mpz_clear(bb->z);
839 #if defined(LDEBUG)
840  bb->debug=654324;
841 #endif
842  FREE_RNUMBER(bb);
843  }
844  u=nlShort3(u);
845  nlTest(u,r);
846  return u;
847 }
#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:2281
#define FREE_RNUMBER(x)
Definition: coeffs.h:85
void WerrorS(const char *s)
Definition: feFopen.cc:24
#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 SR_INT
Definition: longrat.h:65
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
#define MPZ_DIV(A, B, C)
Definition: longrat.cc:162
#define SR_HDL(A)
Definition: tgb.cc:35
const poly b
Definition: syzextra.cc:213
#define nlTest(a, r)
Definition: longrat.cc:90
number nlIntMod ( number  a,
number  b,
const coeffs  r 
)

Definition at line 852 of file longrat.cc.

853 {
854  if (b==INT_TO_SR(0))
855  {
856  WerrorS(nDivBy0);
857  return INT_TO_SR(0);
858  }
859  if (a==INT_TO_SR(0))
860  return INT_TO_SR(0);
861  number u;
862  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
863  {
864  LONG bb=SR_TO_INT(b);
865  LONG c=SR_TO_INT(a) % bb;
866  return INT_TO_SR(c);
867  }
868  if (SR_HDL(a) & SR_INT)
869  {
870  mpz_t aa;
871  mpz_init(aa);
872  mpz_set_si(aa, SR_TO_INT(a));
873  u=ALLOC_RNUMBER();
874 #if defined(LDEBUG)
875  u->debug=123456;
876 #endif
877  u->s = 3;
878  mpz_init(u->z);
879  mpz_mod(u->z,aa,b->z);
880  mpz_clear(aa);
881  u=nlShort3(u);
882  nlTest(u,r);
883  return u;
884  }
885  number bb=NULL;
886  if (SR_HDL(b) & SR_INT)
887  {
888  bb=nlRInit(SR_TO_INT(b));
889  b=bb;
890  }
891  u=ALLOC_RNUMBER();
892 #if defined(LDEBUG)
893  u->debug=123456;
894 #endif
895  mpz_init(u->z);
896  u->s = 3;
897  mpz_mod(u->z,a->z,b->z);
898  if (bb!=NULL)
899  {
900  mpz_clear(bb->z);
901 #if defined(LDEBUG)
902  bb->debug=654324;
903 #endif
904  FREE_RNUMBER(bb);
905  }
906  u=nlShort3(u);
907  nlTest(u,r);
908  return u;
909 }
#define INT_TO_SR(INT)
Definition: longrat.h:66
const poly a
Definition: syzextra.cc:212
number nlRInit(long i)
Definition: longrat.cc:2281
#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 LONG
Definition: longrat.cc:108
#define nlTest(a, r)
Definition: longrat.cc:90
number nlInvers ( number  a,
const coeffs  r 
)

Definition at line 656 of file longrat.cc.

657 {
658  nlTest(a, r);
659  number n;
660  if (SR_HDL(a) & SR_INT)
661  {
662  if ((a==INT_TO_SR(1L)) || (a==INT_TO_SR(-1L)))
663  {
664  return a;
665  }
666  if (nlIsZero(a,r))
667  {
668  WerrorS(nDivBy0);
669  return INT_TO_SR(0);
670  }
671  n=ALLOC_RNUMBER();
672 #if defined(LDEBUG)
673  n->debug=123456;
674 #endif
675  n->s=1;
676  if ((long)a>0L)
677  {
678  mpz_init_set_si(n->z,(long)1);
679  mpz_init_set_si(n->n,(long)SR_TO_INT(a));
680  }
681  else
682  {
683  mpz_init_set_si(n->z,(long)-1);
684  mpz_init_set_si(n->n,(long)-SR_TO_INT(a));
685  }
686  nlTest(n, r);
687  return n;
688  }
689  n=ALLOC_RNUMBER();
690 #if defined(LDEBUG)
691  n->debug=123456;
692 #endif
693  {
694  n->s=a->s;
695  mpz_init_set(n->n,a->z);
696  switch (a->s)
697  {
698  case 0:
699  case 1:
700  mpz_init_set(n->z,a->n);
701  if (mpz_isNeg(n->n)) /* && n->s<2*/
702  {
703  mpz_neg(n->z,n->z);
704  mpz_neg(n->n,n->n);
705  }
706  if (mpz_cmp_si(n->n,(long)1)==0)
707  {
708  mpz_clear(n->n);
709  n->s=3;
710  n=nlShort3(n);
711  }
712  break;
713  case 3:
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,(long)-1);
719  }
720  else
721  {
722  mpz_init_set_si(n->z,(long)1);
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:2384
#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 1166 of file longrat.cc.

1167 {
1168 #ifdef LDEBUG
1169  if (a==NULL) return FALSE;
1170  nlTest(a, r);
1171 #endif
1172  return (a==INT_TO_SR(-1L));
1173 }
#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 2375 of file longrat.cc.

2376 {
2377 #ifdef LDEBUG
2378  if (a==NULL) return FALSE;
2379  nlTest(a, r);
2380 #endif
2381  return (a==INT_TO_SR(1));
2382 }
#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 969 of file longrat.cc.

970 {
971  return ((SR_HDL(a) & SR_INT) && (ABS(SR_TO_INT(a))==1));
972 }
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 2384 of file longrat.cc.

2385 {
2386  #if 0
2387  if (a==INT_TO_SR(0)) return TRUE;
2388  if ((SR_HDL(a) & SR_INT)||(a==NULL)) return FALSE;
2389  if (mpz_cmp_si(a->z,(long)0)==0)
2390  {
2391  printf("gmp-0 in nlIsZero\n");
2392  dErrorBreak();
2393  return TRUE;
2394  }
2395  return FALSE;
2396  #else
2397  return (a==INT_TO_SR(0));
2398  #endif
2399 }
#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 3114 of file longrat.cc.

3115 {
3116  number g=nlGcd(a,b,r);
3117  number n1=nlMult(a,b,r);
3118  number n2=nlDiv(n1,g,r);
3119  nlDelete(&g,r);
3120  nlDelete(&n1,r);
3121  return n2;
3122 }
const poly a
Definition: syzextra.cc:212
number nlGcd(number a, number b, const coeffs r)
Definition: longrat.cc:1178
g
Definition: cfModGcd.cc:4031
number nlDiv(number a, number b, const coeffs r)
Definition: longrat.cc:978
LINLINE number nlMult(number a, number b, const coeffs r)
Definition: longrat.cc:2488
LINLINE void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2417
const poly b
Definition: syzextra.cc:213
number nlMapGMP ( number  from,
const coeffs  src,
const coeffs  dst 
)

Definition at line 210 of file longrat.cc.

211 {
212  number z=ALLOC_RNUMBER();
213 #if defined(LDEBUG)
214  z->debug=123456;
215 #endif
216  mpz_init_set(z->z,(mpz_ptr) from);
217  //mpz_init_set_ui(&z->n,1);
218  z->s = 3;
219  z=nlShort3(z);
220  return z;
221 }
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)omAlloc(sizeof(mp_limb_t)*bl);
480  nn[bl-1] = 1;
481  for (i=bl-2;i>=0;i--) nn[i] = 0;
482  ndest = res->n;
483  ndest->_mp_d = nn;
484  ndest->_mp_alloc = ndest->_mp_size = bl;
485  res->s = 0;
486  }
487  else
488  {
489  al = dest->_mp_size = size+e;
490  if (al<2) al = 2;
491  dd = (mp_ptr)omAlloc(sizeof(mp_limb_t)*al);
492  for (i=0;i<size;i++) dd[i+e] = qp[i];
493  for (i=0;i<e;i++) dd[i] = 0;
494  res->s = 3;
495  }
496 
497  dest->_mp_d = dd;
498  dest->_mp_alloc = al;
499  if (negative) dest->_mp_size = -dest->_mp_size;
500 
501  if (res->s==0)
502  nlNormalize(res,dst);
503  else if (mpz_size1(res->z)<=MP_SMALL)
504  {
505  // res is new, res->ref is 1
506  res=nlShort3(res);
507  }
508  nlTest(res, dst);
509  return res;
510 }
#define INT_TO_SR(INT)
Definition: longrat.h:66
mpf_t * _mpfp()
Definition: mpr_complex.h:134
f
Definition: cfModGcd.cc:4022
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
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:1277
#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 nlTest(a, r)
Definition: longrat.cc:90
number nlMapMachineInt ( number  from,
const coeffs  ,
const coeffs   
)

Definition at line 235 of file longrat.cc.

236 {
237  number z=ALLOC_RNUMBER();
238 #if defined(LDEBUG)
239  z->debug=123456;
240 #endif
241  mpz_init_set_ui(z->z,(unsigned long) from);
242  z->s = 3;
243  z=nlShort3(z);
244  return z;
245 }
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 193 of file longrat.cc.

194 {
195  assume( getCoeffType(src) == n_Zp );
196 
197  number to = nlInit(npInt(from,src), dst); // FIXME? TODO? // extern long npInt (number &n, const coeffs r);
198 
199  return to;
200 }
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:2357
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
f
Definition: cfModGcd.cc:4022
number nlRInit(long i)
Definition: longrat.cc:2281
single prescision (6,6) real numbers
Definition: coeffs.h:32
LINLINE number nlNeg(number za, const coeffs r)
Definition: longrat.cc:2433
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
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:1277
number nlMapZ ( number  from,
const coeffs  src,
const coeffs  dst 
)

Definition at line 223 of file longrat.cc.

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

Definition at line 1368 of file longrat.cc.

1369 {
1370  const int p = n_GetChar(Zp);
1371  assume( p > 0 );
1372 
1373  const long P = p;
1374  assume( P > 0 );
1375 
1376  // embedded long within q => only long numerator has to be converted
1377  // to int (modulo char.)
1378  if (SR_HDL(q) & SR_INT)
1379  {
1380  long i = SR_TO_INT(q);
1381  return n_Init( i, Zp );
1382  }
1383 
1384  const unsigned long PP = p;
1385 
1386  // numerator modulo char. should fit into int
1387  number z = n_Init( static_cast<long>(mpz_fdiv_ui(q->z, PP)), Zp );
1388 
1389  // denominator != 1?
1390  if (q->s!=3)
1391  {
1392  // denominator modulo char. should fit into int
1393  number n = n_Init( static_cast<long>(mpz_fdiv_ui(q->n, PP)), Zp );
1394 
1395  number res = n_Div( z, n, Zp );
1396 
1397  n_Delete(&z, Zp);
1398  n_Delete(&n, Zp);
1399 
1400  return res;
1401  }
1402 
1403  return z;
1404 }
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:615
#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 2570 of file longrat.cc.

2571 {
2572  nlTest(n, r);
2573  nlNormalize(n, r);
2574  if (SR_HDL(n) & SR_INT) mpz_init_set_si(m, SR_TO_INT(n)); /* n fits in an int */
2575  else mpz_init_set(m, (mpz_ptr)n->z);
2576 }
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:1277
#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 2488 of file longrat.cc.

2489 {
2490  nlTest(a, R);
2491  nlTest(b, R);
2492  if (a==INT_TO_SR(0)) return INT_TO_SR(0);
2493  if (b==INT_TO_SR(0)) return INT_TO_SR(0);
2494  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
2495  {
2496  LONG r=(LONG)((unsigned LONG)(SR_HDL(a)-1L))*((unsigned LONG)(SR_HDL(b)>>1));
2497  if ((r/(SR_HDL(b)>>1))==(SR_HDL(a)-1L))
2498  {
2499  number u=((number) ((r>>1)+SR_INT));
2500  if (((((LONG)SR_HDL(u))<<1)>>1)==SR_HDL(u)) return (u);
2501  return nlRInit(SR_HDL(u)>>2);
2502  }
2503  number u = _nlMult_aImm_bImm_rNoImm(a, b);
2504  nlTest(u, R);
2505  return u;
2506 
2507  }
2508  number u = _nlMult_aNoImm_OR_bNoImm(a, b);
2509  nlTest(u, R);
2510  return u;
2511 
2512 }
#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:2131
number nlRInit(long i)
Definition: longrat.cc:2281
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:2118
#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 2433 of file longrat.cc.

2434 {
2435  nlTest(a, R);
2436  if(SR_HDL(a) &SR_INT)
2437  {
2438  LONG r=SR_TO_INT(a);
2439  if (r==(-(POW_2_28))) a=nlRInit(POW_2_28);
2440  else a=INT_TO_SR(-r);
2441  return a;
2442  }
2443  a = _nlNeg_NoImm(a);
2444  nlTest(a, R);
2445  return a;
2446 
2447 }
#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:2281
const ring R
Definition: DebugPrint.cc:36
#define SR_TO_INT(SR)
Definition: longrat.h:67
number _nlNeg_NoImm(number a)
Definition: longrat.cc:1577
#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 1277 of file longrat.cc.

1278 {
1279  if ((SR_HDL(x) & SR_INT) ||(x==NULL))
1280  return;
1281  if (x->s==3)
1282  {
1284  nlTest(x,r);
1285  return;
1286  }
1287  else if (x->s==0)
1288  {
1289  if (mpz_cmp_si(x->n,(long)1)==0)
1290  {
1291  mpz_clear(x->n);
1292  x->s=3;
1293  x=nlShort3(x);
1294  }
1295  else
1296  {
1297  mpz_t gcd;
1298  mpz_init(gcd);
1299  mpz_gcd(gcd,x->z,x->n);
1300  x->s=1;
1301  if (mpz_cmp_si(gcd,(long)1)!=0)
1302  {
1303  MPZ_EXACTDIV(x->z,x->z,gcd);
1304  MPZ_EXACTDIV(x->n,x->n,gcd);
1305  if (mpz_cmp_si(x->n,(long)1)==0)
1306  {
1307  mpz_clear(x->n);
1308  x->s=3;
1310  }
1311  }
1312  mpz_clear(gcd);
1313  }
1314  }
1315  nlTest(x, r);
1316 }
#define MPZ_EXACTDIV(A, B, C)
Definition: longrat.cc:163
number nlShort3_noinline(number x)
Definition: longrat.cc:174
#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
number nlNormalizeHelper ( number  a,
number  b,
const coeffs  r 
)

Definition at line 1321 of file longrat.cc.

1322 {
1323  number result;
1324  nlTest(a, r);
1325  nlTest(b, r);
1326  if ((SR_HDL(b) & SR_INT)
1327  || (b->s==3))
1328  {
1329  // b is 1/(b->n) => b->n is 1 => result is a
1330  return nlCopy(a,r);
1331  }
1332  result=ALLOC_RNUMBER();
1333 #if defined(LDEBUG)
1334  result->debug=123456;
1335 #endif
1336  result->s=3;
1337  mpz_t gcd;
1338  mpz_init(gcd);
1339  mpz_init(result->z);
1340  if (SR_HDL(a) & SR_INT)
1341  mpz_gcd_ui(gcd,b->n,ABS(SR_TO_INT(a)));
1342  else
1343  mpz_gcd(gcd,a->z,b->n);
1344  if (mpz_cmp_si(gcd,(long)1)!=0)
1345  {
1346  mpz_t bt;
1347  mpz_init_set(bt,b->n);
1348  MPZ_EXACTDIV(bt,bt,gcd);
1349  if (SR_HDL(a) & SR_INT)
1350  mpz_mul_si(result->z,bt,SR_TO_INT(a));
1351  else
1352  mpz_mul(result->z,bt,a->z);
1353  mpz_clear(bt);
1354  }
1355  else
1356  if (SR_HDL(a) & SR_INT)
1357  mpz_mul_si(result->z,b->n,SR_TO_INT(a));
1358  else
1359  mpz_mul(result->z,b->n,a->z);
1360  mpz_clear(gcd);
1361  result=nlShort3(result);
1362  nlTest(result, r);
1363  return result;
1364 }
#define MPZ_EXACTDIV(A, B, C)
Definition: longrat.cc:163
void mpz_mul_si(mpz_ptr r, mpz_srcptr s, long int si)
Definition: longrat.cc:181
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:2404
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 1088 of file longrat.cc.

1089 {
1090  *u = INT_TO_SR(0); // 0^e, e!=0
1091  if (exp==0)
1092  *u= INT_TO_SR(1);
1093  else if (!nlIsZero(x,r))
1094  {
1095  nlTest(x, r);
1096  number aa=NULL;
1097  if (SR_HDL(x) & SR_INT)
1098  {
1099  aa=nlRInit(SR_TO_INT(x));
1100  x=aa;
1101  }
1102  else if (x->s==0)
1103  nlNormalize(x,r);
1104  *u=ALLOC_RNUMBER();
1105 #if defined(LDEBUG)
1106  (*u)->debug=123456;
1107 #endif
1108  mpz_init((*u)->z);
1109  mpz_pow_ui((*u)->z,x->z,(unsigned long)exp);
1110  if (x->s<2)
1111  {
1112  if (mpz_cmp_si(x->n,(long)1)==0)
1113  {
1114  x->s=3;
1115  mpz_clear(x->n);
1116  }
1117  else
1118  {
1119  mpz_init((*u)->n);
1120  mpz_pow_ui((*u)->n,x->n,(unsigned long)exp);
1121  }
1122  }
1123  (*u)->s = x->s;
1124  if ((*u)->s==3) *u=nlShort3(*u);
1125  if (aa!=NULL)
1126  {
1127  mpz_clear(aa->z);
1128  FREE_RNUMBER(aa);
1129  }
1130  }
1131 #ifdef LDEBUG
1132  if (exp<0) Print("nlPower: neg. exp. %d\n",exp);
1133  nlTest(*u, r);
1134 #endif
1135 }
#define INT_TO_SR(INT)
Definition: longrat.h:66
#define Print
Definition: emacs.cc:83
number nlRInit(long i)
Definition: longrat.cc:2281
#define FREE_RNUMBER(x)
Definition: coeffs.h:85
LINLINE BOOLEAN nlIsZero(number za, const coeffs r)
Definition: longrat.cc:2384
#define SR_TO_INT(SR)
Definition: longrat.h:67
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1277
#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 944 of file longrat.cc.

945 {
946  long ch = r->cfInt(c, r);
947  int p=IsPrime(ch);
948  coeffs rr=NULL;
949  if ((long)p==ch)
950  {
951  rr = nInitChar(n_Zp,(void*)ch);
952  }
953  #ifdef HAVE_RINGS
954  else
955  {
956  mpz_ptr dummy;
957  dummy = (mpz_ptr) omAlloc(sizeof(mpz_t));
958  mpz_init_set_ui(dummy, ch);
959  ZnmInfo info;
960  info.base = dummy;
961  info.exp = (unsigned long) 1;
962  rr = nInitChar(n_Zn, (void*)&info);
963  }
964  #endif
965  return(rr);
966 }
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
static number nlRandom ( siRandProc  p,
number  v2,
number  ,
const coeffs  cf 
)
static

Definition at line 3124 of file longrat.cc.

3125 {
3126  number a=nlInit(p(),cf);
3127  if (v2!=NULL)
3128  {
3129  number b=nlInit(p(),cf);
3130  number c=nlDiv(a,b,cf);
3131  nlDelete(&b,cf);
3132  nlDelete(&a,cf);
3133  a=c;
3134  }
3135  return a;
3136 }
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:978
#define NULL
Definition: omList.c:10
LINLINE void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2417
LINLINE number nlInit(long i, const coeffs r)
Definition: longrat.cc:2357
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,(long)0)==0)
81  {
83  mpz_clear(n);
84  (*a)->s = 3;
85  }
86  else if (mpz_cmp_si(n,(long)1)==0)
87  {
88  mpz_clear(n);
89  (*a)->s=3;
90  }
91  }
92  if (mpz_cmp_si(z,(long)0)==0)
93  {
94  mpz_clear(z);
95  FREE_RNUMBER(*a);
96  *a=INT_TO_SR(0);
97  }
98  else
99  if ((*a)->s==3)
100  {
101  number nlShort3_noinline(number x);
102  *a=nlShort3_noinline(*a);
103  }
104  else
105  {
106  number aa=*a;
107  nlNormalize(aa,r); // FIXME? TODO? // extern void nlNormalize(number &x, const coeffs r);
108  *a=aa;
109  }
110  }
111  return s;
112 }
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:174
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1277
#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 3040 of file longrat.cc.

3041 {
3042  int sub_type=-1;
3043  sub_type=s_readint(f);
3044  switch(sub_type)
3045  {
3046  case 0:
3047  case 1:
3048  {// read mpz_t, mpz_t
3049  number n=nlRInit(0);
3050  mpz_init(n->n);
3051  s_readmpz(f,n->z);
3052  s_readmpz(f,n->n);
3053  n->s=sub_type;
3054  return n;
3055  }
3056 
3057  case 3:
3058  {// read mpz_t
3059  number n=nlRInit(0);
3060  s_readmpz(f,n->z);
3061  n->s=3; /*sub_type*/
3062  #if SIZEOF_LONG == 8
3063  n=nlShort3(n);
3064  #endif
3065  return n;
3066  }
3067  case 4:
3068  {
3069  LONG dd=s_readlong(f);
3070  //#if SIZEOF_LONG == 8
3071  return INT_TO_SR(dd);
3072  //#else
3073  //return nlInit(dd,NULL);
3074  //#endif
3075  }
3076  case 5:
3077  case 6:
3078  {// read raw mpz_t, mpz_t
3079  number n=nlRInit(0);
3080  mpz_init(n->n);
3081  s_readmpz_base (f,n->z, SSI_BASE);
3082  s_readmpz_base (f,n->n, SSI_BASE);
3083  n->s=sub_type-5;
3084  return n;
3085  }
3086  case 8:
3087  {// read raw mpz_t
3088  number n=nlRInit(0);
3089  s_readmpz_base (f,n->z, SSI_BASE);
3090  n->s=sub_type=3; /*subtype-5*/
3091  #if SIZEOF_LONG == 8
3092  n=nlShort3(n);
3093  #endif
3094  return n;
3095  }
3096 
3097  default: Werror("error in reading number: invalid subtype %d",sub_type);
3098  return NULL;
3099  }
3100  return NULL;
3101 }
#define INT_TO_SR(INT)
Definition: longrat.h:66
f
Definition: cfModGcd.cc:4022
number nlRInit(long i)
Definition: longrat.cc:2281
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 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
#define SSI_BASE
Definition: longrat.cc:2992
number nlRInit ( long  i)

Definition at line 2281 of file longrat.cc.

2282 {
2283  number z=ALLOC_RNUMBER();
2284 #if defined(LDEBUG)
2285  z->debug=123456;
2286 #endif
2287  mpz_init_set_si(z->z,i);
2288  z->s = 3;
2289  return z;
2290 }
int i
Definition: cfEzgcd.cc:123
#define ALLOC_RNUMBER()
Definition: coeffs.h:86
nMapFunc nlSetMap ( const coeffs  src,
const coeffs  dst 
)

Definition at line 2244 of file longrat.cc.

2245 {
2246  if (src->rep==n_rep_gap_rat) /*Q, coeffs_BIGINT */
2247  {
2248  return ndCopyMap;
2249  }
2250  if ((src->rep==n_rep_int) && nCoeff_is_Zp(src))
2251  {
2252  return nlMapP;
2253  }
2254  if ((src->rep==n_rep_float) && nCoeff_is_R(src))
2255  {
2256  return nlMapR;
2257  }
2258  if ((src->rep==n_rep_gmp_float) && nCoeff_is_long_R(src))
2259  {
2260  return nlMapLongR; /* long R -> Q */
2261  }
2262 #ifdef HAVE_RINGS
2263  if (src->rep==n_rep_gmp) // nCoeff_is_Ring_Z(src) || nCoeff_is_Ring_PtoM(src) || nCoeff_is_Ring_ModN(src))
2264  {
2265  return nlMapGMP;
2266  }
2267  if (src->rep==n_rep_gap_gmp)
2268  {
2269  return nlMapZ;
2270  }
2271  if ((src->rep==n_rep_int) && nCoeff_is_Ring_2toM(src))
2272  {
2273  return nlMapMachineInt;
2274  }
2275 #endif
2276  return NULL;
2277 }
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition: coeffs.h:818
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:892
static FORCE_INLINE BOOLEAN nCoeff_is_R(const coeffs r)
Definition: coeffs.h:834
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_2toM(const coeffs r)
Definition: coeffs.h:741
(), see rinteger.h, new impl.
Definition: coeffs.h:111
number nlMapZ(number from, const coeffs src, const coeffs dst)
Definition: longrat.cc:223
static number nlMapP(number from, const coeffs src, const coeffs dst)
Definition: longrat.cc:193
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:210
(int), see modulop.h
Definition: coeffs.h:109
number nlMapMachineInt(number from, const coeffs, const coeffs)
Definition: longrat.cc:235
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 1256 of file longrat.cc.

1257 {
1258  assume(x->s<2);
1259  if (mpz_cmp_ui(x->z,(long)0)==0)
1260  {
1261  _nlDelete_NoImm(&x);
1262  return INT_TO_SR(0);
1263  }
1264  if (x->s<2)
1265  {
1266  if (mpz_cmp(x->z,x->n)==0)
1267  {
1268  _nlDelete_NoImm(&x);
1269  return INT_TO_SR(1);
1270  }
1271  }
1272  return x;
1273 }
#define INT_TO_SR(INT)
Definition: longrat.h:66
#define assume(x)
Definition: mod2.h:405
void _nlDelete_NoImm(number *a)
Definition: longrat.cc:1559
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,(long)0)==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 174 of file longrat.cc.

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

Definition at line 577 of file longrat.cc.

578 {
579  if (a==INT_TO_SR(0))
580  return 0; /* rational 0*/
581  if (SR_HDL(a) & SR_INT)
582  return 1; /* immidiate int */
583  int s=a->z[0]._mp_alloc;
584 // while ((s>0) &&(a->z._mp_d[s]==0L)) s--;
585 //#if SIZEOF_LONG == 8
586 // if (a->z._mp_d[s] < (unsigned long)0x100000000L) s=s*2-1;
587 // else s *=2;
588 //#endif
589 // s++;
590  if (a->s<2)
591  {
592  int d=a->n[0]._mp_alloc;
593 // while ((d>0) && (a->n._mp_d[d]==0L)) d--;
594 //#if SIZEOF_LONG == 8
595 // if (a->n._mp_d[d] < (unsigned long)0x100000000L) d=d*2-1;
596 // else d *=2;
597 //#endif
598  s+=d;
599  }
600  return s;
601 }
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 2518 of file longrat.cc.

2519 {
2520  if (SR_HDL(a) & SR_HDL(b) & SR_INT)
2521  {
2522  LONG r=SR_HDL(a)-SR_HDL(b)+1;
2523  if ( ((r << 1) >> 1) == r )
2524  {
2525  return (number)(long)r;
2526  }
2527  else
2528  return nlRInit(SR_TO_INT(r));
2529  }
2530  number u = _nlSub_aNoImm_OR_bNoImm(a, b);
2531  nlTest(u, r);
2532  return u;
2533 
2534 }
const poly a
Definition: syzextra.cc:212
number nlRInit(long i)
Definition: longrat.cc:2281
#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:1894
#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 117 of file longrat0.cc.

118 {
119  char *s,*z;
120  if (SR_HDL(a) & SR_INT)
121  {
122  StringAppend("%ld",SR_TO_INT(a));
123  }
124  else if (a==NULL)
125  {
126  StringAppendS("o");
127  }
128  else
129  {
130  if (a->s==0)
131  {
132  nlNormalize(a,r); // FIXME? TODO? // extern void nlNormalize(number &x, const coeffs r);
133  nlWrite(a,r);
134  return;
135  }
136  int l=mpz_sizeinbase(a->z,10);
137  if (a->s<2) l=si_max(l,(int)mpz_sizeinbase(a->n,10));
138  l+=2;
139  s=(char*)omAlloc(l);
140  z=mpz_get_str(s,10,a->z);
141  StringAppendS(z);
142  if (a->s!=3)
143  {
144  StringAppendS("/");
145  z=mpz_get_str(s,10,a->n);
146  StringAppendS(z);
147  }
148  omFreeSize((void *)s,l);
149  }
150 }
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:117
#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:1277
#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 2994 of file longrat.cc.

2995 {
2996  if(SR_HDL(n) & SR_INT)
2997  {
2998  #if SIZEOF_LONG == 4
2999  fprintf(f,"4 %ld ",SR_TO_INT(n));
3000  #else
3001  long nn=SR_TO_INT(n);
3002  if ((nn<POW_2_28_32)&&(nn>= -POW_2_28_32))
3003  {
3004  int nnn=(int)nn;
3005  fprintf(f,"4 %d ",nnn);
3006  }
3007  else
3008  {
3009  mpz_t tmp;
3010  mpz_init_set_si(tmp,nn);
3011  fputs("8 ",f);
3012  mpz_out_str (f,SSI_BASE, tmp);
3013  fputc(' ',f);
3014  mpz_clear(tmp);
3015  }
3016  #endif
3017  }
3018  else if (n->s<2)
3019  {
3020  //gmp_fprintf(f,"%d %Zd %Zd ",n->s,n->z,n->n);
3021  fprintf(f,"%d ",n->s+5);
3022  mpz_out_str (f,SSI_BASE, n->z);
3023  fputc(' ',f);
3024  mpz_out_str (f,SSI_BASE, n->n);
3025  fputc(' ',f);
3026 
3027  //if (d->f_debug!=NULL) gmp_fprintf(d->f_debug,"number: s=%d gmp/gmp \"%Zd %Zd\" ",n->s,n->z,n->n);
3028  }
3029  else /*n->s==3*/
3030  {
3031  //gmp_fprintf(d->f_write,"3 %Zd ",n->z);
3032  fputs("8 ",f);
3033  mpz_out_str (f,SSI_BASE, n->z);
3034  fputc(' ',f);
3035 
3036  //if (d->f_debug!=NULL) gmp_fprintf(d->f_debug,"number: gmp \"%Zd\" ",n->z);
3037  }
3038 }
f
Definition: cfModGcd.cc:4022
#define POW_2_28_32
Definition: longrat.cc:107
#define SR_TO_INT(SR)
Definition: longrat.h:67
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
#define SSI_BASE
Definition: longrat.cc:2992

Variable Documentation

int n_SwitchChinRem =0

Definition at line 2753 of file longrat.cc.