1 | #include "mod2.h" |
---|
2 | #include "janet.h" |
---|
3 | #include "kstd1.h" |
---|
4 | #include "ipid.h" |
---|
5 | |
---|
6 | #define pow_(x) pTotaldegree((x)) |
---|
7 | |
---|
8 | //extern int (*ListGreatMove)(jList *,jList *,poly); |
---|
9 | extern int ComputeBasis(jList *,jList *); |
---|
10 | extern void Initialization(char *); |
---|
11 | |
---|
12 | BOOLEAN jjJanetBasis(leftv res, leftv v) |
---|
13 | { |
---|
14 | Initialization(rOrdStr(currRing)); |
---|
15 | |
---|
16 | jList *Q=(jList *)GCM(sizeof(jList)); |
---|
17 | Q->root=NULL; |
---|
18 | |
---|
19 | jList *T=(jList *)GCM(sizeof(jList)); |
---|
20 | T->root=NULL; |
---|
21 | |
---|
22 | ideal input = (ideal)(v->Data()); |
---|
23 | /* the second arg is an integer, defining what to return: |
---|
24 | 0 (default case) = Groebner basis, |
---|
25 | 1 = Janet basis. |
---|
26 | */ |
---|
27 | int doJanet; |
---|
28 | if ((v->next!=NULL) && (v->next->Typ() == INT_CMD)) |
---|
29 | { |
---|
30 | doJanet = (int)v->next->CopyD(); |
---|
31 | // Print("doJanet:%d\n",doJanet); |
---|
32 | } |
---|
33 | else |
---|
34 | { |
---|
35 | doJanet = 0; |
---|
36 | } |
---|
37 | ideal result; |
---|
38 | int dpO = !doJanet; /* compatibility */ |
---|
39 | |
---|
40 | for (int i=0; i < input->idelems(); i++) |
---|
41 | { |
---|
42 | /* nonzero constant check */ |
---|
43 | if (pIsConstant(input->m[i])) { goto zero; } |
---|
44 | Poly *beg=NewPoly(pCopy(input->m[i])); |
---|
45 | InitHistory(beg); |
---|
46 | InitProl(beg); |
---|
47 | InitLead(beg); |
---|
48 | InsertInCount(Q,beg); |
---|
49 | } |
---|
50 | |
---|
51 | if (ComputeBasis(T,Q)) |
---|
52 | { |
---|
53 | // dpO=(strstr(rOrdStr(currRing),"dp")!=NULL); |
---|
54 | int ideal_length= dpO ? GB_length() : CountList(T); |
---|
55 | result=idInit(ideal_length,1); |
---|
56 | int ideal_index=0; |
---|
57 | |
---|
58 | LCI iT=T->root; |
---|
59 | |
---|
60 | while (iT) |
---|
61 | { |
---|
62 | #ifdef PDEBUG |
---|
63 | pTest(iT->info->root); |
---|
64 | #endif |
---|
65 | if (!(dpO && (pow_(iT->info->lead) != pow_(iT->info->history)))) |
---|
66 | { |
---|
67 | result->m[ideal_length-ideal_index-1]=pCopy(iT->info->root); |
---|
68 | if (!nGreaterZero(pGetCoeff(iT->info->root))) |
---|
69 | { |
---|
70 | result->m[ideal_length-ideal_index-1]=pNeg(result->m[ideal_length-ideal_index-1]); |
---|
71 | } |
---|
72 | ideal_index++; |
---|
73 | } |
---|
74 | iT=iT->next; |
---|
75 | } |
---|
76 | } |
---|
77 | else |
---|
78 | { |
---|
79 | zero: |
---|
80 | result=idInit(1,1); |
---|
81 | result->m[0]=pOne(); |
---|
82 | } |
---|
83 | |
---|
84 | /* now we make the basis shorter... getting Groebner */ |
---|
85 | if (!doJanet) /* if (!dpO) */ |
---|
86 | { |
---|
87 | if (TEST_OPT_PROT) |
---|
88 | { |
---|
89 | Print ("interred\n"); |
---|
90 | } |
---|
91 | result=kInterRed(result); |
---|
92 | idSkipZeroes(result); |
---|
93 | } |
---|
94 | res->data = (char *)result; |
---|
95 | res->rtyp = v->Typ(); |
---|
96 | if (!doJanet) setFlag(res,FLAG_STD); |
---|
97 | |
---|
98 | DestroyList(Q); |
---|
99 | DestroyList(T); |
---|
100 | |
---|
101 | return FALSE; |
---|
102 | } |
---|