[5a66d0] | 1 | #include <string.h> |
---|
| 2 | #include "mod2.h" |
---|
| 3 | #include "febase.h" |
---|
| 4 | #include "polys.h" |
---|
| 5 | #include "kstd1.h" |
---|
| 6 | #include "subexpr.h" |
---|
| 7 | #include "ideals.h" |
---|
| 8 | #include "ring.h" |
---|
| 9 | #include "janet.h" |
---|
| 10 | |
---|
| 11 | #define pow_(x) pTotaldegree((x)) |
---|
| 12 | |
---|
| 13 | //extern int (*ListGreatMove)(jList *,jList *,poly); |
---|
| 14 | extern int ComputeBasis(jList *,jList *); |
---|
| 15 | extern void Initialization(char *); |
---|
| 16 | |
---|
| 17 | BOOLEAN jInitBasis(ideal v, jList **TT,jList **QQ) |
---|
| 18 | { |
---|
[753f9d2] | 19 | if (rHasLocalOrMixedOrdering_currRing()) |
---|
[5a66d0] | 20 | { |
---|
| 21 | WerrorS("janet only for well-orderings"); |
---|
| 22 | return TRUE; |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | Initialization(rOrdStr(currRing)); |
---|
| 26 | |
---|
| 27 | jList *Q=(jList *)GCM(sizeof(jList)); |
---|
| 28 | Q->root=NULL; |
---|
| 29 | |
---|
| 30 | jList *T=(jList *)GCM(sizeof(jList)); |
---|
| 31 | T->root=NULL; |
---|
| 32 | |
---|
[52cc7a4] | 33 | for (int i=0; i < IDELEMS(v); i++) |
---|
[5a66d0] | 34 | { |
---|
| 35 | if (v->m[i]!=NULL) |
---|
| 36 | { |
---|
| 37 | Poly *beg=NewPoly(pCopy(v->m[i])); |
---|
| 38 | |
---|
| 39 | InitHistory(beg); |
---|
| 40 | InitProl(beg); |
---|
| 41 | InitLead(beg); |
---|
| 42 | |
---|
| 43 | InsertInCount(Q,beg); |
---|
| 44 | } |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | BOOLEAN r= !(ComputeBasis(T,Q)); |
---|
| 48 | *TT=T; |
---|
| 49 | *QQ=Q; |
---|
| 50 | return r; |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | BOOLEAN jjStdJanetBasis(leftv res, leftv v, int flag) |
---|
| 54 | { |
---|
| 55 | ideal result; |
---|
| 56 | int dpO; |
---|
| 57 | |
---|
| 58 | jList *T; |
---|
| 59 | jList *Q; |
---|
| 60 | ideal I=(ideal)v->Data(); |
---|
| 61 | BOOLEAN is_zero=TRUE; |
---|
[52cc7a4] | 62 | for (int i=0; i < IDELEMS(I); i++) |
---|
[5a66d0] | 63 | { |
---|
| 64 | if ((I->m[i]!=NULL)&& (pIsConstant(I->m[i]))) |
---|
| 65 | { |
---|
| 66 | goto zero; |
---|
| 67 | } |
---|
| 68 | else |
---|
| 69 | is_zero=FALSE; |
---|
| 70 | } |
---|
| 71 | if (is_zero) |
---|
| 72 | goto zero; |
---|
| 73 | if (!jInitBasis(I,&T,&Q)) |
---|
| 74 | { |
---|
| 75 | dpO=(strstr(rOrdStr(currRing),"dp")!=NULL); |
---|
| 76 | int ideal_length; |
---|
| 77 | if (flag==1) |
---|
| 78 | ideal_length= dpO ? GB_length() : CountList(T); |
---|
| 79 | else |
---|
| 80 | ideal_length=CountList(T); |
---|
| 81 | |
---|
| 82 | result=idInit(ideal_length,1); |
---|
| 83 | |
---|
| 84 | int ideal_index=0; |
---|
| 85 | |
---|
| 86 | LCI iT=T->root; |
---|
| 87 | |
---|
| 88 | while(iT) |
---|
| 89 | { |
---|
| 90 | pTest(iT->info->root); |
---|
| 91 | if ((flag==1) && dpO) |
---|
| 92 | { |
---|
| 93 | //if (pow_(iT->info->lead) == pow_(iT->info->history)) |
---|
| 94 | if (pDeg(iT->info->lead) == pDeg(iT->info->history)) |
---|
| 95 | { |
---|
| 96 | result->m[ideal_length-ideal_index-1]=pCopy(iT->info->root); |
---|
| 97 | if (!nGreaterZero(pGetCoeff(iT->info->root))) |
---|
| 98 | result->m[ideal_length-ideal_index-1] |
---|
| 99 | =pNeg(result->m[ideal_length-ideal_index-1]); |
---|
| 100 | |
---|
| 101 | ideal_index++; |
---|
| 102 | } |
---|
| 103 | } |
---|
| 104 | else |
---|
| 105 | { |
---|
| 106 | result->m[ideal_length-ideal_index-1]=pCopy(iT->info->root); |
---|
| 107 | if (!nGreaterZero(pGetCoeff(iT->info->root))) |
---|
| 108 | result->m[ideal_length-ideal_index-1] |
---|
| 109 | =pNeg(result->m[ideal_length-ideal_index-1]); |
---|
| 110 | |
---|
| 111 | ideal_index++; |
---|
| 112 | } |
---|
| 113 | iT=iT->next; |
---|
| 114 | } |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | if ((flag==1) && (!dpO)) |
---|
| 118 | { |
---|
| 119 | //Print ("interred\n"); |
---|
[e7c6b22] | 120 | result=kInterRedOld(result); |
---|
[5a66d0] | 121 | idSkipZeroes(result); |
---|
| 122 | } |
---|
| 123 | res->data = (char *)result; |
---|
| 124 | res->rtyp = IDEAL_CMD; |
---|
| 125 | |
---|
| 126 | DestroyList(Q); |
---|
| 127 | DestroyList(T); |
---|
| 128 | |
---|
| 129 | return FALSE; |
---|
| 130 | |
---|
| 131 | zero: |
---|
| 132 | result=idInit(1,1); |
---|
| 133 | if (!is_zero) result->m[0]=pOne(); |
---|
| 134 | res->data = (char *)result; |
---|
| 135 | res->rtyp = IDEAL_CMD; |
---|
| 136 | return FALSE; |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | BOOLEAN jjJanetBasis(leftv res, leftv v) |
---|
| 140 | { |
---|
| 141 | return jjStdJanetBasis(res,v,0); |
---|
| 142 | } |
---|