source: git/Singular/dyn_modules/gfanlib/tropical.cc @ fb1872

spielwiese
Last change on this file since fb1872 was fb1872, checked in by Yue Ren <ren@…>, 9 years ago
fix: error when calling tropicalStartingPoint in the trivial case
  • Property mode set to 100644
File size: 6.3 KB
Line 
1#include <libpolys/polys/monomials/p_polys.h>
2#include <libpolys/coeffs/coeffs.h>
3
4#include <callgfanlib_conversion.h>
5#include <bbcone.h>
6#include <ppinitialReduction.h>
7#include <ttinitialReduction.h>
8#include <containsMonomial.h>
9#include <initial.h>
10#include <witness.h>
11#include <tropicalCurves.h>
12#include <neighbours.h>
13#include <tropicalStrategy.h>
14#include <startingCone.h>
15#include <tropicalVariety.h>
16
17
18gfan::ZCone homogeneitySpace(ideal I, ring r)
19{
20  int n = rVar(r);
21  poly g;
22  int* leadexpv = (int*) omAlloc((n+1)*sizeof(int));
23  int* tailexpv = (int*) omAlloc((n+1)*sizeof(int));
24  gfan::ZVector leadexpw = gfan::ZVector(n);
25  gfan::ZVector tailexpw = gfan::ZVector(n);
26  gfan::ZMatrix equations = gfan::ZMatrix(0,n);
27  for (int i=0; i<IDELEMS(I); i++)
28  {
29    g = (poly) I->m[i]; pGetExpV(g,leadexpv);
30    leadexpw = intStar2ZVector(n, leadexpv);
31    pIter(g);
32    while (g != NULL)
33    {
34      pGetExpV(g,tailexpv);
35      tailexpw = intStar2ZVector(n, tailexpv);
36      equations.appendRow(leadexpw-tailexpw);
37      pIter(g);
38    }
39  }
40  omFreeSize(leadexpv,(n+1)*sizeof(int));
41  omFreeSize(tailexpv,(n+1)*sizeof(int));
42  return gfan::ZCone(gfan::ZMatrix(0, equations.getWidth()),equations);
43}
44
45
46BOOLEAN homogeneitySpace(leftv res, leftv args)
47{
48  leftv u = args;
49  if ((u != NULL) && (u->Typ() == IDEAL_CMD))
50  {
51    leftv v = u->next;
52    if (v == NULL)
53    {
54      ideal I = (ideal) u->Data();
55      res->rtyp = coneID;
56      res->data = (void*) new gfan::ZCone(homogeneitySpace(I,currRing));
57      return FALSE;
58    }
59  }
60  WerrorS("homogeneitySpace: unexpected parameters");
61  return TRUE;
62}
63
64
65BOOLEAN groebnerCone(leftv res, leftv args)
66{
67  leftv u = args;
68  if ((u != NULL) && (u->Typ() == IDEAL_CMD))
69  {
70    leftv v = u->next;
71    if (v == NULL)
72    {
73      int n = currRing->N;
74      ideal I = (ideal) u->Data();
75      poly g = NULL;
76      int* leadexpv = (int*) omAlloc((n+1)*sizeof(int));
77      int* tailexpv = (int*) omAlloc((n+1)*sizeof(int));
78      gfan::ZVector leadexpw = gfan::ZVector(n);
79      gfan::ZVector tailexpw = gfan::ZVector(n);
80      gfan::ZMatrix inequalities = gfan::ZMatrix(0,n);
81      gfan::ZMatrix equations = gfan::ZMatrix(0,n);
82      long d;
83      for (int i=0; i<IDELEMS(I); i++)
84      {
85        g = (poly) I->m[i]; pGetExpV(g,leadexpv);
86        leadexpw = intStar2ZVector(n, leadexpv);
87        pIter(g);
88        d = p_Deg(g,currRing);
89        while ((g != NULL) && (p_Deg(g,currRing) == d))
90        {
91          pGetExpV(g,tailexpv);
92          tailexpw = intStar2ZVector(n, tailexpv);
93          equations.appendRow(leadexpw-tailexpw);
94          pIter(g);
95        }
96
97        if (g != NULL)
98        {
99          while (g != NULL)
100          {
101            pGetExpV(g,tailexpv);
102            tailexpw = intStar2ZVector(n, tailexpv);
103            inequalities.appendRow(leadexpw-tailexpw);
104            pIter(g);
105          }
106        }
107      }
108      gfan::ZCone* gCone = new gfan::ZCone(inequalities,equations);
109      omFreeSize(leadexpv,(n+1)*sizeof(int));
110      omFreeSize(tailexpv,(n+1)*sizeof(int));
111
112      res->rtyp = coneID;
113      res->data = (void*) gCone;
114      return FALSE;
115    }
116  }
117  WerrorS("groebnerCone: unexpected parameters");
118  return TRUE;
119}
120
121
122gfan::ZCone* maximalGroebnerCone(const ring &r, const ideal &I)
123{
124  int n = rVar(r);
125  poly g = NULL;
126  int* leadexpv = (int*) omAlloc((n+1)*sizeof(int));
127  int* tailexpv = (int*) omAlloc((n+1)*sizeof(int));
128  gfan::ZVector leadexpw = gfan::ZVector(n);
129  gfan::ZVector tailexpw = gfan::ZVector(n);
130  gfan::ZMatrix inequalities = gfan::ZMatrix(0,n);
131  for (int i=0; i<IDELEMS(I); i++)
132  {
133    g = (poly) I->m[i]; pGetExpV(g,leadexpv);
134    leadexpw = intStar2ZVector(n, leadexpv);
135    pIter(g);
136    while (g != NULL)
137    {
138      pGetExpV(g,tailexpv);
139      tailexpw = intStar2ZVector(n, tailexpv);
140      inequalities.appendRow(leadexpw-tailexpw);
141      pIter(g);
142    }
143  }
144  omFreeSize(leadexpv,(n+1)*sizeof(int));
145  omFreeSize(tailexpv,(n+1)*sizeof(int));
146  return new gfan::ZCone(inequalities,gfan::ZMatrix(0, inequalities.getWidth()));
147}
148
149
150BOOLEAN maximalGroebnerCone(leftv res, leftv args)
151{
152  leftv u = args;
153  if ((u != NULL) && (u->Typ() == IDEAL_CMD))
154  {
155    leftv v = u->next;
156    if (v == NULL)
157    {
158      ideal I = (ideal) u->Data();
159      res->rtyp = coneID;
160      res->data = (void*) maximalGroebnerCone(currRing, I);
161      return FALSE;
162    }
163  }
164  WerrorS("maximalGroebnerCone: unexpected parameters");
165  return TRUE;
166}
167
168
169void tropical_setup(SModulFunctions* p)
170{
171  p->iiAddCproc("","groebnerCone",FALSE,groebnerCone);
172  p->iiAddCproc("","maximalGroebnerCone",FALSE,maximalGroebnerCone);
173  p->iiAddCproc("","initial",FALSE,initial);
174  // p->iiAddCproc("","tropicalNeighbours",FALSE,tropicalNeighbours);
175#ifndef NDEBUG
176  // p->iiAddCproc("","initial0",FALSE,initial0);
177  // p->iiAddCproc("","pppReduce",FALSE,pppReduce);
178  // p->iiAddCproc("","ppreduceInitially0",FALSE,ppreduceInitially0);
179  // p->iiAddCproc("","ppreduceInitially1",FALSE,ppreduceInitially1);
180  // p->iiAddCproc("","ppreduceInitially2",FALSE,ppreduceInitially2);
181  // p->iiAddCproc("","ppreduceInitially3",FALSE,ppreduceInitially3);
182  // p->iiAddCproc("","ppreduceInitially4",FALSE,ppreduceInitially4);
183  // p->iiAddCproc("","ttpReduce",FALSE,ttpReduce);
184  // p->iiAddCproc("","ttreduceInitially0",FALSE,ttreduceInitially0);
185  // p->iiAddCproc("","ttreduceInitially1",FALSE,ttreduceInitially1);
186  // p->iiAddCproc("","ttreduceInitially2",FALSE,ttreduceInitially2);
187  // p->iiAddCproc("","ttreduceInitially3",FALSE,ttreduceInitially3);
188  // p->iiAddCproc("","ttreduceInitially4",FALSE,ttreduceInitially4);
189  // p->iiAddCproc("","checkForMonomial",FALSE,checkForMonomial);
190  // p->iiAddCproc("","dwr0",FALSE,dwr0);
191  // p->iiAddCproc("","witness0",FALSE,witness0);
192  // p->iiAddCproc("","tropicalVariety00",FALSE,tropicalVariety00);
193  // p->iiAddCproc("","tropicalVariety01",FALSE,tropicalVariety01);
194  // p->iiAddCproc("","tropicalCurve0",FALSE,tropicalCurve0);
195  // p->iiAddCproc("","tropicalCurve1",FALSE,tropicalCurve1);
196  p->iiAddCproc("","tropicalStartingPoint",FALSE,tropicalStartingPoint);
197  p->iiAddCproc("","tropicalStartingCone",FALSE,tropicalStartingCone);
198  p->iiAddCproc("","tropicalVariety",FALSE,tropicalVariety);
199#endif //NDEBUG
200  // p->iiAddCproc("","ppreduceInitially",FALSE,ppreduceInitially);
201  // p->iiAddCproc("","ttreduceInitially",FALSE,ttreduceInitially);
202  // p->iiAddCproc("","homogeneitySpace",FALSE,homogeneitySpace);
203}
Note: See TracBrowser for help on using the repository browser.