1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* $Id: f5gb.cc,v 1.15 2008-12-27 13:50:05 ederc Exp $ */ |
---|
5 | /* |
---|
6 | * ABSTRACT: f5gb interface |
---|
7 | */ |
---|
8 | #include "mod2.h" |
---|
9 | #ifdef HAVE_F5 |
---|
10 | #include "kutil.h" |
---|
11 | #include "structs.h" |
---|
12 | #include "omalloc.h" |
---|
13 | #include "polys.h" |
---|
14 | #include "p_polys.h" |
---|
15 | #include "ideals.h" |
---|
16 | #include "febase.h" |
---|
17 | #include "kstd1.h" |
---|
18 | #include "khstd.h" |
---|
19 | #include "kbuckets.h" |
---|
20 | #include "weight.h" |
---|
21 | #include "intvec.h" |
---|
22 | #include "pInline1.h" |
---|
23 | #include "f5gb.h" |
---|
24 | #include "lpolynomial.h" |
---|
25 | #include "lists.h" |
---|
26 | |
---|
27 | |
---|
28 | /* |
---|
29 | ================================================ |
---|
30 | computation of ONE polynomial as global variable |
---|
31 | ================================================ |
---|
32 | */ |
---|
33 | poly one_poly() { |
---|
34 | poly one = pInit(); |
---|
35 | pSetCoeff(one,nInit(1)); |
---|
36 | return one; |
---|
37 | } |
---|
38 | |
---|
39 | |
---|
40 | |
---|
41 | /* |
---|
42 | ==================================================================== |
---|
43 | sorting ideals by decreasing total degree "left" and "right" are the |
---|
44 | pointer of the first and last polynomial in the considered ideal |
---|
45 | ==================================================================== |
---|
46 | */ |
---|
47 | void qsortDegree(poly* left, poly* right) { |
---|
48 | poly* ptr1 = left; |
---|
49 | poly* ptr2 = right; |
---|
50 | poly p1,p2; |
---|
51 | p2 = *(left + (right - left >> 1)); |
---|
52 | do { |
---|
53 | while(pTotaldegree(*ptr1, currRing) < pTotaldegree(p2, currRing)) { |
---|
54 | ptr1++; |
---|
55 | } |
---|
56 | while(pTotaldegree(*ptr2, currRing) > pTotaldegree(p2,currRing)) { |
---|
57 | ptr2--; |
---|
58 | } |
---|
59 | if(ptr1 > ptr2) { |
---|
60 | break; |
---|
61 | } |
---|
62 | p1 = *ptr1; |
---|
63 | *ptr1 = *ptr2; |
---|
64 | *ptr2 = p1; |
---|
65 | } while(++ptr1 <= --ptr2); |
---|
66 | |
---|
67 | if(left < ptr2) { |
---|
68 | qsortDegree(left,ptr2); |
---|
69 | } |
---|
70 | if(ptr1 < right) { |
---|
71 | qsortDegree(ptr1,right); |
---|
72 | } |
---|
73 | } |
---|
74 | |
---|
75 | |
---|
76 | /* |
---|
77 | ================================================== |
---|
78 | computes incrementally gbs of subsets of the input |
---|
79 | gb{f_m} -> gb{f_m,f_(m-1)} -> gb{f_m,...,f_1} |
---|
80 | ================================================== |
---|
81 | */ |
---|
82 | LList* F5inc(long* i, poly* f_i, LList* g_prev) { |
---|
83 | poly one = pInit(); |
---|
84 | pSetCoeff(one, nInit(1)); |
---|
85 | static poly ONE = one; |
---|
86 | //poly ONE = pOne(); |
---|
87 | LList* g_curr = g_prev; |
---|
88 | LNode* prev_last = g_prev->getLast(); //tags the end of g_prev->only 1 list for g_prev & g_curr |
---|
89 | g_curr->append(&ONE,i,f_i); |
---|
90 | |
---|
91 | return g_curr; |
---|
92 | } |
---|
93 | |
---|
94 | /* |
---|
95 | ========================================================================== |
---|
96 | MAIN:computes a gb of the ideal i in the ring r with our f5 implementation |
---|
97 | ========================================================================== |
---|
98 | */ |
---|
99 | ideal F5main(ideal id, ring r) { |
---|
100 | |
---|
101 | static poly ONE = pOne(); |
---|
102 | long i,j; |
---|
103 | |
---|
104 | // definition of one-polynomial as global constant ONE |
---|
105 | //poly one = pInit(); |
---|
106 | //pSetCoeff(one, nInit(1)); |
---|
107 | //static poly ONE = one; |
---|
108 | |
---|
109 | for(j=0; j<IDELEMS(id); j++) { |
---|
110 | if(NULL != id->m[j]) { |
---|
111 | if(pComparePolys(id->m[j],ONE)) { |
---|
112 | Print("One Polynomial in Input => Computations stopped\n"); |
---|
113 | ideal id_new = idInit(1,1); |
---|
114 | id_new->m[0] = ONE; |
---|
115 | return(id_new); |
---|
116 | } |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | id = kInterRed(id,0); |
---|
121 | qsortDegree(&id->m[0],&id->m[IDELEMS(id)-1]); |
---|
122 | idShow(id); |
---|
123 | i = 1; |
---|
124 | //lp->setIndex(&i); |
---|
125 | //lp->setTerm(&ONE); |
---|
126 | //lp->setPoly(&id->m[0]); |
---|
127 | LPoly* lp = new LPoly(&ONE,&i,&ONE); |
---|
128 | |
---|
129 | // only for debugging |
---|
130 | long k = 2; |
---|
131 | LList* g_prev = new LList(&ONE,&k,&id->m[2]); |
---|
132 | LNode* current; |
---|
133 | LPoly* lp2 = new LPoly(&ONE,&k,&ONE); |
---|
134 | //LList* g_curr = new LList(lp); |
---|
135 | k = 134; |
---|
136 | g_prev->append(&ONE,&k,&id->m[3]); |
---|
137 | g_prev->append(&ONE,&k,&id->m[3]); |
---|
138 | g_prev->append(lp2); |
---|
139 | g_prev->append(lp2); |
---|
140 | g_prev->append(lp); |
---|
141 | g_prev->append(&ONE,&k,&id->m[1]); |
---|
142 | g_prev->append(&ONE,&k,&id->m[3]); |
---|
143 | g_prev->append(lp2); |
---|
144 | i = g_prev->getLength(); |
---|
145 | Print("%ld\n\n",i); |
---|
146 | current = g_prev->getFirst(); |
---|
147 | while(NULL != current) { |
---|
148 | Print("Index: %ld\n",*(current->getLPoly()->getIndex())); |
---|
149 | Print("Pointer comparison: %p , %p\n\n",g_prev->getFirst(),current); |
---|
150 | current = current->getNext(); |
---|
151 | } |
---|
152 | //for(i=2; i<IDELEMS(id); i++) { |
---|
153 | //g_curr = F5inc(&i,&id->m[i],g_prev); |
---|
154 | //if(g_curr->polyTest(&ONE)) { |
---|
155 | // Print("One Polynomial in Input => Computations stopped\n"); |
---|
156 | // ideal id_new = idInit(1,1); |
---|
157 | // id_new->m[0] = ONE; |
---|
158 | // return(id_new); |
---|
159 | //} |
---|
160 | //} |
---|
161 | return(id); |
---|
162 | |
---|
163 | |
---|
164 | } |
---|
165 | |
---|
166 | #endif |
---|