tropicalVariety.cc
Go to the documentation of this file.
2 #include "std_wrapper.h"
3 #include "bbfan.h"
4 #include "groebnerCone.h"
7 #include "coeffs/numbers.h"
8 #include "misc/options.h"
9 #include "kernel/structs.h"
10 
11 #include "gfanlib/gfanlib_zfan.h"
12 
14 
15 
16 /***
17  * sets option(redSB)
18  **/
19 static void setOptionRedSB()
20 {
23 }
24 
25 
26 /***
27  * sets option(noredSB);
28  **/
29 static void undoSetOptionRedSB()
30 {
32 }
33 
34 static gfan::ZFan* toZFan(std::set<gfan::ZCone> maxCones, int d)
35 {
36  gfan::ZFan* zf = new gfan::ZFan(d);
37  for (std::set<gfan::ZCone>::iterator sigma = maxCones.begin(); sigma!=maxCones.end(); sigma++)
38  zf->insert(*sigma);
39  return zf;
40 }
41 
42 
44 {
45  leftv u = args;
46  if ((u!=NULL) && (u->Typ()==POLY_CMD))
47  {
48  poly g = (poly) u->Data();
49  leftv v = u->next;
50  if (v==NULL)
51  {
52  try
53  {
54  ideal I = idInit(1);
55  I->m[0] = g;
56  tropicalStrategy currentStrategy(I,currRing);
57  std::set<gfan::ZCone> maxCones = tropicalVariety(g,currRing,&currentStrategy);
58  res->rtyp = fanID;
59  res->data = (char*) toZFan(maxCones,currentStrategy.getExpectedAmbientDimension());
60  I->m[0] = NULL;
61  id_Delete(&I,currRing);
62  return FALSE;
63  }
64  catch (const std::exception& ex)
65  {
66  Werror("ERROR: %s",ex.what());
67  return TRUE;
68  }
69  }
70  if ((v!=NULL) && (v->Typ()==NUMBER_CMD))
71  {
72  try
73  {
74  ideal I = idInit(1);
75  I->m[0] = g;
76  number p = (number) v->Data();
77  tropicalStrategy currentStrategy(I,p,currRing);
78  ideal startingIdeal = currentStrategy.getStartingIdeal();
79  ring startingRing = currentStrategy.getStartingRing();
80  poly gStart = startingIdeal->m[0];
81  std::set<gfan::ZCone> maxCones = tropicalVariety(gStart,startingRing,&currentStrategy);
82  res->rtyp = fanID;
83  res->data = (char*) toZFan(maxCones,currentStrategy.getExpectedAmbientDimension());
84  I->m[0] = NULL;
85  id_Delete(&I,currRing);
86  return FALSE;
87  }
88  catch (const std::exception& ex)
89  {
90  Werror("ERROR: %s",ex.what());
91  return TRUE;
92  }
93 
94  }
95  }
96  if ((u!=NULL) && (u->Typ()==IDEAL_CMD))
97  {
98  ideal I = (ideal) u->Data();
99  leftv v = u->next;
100 
101  if ((I->m[0]!=NULL) && (idElem(I)==1))
102  {
103  poly g = I->m[0];
104  if (v==NULL)
105  {
106  try
107  {
108  tropicalStrategy currentStrategy(I,currRing);
109  std::set<gfan::ZCone> maxCones = tropicalVariety(g,currRing,&currentStrategy);
110  res->rtyp = fanID;
111  res->data = (char*) toZFan(maxCones,currentStrategy.getExpectedAmbientDimension());
112  return FALSE;
113  }
114  catch (const std::exception& ex)
115  {
116  Werror("ERROR: %s",ex.what());
117  return TRUE;
118  }
119  }
120  if ((v!=NULL) && (v->Typ()==NUMBER_CMD))
121  {
122  try
123  {
124  number p = (number) v->Data();
125  tropicalStrategy currentStrategy(I,p,currRing);
126  ideal startingIdeal = currentStrategy.getStartingIdeal();
127  ring startingRing = currentStrategy.getStartingRing();
128  poly gStart = startingIdeal->m[0];
129  std::set<gfan::ZCone> maxCones = tropicalVariety(gStart,startingRing,&currentStrategy);
130  res->rtyp = fanID;
131  res->data = (char*) toZFan(maxCones,currentStrategy.getExpectedAmbientDimension());
132  return FALSE;
133  }
134  catch (const std::exception& ex)
135  {
136  Werror("ERROR: %s",ex.what());
137  return TRUE;
138  }
139  }
140  }
141 
142  if (v==NULL)
143  {
144  try
145  {
146  setOptionRedSB();
147  ideal stdI;
148  if (!hasFlag(u,FLAG_STD))
149  stdI = gfanlib_kStd_wrapper(I,currRing);
150  else
151  stdI = id_Copy(I,currRing);
152  tropicalStrategy currentStrategy(stdI,currRing);
153  gfan::ZFan* tropI = tropicalVariety(currentStrategy);
154  res->rtyp = fanID;
155  res->data = (char*) tropI;
157  id_Delete(&stdI,currRing);
158  return FALSE;
159  }
160  catch (const std::exception& ex)
161  {
162  Werror("ERROR: %s",ex.what());
163  return TRUE;
164  }
165  }
166  if ((v!=NULL) && (v->Typ()==NUMBER_CMD))
167  {
168  try
169  {
170  number p = (number) v->Data();
171  ideal stdI;
172  if (!hasFlag(u,FLAG_STD))
173  stdI = gfanlib_kStd_wrapper(I,currRing);
174  else
175  stdI = id_Copy(I,currRing);
176  tropicalStrategy currentStrategy(stdI,p,currRing);
177  gfan::ZFan* tropI = tropicalVariety(currentStrategy);
178  res->rtyp = fanID;
179  res->data = (char*) tropI;
180  id_Delete(&stdI,currRing);
181  return FALSE;
182  }
183  catch (const std::exception& ex)
184  {
185  Werror("ERROR: %s",ex.what());
186  return TRUE;
187  }
188  }
189  return FALSE;
190  }
191  WerrorS("tropicalVariety: unexpected parameters");
192  return TRUE;
193 }
#define OPT_REDSB
Definition: options.h:75
unsigned si_opt_1
Definition: options.c:5
Class used for (list of) interpreter objects.
Definition: subexpr.h:82
#define FALSE
Definition: auxiliary.h:94
static void setOptionRedSB()
ideal id_Copy(ideal h1, const ring r)
copy an ideal
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
ring getStartingRing() const
returns the polynomial ring over the valuation ring
#define TRUE
Definition: auxiliary.h:98
int getExpectedAmbientDimension() const
g
Definition: cfModGcd.cc:4031
void WerrorS(const char *s)
Definition: feFopen.cc:24
int fanID
Definition: bbfan.cc:19
#define BITSET
Definition: structs.h:20
int Typ()
Definition: subexpr.cc:1033
#define Sy_bit(x)
Definition: options.h:32
void * data
Definition: subexpr.h:88
#define SI_RESTORE_OPT(A, B)
Definition: options.h:24
static gfan::ZFan * toZFan(std::set< gfan::ZCone > maxCones, int d)
CanonicalForm res
Definition: facAbsFact.cc:64
ideal gfanlib_kStd_wrapper(ideal I, ring r, tHomog h=testHomog)
Definition: std_wrapper.cc:6
ideal getStartingIdeal() const
returns the input ideal
BITSET bitsetSave2
BOOLEAN tropicalVariety(leftv res, leftv args)
#define FLAG_STD
Definition: ipid.h:104
leftv next
Definition: subexpr.h:86
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition: simpleideals.cc:35
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
#define NULL
Definition: omList.c:12
implementation of the class groebnerCone
BITSET bitsetSave1
#define hasFlag(A, F)
Definition: ipid.h:107
int rtyp
Definition: subexpr.h:91
#define SI_SAVE_OPT(A, B)
Definition: options.h:21
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:12
void * Data()
Definition: subexpr.cc:1176
int idElem(const ideal F)
count non-zero elements
int p
Definition: cfModGcd.cc:4019
static void undoSetOptionRedSB()
int BOOLEAN
Definition: auxiliary.h:85
void Werror(const char *fmt,...)
Definition: reporter.cc:189