1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* $Id: f5gb.cc,v 1.16 2009-01-15 17:44:23 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 | sorting ideals by decreasing total degree "left" and "right" are the |
---|
31 | pointer of the first and last polynomial in the considered ideal |
---|
32 | ==================================================================== |
---|
33 | */ |
---|
34 | void qsortDegree(poly* left, poly* right) { |
---|
35 | poly* ptr1 = left; |
---|
36 | poly* ptr2 = right; |
---|
37 | poly p1,p2; |
---|
38 | p2 = *(left + (right - left >> 1)); |
---|
39 | do { |
---|
40 | while(pTotaldegree(*ptr1, currRing) < pTotaldegree(p2, currRing)) { |
---|
41 | ptr1++; |
---|
42 | } |
---|
43 | while(pTotaldegree(*ptr2, currRing) > pTotaldegree(p2,currRing)) { |
---|
44 | ptr2--; |
---|
45 | } |
---|
46 | if(ptr1 > ptr2) { |
---|
47 | break; |
---|
48 | } |
---|
49 | p1 = *ptr1; |
---|
50 | *ptr1 = *ptr2; |
---|
51 | *ptr2 = p1; |
---|
52 | } while(++ptr1 <= --ptr2); |
---|
53 | |
---|
54 | if(left < ptr2) { |
---|
55 | qsortDegree(left,ptr2); |
---|
56 | } |
---|
57 | if(ptr1 < right) { |
---|
58 | qsortDegree(ptr1,right); |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | |
---|
63 | /* |
---|
64 | ================================================== |
---|
65 | computes incrementally gbs of subsets of the input |
---|
66 | gb{f_m} -> gb{f_m,f_(m-1)} -> gb{f_m,...,f_1} |
---|
67 | ================================================== |
---|
68 | */ |
---|
69 | LList* F5inc(int* i, poly* f_i, LList* g_prev, poly* ONE) { |
---|
70 | LList* g_curr = g_prev; |
---|
71 | g_curr->insert(ONE,i,f_i); |
---|
72 | |
---|
73 | return g_curr; |
---|
74 | } |
---|
75 | |
---|
76 | /* |
---|
77 | ========================================================================== |
---|
78 | MAIN:computes a gb of the ideal i in the ring r with our f5 implementation |
---|
79 | ========================================================================== |
---|
80 | */ |
---|
81 | ideal F5main(ideal id, ring r) { |
---|
82 | int i,j; |
---|
83 | const int idElems = IDELEMS(id); |
---|
84 | // 1 polynomial for defining initial labels & further tests |
---|
85 | static poly ONE = pOne(); |
---|
86 | |
---|
87 | |
---|
88 | // definition of one-polynomial as global constant ONE |
---|
89 | //poly one = pInit(); |
---|
90 | //pSetCoeff(one, nInit(1)); |
---|
91 | //static poly ONE = one; |
---|
92 | |
---|
93 | for(j=0; j<IDELEMS(id); j++) { |
---|
94 | if(NULL != id->m[j]) { |
---|
95 | if(pComparePolys(id->m[j],ONE)) { |
---|
96 | Print("One Polynomial in Input => Computations stopped\n"); |
---|
97 | ideal id_new = idInit(1,1); |
---|
98 | id_new->m[0] = ONE; |
---|
99 | return(id_new); |
---|
100 | } |
---|
101 | } |
---|
102 | } |
---|
103 | |
---|
104 | id = kInterRed(id,0); |
---|
105 | qsortDegree(&id->m[0],&id->m[IDELEMS(id)-1]); |
---|
106 | idShow(id); |
---|
107 | i = 1; |
---|
108 | // only for debugging |
---|
109 | //LNode* current; |
---|
110 | //LList* g_curr = new LList(lp); |
---|
111 | //} |
---|
112 | //for(i=2; i<IDELEMS(id); i++) { |
---|
113 | //g_curr = F5inc(&i,&id->m[i],g_prev); |
---|
114 | //if(g_curr->polyTest(&ONE)) { |
---|
115 | // Print("One Polynomial in Input => Computations stopped\n"); |
---|
116 | // ideal id_new = idInit(1,1); |
---|
117 | // id_new->m[0] = ONE; |
---|
118 | // return(id_new); |
---|
119 | //} |
---|
120 | //} |
---|
121 | return(id); |
---|
122 | |
---|
123 | |
---|
124 | } |
---|
125 | |
---|
126 | #endif |
---|