1 | #ifdef HAVE_CONFIG_H |
---|
2 | #include "singularconfig.h" |
---|
3 | #endif /* HAVE_CONFIG_H */ |
---|
4 | #include "mod2.h" |
---|
5 | |
---|
6 | #include <omalloc/omalloc.h> |
---|
7 | #include <misc/auxiliary.h> |
---|
8 | #include <misc/options.h> |
---|
9 | #include <misc/intvec.h> |
---|
10 | |
---|
11 | #include <kernel/polys.h> |
---|
12 | #include <polys/monomials/ring.h> |
---|
13 | |
---|
14 | |
---|
15 | #include <kernel/febase.h> |
---|
16 | #include <kernel/ideals.h> |
---|
17 | #include <kernel/kstd1.h> |
---|
18 | #include <kernel/khstd.h> |
---|
19 | |
---|
20 | #include <kernel/kutil.h> |
---|
21 | |
---|
22 | |
---|
23 | #ifdef HAVE_PLURAL |
---|
24 | #include <polys/nc/nc.h> |
---|
25 | #endif |
---|
26 | |
---|
27 | /*2 |
---|
28 | *shifts the variables between minvar and maxvar of p \in p_ring to the |
---|
29 | *first maxvar-minvar+1 variables in the actual ring |
---|
30 | *be carefull: there is no range check for the variables of p |
---|
31 | */ |
---|
32 | static poly pChangeSizeOfPoly(ring p_ring, poly p,int minvar,int maxvar, const ring dst_r) |
---|
33 | { |
---|
34 | int i; |
---|
35 | poly result = NULL,resultWorkP; |
---|
36 | number n; |
---|
37 | |
---|
38 | if (p==NULL) return result; |
---|
39 | else result = p_Init(dst_r); |
---|
40 | resultWorkP = result; |
---|
41 | while (p!=NULL) |
---|
42 | { |
---|
43 | for (i=minvar;i<=maxvar;i++) |
---|
44 | p_SetExp(resultWorkP,i-minvar+1,p_GetExp(p,i,p_ring),dst_r); |
---|
45 | p_SetComp(resultWorkP,p_GetComp(p,p_ring),dst_r); |
---|
46 | n=n_Copy(pGetCoeff(p),dst_r->cf); |
---|
47 | p_SetCoeff(resultWorkP,n,dst_r); |
---|
48 | p_Setm(resultWorkP,dst_r); |
---|
49 | pIter(p); |
---|
50 | if (p!=NULL) |
---|
51 | { |
---|
52 | pNext(resultWorkP) = p_Init(dst_r); |
---|
53 | pIter(resultWorkP); |
---|
54 | } |
---|
55 | } |
---|
56 | return result; |
---|
57 | } |
---|
58 | |
---|
59 | |
---|
60 | |
---|
61 | /*2 |
---|
62 | *returns the preimage of id under theMap, |
---|
63 | *if id is empty or zero the kernel is computed |
---|
64 | * (assumes) that both ring have the same coeff.field |
---|
65 | */ |
---|
66 | ideal maGetPreimage(ring theImageRing, map theMap, ideal id, const ring dst_r) |
---|
67 | { |
---|
68 | ring sourcering = dst_r; |
---|
69 | |
---|
70 | #ifdef HAVE_PLURAL |
---|
71 | if (rIsPluralRing(theImageRing)) |
---|
72 | { |
---|
73 | if ((rIsPluralRing(sourcering)) && (ncRingType(sourcering)!=nc_comm)) |
---|
74 | { |
---|
75 | Werror("Sorry, not yet implemented for noncomm. rings"); |
---|
76 | return NULL; |
---|
77 | } |
---|
78 | } |
---|
79 | #endif |
---|
80 | |
---|
81 | int i,j; |
---|
82 | poly p,/*pp,*/q; |
---|
83 | ideal temp1; |
---|
84 | ideal temp2; |
---|
85 | |
---|
86 | int imagepvariables = rVar(theImageRing); |
---|
87 | int N = rVar(dst_r)+imagepvariables; |
---|
88 | |
---|
89 | ring tmpR; |
---|
90 | if (rSumInternal(theImageRing,sourcering,tmpR,FALSE,TRUE)!=1) |
---|
91 | { |
---|
92 | WerrorS("error in rSumInternal"); |
---|
93 | return NULL; |
---|
94 | } |
---|
95 | |
---|
96 | assume(n_SetMap(theImageRing->cf, dst_r->cf) == ndCopyMap); |
---|
97 | |
---|
98 | if (theImageRing->cf != dst_r->cf) |
---|
99 | { |
---|
100 | /// TODO: there might be extreme cases where this doesn't hold... |
---|
101 | Werror("Coefficient fields/rings must be equal"); |
---|
102 | return NULL; |
---|
103 | } |
---|
104 | |
---|
105 | const ring save_ring = currRing; if (currRing!=tmpR) rChangeCurrRing(tmpR); // due to kStd |
---|
106 | |
---|
107 | if (id==NULL) |
---|
108 | j = 0; |
---|
109 | else |
---|
110 | j = IDELEMS(id); |
---|
111 | int j0=j; |
---|
112 | if (theImageRing->qideal!=NULL) j+=IDELEMS(theImageRing->qideal); |
---|
113 | temp1 = idInit(sourcering->N+j,1); |
---|
114 | for (i=0;i<sourcering->N;i++) |
---|
115 | { |
---|
116 | q = p_ISet(-1,tmpR); |
---|
117 | p_SetExp(q,i+1+imagepvariables,1,tmpR); |
---|
118 | p_Setm(q,tmpR); |
---|
119 | if ((i<IDELEMS(theMap)) && (theMap->m[i]!=NULL)) |
---|
120 | { |
---|
121 | p = p_SortMerge( |
---|
122 | pChangeSizeOfPoly(theImageRing, theMap->m[i], 1, imagepvariables, tmpR), |
---|
123 | tmpR); |
---|
124 | p=p_Add_q(p,q,tmpR); |
---|
125 | } |
---|
126 | else |
---|
127 | { |
---|
128 | p = q; |
---|
129 | } |
---|
130 | temp1->m[i] = p; |
---|
131 | } |
---|
132 | id_Test(temp1, tmpR); |
---|
133 | for (i=sourcering->N;i<sourcering->N+j0;i++) |
---|
134 | { |
---|
135 | temp1->m[i] = p_SortMerge( |
---|
136 | pChangeSizeOfPoly(theImageRing, id->m[i-sourcering->N], 1, imagepvariables, tmpR), |
---|
137 | tmpR); |
---|
138 | } |
---|
139 | for (i=sourcering->N+j0;i<sourcering->N+j;i++) |
---|
140 | { |
---|
141 | temp1->m[i] = p_SortMerge( |
---|
142 | pChangeSizeOfPoly(theImageRing, theImageRing->qideal->m[i-sourcering->N-j0], 1, imagepvariables, tmpR), |
---|
143 | tmpR); |
---|
144 | } |
---|
145 | // we ignore here homogenity - may be changed later: |
---|
146 | |
---|
147 | temp2 = kStd(temp1,NULL,isNotHomog,NULL); |
---|
148 | |
---|
149 | id_Delete(&temp1,tmpR); |
---|
150 | for (i=0;i<IDELEMS(temp2);i++) |
---|
151 | { |
---|
152 | if (p_LowVar(temp2->m[i], currRing)<imagepvariables) p_Delete(&(temp2->m[i]),tmpR); |
---|
153 | } |
---|
154 | |
---|
155 | // let's get back to the original ring |
---|
156 | //rChangeCurrRing(sourcering); |
---|
157 | temp1 = idInit(5,1); |
---|
158 | j = 0; |
---|
159 | for (i=0;i<IDELEMS(temp2);i++) |
---|
160 | { |
---|
161 | p = temp2->m[i]; |
---|
162 | if (p!=NULL) |
---|
163 | { |
---|
164 | q = p_SortMerge( |
---|
165 | pChangeSizeOfPoly(tmpR, p, imagepvariables+1, N, sourcering), |
---|
166 | sourcering); |
---|
167 | if (j>=IDELEMS(temp1)) |
---|
168 | { |
---|
169 | pEnlargeSet(&(temp1->m),IDELEMS(temp1),5); |
---|
170 | IDELEMS(temp1)+=5; |
---|
171 | } |
---|
172 | temp1->m[j] = q; |
---|
173 | j++; |
---|
174 | } |
---|
175 | } |
---|
176 | id_Delete(&temp2, tmpR); |
---|
177 | idSkipZeroes(temp1); |
---|
178 | |
---|
179 | if (currRing!=save_ring) rChangeCurrRing(save_ring); |
---|
180 | |
---|
181 | rDelete(tmpR); |
---|
182 | return temp1; |
---|
183 | } |
---|
184 | |
---|