My Project
Loading...
Searching...
No Matches
tropicalStrategy.cc
Go to the documentation of this file.
1#include "tropicalStrategy.h"
2#include "singularWishlist.h"
3#include "adjustWeights.h"
5// #include "ttinitialReduction.h"
6#include "tropical.h"
7#include "std_wrapper.h"
8#include "tropicalCurves.h"
9#include "tropicalDebug.h"
10#include "containsMonomial.h"
11
12
13// for various commands in dim(ideal I, ring r):
14#include "kernel/ideals.h"
17#include "misc/prime.h" // for isPrime(int i)
18
19/***
20 * Computes the dimension of an ideal I in ring r
21 * Copied from jjDim in iparith.cc
22 **/
23int dim(ideal I, ring r)
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}
49
50static void swapElements(ideal I, ideal J)
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}
61
62static bool noExtraReduction(ideal I, ring r, number /*p*/)
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}
131
132/**
133 * Initializes all relevant structures and information for the trivial valuation case,
134 * i.e. computing a tropical variety without any valuation.
135 */
161
162/**
163 * Given a polynomial ring r over the rational numbers and a weighted ordering,
164 * returns a polynomial ring s over the integers with one extra variable, which is weighted -1.
165 */
166static ring constructStartingRing(ring r)
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}
226
227static ideal constructStartingIdeal(ideal originalIdeal, ring originalRing, number uniformizingParameter, ring startingRing)
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}
270
271static number nMap_dummy(number a, const coeffs src, const coeffs dst)
272{
273 return n_Init(n_Int(a,src),dst);
274}
275
276/***
277 * Initializes all relevant structures and information for the valued case,
278 * i.e. computing a tropical variety over the rational numbers with p-adic valuation
279 **/
280tropicalStrategy::tropicalStrategy(ideal J, number q, ring s):
284 linealitySpace(gfan::ZCone()), // to come, see below
285 startingRing(NULL), // to come, see below
286 startingIdeal(NULL), // to come, see below
287 uniformizingParameter(NULL), // to come, see below
288 shortcutRing(NULL), // to come, see below
289 onlyLowerHalfSpace(true),
293{
294 /* assume that the ground field of the originalRing is Q */
296
297 /* replace Q with Z for the startingRing
298 * and add an extra variable for tracking the uniformizing parameter */
300
301 /* map the uniformizing parameter into the new coefficient domain */
303 if (nMap==NULL)
304 nMap=nMap_dummy;
306
307 /* map the input ideal into the new polynomial ring */
310
312
313 /* construct the shorcut ring */
314 shortcutRing = rCopy0(startingRing,FALSE); // do not copy q-ideal
319}
320
322 originalRing(rCopy(currentStrategy.getOriginalRing())),
323 originalIdeal(id_Copy(currentStrategy.getOriginalIdeal(),currentStrategy.getOriginalRing())),
324 expectedDimension(currentStrategy.getExpectedDimension()),
325 linealitySpace(currentStrategy.getHomogeneitySpace()),
326 startingRing(rCopy(currentStrategy.getStartingRing())),
327 startingIdeal(id_Copy(currentStrategy.getStartingIdeal(),currentStrategy.getStartingRing())),
334{
339 if (currentStrategy.getUniformizingParameter())
340 {
341 uniformizingParameter = n_Copy(currentStrategy.getUniformizingParameter(),startingRing->cf);
342 n_Test(uniformizingParameter,startingRing->cf);
343 }
344 if (currentStrategy.getShortcutRing())
345 {
346 shortcutRing = rCopy(currentStrategy.getShortcutRing());
347 rTest(shortcutRing);
348 }
349}
350
367
391
392void tropicalStrategy::putUniformizingBinomialInFront(ideal I, const ring r, const number q) const
393{
394 poly p = p_One(r);
395 p_SetCoeff(p,q,r);
396 poly t = p_One(r);
397 p_SetExp(t,1,1,r);
398 p_Setm(t,r);
399 poly pt = p_Add_q(p,p_Neg(t,r),r);
400
401 int k = IDELEMS(I);
402 int l;
403 for (l=0; l<k; l++)
404 {
405 if (p_EqualPolys(I->m[l],pt,r))
406 break;
407 }
408 p_Delete(&pt,r);
409
410 if (l>1)
411 {
412 pt = I->m[l];
413 for (int i=l; i>0; i--)
414 I->m[l] = I->m[l-1];
415 I->m[0] = pt;
416 pt = NULL;
417 }
418 return;
419}
420
421bool tropicalStrategy::reduce(ideal I, const ring r) const
422{
423 rTest(r);
424 id_Test(I,r);
425
426 nMapFunc identity = n_SetMap(startingRing->cf,r->cf);
427 number p = NULL;
429 p = identity(uniformizingParameter,startingRing->cf,r->cf);
430 bool b = extraReductionAlgorithm(I,r,p);
431 // putUniformizingBinomialInFront(I,r,p);
432 if (p!=NULL) n_Delete(&p,r->cf);
433
434 return b;
435}
436
437void tropicalStrategy::pReduce(ideal I, const ring r) const
438{
439 rTest(r);
440 id_Test(I,r);
441
442 if (isValuationTrivial())
443 return;
444
445 nMapFunc identity = n_SetMap(startingRing->cf,r->cf);
446 number p = identity(uniformizingParameter,startingRing->cf,r->cf);
447 ::pReduce(I,p,r);
448 n_Delete(&p,r->cf);
449
450 return;
451}
452
453ring tropicalStrategy::getShortcutRingPrependingWeight(const ring r, const gfan::ZVector &v) const
454{
455 ring rShortcut = rCopy0(r,FALSE); // do not copy q-ideal
456
457 // save old ordering
458 rRingOrder_t* order = rShortcut->order;
459 int* block0 = rShortcut->block0;
460 int* block1 = rShortcut->block1;
461 int** wvhdl = rShortcut->wvhdl;
462
463 // adjust weight and create new ordering
464 gfan::ZVector w = adjustWeightForHomogeneity(v);
465 int h = rBlocks(r); int n = rVar(r);
466 rShortcut->order = (rRingOrder_t*) omAlloc0((h+2)*sizeof(rRingOrder_t));
467 rShortcut->block0 = (int*) omAlloc0((h+2)*sizeof(int));
468 rShortcut->block1 = (int*) omAlloc0((h+2)*sizeof(int));
469 rShortcut->wvhdl = (int**) omAlloc0((h+2)*sizeof(int*));
470 rShortcut->order[0] = ringorder_a;
471 rShortcut->block0[0] = 1;
472 rShortcut->block1[0] = n;
473 bool overflow;
474 rShortcut->wvhdl[0] = ZVectorToIntStar(w,overflow);
475 for (int i=1; i<=h; i++)
476 {
477 rShortcut->order[i] = order[i-1];
478 rShortcut->block0[i] = block0[i-1];
479 rShortcut->block1[i] = block1[i-1];
480 rShortcut->wvhdl[i] = wvhdl[i-1];
481 }
482
483 // if valuation non-trivial, change coefficient ring to residue field
485 {
486 nKillChar(rShortcut->cf);
487 rShortcut->cf = nCopyCoeff(shortcutRing->cf);
488 }
489 rComplete(rShortcut);
490 rTest(rShortcut);
491
492 // delete old ordering
493 omFree(order);
494 omFree(block0);
495 omFree(block1);
496 omFree(wvhdl);
497
498 return rShortcut;
499}
500
501std::pair<poly,int> tropicalStrategy::checkInitialIdealForMonomial(const ideal I, const ring r, const gfan::ZVector &w) const
502{
503 // quick check whether I already contains an ideal
504 int k = IDELEMS(I);
505 for (int i=0; i<k; i++)
506 {
507 poly g = I->m[i];
508 if (g!=NULL
509 && pNext(g)==NULL
510 && (isValuationTrivial() || n_IsOne(p_GetCoeff(g,r),r->cf)))
511 return std::pair<poly,int>(g,i);
512 }
513
514 ring rShortcut;
515 ideal inIShortcut;
516 if (w.size()>0)
517 {
518 // if needed, prepend extra weight for homogeneity
519 // switch to residue field if valuation is non trivial
520 rShortcut = getShortcutRingPrependingWeight(r,w);
521
522 // compute the initial ideal and map it into the constructed ring
523 // if switched to residue field, remove possibly 0 elements
524 ideal inI = initial(I,r,w);
525 inIShortcut = idInit(k);
526 nMapFunc intoShortcut = n_SetMap(r->cf,rShortcut->cf);
527 for (int i=0; i<k; i++)
528 inIShortcut->m[i] = p_PermPoly(inI->m[i],NULL,r,rShortcut,intoShortcut,NULL,0);
530 idSkipZeroes(inIShortcut);
531 id_Delete(&inI,r);
532 }
533 else
534 {
535 rShortcut = r;
536 inIShortcut = I;
537 }
538
539 gfan::ZCone C0 = homogeneitySpace(inIShortcut,rShortcut);
540 gfan::ZCone pos = gfan::ZCone::positiveOrthant(C0.ambientDimension());
541 gfan::ZCone C0pos = intersection(C0,pos);
542 C0pos.canonicalize();
543 gfan::ZVector wpos = C0pos.getRelativeInteriorPoint();
545
546 // check initial ideal for monomial and
547 // if it exsists, return a copy of the monomial in the input ring
548 poly p = searchForMonomialViaStepwiseSaturation(inIShortcut,rShortcut,wpos);
549 poly monomial = NULL;
550 if (p!=NULL)
551 {
552 monomial=p_One(r);
553 for (int i=1; i<=rVar(r); i++)
554 p_SetExp(monomial,i,p_GetExp(p,i,rShortcut),r);
555 p_Setm(monomial,r);
556 p_Delete(&p,rShortcut);
557 }
558
559
560 if (w.size()>0)
561 {
562 // if needed, cleanup
563 id_Delete(&inIShortcut,rShortcut);
564 rDelete(rShortcut);
565 }
566 return std::pair<poly,int>(monomial,-1);
567}
568
570{
571 ring rShortcut = rCopy0(r,FALSE); // do not copy q-ideal
572 nKillChar(rShortcut->cf);
573 rShortcut->cf = nCopyCoeff(shortcutRing->cf);
574 rComplete(rShortcut);
575 rTest(rShortcut);
576 return rShortcut;
577}
578
579ideal tropicalStrategy::computeWitness(const ideal inJ, const ideal inI, const ideal I, const ring r) const
580{
581 // if the valuation is trivial and the ring and ideal have not been extended,
582 // then it is sufficient to return the difference between the elements of inJ
583 // and their normal forms with respect to I and r
584 if (isValuationTrivial())
585 return witness(inJ,I,r);
586 // if the valuation is non-trivial and the ring and ideal have been extended,
587 // then we can make a shortcut through the residue field
588 else
589 {
590 assume(IDELEMS(inI)==IDELEMS(I));
592 assume(uni>=0);
593 /**
594 * change ground ring into finite field
595 * and map the data into it
596 */
597 ring rShortcut = copyAndChangeCoefficientRing(r);
598
599 int k = IDELEMS(inJ);
600 int l = IDELEMS(I);
601 ideal inJShortcut = idInit(k);
602 ideal inIShortcut = idInit(l);
603 nMapFunc takingResidues = n_SetMap(r->cf,rShortcut->cf);
604 for (int i=0; i<k; i++)
605 inJShortcut->m[i] = p_PermPoly(inJ->m[i],NULL,r,rShortcut,takingResidues,NULL,0);
606 for (int j=0; j<l; j++)
607 inIShortcut->m[j] = p_PermPoly(inI->m[j],NULL,r,rShortcut,takingResidues,NULL,0);
608 id_Test(inJShortcut,rShortcut);
609 id_Test(inIShortcut,rShortcut);
610
611 /**
612 * Compute a division with remainder over the finite field
613 * and map the result back to r
614 */
615 matrix QShortcut = divisionDiscardingRemainder(inJShortcut,inIShortcut,rShortcut);
616 matrix Q = mpNew(l,k);
617 nMapFunc takingRepresentatives = n_SetMap(rShortcut->cf,r->cf);
618 for (int ij=k*l-1; ij>=0; ij--)
619 Q->m[ij] = p_PermPoly(QShortcut->m[ij],NULL,rShortcut,r,takingRepresentatives,NULL,0);
620
621 nMapFunc identity = n_SetMap(startingRing->cf,r->cf);
622 number p = identity(uniformizingParameter,startingRing->cf,r->cf);
623
624 /**
625 * Compute the normal forms
626 */
627 ideal J = idInit(k);
628 for (int j=0; j<k; j++)
629 {
630 poly q0 = p_Copy(inJ->m[j],r);
631 for (int i=0; i<l; i++)
632 {
633 poly qij = p_Copy(MATELEM(Q,i+1,j+1),r);
634 poly inIi = p_Copy(inI->m[i],r);
635 q0 = p_Add_q(q0,p_Neg(p_Mult_q(qij,inIi,r),r),r);
636 }
637 q0 = p_Div_nn(q0,p,r);
638 poly q0g0 = p_Mult_q(q0,p_Copy(I->m[uni],r),r);
639 // q0 = NULL;
640 poly qigi = NULL;
641 for (int i=0; i<l; i++)
642 {
643 poly qij = p_Copy(MATELEM(Q,i+1,j+1),r);
644 // poly inIi = p_Copy(I->m[i],r);
645 poly Ii = p_Copy(I->m[i],r);
646 qigi = p_Add_q(qigi,p_Mult_q(qij,Ii,r),r);
647 }
648 J->m[j] = p_Add_q(q0g0,qigi,r);
649 }
650
651 id_Delete(&inIShortcut,rShortcut);
652 id_Delete(&inJShortcut,rShortcut);
653 mp_Delete(&QShortcut,rShortcut);
654 rDelete(rShortcut);
655 mp_Delete(&Q,r);
656 n_Delete(&p,r->cf);
657 return J;
658 }
659}
660
661ideal tropicalStrategy::computeStdOfInitialIdeal(const ideal inI, const ring r) const
662{
663 // if valuation trivial, then compute std as usual
664 if (isValuationTrivial())
665 return gfanlib_kStd_wrapper(inI,r);
666
667 // if valuation non-trivial, then uniformizing parameter is in ideal
668 // so switch to residue field first and compute standard basis over the residue field
669 ring rShortcut = copyAndChangeCoefficientRing(r);
670 nMapFunc takingResidues = n_SetMap(r->cf,rShortcut->cf);
671 int k = IDELEMS(inI);
672 ideal inIShortcut = idInit(k);
673 for (int i=0; i<k; i++)
674 inIShortcut->m[i] = p_PermPoly(inI->m[i],NULL,r,rShortcut,takingResidues,NULL,0);
675 ideal inJShortcut = gfanlib_kStd_wrapper(inIShortcut,rShortcut);
676
677 // and lift the result back to the ring with valuation
678 nMapFunc takingRepresentatives = n_SetMap(rShortcut->cf,r->cf);
679 k = IDELEMS(inJShortcut);
680 ideal inJ = idInit(k+1);
681 inJ->m[0] = p_One(r);
682 nMapFunc identity = n_SetMap(startingRing->cf,r->cf);
683 p_SetCoeff(inJ->m[0],identity(uniformizingParameter,startingRing->cf,r->cf),r);
684 for (int i=0; i<k; i++)
685 inJ->m[i+1] = p_PermPoly(inJShortcut->m[i],NULL,rShortcut,r,takingRepresentatives,NULL,0);
686
687 id_Delete(&inJShortcut,rShortcut);
688 id_Delete(&inIShortcut,rShortcut);
689 rDelete(rShortcut);
690 return inJ;
691}
692
693ideal tropicalStrategy::computeLift(const ideal inJs, const ring s, const ideal inIr, const ideal Ir, const ring r) const
694{
695 int k = IDELEMS(inJs);
696 ideal inJr = idInit(k);
697 nMapFunc identitysr = n_SetMap(s->cf,r->cf);
698 for (int i=0; i<k; i++)
699 inJr->m[i] = p_PermPoly(inJs->m[i],NULL,s,r,identitysr,NULL,0);
700
701 ideal Jr = computeWitness(inJr,inIr,Ir,r);
702 nMapFunc identityrs = n_SetMap(r->cf,s->cf);
703 ideal Js = idInit(k);
704 for (int i=0; i<k; i++)
705 Js->m[i] = p_PermPoly(Jr->m[i],NULL,r,s,identityrs,NULL,0);
706 return Js;
707}
708
709ring tropicalStrategy::copyAndChangeOrderingWP(const ring r, const gfan::ZVector &w, const gfan::ZVector &v) const
710{
711 // copy shortcutRing and change to desired ordering
712 bool ok;
713 ring s = rCopy0(r,FALSE,FALSE);
714 int n = rVar(s);
715 gfan::ZVector wAdjusted = adjustWeightForHomogeneity(w);
716 gfan::ZVector vAdjusted = adjustWeightUnderHomogeneity(v,wAdjusted);
717 s->order = (rRingOrder_t*) omAlloc0(5*sizeof(rRingOrder_t));
718 s->block0 = (int*) omAlloc0(5*sizeof(int));
719 s->block1 = (int*) omAlloc0(5*sizeof(int));
720 s->wvhdl = (int**) omAlloc0(5*sizeof(int**));
721 s->order[0] = ringorder_a;
722 s->block0[0] = 1;
723 s->block1[0] = n;
724 s->wvhdl[0] = ZVectorToIntStar(wAdjusted,ok);
725 s->order[1] = ringorder_a;
726 s->block0[1] = 1;
727 s->block1[1] = n;
728 s->wvhdl[1] = ZVectorToIntStar(vAdjusted,ok);
729 s->order[2] = ringorder_lp;
730 s->block0[2] = 1;
731 s->block1[2] = n;
732 s->order[3] = ringorder_C;
733 rComplete(s);
734 rTest(s);
735
736 return s;
737}
738
739ring tropicalStrategy::copyAndChangeOrderingLS(const ring r, const gfan::ZVector &w, const gfan::ZVector &v) const
740{
741 // copy shortcutRing and change to desired ordering
742 bool ok;
743 ring s = rCopy0(r,FALSE,FALSE);
744 int n = rVar(s);
745 s->order = (rRingOrder_t*) omAlloc0(5*sizeof(rRingOrder_t));
746 s->block0 = (int*) omAlloc0(5*sizeof(int));
747 s->block1 = (int*) omAlloc0(5*sizeof(int));
748 s->wvhdl = (int**) omAlloc0(5*sizeof(int**));
749 s->order[0] = ringorder_a;
750 s->block0[0] = 1;
751 s->block1[0] = n;
752 s->wvhdl[0] = ZVectorToIntStar(w,ok);
753 s->order[1] = ringorder_a;
754 s->block0[1] = 1;
755 s->block1[1] = n;
756 s->wvhdl[1] = ZVectorToIntStar(v,ok);
757 s->order[2] = ringorder_lp;
758 s->block0[2] = 1;
759 s->block1[2] = n;
760 s->order[3] = ringorder_C;
761 rComplete(s);
762 rTest(s);
763
764 return s;
765}
766
767std::pair<ideal,ring> tropicalStrategy::computeFlip(const ideal Ir, const ring r,
768 const gfan::ZVector &interiorPoint,
769 const gfan::ZVector &facetNormal) const
770{
771 assume(isValuationTrivial() || interiorPoint[0].sign()<0);
773 assume(checkWeightVector(Ir,r,interiorPoint));
774
775 // get a generating system of the initial ideal
776 // and compute a standard basis with respect to adjacent ordering
777 ideal inIr = initial(Ir,r,interiorPoint);
778 ring sAdjusted = copyAndChangeOrderingWP(r,interiorPoint,facetNormal);
779 nMapFunc identity = n_SetMap(r->cf,sAdjusted->cf);
780 int k = IDELEMS(Ir);
781 ideal inIsAdjusted = idInit(k);
782 for (int i=0; i<k; i++)
783 inIsAdjusted->m[i] = p_PermPoly(inIr->m[i],NULL,r,sAdjusted,identity,NULL,0);
784 ideal inJsAdjusted = computeStdOfInitialIdeal(inIsAdjusted,sAdjusted);
785
786 // find witnesses of the new standard basis elements of the initial ideal
787 // with the help of the old standard basis of the ideal
788 k = IDELEMS(inJsAdjusted);
789 ideal inJr = idInit(k);
790 identity = n_SetMap(sAdjusted->cf,r->cf);
791 for (int i=0; i<k; i++)
792 inJr->m[i] = p_PermPoly(inJsAdjusted->m[i],NULL,sAdjusted,r,identity,NULL,0);
793
794 ideal Jr = computeWitness(inJr,inIr,Ir,r);
795 ring s = copyAndChangeOrderingLS(r,interiorPoint,facetNormal);
796 identity = n_SetMap(r->cf,s->cf);
797 ideal Js = idInit(k);
798 for (int i=0; i<k; i++)
799 Js->m[i] = p_PermPoly(Jr->m[i],NULL,r,s,identity,NULL,0);
800
801 reduce(Js,s);
802 assume(areIdealsEqual(Js,s,Ir,r));
804 assume(checkWeightVector(Js,s,interiorPoint));
805
806 // cleanup
807 id_Delete(&inIsAdjusted,sAdjusted);
808 id_Delete(&inJsAdjusted,sAdjusted);
809 rDelete(sAdjusted);
810 id_Delete(&inIr,r);
811 id_Delete(&Jr,r);
812 id_Delete(&inJr,r);
813
815 return std::make_pair(Js,s);
816}
817
818
819bool tropicalStrategy::checkForUniformizingBinomial(const ideal I, const ring r) const
820{
821 // if the valuation is trivial,
822 // then there is no special condition the first generator has to fullfill
823 if (isValuationTrivial())
824 return true;
825
826 // if the valuation is non-trivial then checks if the first generator is p-t
827 nMapFunc identity = n_SetMap(startingRing->cf,r->cf);
828 poly p = p_One(r);
829 p_SetCoeff(p,identity(uniformizingParameter,startingRing->cf,r->cf),r);
830 poly t = p_One(r);
831 p_SetExp(t,1,1,r);
832 p_Setm(t,r);
833 poly pt = p_Add_q(p,p_Neg(t,r),r);
834
835 for (int i=0; i<IDELEMS(I); i++)
836 {
837 if (p_EqualPolys(I->m[i],pt,r))
838 {
839 p_Delete(&pt,r);
840 return true;
841 }
842 }
843 p_Delete(&pt,r);
844 return false;
845}
846
847int tropicalStrategy::findPositionOfUniformizingBinomial(const ideal I, const ring r) const
848{
850
851 // if the valuation is non-trivial then checks if the first generator is p-t
852 nMapFunc identity = n_SetMap(startingRing->cf,r->cf);
853 poly p = p_One(r);
854 p_SetCoeff(p,identity(uniformizingParameter,startingRing->cf,r->cf),r);
855 poly t = p_One(r);
856 p_SetExp(t,1,1,r);
857 p_Setm(t,r);
858 poly pt = p_Add_q(p,p_Neg(t,r),r);
859
860 for (int i=0; i<IDELEMS(I); i++)
861 {
862 if (p_EqualPolys(I->m[i],pt,r))
863 {
864 p_Delete(&pt,r);
865 return i;
866 }
867 }
868 p_Delete(&pt,r);
869 return -1;
870}
871
872bool tropicalStrategy::checkForUniformizingParameter(const ideal inI, const ring r) const
873{
874 // if the valuation is trivial,
875 // then there is no special condition the first generator has to fullfill
876 if (isValuationTrivial())
877 return true;
878
879 // if the valuation is non-trivial then checks if the first generator is p
880 if (inI->m[0]==NULL)
881 return false;
882 nMapFunc identity = n_SetMap(startingRing->cf,r->cf);
883 poly p = p_One(r);
884 p_SetCoeff(p,identity(uniformizingParameter,startingRing->cf,r->cf),r);
885
886 for (int i=0; i<IDELEMS(inI); i++)
887 {
888 if (p_EqualPolys(inI->m[i],p,r))
889 {
890 p_Delete(&p,r);
891 return true;
892 }
893 }
894 p_Delete(&p,r);
895 return false;
896}
gfan::ZVector nonvalued_adjustWeightForHomogeneity(const gfan::ZVector &w)
gfan::ZVector nonvalued_adjustWeightUnderHomogeneity(const gfan::ZVector &e, const gfan::ZVector &)
gfan::ZVector valued_adjustWeightForHomogeneity(const gfan::ZVector &w)
gfan::ZVector valued_adjustWeightUnderHomogeneity(const gfan::ZVector &e, const gfan::ZVector &w)
#define FALSE
Definition auxiliary.h:97
int * ZVectorToIntStar(const gfan::ZVector &v, bool &overflow)
int l
Definition cfEzgcd.cc:100
int i
Definition cfEzgcd.cc:132
int k
Definition cfEzgcd.cc:99
int p
Definition cfModGcd.cc:4086
return false
Definition cfModGcd.cc:85
g
Definition cfModGcd.cc:4098
CanonicalForm b
Definition cfModGcd.cc:4111
poly * m
Definition matpol.h:18
int expectedDimension
the expected Dimension of the polyhedral output, i.e.
bool isValuationTrivial() const
ideal getOriginalIdeal() const
returns the input ideal over the field with valuation
tropicalStrategy(const ideal I, const ring r, const bool completelyHomogeneous=true, const bool completeSpace=true)
Constructor for the trivial valuation case.
bool isValuationNonTrivial() const
std::pair< ideal, ring > computeFlip(const ideal Ir, const ring r, const gfan::ZVector &interiorPoint, const gfan::ZVector &facetNormal) const
given an interior point of a groebner cone computes the groebner cone adjacent to it
tropicalStrategy & operator=(const tropicalStrategy &currentStrategy)
assignment operator
ring copyAndChangeOrderingLS(const ring r, const gfan::ZVector &w, const gfan::ZVector &v) const
void putUniformizingBinomialInFront(ideal I, const ring r, const number q) const
gfan::ZVector adjustWeightUnderHomogeneity(gfan::ZVector v, gfan::ZVector w) const
Given strictly positive weight w and weight v, returns a strictly positive weight u such that on an i...
bool reduce(ideal I, const ring r) const
reduces the generators of an ideal I so that the inequalities and equations of the Groebner cone can ...
gfan::ZCone getHomogeneitySpace() const
returns the homogeneity space of the preimage ideal
bool onlyLowerHalfSpace
true if valuation non-trivial, false otherwise
gfan::ZCone linealitySpace
the homogeneity space of the Grobner fan
int getExpectedDimension() const
returns the expected Dimension of the polyhedral output
ring startingRing
polynomial ring over the valuation ring extended by one extra variable t
ideal originalIdeal
input ideal, assumed to be a homogeneous prime ideal
gfan::ZVector(* weightAdjustingAlgorithm1)(const gfan::ZVector &w)
A function such that: Given weight w, returns a strictly positive weight u such that an ideal satisfy...
void pReduce(ideal I, const ring r) const
~tropicalStrategy()
destructor
int findPositionOfUniformizingBinomial(const ideal I, const ring r) const
ideal computeWitness(const ideal inJ, const ideal inI, const ideal I, const ring r) const
suppose w a weight in maximal groebner cone of > suppose I (initially) reduced standard basis w....
ring shortcutRing
polynomial ring over the residue field
bool(* extraReductionAlgorithm)(ideal I, ring r, number p)
A function that reduces the generators of an ideal I so that the inequalities and equations of the Gr...
ring getStartingRing() const
returns the polynomial ring over the valuation ring
gfan::ZVector adjustWeightForHomogeneity(gfan::ZVector w) const
Given weight w, returns a strictly positive weight u such that an ideal satisfying the valuation-sepc...
ring getShortcutRingPrependingWeight(const ring r, const gfan::ZVector &w) const
If valuation trivial, returns a copy of r with a positive weight prepended, such that any ideal homog...
number uniformizingParameter
uniformizing parameter in the valuation ring
ring copyAndChangeCoefficientRing(const ring r) const
ring copyAndChangeOrderingWP(const ring r, const gfan::ZVector &w, const gfan::ZVector &v) const
ideal computeLift(const ideal inJs, const ring s, const ideal inIr, const ideal Ir, const ring r) const
ideal startingIdeal
preimage of the input ideal under the map that sends t to the uniformizing parameter
bool checkForUniformizingParameter(const ideal inI, const ring r) const
if valuation non-trivial, checks whether the genearting system contains p otherwise returns true
ideal getStartingIdeal() const
returns the input ideal
bool restrictToLowerHalfSpace() const
returns true, if valuation non-trivial, false otherwise
gfan::ZVector(* weightAdjustingAlgorithm2)(const gfan::ZVector &v, const gfan::ZVector &w)
A function such that: Given strictly positive weight w and weight v, returns a strictly positive weig...
ideal computeStdOfInitialIdeal(const ideal inI, const ring r) const
given generators of the initial ideal, computes its standard basis
ring getOriginalRing() const
returns the polynomial ring over the field with valuation
number getUniformizingParameter() const
returns the uniformizing parameter in the valuation ring
std::pair< poly, int > checkInitialIdealForMonomial(const ideal I, const ring r, const gfan::ZVector &w=0) const
If given w, assuming w is in the Groebner cone of the ordering on r and I is a standard basis with re...
bool checkForUniformizingBinomial(const ideal I, const ring r) const
if valuation non-trivial, checks whether the generating system contains p-t otherwise returns true
ring getShortcutRing() const
ring originalRing
polynomial ring over a field with valuation
static FORCE_INLINE long n_Int(number &n, const coeffs r)
conversion of n to an int; 0 if not possible in Z/pZ: the representing int lying in (-p/2 ....
Definition coeffs.h:550
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of 'n'
Definition coeffs.h:457
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r).
Definition coeffs.h:715
@ n_Zp
\F{p < 2^31}
Definition coeffs.h:29
@ n_Z
only used if HAVE_RINGS is defined
Definition coeffs.h:43
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:521
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:703
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition numbers.cc:412
static FORCE_INLINE coeffs nCopyCoeff(const coeffs r)
"copy" coeffs, i.e. increment ref
Definition coeffs.h:439
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition coeffs.h:461
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:541
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition coeffs.h:80
void nKillChar(coeffs r)
undo all initialisations
Definition numbers.cc:563
static FORCE_INLINE BOOLEAN n_IsOne(number n, const coeffs r)
TRUE iff 'n' represents the one element.
Definition coeffs.h:474
poly searchForMonomialViaStepwiseSaturation(const ideal I, const ring r, const gfan::ZVector w0)
const CanonicalForm int s
Definition facAbsFact.cc:51
const CanonicalForm & w
Definition facAbsFact.cc:51
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39
int j
Definition facHensel.cc:110
if(!FE_OPT_NO_SHELL_FLAG)
Definition fehelp.cc:1000
int scDimInt(ideal S, ideal Q)
ideal dimension
Definition hdegree.cc:78
#define idDelete(H)
delete an ideal
Definition ideals.h:29
ideal id_Copy(ideal h1, const ring r)
copy an ideal
#define idPosConstant(I)
index of generator with leading term in ground ring (if any); otherwise -1
Definition ideals.h:37
poly initial(const poly p, const ring r, const gfan::ZVector &w)
Returns the initial form of p with respect to w.
Definition initial.cc:30
STATIC_VAR Poly * h
Definition janet.cc:971
poly kNF(ideal F, ideal Q, poly p, int syzComp, int lazyReduce)
Definition kstd1.cc:3230
void mp_Delete(matrix *a, const ring r)
Definition matpol.cc:874
matrix mpNew(int r, int c)
create a r x c zero-matrix
Definition matpol.cc:37
#define MATELEM(mat, i, j)
1-based access to matrix
Definition matpol.h:29
ip_smatrix * matrix
Definition matpol.h:43
#define assume(x)
Definition mod2.h:389
#define pNext(p)
Definition monomials.h:36
#define p_GetCoeff(p, r)
Definition monomials.h:50
The main handler for Singular numbers which are suitable for Singular polynomials.
#define omStrDup(s)
#define omFreeSize(addr, size)
#define omAlloc(size)
#define omFree(addr)
#define omAlloc0(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:4269
poly p_Div_nn(poly p, const number n, const ring r)
Definition p_polys.cc:1506
poly p_One(const ring r)
Definition p_polys.cc:1314
BOOLEAN p_EqualPolys(poly p1, poly p2, const ring r)
Definition p_polys.cc:4679
static poly p_Neg(poly p, const ring r)
Definition p_polys.h:1114
static poly p_Add_q(poly p, poly q, const ring r)
Definition p_polys.h:938
static poly p_Mult_q(poly p, poly q, const ring r)
Definition p_polys.h:1125
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
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent @Note: the integer VarOffset encodes:
Definition p_polys.h:471
static void p_Delete(poly *p, const ring r)
Definition p_polys.h:903
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition p_polys.h:848
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
#define pDelete(p_ptr)
Definition polys.h:187
bool isOrderingLocalInT(const ring r)
bool ppreduceInitially(poly *hStar, const poly g, const ring r)
reduces h initially with respect to g, returns false if h was initially reduced in the first place,...
int IsPrime(int p)
Definition prime.cc:61
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:3527
ring rCopy0(const ring r, BOOLEAN copy_qideal, BOOLEAN copy_ordering)
Definition ring.cc:1427
void rDelete(ring r)
unconditionally deletes fields in r
Definition ring.cc:454
static int sign(int x)
Definition ring.cc:3504
ring rCopy(ring r)
Definition ring.cc:1737
static BOOLEAN rField_is_Z(const ring r)
Definition ring.h:520
static BOOLEAN rField_is_Zp(const ring r)
Definition ring.h:506
static int rBlocks(const ring r)
Definition ring.h:579
rRingOrder_t
order stuff
Definition ring.h:69
@ ringorder_lp
Definition ring.h:78
@ ringorder_a
Definition ring.h:71
@ 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:517
static short rVar(const ring r)
define rVar(r) (r->N)
Definition ring.h:603
#define rTest(r)
Definition ring.h:799
#define rField_is_Ring(R)
Definition ring.h:491
ideal idInit(int idsize, int rank)
initialise an ideal / module
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
ideal id_Head(ideal h, const ring r)
returns the ideals of initial terms
void idSkipZeroes(ideal ide)
gives an ideal/module the minimal possible size
#define IDELEMS(i)
#define id_Test(A, lR)
#define Q
Definition sirandom.c:26
ideal gfanlib_kStd_wrapper(ideal I, ring r, tHomog h=testHomog)
Definition std_wrapper.cc:6
bool checkWeightVector(const ideal I, const ring r, const gfan::ZVector &weightVector, bool checkBorder)
bool checkForNonPositiveEntries(const gfan::ZVector &w)
bool areIdealsEqual(ideal I, ring r, ideal J, ring s)
static bool noExtraReduction(ideal I, ring r, number)
int dim(ideal I, ring r)
static ideal constructStartingIdeal(ideal originalIdeal, ring originalRing, number uniformizingParameter, ring startingRing)
static ring constructStartingRing(ring r)
Given a polynomial ring r over the rational numbers and a weighted ordering, returns a polynomial rin...
static void swapElements(ideal I, ideal J)
static number nMap_dummy(number a, const coeffs src, const coeffs dst)
implementation of the class tropicalStrategy
gfan::ZCone homogeneitySpace(ideal I, ring r)
Definition tropical.cc:19
matrix divisionDiscardingRemainder(const poly f, const ideal G, const ring r)
Computes a division discarding remainder of f with respect to G.
Definition witness.cc:9
poly witness(const poly m, const ideal I, const ideal inI, const ring r)
Let w be the uppermost weight vector in the matrix defining the ordering on r.
Definition witness.cc:34