1 | #include <utility> |
---|
2 | #include "kernel/GBEngine/kstd1.h" |
---|
3 | #include "gfanlib/gfanlib_vector.h" |
---|
4 | #include "callgfanlib_conversion.h" |
---|
5 | #include "singularWishlist.h" |
---|
6 | #include "initial.h" |
---|
7 | #include "lift.h" |
---|
8 | |
---|
9 | /*** |
---|
10 | * Given a Groebner basis I of an ideal in r, an interior Point |
---|
11 | * on a face of the maximal Groebner cone associated to the ordering on r, |
---|
12 | * and a vector pointing outwards from it, |
---|
13 | * returns a pair (Is,s) such that: |
---|
14 | * (1) s is the same mathematical ring as r, but with a new ordering such that |
---|
15 | * the interior point lies on the intersection of both maximal Groebner cones |
---|
16 | * (2) Is is a Groebner basis of the same ideal with respect to the ordering on s |
---|
17 | **/ |
---|
18 | std::pair<ideal,ring> flip(const ideal I, const ring r, |
---|
19 | const gfan::ZVector interiorPoint, |
---|
20 | const gfan::ZVector facetNormal, |
---|
21 | const gfan::ZVector adjustedInteriorPoint, |
---|
22 | const gfan::ZVector adjustedFacetNormal) |
---|
23 | { |
---|
24 | /* create a ring with weighted ordering */ |
---|
25 | bool ok; |
---|
26 | ring sAdjusted = rCopy0(r,FALSE,FALSE); |
---|
27 | int n = rVar(sAdjusted); |
---|
28 | sAdjusted->order = (rRingOrder_t*) omAlloc0(5*sizeof(rRingOrder_t)); |
---|
29 | sAdjusted->block0 = (int*) omAlloc0(5*sizeof(int)); |
---|
30 | sAdjusted->block1 = (int*) omAlloc0(5*sizeof(int)); |
---|
31 | sAdjusted->wvhdl = (int**) omAlloc0(5*sizeof(int**)); |
---|
32 | sAdjusted->order[0] = ringorder_a; |
---|
33 | sAdjusted->block0[0] = 1; |
---|
34 | sAdjusted->block1[0] = n; |
---|
35 | sAdjusted->wvhdl[0] = ZVectorToIntStar(adjustedInteriorPoint,ok); |
---|
36 | sAdjusted->order[1] = ringorder_a; |
---|
37 | sAdjusted->block0[1] = 1; |
---|
38 | sAdjusted->block1[1] = n; |
---|
39 | sAdjusted->wvhdl[1] = ZVectorToIntStar(adjustedFacetNormal,ok); |
---|
40 | sAdjusted->order[2] = ringorder_lp; |
---|
41 | sAdjusted->block0[2] = 1; |
---|
42 | sAdjusted->block1[2] = n; |
---|
43 | sAdjusted->wvhdl[2] = ZVectorToIntStar(adjustedFacetNormal,ok); |
---|
44 | sAdjusted->order[3] = ringorder_C; |
---|
45 | rComplete(sAdjusted); |
---|
46 | rTest(sAdjusted); |
---|
47 | nMapFunc identity = n_SetMap(r->cf,sAdjusted->cf); |
---|
48 | |
---|
49 | /* compute initial ideal and map it to the new ordering */ |
---|
50 | ideal inIr = initial(I,r,interiorPoint); |
---|
51 | int k = IDELEMS(I); ideal inIsAdjusted = idInit(k); |
---|
52 | for (int i=0; i<k; i++) |
---|
53 | { |
---|
54 | if (inIr->m[i]!=NULL) |
---|
55 | { |
---|
56 | inIsAdjusted->m[i] = p_PermPoly(inIr->m[i],NULL,r,sAdjusted,identity,NULL,0); |
---|
57 | } |
---|
58 | } |
---|
59 | id_Delete(&inIr,r); |
---|
60 | |
---|
61 | /* compute Groebner basis of the initial ideal */ |
---|
62 | intvec* nullVector = NULL; |
---|
63 | ring origin = currRing; |
---|
64 | rChangeCurrRing(sAdjusted); |
---|
65 | ideal inIsAdjustedGB = kStd(inIsAdjusted,currRing->qideal,testHomog,&nullVector); |
---|
66 | ideal IsAdjustedGB = lift(I,r,inIsAdjustedGB,sAdjusted); |
---|
67 | id_Delete(&inIsAdjusted,sAdjusted); |
---|
68 | id_Delete(&inIsAdjustedGB,sAdjusted); |
---|
69 | |
---|
70 | ring s = rCopy0(r,FALSE,FALSE); |
---|
71 | n = rVar(s); |
---|
72 | s->order = (rRingOrder_t*) omAlloc0(5*sizeof(rRingOrder_t)); |
---|
73 | s->block0 = (int*) omAlloc0(5*sizeof(int)); |
---|
74 | s->block1 = (int*) omAlloc0(5*sizeof(int)); |
---|
75 | s->wvhdl = (int**) omAlloc0(5*sizeof(int**)); |
---|
76 | s->order[0] = ringorder_a; |
---|
77 | s->block0[0] = 1; |
---|
78 | s->block1[0] = n; |
---|
79 | s->wvhdl[0] = ZVectorToIntStar(interiorPoint,ok); |
---|
80 | s->order[1] = ringorder_a; |
---|
81 | s->block0[1] = 1; |
---|
82 | s->block1[1] = n; |
---|
83 | s->wvhdl[1] = ZVectorToIntStar(facetNormal,ok); |
---|
84 | s->order[2] = ringorder_lp; |
---|
85 | s->block0[2] = 1; |
---|
86 | s->block1[2] = n; |
---|
87 | s->order[3] = ringorder_C; |
---|
88 | rComplete(s); |
---|
89 | rTest(s); |
---|
90 | identity = n_SetMap(sAdjusted->cf,s->cf); |
---|
91 | k = IDELEMS(IsAdjustedGB); ideal IsGB = idInit(k); |
---|
92 | for (int i=0; i<k; i++) |
---|
93 | { |
---|
94 | if (IsAdjustedGB->m[i]!=NULL) |
---|
95 | { |
---|
96 | IsGB->m[i] = p_PermPoly(IsAdjustedGB->m[i],NULL,sAdjusted,s,identity,NULL,0); |
---|
97 | } |
---|
98 | } |
---|
99 | id_Delete(&IsAdjustedGB,sAdjusted); |
---|
100 | rDelete(sAdjusted); |
---|
101 | rChangeCurrRing(origin); |
---|
102 | |
---|
103 | /* lift the Groebner basis of the initial ideal |
---|
104 | * to a Groebner basis of the original ideal, |
---|
105 | * the currRingChange is solely for sake of performance */ |
---|
106 | |
---|
107 | return std::make_pair(IsGB,s); |
---|
108 | } |
---|