My Project
Loading...
Searching...
No Matches
tropicalStrategy.cc File Reference
#include "tropicalStrategy.h"
#include "singularWishlist.h"
#include "adjustWeights.h"
#include "ppinitialReduction.h"
#include "tropical.h"
#include "std_wrapper.h"
#include "tropicalCurves.h"
#include "tropicalDebug.h"
#include "containsMonomial.h"
#include "kernel/ideals.h"
#include "kernel/combinatorics/stairc.h"
#include "kernel/GBEngine/kstd1.h"
#include "misc/prime.h"

Go to the source code of this file.

Functions

int dim (ideal I, ring r)
 
static void swapElements (ideal I, ideal J)
 
static bool noExtraReduction (ideal I, ring r, number)
 
static ring constructStartingRing (ring r)
 Given a polynomial ring r over the rational numbers and a weighted ordering, returns a polynomial ring s over the integers with one extra variable, which is weighted -1.
 
static ideal constructStartingIdeal (ideal originalIdeal, ring originalRing, number uniformizingParameter, ring startingRing)
 

Function Documentation

◆ constructStartingIdeal()

static ideal constructStartingIdeal ( ideal originalIdeal,
ring originalRing,
number uniformizingParameter,
ring startingRing )
static

Definition at line 227 of file tropicalStrategy.cc.

228{
229 // construct p-t
230 poly g = p_One(startingRing);
231 p_SetCoeff(g,uniformizingParameter,startingRing);
232 pNext(g) = p_One(startingRing);
233 p_SetExp(pNext(g),1,1,startingRing);
234 p_SetCoeff(pNext(g),n_Init(-1,startingRing->cf),startingRing);
235 p_Setm(pNext(g),startingRing);
236 ideal pt = idInit(1);
237 pt->m[0] = g;
238
239 // map originalIdeal from originalRing into startingRing
240 int k = IDELEMS(originalIdeal);
241 ideal J = idInit(k+1);
242 nMapFunc nMap = n_SetMap(originalRing->cf,startingRing->cf);
243 int n = rVar(originalRing);
244 int* shiftByOne = (int*) omAlloc((n+1)*sizeof(int));
245 for (int i=1; i<=n; i++)
246 shiftByOne[i]=i+1;
247 for (int i=0; i<k; i++)
248 {
249 if(originalIdeal->m[i]!=NULL)
250 {
251 J->m[i] = p_PermPoly(originalIdeal->m[i],shiftByOne,originalRing,startingRing,nMap,NULL,0);
252 }
253 }
254 omFreeSize(shiftByOne,(n+1)*sizeof(int));
255
256 ring origin = currRing;
257 rChangeCurrRing(startingRing);
258 ideal startingIdeal = kNF(pt,startingRing->qideal,J); // mathematically redundant,
259 rChangeCurrRing(origin); // but helps with upcoming std computation
260 // ideal startingIdeal = J; J = NULL;
261 assume(startingIdeal->m[k]==NULL);
262 startingIdeal->m[k] = pt->m[0];
263 startingIdeal = gfanlib_kStd_wrapper(startingIdeal,startingRing);
264
265 id_Delete(&J,startingRing);
266 pt->m[0] = NULL;
267 id_Delete(&pt,startingRing);
268 return startingIdeal;
269}
int i
Definition cfEzgcd.cc:132
int k
Definition cfEzgcd.cc:99
g
Definition cfModGcd.cc:4098
static FORCE_INLINE nMapFunc n_SetMap(const coeffs src, const coeffs dst)
set the mapping function pointers for translating numbers from src to dst
Definition coeffs.h:701
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition coeffs.h:539
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition coeffs.h:80
poly kNF(ideal F, ideal Q, poly p, int syzComp, int lazyReduce)
Definition kstd1.cc:3224
#define assume(x)
Definition mod2.h:389
#define pNext(p)
Definition monomials.h:36
#define omFreeSize(addr, size)
#define omAlloc(size)
#define NULL
Definition omList.c:12
poly p_PermPoly(poly p, const int *perm, const ring oldRing, const ring dst, nMapFunc nMap, const int *par_perm, int OldPar, BOOLEAN use_mult)
Definition p_polys.cc:4211
poly p_One(const ring r)
Definition p_polys.cc:1314
static unsigned long p_SetExp(poly p, const unsigned long e, const unsigned long iBitmask, const int VarOffset)
set a single variable exponent @Note: VarOffset encodes the position in p->exp
Definition p_polys.h:490
static void p_Setm(poly p, const ring r)
Definition p_polys.h:235
static number p_SetCoeff(poly p, number n, ring r)
Definition p_polys.h:414
void rChangeCurrRing(ring r)
Definition polys.cc:16
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition polys.cc:13
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition ring.h:598
ideal idInit(int idsize, int rank)
initialise an ideal / module
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
#define IDELEMS(i)
ideal gfanlib_kStd_wrapper(ideal I, ring r, tHomog h=testHomog)
Definition std_wrapper.cc:6

◆ constructStartingRing()

static ring constructStartingRing ( ring r)
static

Given a polynomial ring r over the rational numbers and a weighted ordering, returns a polynomial ring s over the integers with one extra variable, which is weighted -1.

Definition at line 166 of file tropicalStrategy.cc.

167{
169
170 ring s = rCopy0(r,FALSE,FALSE);
171 nKillChar(s->cf);
172 s->cf = nInitChar(n_Z,NULL);
173
174 int n = rVar(s)+1;
175 s->N = n;
176 char** oldNames = s->names;
177 s->names = (char**) omAlloc((n+1)*sizeof(char**));
178 s->names[0] = omStrDup("t");
179 for (int i=1; i<n; i++)
180 s->names[i] = oldNames[i-1];
181 omFree(oldNames);
182
183 s->order = (rRingOrder_t*) omAlloc0(3*sizeof(rRingOrder_t));
184 s->block0 = (int*) omAlloc0(3*sizeof(int));
185 s->block1 = (int*) omAlloc0(3*sizeof(int));
186 s->wvhdl = (int**) omAlloc0(3*sizeof(int**));
187 s->order[0] = ringorder_ws;
188 s->block0[0] = 1;
189 s->block1[0] = n;
190 s->wvhdl[0] = (int*) omAlloc(n*sizeof(int));
191 s->wvhdl[0][0] = 1;
192 if (r->order[0] == ringorder_lp)
193 {
194 s->wvhdl[0][1] = 1;
195 }
196 else if (r->order[0] == ringorder_ls)
197 {
198 s->wvhdl[0][1] = -1;
199 }
200 else if (r->order[0] == ringorder_dp)
201 {
202 for (int i=1; i<n; i++)
203 s->wvhdl[0][i] = -1;
204 }
205 else if (r->order[0] == ringorder_ds)
206 {
207 for (int i=1; i<n; i++)
208 s->wvhdl[0][i] = 1;
209 }
210 else if (r->order[0] == ringorder_ws)
211 {
212 for (int i=1; i<n; i++)
213 s->wvhdl[0][i] = r->wvhdl[0][i-1];
214 }
215 else
216 {
217 for (int i=1; i<n; i++)
218 s->wvhdl[0][i] = -r->wvhdl[0][i-1];
219 }
220 s->order[1] = ringorder_C;
221
222 rComplete(s);
223 rTest(s);
224 return s;
225}
#define FALSE
Definition auxiliary.h:97
@ n_Z
only used if HAVE_RINGS is defined
Definition coeffs.h:43
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition numbers.cc:406
void nKillChar(coeffs r)
undo all initialisations
Definition numbers.cc:556
const CanonicalForm int s
Definition facAbsFact.cc:51
#define omStrDup(s)
#define omFree(addr)
#define omAlloc0(size)
BOOLEAN rComplete(ring r, int force)
this needs to be called whenever a new ring is created: new fields in ring are created (like VarOffse...
Definition ring.cc:3526
ring rCopy0(const ring r, BOOLEAN copy_qideal, BOOLEAN copy_ordering)
Definition ring.cc:1426
rRingOrder_t
order stuff
Definition ring.h:69
@ ringorder_lp
Definition ring.h:78
@ ringorder_C
Definition ring.h:74
@ ringorder_ds
Definition ring.h:86
@ ringorder_dp
Definition ring.h:79
@ ringorder_ws
Definition ring.h:88
@ ringorder_ls
degree, ip
Definition ring.h:85
static BOOLEAN rField_is_Q(const ring r)
Definition ring.h:512
#define rTest(r)
Definition ring.h:794

◆ dim()

int dim ( ideal I,
ring r )

Definition at line 23 of file tropicalStrategy.cc.

24{
25 ring origin = currRing;
26 if (origin != r)
28 int d;
30 {
31 int i = idPosConstant(I);
32 if ((i != -1)
33 && (n_IsUnit(p_GetCoeff(I->m[i],currRing->cf),currRing->cf))
34 )
35 return -1;
36 ideal vv = id_Head(I,currRing);
37 if (i != -1) pDelete(&vv->m[i]);
38 d = scDimInt(vv, currRing->qideal);
39 if (rField_is_Z(currRing) && (i==-1)) d++;
40 idDelete(&vv);
41 return d;
42 }
43 else
44 d = scDimInt(I,currRing->qideal);
45 if (origin != r)
46 rChangeCurrRing(origin);
47 return d;
48}
static FORCE_INLINE BOOLEAN n_IsUnit(number n, const coeffs r)
TRUE iff n has a multiplicative inverse in the given coeff field/ring r.
Definition coeffs.h:519
int scDimInt(ideal S, ideal Q)
ideal dimension
Definition hdegree.cc:78
#define idDelete(H)
delete an ideal
Definition ideals.h:29
#define idPosConstant(I)
index of generator with leading term in ground ring (if any); otherwise -1
Definition ideals.h:37
#define p_GetCoeff(p, r)
Definition monomials.h:50
#define pDelete(p_ptr)
Definition polys.h:187
static BOOLEAN rField_is_Z(const ring r)
Definition ring.h:515
#define rField_is_Ring(R)
Definition ring.h:491
ideal id_Head(ideal h, const ring r)
returns the ideals of initial terms

◆ noExtraReduction()

static bool noExtraReduction ( ideal I,
ring r,
number  )
static

Definition at line 62 of file tropicalStrategy.cc.

63{
64 int n = rVar(r);
65 gfan::ZVector allOnes(n);
66 for (int i=0; i<n; i++)
67 allOnes[i] = 1;
68 ring rShortcut = rCopy0(r);
69
70 rRingOrder_t* order = rShortcut->order;
71 int* block0 = rShortcut->block0;
72 int* block1 = rShortcut->block1;
73 int** wvhdl = rShortcut->wvhdl;
74
75 int h = rBlocks(r);
76 rShortcut->order = (rRingOrder_t*) omAlloc0((h+2)*sizeof(rRingOrder_t));
77 rShortcut->block0 = (int*) omAlloc0((h+2)*sizeof(int));
78 rShortcut->block1 = (int*) omAlloc0((h+2)*sizeof(int));
79 rShortcut->wvhdl = (int**) omAlloc0((h+2)*sizeof(int*));
80 rShortcut->order[0] = ringorder_a;
81 rShortcut->block0[0] = 1;
82 rShortcut->block1[0] = n;
83 bool overflow;
84 rShortcut->wvhdl[0] = ZVectorToIntStar(allOnes,overflow);
85 for (int i=1; i<=h; i++)
86 {
87 rShortcut->order[i] = order[i-1];
88 rShortcut->block0[i] = block0[i-1];
89 rShortcut->block1[i] = block1[i-1];
90 rShortcut->wvhdl[i] = wvhdl[i-1];
91 }
92 //rShortcut->order[h+1] = (rRingOrder_t)0; -- done by omAlloc0
93 //rShortcut->block0[h+1] = 0;
94 //rShortcut->block1[h+1] = 0;
95 //rShortcut->wvhdl[h+1] = NULL;
96
97 rComplete(rShortcut);
98 rTest(rShortcut);
99
100 omFree(order);
101 omFree(block0);
102 omFree(block1);
103 omFree(wvhdl);
104
105 int k = IDELEMS(I);
106 ideal IShortcut = idInit(k);
107 nMapFunc intoShortcut = n_SetMap(r->cf,rShortcut->cf);
108 for (int i=0; i<k; i++)
109 {
110 if(I->m[i]!=NULL)
111 {
112 IShortcut->m[i] = p_PermPoly(I->m[i],NULL,r,rShortcut,intoShortcut,NULL,0);
113 }
114 }
115
116 ideal JShortcut = gfanlib_kStd_wrapper(IShortcut,rShortcut);
117
118 ideal J = idInit(k);
119 nMapFunc outofShortcut = n_SetMap(rShortcut->cf,r->cf);
120 for (int i=0; i<k; i++)
121 J->m[i] = p_PermPoly(JShortcut->m[i],NULL,rShortcut,r,outofShortcut,NULL,0);
122
123 assume(areIdealsEqual(J,r,I,r));
124 swapElements(I,J);
125 id_Delete(&IShortcut,rShortcut);
126 id_Delete(&JShortcut,rShortcut);
127 rDelete(rShortcut);
128 id_Delete(&J,r);
129 return false;
130}
int * ZVectorToIntStar(const gfan::ZVector &v, bool &overflow)
STATIC_VAR Poly * h
Definition janet.cc:971
void rDelete(ring r)
unconditionally deletes fields in r
Definition ring.cc:454
static int rBlocks(const ring r)
Definition ring.h:574
@ ringorder_a
Definition ring.h:71
bool areIdealsEqual(ideal I, ring r, ideal J, ring s)
static void swapElements(ideal I, ideal J)

◆ swapElements()

static void swapElements ( ideal I,
ideal J )
static

Definition at line 50 of file tropicalStrategy.cc.

51{
52 assume(IDELEMS(I)==IDELEMS(J));
53
54 for (int i=IDELEMS(I)-1; i>=0; i--)
55 {
56 poly cache = I->m[i];
57 I->m[i] = J->m[i];
58 J->m[i] = cache;
59 }
60}