1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* $Id: ringgb.cc,v 1.6 2006-02-14 13:45:48 Singular Exp $ */ |
---|
5 | /* |
---|
6 | * ABSTRACT: ringgb interface |
---|
7 | */ |
---|
8 | //#define HAVE_TAIL_RING |
---|
9 | #define NO_BUCKETS |
---|
10 | |
---|
11 | #include "mod2.h" |
---|
12 | #include "kutil.h" |
---|
13 | #include "structs.h" |
---|
14 | #include "omalloc.h" |
---|
15 | #include "polys.h" |
---|
16 | #include "p_polys.h" |
---|
17 | #include "ideals.h" |
---|
18 | #include "febase.h" |
---|
19 | #include "kstd1.h" |
---|
20 | #include "khstd.h" |
---|
21 | #include "kbuckets.h" |
---|
22 | #include "weight.h" |
---|
23 | #include "intvec.h" |
---|
24 | #include "pInline1.h" |
---|
25 | #ifdef HAVE_PLURAL |
---|
26 | #include "gring.h" |
---|
27 | #endif |
---|
28 | |
---|
29 | #include "ringgb.h" |
---|
30 | |
---|
31 | #ifdef HAVE_RING2TOM |
---|
32 | poly reduce_poly_fct(poly p, ring r) |
---|
33 | { |
---|
34 | return kFindZeroPoly(p, r, r); |
---|
35 | } |
---|
36 | |
---|
37 | /* |
---|
38 | * Returns maximal k, such that |
---|
39 | * 2^k | n |
---|
40 | */ |
---|
41 | int indexOf2(number n) { |
---|
42 | long test = (long) n; |
---|
43 | int i = 0; |
---|
44 | while (test%2 == 0) { |
---|
45 | i++; |
---|
46 | test = test / 2; |
---|
47 | } |
---|
48 | return i; |
---|
49 | } |
---|
50 | |
---|
51 | /* |
---|
52 | * Find an index i from G, such that |
---|
53 | * LT(rside) = x * LT(G[i]) has a solution |
---|
54 | * or -1 if rside is not in the |
---|
55 | * ideal of the leading coefficients |
---|
56 | * of the suitable g from G. |
---|
57 | */ |
---|
58 | int findRing2toMsolver(poly rside, ideal G, ring r) { |
---|
59 | if (rside == NULL) return -1; |
---|
60 | int i; |
---|
61 | int iO2rside = indexOf2(pGetCoeff(rside)); |
---|
62 | for (i = 0; i < IDELEMS(G); i++) { |
---|
63 | if (indexOf2(pGetCoeff(G->m[i])) <= iO2rside && p_LmDivisibleBy(G->m[i], rside, r)) { |
---|
64 | return i; |
---|
65 | } |
---|
66 | } |
---|
67 | return -1; |
---|
68 | } |
---|
69 | |
---|
70 | /*************************************************************** |
---|
71 | * |
---|
72 | * Lcm business |
---|
73 | * |
---|
74 | ***************************************************************/ |
---|
75 | // get m1 = LCM(LM(p1), LM(p2))/LM(p1) |
---|
76 | // m2 = LCM(LM(p1), LM(p2))/LM(p2) |
---|
77 | BOOLEAN ring2toM_GetLeadTerms(const poly p1, const poly p2, const ring p_r, |
---|
78 | poly &m1, poly &m2, const ring m_r) |
---|
79 | { |
---|
80 | |
---|
81 | int i; |
---|
82 | Exponent_t x; |
---|
83 | m1 = p_Init(m_r); |
---|
84 | m2 = p_Init(m_r); |
---|
85 | |
---|
86 | for (i = p_r->N; i; i--) |
---|
87 | { |
---|
88 | x = p_GetExpDiff(p1, p2, i, p_r); |
---|
89 | if (x > 0) |
---|
90 | { |
---|
91 | p_SetExp(m2,i,x, m_r); |
---|
92 | p_SetExp(m1,i,0, m_r); |
---|
93 | } |
---|
94 | else |
---|
95 | { |
---|
96 | p_SetExp(m1,i,-x, m_r); |
---|
97 | p_SetExp(m2,i,0, m_r); |
---|
98 | } |
---|
99 | } |
---|
100 | p_Setm(m1, m_r); |
---|
101 | p_Setm(m2, m_r); |
---|
102 | long cp1 = (long) pGetCoeff(p1); |
---|
103 | long cp2 = (long) pGetCoeff(p2); |
---|
104 | if (cp1 != 0 && cp2 != 0) { |
---|
105 | while (cp1%2 == 0 && cp2%2 == 0) { |
---|
106 | cp1 = cp1 / 2; |
---|
107 | cp2 = cp2 / 2; |
---|
108 | } |
---|
109 | } |
---|
110 | p_SetCoeff(m1, (number) cp2, m_r); |
---|
111 | p_SetCoeff(m2, (number) cp1, m_r); |
---|
112 | return TRUE; |
---|
113 | } |
---|
114 | |
---|
115 | void printPolyMsg(const char * start, poly f, const char * end) |
---|
116 | { |
---|
117 | PrintS(start); |
---|
118 | wrp(f); |
---|
119 | PrintS(end); |
---|
120 | } |
---|
121 | |
---|
122 | poly spolyRing2toM(poly f, poly g, ring r) { |
---|
123 | poly m1 = NULL; |
---|
124 | poly m2 = NULL; |
---|
125 | ring2toM_GetLeadTerms(f, g, r, m1, m2, r); |
---|
126 | printPolyMsg("spoly: m1=", m1, " | "); |
---|
127 | printPolyMsg("m2=", m2, ""); |
---|
128 | PrintLn(); |
---|
129 | return pSub(pp_Mult_mm(f, m1, r), pp_Mult_mm(g, m2, r)); |
---|
130 | } |
---|
131 | |
---|
132 | poly ringNF(poly f, ideal G, ring r) { |
---|
133 | // If f = 0, then normal form is also 0 |
---|
134 | if (f == NULL) { return NULL; } |
---|
135 | poly h = pCopy(f); |
---|
136 | int i = findRing2toMsolver(h, G, r); |
---|
137 | int c = 1; |
---|
138 | while (h != NULL && i >= 0 && c < 20) { |
---|
139 | Print("%d-step NF - h:", c); |
---|
140 | wrp(h); |
---|
141 | PrintS(" "); |
---|
142 | PrintS("G->m[i]:"); |
---|
143 | wrp(G->m[i]); |
---|
144 | PrintLn(); |
---|
145 | h = spolyRing2toM(h, G->m[i], r); |
---|
146 | PrintS("=> h="); |
---|
147 | wrp(h); |
---|
148 | PrintLn(); |
---|
149 | i = findRing2toMsolver(h, G, r); |
---|
150 | c++; |
---|
151 | } |
---|
152 | return h; |
---|
153 | } |
---|
154 | |
---|
155 | poly ringRedNF (poly f, ideal G, ring r) { |
---|
156 | // If f = 0, then normal form is also 0 |
---|
157 | if (f == NULL) { return NULL; } |
---|
158 | poly h = NULL; |
---|
159 | poly g = pCopy(f); |
---|
160 | int c = 0; |
---|
161 | while (g != NULL && c < 20) { |
---|
162 | Print("%d-step RedNF - g=", c); |
---|
163 | wrp(g); |
---|
164 | PrintS(" | h="); |
---|
165 | wrp(h); |
---|
166 | PrintLn(); |
---|
167 | g = ringNF(g, G, r); |
---|
168 | if (g != NULL) { |
---|
169 | h = pAdd(h, pHead(g)); |
---|
170 | pLmDelete(&g); |
---|
171 | } |
---|
172 | c++; |
---|
173 | } |
---|
174 | return h; |
---|
175 | } |
---|
176 | #endif |
---|