source: git/Singular/dyn_modules/gfanlib/tropicalVariety.cc @ 395376

fieker-DuValspielwiese
Last change on this file since 395376 was 395376, checked in by Hans Schönemann <hannes@…>, 7 years ago
use include ".." for singular related .h, p3
  • Property mode set to 100644
File size: 5.0 KB
Line 
1#include "callgfanlib_conversion.h"
2#include "std_wrapper.h"
3#include "bbfan.h"
4#include "groebnerCone.h"
5#include "tropicalVarietyOfPolynomials.h"
6#include "tropicalVarietyOfIdeals.h"
7#include "coeffs/numbers.h"
8#include "misc/options.h"
9#include "kernel/structs.h"
10
11#include <iostream>
12#include "gfanlib/gfanlib_zfan.h"
13
14BITSET bitsetSave1, bitsetSave2;
15
16
17/***
18 * sets option(redSB)
19 **/
20static void setOptionRedSB()
21{
22  SI_SAVE_OPT(bitsetSave1,bitsetSave2);
23  si_opt_1|=Sy_bit(OPT_REDSB);
24}
25
26
27/***
28 * sets option(noredSB);
29 **/
30static void undoSetOptionRedSB()
31{
32  SI_RESTORE_OPT(bitsetSave1,bitsetSave2);
33}
34
35static gfan::ZFan* toZFan(std::set<gfan::ZCone> maxCones, int d)
36{
37  gfan::ZFan* zf = new gfan::ZFan(d);
38  for (std::set<gfan::ZCone>::iterator sigma = maxCones.begin(); sigma!=maxCones.end(); sigma++)
39    zf->insert(*sigma);
40  return zf;
41}
42
43
44BOOLEAN tropicalVariety(leftv res, leftv args)
45{
46  leftv u = args;
47  if ((u!=NULL) && (u->Typ()==POLY_CMD))
48  {
49    poly g = (poly) u->Data();
50    leftv v = u->next;
51    if (v==NULL)
52    {
53      try
54      {
55        ideal I = idInit(1);
56        I->m[0] = g;
57        tropicalStrategy currentStrategy(I,currRing);
58        std::set<gfan::ZCone> maxCones = tropicalVariety(g,currRing,&currentStrategy);
59        res->rtyp = fanID;
60        res->data = (char*) toZFan(maxCones,currentStrategy.getExpectedAmbientDimension());
61        I->m[0] = NULL;
62        id_Delete(&I,currRing);
63        return FALSE;
64      }
65      catch (const std::exception& ex)
66      {
67        Werror("ERROR: %s",ex.what());
68        return TRUE;
69      }
70    }
71    if ((v!=NULL) && (v->Typ()==NUMBER_CMD))
72    {
73      try
74      {
75        ideal I = idInit(1);
76        I->m[0] = g;
77        number p = (number) v->Data();
78        tropicalStrategy currentStrategy(I,p,currRing);
79        ideal startingIdeal = currentStrategy.getStartingIdeal();
80        ring startingRing = currentStrategy.getStartingRing();
81        poly gStart = startingIdeal->m[0];
82        std::set<gfan::ZCone> maxCones = tropicalVariety(gStart,startingRing,&currentStrategy);
83        res->rtyp = fanID;
84        res->data = (char*) toZFan(maxCones,currentStrategy.getExpectedAmbientDimension());
85        I->m[0] = NULL;
86        id_Delete(&I,currRing);
87        return FALSE;
88      }
89      catch (const std::exception& ex)
90      {
91        Werror("ERROR: %s",ex.what());
92        return TRUE;
93      }
94
95    }
96  }
97  if ((u!=NULL) && (u->Typ()==IDEAL_CMD))
98  {
99    ideal I = (ideal) u->Data();
100    leftv v = u->next;
101
102    if ((I->m[0]!=NULL) && (idElem(I)==1))
103    {
104      poly g = I->m[0];
105      if (v==NULL)
106      {
107        try
108        {
109          tropicalStrategy currentStrategy(I,currRing);
110          std::set<gfan::ZCone> maxCones = tropicalVariety(g,currRing,&currentStrategy);
111          res->rtyp = fanID;
112          res->data = (char*) toZFan(maxCones,currentStrategy.getExpectedAmbientDimension());
113          return FALSE;
114        }
115        catch (const std::exception& ex)
116        {
117          Werror("ERROR: %s",ex.what());
118          return TRUE;
119        }
120      }
121      if ((v!=NULL) && (v->Typ()==NUMBER_CMD))
122      {
123        try
124        {
125          number p = (number) v->Data();
126          tropicalStrategy currentStrategy(I,p,currRing);
127          ideal startingIdeal = currentStrategy.getStartingIdeal();
128          ring startingRing = currentStrategy.getStartingRing();
129          poly gStart = startingIdeal->m[0];
130          std::set<gfan::ZCone> maxCones = tropicalVariety(gStart,startingRing,&currentStrategy);
131          res->rtyp = fanID;
132          res->data = (char*) toZFan(maxCones,currentStrategy.getExpectedAmbientDimension());
133          return FALSE;
134        }
135        catch (const std::exception& ex)
136        {
137          Werror("ERROR: %s",ex.what());
138          return TRUE;
139        }
140      }
141    }
142
143    if (v==NULL)
144    {
145      try
146      {
147        setOptionRedSB();
148        ideal stdI;
149        if (!hasFlag(u,FLAG_STD))
150          stdI = gfanlib_kStd_wrapper(I,currRing);
151        else
152          stdI = id_Copy(I,currRing);
153        tropicalStrategy currentStrategy(stdI,currRing);
154        gfan::ZFan* tropI = tropicalVariety(currentStrategy);
155        res->rtyp = fanID;
156        res->data = (char*) tropI;
157        undoSetOptionRedSB();
158        id_Delete(&stdI,currRing);
159        return FALSE;
160      }
161      catch (const std::exception& ex)
162      {
163        Werror("ERROR: %s",ex.what());
164        return TRUE;
165      }
166    }
167    if ((v!=NULL) && (v->Typ()==NUMBER_CMD))
168    {
169      try
170      {
171        number p = (number) v->Data();
172        ideal stdI;
173        if (!hasFlag(u,FLAG_STD))
174          stdI = gfanlib_kStd_wrapper(I,currRing);
175        else
176          stdI = id_Copy(I,currRing);
177        tropicalStrategy currentStrategy(stdI,p,currRing);
178        gfan::ZFan* tropI = tropicalVariety(currentStrategy);
179        res->rtyp = fanID;
180        res->data = (char*) tropI;
181        id_Delete(&stdI,currRing);
182        return FALSE;
183      }
184      catch (const std::exception& ex)
185      {
186        Werror("ERROR: %s",ex.what());
187        return TRUE;
188      }
189    }
190    return FALSE;
191  }
192  WerrorS("tropicalVariety: unexpected parameters");
193  return TRUE;
194}
Note: See TracBrowser for help on using the repository browser.