p_Numbers.h
Go to the documentation of this file.
1 /****************************************
2 * Computer Algebra System SINGULAR *
3 ****************************************/
4 /***************************************************************
5  * File: p_Numbers.h
6  * Purpose: macros/inline functions for number operations
7  * Author: obachman (Olaf Bachmann)
8  * Created: 8/00
9  *******************************************************************/
10 #ifndef P_NUMBERS_H
11 #define P_NUMBERS_H
12 
13 #include <misc/auxiliary.h>
14 #include <coeffs/coeffs.h>
15 #include <coeffs/numbers.h>
16 #include <polys/monomials/ring.h>
17 
18 static FORCE_INLINE number n_Copy_FieldGeneral(number n, const coeffs r)
19 { return n_Copy(n,r); }
20 
21 static FORCE_INLINE void n_Delete_FieldGeneral(number* p, const coeffs r)
22 { n_Delete(p,r); }
23 
24 static FORCE_INLINE number n_Mult_FieldGeneral(number n1, number n2, const coeffs r)
25 { return n_Mult(n1, n2, r); }
26 
27 static FORCE_INLINE number n_Add_FieldGeneral(number n1, number n2, const coeffs r)
28 { return n_Add(n1, n2, r); }
29 
31 { return n_IsZero(n, r); }
32 
33 static FORCE_INLINE BOOLEAN n_Equal_FieldGeneral(number n1, number n2, const coeffs r)
34 { return n_Equal(n1, n2, r); }
35 
36 static FORCE_INLINE number n_Neg_FieldGeneral(number n, const coeffs r)
37 { return n_InpNeg(n, r); }
38 
39 static FORCE_INLINE number n_Sub_FieldGeneral(number n1, number n2, const coeffs r)
40 { return n_Sub(n1, n2, r); }
41 
42 static FORCE_INLINE void n_InpMult_FieldGeneral(number &n1, number n2, const coeffs r)
43 { n_InpMult(n1, n2, r); }
44 
45 static FORCE_INLINE void n_InpAdd_FieldGeneral(number &n1, number n2, const coeffs r)
46 { n_InpAdd(n1, n2, r); }
47 
48 #ifdef HAVE_RINGS
49 #define n_Copy_RingGeneral(n, r) n_Copy_FieldGeneral(n, r)
50 #define n_Delete_RingGeneral(n, r) n_Delete_FieldGeneral(n, r)
51 #define n_Mult_RingGeneral(n1, n2, r) n_Mult_FieldGeneral(n1, n2, r)
52 #define n_Add_RingGeneral(n1, n2, r) n_Add_FieldGeneral(n1, n2, r)
53 #define n_IsZero_RingGeneral(n, r) n_IsZero_FieldGeneral(n, r)
54 #define n_Equal_RingGeneral(n1, n2, r) n_Equal_FieldGeneral(n1, n2, r)
55 #define n_Neg_RingGeneral(n, r) n_Neg_FieldGeneral(n, r)
56 #define n_Sub_RingGeneral(n1, n2, r) n_Sub_FieldGeneral(n1, n2, r)
57 //#define n_InpMult_RingGeneral(n1, n2, r) n_InpMult_FieldGeneral(n1, n2, r)
58 #define n_InpMult_RingGeneral(n1, n2, r) n_InpMult_FieldGeneral(n1, n2, r)
59 
60 static FORCE_INLINE void n_InpAdd_RingGeneral(number &n1, number n2, const coeffs r)
61 { assume(nCoeff_is_Ring(r)); n_InpAdd(n1, n2, r); }
62 #endif
63 
64 #include <coeffs/modulop.h>
65 
66 #define n_Copy_FieldZp(n, r) n
67 #define n_Delete_FieldZp(n, r) do {} while (0)
68 
69 static FORCE_INLINE number n_Mult_FieldZp(number n1, number n2, const coeffs r)
70 { STATISTIC(n_Mult); return npMultM(n1, n2, r); }
71 
72 #ifdef HAVE_NUMSTATS
73 static FORCE_INLINE number n_Add_FieldZp(number n1, number n2, const coeffs r)
74 { STATISTIC(n_Add); const number sum = npAddM(n1, n2, r);
75  // avoid double counting
76  if( npIsZeroM(sum,r) ) STATISTIC(n_CancelOut);
77  return sum;
78 }
79 #else
80 static FORCE_INLINE number n_Add_FieldZp(number n1, number n2, const coeffs r)
81 { return npAddM(n1, n2, r); }
82 #endif
83 
84 #ifdef HAVE_NUMSTATS
85 static FORCE_INLINE number n_Sub_FieldZp(number n1, number n2, const coeffs r)
86 { STATISTIC(n_Sub); const number d = npSubM(n1, n2, r);
87  // avoid double counting
88  if( npIsZeroM(d,r) ) STATISTIC(n_CancelOut);
89  return d;
90 }
91 #else
92 static FORCE_INLINE number n_Sub_FieldZp(number n1, number n2, const coeffs r)
93 { return npSubM(n1, n2, r); }
94 #endif
95 
96 static FORCE_INLINE BOOLEAN n_IsZero_FieldZp(number n, const coeffs r)
97 { STATISTIC(n_IsZero); return npIsZeroM(n, r); }
98 
99 static FORCE_INLINE BOOLEAN n_Equal_FieldZp(number n1, number n2, const coeffs r)
100 { STATISTIC(n_Equal); return npEqualM(n1, n2, r); }
101 
102 static FORCE_INLINE number n_Neg_FieldZp(number n, const coeffs r)
103 { STATISTIC(n_InpNeg); return npNegM(n, r); }
104 
105 static FORCE_INLINE void n_InpMult_FieldZp(number &n1, number n2, const coeffs r)
106 { STATISTIC(n_InpMult); n1=npMultM(n1, n2, r); }
107 
108 #ifdef HAVE_NUMSTATS
109 static FORCE_INLINE void n_InpAdd_FieldZp(number &n1, number n2, const coeffs r)
110 {
111  STATISTIC(n_InpAdd); n1=npAddM(n1, n2, r);
112  // avoid double counting
113  if( npIsZeroM(n1,r) ) STATISTIC(n_CancelOut);
114 }
115 #else
116 static FORCE_INLINE void n_InpAdd_FieldZp(number &n1, number n2, const coeffs r)
117 { n1=npAddM(n1, n2, r); }
118 #endif
119 
120 #define DO_LFORCE_INLINE
121 #include <coeffs/longrat.cc> // for inlining... TODO: fix this Uglyness?!!!
122 
123 static FORCE_INLINE number n_Copy_FieldQ(number n, const coeffs r)
124 { STATISTIC(n_Copy); return nlCopy(n, r); }
125 
126 static FORCE_INLINE void n_Delete_FieldQ(number* n, const coeffs r)
127 { STATISTIC(n_Delete); nlDelete(n,r); }
128 
129 static FORCE_INLINE number n_Mult_FieldQ(number n1, number n2, const coeffs r)
130 { STATISTIC(n_Mult); return nlMult(n1,n2, r); }
131 
132 #ifdef HAVE_NUMSTATS
133 static FORCE_INLINE number n_Add_FieldQ(number n1, number n2, const coeffs r)
134 { STATISTIC(n_Add); const number sum = nlAdd(n1, n2, r);
135  // avoid double counting
136  if( nlIsZero(sum,r) ) STATISTIC(n_CancelOut);
137  return sum;
138 }
139 #else
140 static FORCE_INLINE number n_Add_FieldQ(number n1, number n2, const coeffs r)
141 { return nlAdd(n1, n2, r); }
142 #endif
143 
144 #ifdef HAVE_NUMSTATS
145 static FORCE_INLINE number n_Sub_FieldQ(number n1, number n2, const coeffs r)
146 { STATISTIC(n_Sub); const number d = nlSub(n1, n2, r);
147  // avoid double counting
148  if( nlIsZero(d,r) ) STATISTIC(n_CancelOut);
149  return d;
150 }
151 #else
152 static FORCE_INLINE number n_Sub_FieldQ(number n1, number n2, const coeffs r)
153 { return nlSub(n1, n2, r); }
154 #endif
155 
156 static FORCE_INLINE BOOLEAN n_IsZero_FieldQ(number n, const coeffs r)
157 { STATISTIC(n_IsZero); return nlIsZero(n, r); }
158 
159 static FORCE_INLINE BOOLEAN n_Equal_FieldQ(number n1, number n2, const coeffs r)
160 { STATISTIC(n_Equal); return nlEqual(n1, n2, r); }
161 
162 static FORCE_INLINE number n_Neg_FieldQ(number n, const coeffs r)
163 { STATISTIC(n_InpNeg); return nlNeg(n, r); }
164 
165 static FORCE_INLINE void n_InpMult_FieldQ(number &n1, number n2, const coeffs r)
166 { STATISTIC(n_InpMult); nlInpMult(n1, n2, r); }
167 
168 #ifdef HAVE_NUMSTATS
169 static FORCE_INLINE void n_InpAdd_FieldQ(number &n1, number n2, const coeffs r)
170 { STATISTIC(n_InpAdd); assume(nCoeff_is_Q(r)); nlInpAdd(n1, n2, r);
171  // avoid double counting
172  if( nlIsZero(n1,r) ) STATISTIC(n_CancelOut);
173 }
174 #else
175 static FORCE_INLINE void n_InpAdd_FieldQ(number &n1, number n2, const coeffs r)
176 { nlInpAdd(n1, n2, r); }
177 #endif
178 
179 #endif
static FORCE_INLINE number n_Sub(number a, number b, const coeffs r)
return the difference of 'a' and 'b', i.e., a-b
Definition: coeffs.h:668
static FORCE_INLINE BOOLEAN n_Equal_FieldZp(number n1, number n2, const coeffs r)
Definition: p_Numbers.h:99
#define STATISTIC(f)
Definition: numstats.h:16
LINLINE number nlSub(number la, number li, const coeffs r)
Definition: longrat.cc:2518
static FORCE_INLINE BOOLEAN n_Equal_FieldGeneral(number n1, number n2, const coeffs r)
Definition: p_Numbers.h:33
static FORCE_INLINE BOOLEAN n_IsZero_FieldQ(number n, const coeffs r)
Definition: p_Numbers.h:156
static number npMultM(number a, number b, const coeffs r)
Definition: modulop.h:49
static FORCE_INLINE void n_InpAdd_FieldQ(number &n1, number n2, const coeffs r)
Definition: p_Numbers.h:175
static FORCE_INLINE void n_InpMult_FieldZp(number &n1, number n2, const coeffs r)
Definition: p_Numbers.h:105
static FORCE_INLINE number n_Sub_FieldZp(number n1, number n2, const coeffs r)
Definition: p_Numbers.h:92
static FORCE_INLINE void n_InpMult(number &a, number b, const coeffs r)
multiplication of 'a' and 'b'; replacement of 'a' by the product a*b
Definition: coeffs.h:640
return P p
Definition: myNF.cc:203
static FORCE_INLINE void n_InpAdd_FieldZp(number &n1, number n2, const coeffs r)
Definition: p_Numbers.h:116
static FORCE_INLINE void n_InpAdd_RingGeneral(number &n1, number n2, const coeffs r)
Definition: p_Numbers.h:60
static FORCE_INLINE number n_Add_FieldZp(number n1, number n2, const coeffs r)
Definition: p_Numbers.h:80
LINLINE void nlInpAdd(number &a, number b, const coeffs r)
Definition: longrat.cc:2470
#define npEqualM(A, B, r)
Definition: modulop.h:132
static FORCE_INLINE void n_Delete_FieldGeneral(number *p, const coeffs r)
Definition: p_Numbers.h:21
LINLINE number nlAdd(number la, number li, const coeffs r)
Definition: longrat.cc:2452
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
#define FORCE_INLINE
Definition: auxiliary.h:386
static FORCE_INLINE number n_Neg_FieldGeneral(number n, const coeffs r)
Definition: p_Numbers.h:36
static FORCE_INLINE BOOLEAN nCoeff_is_Q(const coeffs r)
Definition: coeffs.h:824
static FORCE_INLINE number n_Copy_FieldQ(number n, const coeffs r)
Definition: p_Numbers.h:123
static FORCE_INLINE void n_InpAdd(number &a, number b, const coeffs r)
addition of 'a' and 'b'; replacement of 'a' by the sum a+b
Definition: coeffs.h:645
static FORCE_INLINE BOOLEAN nCoeff_is_Ring(const coeffs r)
Definition: coeffs.h:753
static number npNegM(number a, const coeffs r)
Definition: modulop.h:111
static number npSubM(number a, number b, const coeffs r)
Definition: modulop.h:82
static FORCE_INLINE number n_Add_FieldQ(number n1, number n2, const coeffs r)
Definition: p_Numbers.h:140
static FORCE_INLINE number n_Mult(number a, number b, const coeffs r)
return the product of 'a' and 'b', i.e., a*b
Definition: coeffs.h:635
const ring r
Definition: syzextra.cc:208
LINLINE number nlNeg(number za, const coeffs r)
Definition: longrat.cc:2433
Coefficient rings, fields and other domains suitable for Singular polynomials.
LINLINE number nlMult(number a, number b, const coeffs r)
Definition: longrat.cc:2488
#define assume(x)
Definition: mod2.h:405
The main handler for Singular numbers which are suitable for Singular polynomials.
static FORCE_INLINE number n_Add(number a, number b, const coeffs r)
return the sum of 'a' and 'b', i.e., a+b
Definition: coeffs.h:655
LINLINE void nlInpMult(number &a, number b, const coeffs r)
Definition: longrat.cc:2536
static FORCE_INLINE number n_Sub_FieldQ(number n1, number n2, const coeffs r)
Definition: p_Numbers.h:152
static FORCE_INLINE number n_Mult_FieldZp(number n1, number n2, const coeffs r)
Definition: p_Numbers.h:69
static FORCE_INLINE number n_Mult_FieldGeneral(number n1, number n2, const coeffs r)
Definition: p_Numbers.h:24
static number npAddM(number a, number b, const coeffs r)
Definition: modulop.h:77
All the auxiliary stuff.
static FORCE_INLINE number n_InpNeg(number n, const coeffs r)
in-place negation of n MUST BE USED: n = n_InpNeg(n) (no copy is returned)
Definition: coeffs.h:558
LINLINE BOOLEAN nlEqual(number a, number b, const coeffs r)
Definition: longrat.cc:2348
LINLINE BOOLEAN nlIsZero(number za, const coeffs r)
Definition: longrat.cc:2384
static FORCE_INLINE number n_Copy_FieldGeneral(number n, const coeffs r)
Definition: p_Numbers.h:18
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
Definition: coeffs.h:465
static FORCE_INLINE BOOLEAN n_Equal_FieldQ(number n1, number n2, const coeffs r)
Definition: p_Numbers.h:159
static FORCE_INLINE number n_Neg_FieldQ(number n, const coeffs r)
Definition: p_Numbers.h:162
static FORCE_INLINE void n_InpAdd_FieldGeneral(number &n1, number n2, const coeffs r)
Definition: p_Numbers.h:45
static FORCE_INLINE BOOLEAN n_IsZero_FieldGeneral(number n, const coeffs r)
Definition: p_Numbers.h:30
static FORCE_INLINE number n_Mult_FieldQ(number n1, number n2, const coeffs r)
Definition: p_Numbers.h:129
static BOOLEAN npIsZeroM(number a, const coeffs)
Definition: modulop.h:116
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of 'n'
Definition: coeffs.h:452
LINLINE void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2417
static FORCE_INLINE number n_Sub_FieldGeneral(number n1, number n2, const coeffs r)
Definition: p_Numbers.h:39
static FORCE_INLINE number n_Neg_FieldZp(number n, const coeffs r)
Definition: p_Numbers.h:102
static FORCE_INLINE void n_Delete_FieldQ(number *n, const coeffs r)
Definition: p_Numbers.h:126
static FORCE_INLINE BOOLEAN n_Equal(number a, number b, const coeffs r)
TRUE iff 'a' and 'b' represent the same number; they may have different representations.
Definition: coeffs.h:461
static FORCE_INLINE void n_InpMult_FieldQ(number &n1, number n2, const coeffs r)
Definition: p_Numbers.h:165
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:456
static FORCE_INLINE BOOLEAN n_IsZero_FieldZp(number n, const coeffs r)
Definition: p_Numbers.h:96
static FORCE_INLINE void n_InpMult_FieldGeneral(number &n1, number n2, const coeffs r)
Definition: p_Numbers.h:42
int BOOLEAN
Definition: auxiliary.h:131
static FORCE_INLINE number n_Add_FieldGeneral(number n1, number n2, const coeffs r)
Definition: p_Numbers.h:27
LINLINE number nlCopy(number a, const coeffs r)
Definition: longrat.cc:2404