1 | #include <kernel/mod2.h> |
---|
2 | #include <polys/monomials/p_polys.h> |
---|
3 | #include <kernel/ideals.h> |
---|
4 | #include <polys/monomials/ring.h> |
---|
5 | #include <polys/monomials/maps.h> |
---|
6 | #include <kernel/maps/gen_maps.h> |
---|
7 | |
---|
8 | static poly p_SubstMon(poly p, int var, poly image, const ring preimage_r, const ring image_r, const nMapFunc nMap, matrix cache) |
---|
9 | { |
---|
10 | assume(!rIsPluralRing(image_r)); |
---|
11 | poly q=p_NSet(nMap(pGetCoeff(p),preimage_r->cf,image_r->cf),image_r); |
---|
12 | int i; |
---|
13 | poly h=NULL; |
---|
14 | for(i=1;i<=preimage_r->N; i++) |
---|
15 | { |
---|
16 | int pExp=p_GetExp( p,i,preimage_r); |
---|
17 | if (i!=var) |
---|
18 | { |
---|
19 | p_SetExp(q,i,pExp,image_r); |
---|
20 | } |
---|
21 | else if (pExp!=0) |
---|
22 | { |
---|
23 | h=maEvalVariable(image,var,pExp,(ideal)cache,image_r); |
---|
24 | if (h==NULL) |
---|
25 | { |
---|
26 | p_LmDelete(q,image_r); |
---|
27 | return NULL; |
---|
28 | } |
---|
29 | } |
---|
30 | else |
---|
31 | h=p_One(image_r); |
---|
32 | } |
---|
33 | p_Setm(q,image_r); |
---|
34 | h=p_Mult_mm(h,q,image_r); |
---|
35 | p_LmDelete(q,image_r); |
---|
36 | return h; |
---|
37 | } |
---|
38 | |
---|
39 | poly p_SubstPoly (poly p, int var, poly image, const ring preimage_r, const ring image_r, const nMapFunc nMap, matrix cache) |
---|
40 | { |
---|
41 | if (p==NULL) return NULL; |
---|
42 | |
---|
43 | if (rIsPluralRing(image_r)) |
---|
44 | { |
---|
45 | if((image_r!=preimage_r) |
---|
46 | ||(preimage_r!=currRing)) |
---|
47 | { |
---|
48 | WerrorS("not implemented"); |
---|
49 | return NULL; |
---|
50 | } |
---|
51 | return pSubst(pCopy(p),var,image); |
---|
52 | } |
---|
53 | if (cache==NULL) cache=mpNew(preimage_r->N,maMaxDeg_P(p, preimage_r)); |
---|
54 | |
---|
55 | poly result = NULL; |
---|
56 | sBucket_pt bucket = sBucketCreate(image_r); |
---|
57 | while (p != NULL) |
---|
58 | { |
---|
59 | poly q=p_SubstMon(p,var,image,preimage_r,image_r,nMap,cache); |
---|
60 | pIter(p); |
---|
61 | if (q!=NULL) sBucket_Add_p(bucket,q,pLength(q)); |
---|
62 | } |
---|
63 | int l_dummy; |
---|
64 | sBucketDestroyAdd(bucket, &result, &l_dummy); |
---|
65 | return result; |
---|
66 | } |
---|
67 | |
---|
68 | ideal id_SubstPoly (ideal id, int var, poly image, const ring preimage_r, const ring image_r, const nMapFunc nMap) |
---|
69 | { |
---|
70 | matrix cache=mpNew(preimage_r->N,maMaxDeg_Ma(id, preimage_r)); |
---|
71 | int k=MATROWS((matrix)id)*MATCOLS((matrix)id); |
---|
72 | ideal res=(ideal)mpNew(MATROWS((matrix)id),MATCOLS((matrix)id)); |
---|
73 | res->rank = id->rank; |
---|
74 | for(k--;k>=0;k--) |
---|
75 | { |
---|
76 | res->m[k]=p_SubstPoly(id->m[k],var,image,preimage_r,image_r,nMap,cache); |
---|
77 | } |
---|
78 | return res; |
---|
79 | } |
---|