bbfan.cc
Go to the documentation of this file.
1 #include <kernel/mod2.h>
2 
3 #if HAVE_GFANLIB
4 
5 #include <misc/intvec.h>
6 #include <coeffs/coeffs.h>
7 #include <coeffs/bigintmat.h>
8 
9 #include <Singular/ipid.h>
10 #include <Singular/ipshell.h>
11 #include <Singular/blackbox.h>
12 
13 #include <callgfanlib_conversion.h>
14 #include <bbfan.h>
15 #include <gfan.h>
16 #include <sstream>
17 
18 int fanID;
19 
20 void* bbfan_Init(blackbox* /*b*/)
21 {
22  return (void*) new gfan::ZFan(0);
23 }
24 
25 void bbfan_destroy(blackbox* /*b*/, void *d)
26 {
27  if (d!=NULL)
28  {
29  gfan::ZFan* zf = (gfan::ZFan*) d;
30  delete zf;
31  }
32 }
33 
34 char* bbfan_String(blackbox* /*b*/, void *d)
35 {
36  if (d==NULL) return omStrDup("invalid object");
37  else
38  {
39  gfan::ZFan* zf = (gfan::ZFan*)d;
40  std::string s = zf->toString(2+4+8+128);
41  return omStrDup(s.c_str());
42 // =======
43 // std::stringstream s;
44 // std::string raysAndCones = zf->toStringJustRaysAndMaximalCones();
45 // s << raysAndCones;
46 // if (zf->getDimension() >= 0) // <=> zf is not empty
47 // {
48 // assert(zf->numberOfConesOfDimension(zf->getDimension()-zf->getLinealityDimension(),0,0));
49 // gfan::ZCone zc = zf->getCone(zf->getDimension()-zf->getLinealityDimension(),0,0,0);
50 // gfan::ZMatrix genLinSpace = zc.generatorsOfLinealitySpace();
51 // char* gens = toString(genLinSpace);
52 // s << std::endl << "GENERATORS_LINEALITY_SPACE:" << std::endl;
53 // s << gens;
54 // }
55 // std::string sstring = s.str();
56 // return omStrDup(sstring.c_str());
57 // >>>>>>> status updated 11.03.
58  }
59 }
60 
61 void* bbfan_Copy(blackbox* /*b*/, void *d)
62 {
63  gfan::ZFan* zf = (gfan::ZFan*)d;
64  gfan::ZFan* newZf = new gfan::ZFan(*zf);
65  return newZf;
66 }
67 
69 {
70  gfan::ZFan* newZf;
71  if (r==NULL)
72  {
73  if (l->Data()!=NULL)
74  {
75  gfan::ZFan* zd = (gfan::ZFan*) l->Data();
76  delete zd;
77  }
78  newZf = new gfan::ZFan(0);
79  }
80  else if (r->Typ()==l->Typ())
81  {
82  if (l->Data()!=NULL)
83  {
84  gfan::ZFan* zd = (gfan::ZFan*) l->Data();
85  delete zd;
86  }
87  newZf = (gfan::ZFan*) r->CopyD();
88  }
89  else if (r->Typ()==INT_CMD)
90  {
91  int ambientDim = (int) (long) r->Data();
92  if (ambientDim < 0)
93  {
94  Werror("expected an int >= 0, but got %d", ambientDim);
95  return TRUE;
96  }
97  if (l->Data()!=NULL)
98  {
99  gfan::ZFan* zd = (gfan::ZFan*) l->Data();
100  delete zd;
101  }
102  newZf = new gfan::ZFan(ambientDim);
103  }
104  else
105  {
106  Werror("assign Type(%d) = Type(%d) not implemented",l->Typ(),r->Typ());
107  return TRUE;
108  }
109 
110  if (l->rtyp==IDHDL)
111  {
112  IDDATA((idhdl)l->data) = (char*) newZf;
113  }
114  else
115  {
116  l->data = (void*) newZf;
117  }
118  return FALSE;
119 }
120 
121 /* returns 1 iff all rows consist of entries 1..n,
122  where n is the number of columns of the provided
123  bigintmat; 0 otherwise */
124 static gfan::IntMatrix permutationIntMatrix(const bigintmat* iv)
125 {
126  int cc = iv->cols();
127  int rr = iv->rows();
128  bigintmat* ivCopy = new bigintmat(rr, cc, coeffs_BIGINT);
129  number temp1 = n_Init(1,coeffs_BIGINT);
130  for (int r = 1; r <= rr; r++)
131  for (int c = 1; c <= cc; c++)
132  {
133  number temp2 = n_Sub(IMATELEM(*iv, r, c),temp1,coeffs_BIGINT);
134  ivCopy->set(r,c,temp2);
135  n_Delete(&temp2,coeffs_BIGINT);
136  }
137  n_Delete(&temp1,coeffs_BIGINT);
138  gfan::ZMatrix* zm = bigintmatToZMatrix(ivCopy);
139  gfan::IntMatrix im = gfan::IntMatrix(gfan::ZToIntMatrix(*zm));
140  delete zm;
141  return im;
142 }
144 {
145  int ambientDim = (int)(long)v->Data();
146  if (ambientDim < 0)
147  {
148  Werror("expected non-negative ambient dim but got %d", ambientDim);
149  return TRUE;
150  }
151  res->rtyp = fanID;
152  res->data = (void*)(new gfan::ZFan(ambientDim));
153  return FALSE;
154 }
155 
157 {
158  bigintmat* permutations = (bigintmat*)v->Data();
159  int ambientDim = permutations->cols();
160  gfan::IntMatrix im = permutationIntMatrix(permutations);
161  if (!gfan::Permutation::arePermutations(im))
162  {
163  Werror("provided bigintmat contains invalid permutations of {1, ..., %d}", ambientDim);
164  return TRUE;
165  }
166  gfan::SymmetryGroup sg = gfan::SymmetryGroup(ambientDim);
167  sg.computeClosure(im);
168  res->rtyp = fanID;
169  res->data = (void*)(new gfan::ZFan(sg));
170  return FALSE;
171 }
172 
174 {
175  leftv u = args;
176  if (u == NULL)
177  {
178  res->rtyp = fanID;
179  res->data = (void*) new gfan::ZFan(0);
180  return FALSE;
181  }
182  if ((u != NULL) && (u->Typ() == INT_CMD))
183  {
184  if (u->next == NULL) return jjFANEMPTY_I(res, u);
185  }
186  if ((u != NULL) && (u->Typ() == BIGINTMAT_CMD))
187  {
188  if (u->next == NULL) return jjFANEMPTY_IM(res, u);
189  }
190  WerrorS("emptyFan: unexpected parameters");
191  return TRUE;
192 }
193 
195 {
196  int ambientDim = (int)(long)v->Data();
197  if (ambientDim < 0)
198  {
199  Werror("expected non-negative ambient dim but got %d", ambientDim);
200  return TRUE;
201  }
202  gfan::ZFan* zf = new gfan::ZFan(gfan::ZFan::fullFan(ambientDim));
203  res->rtyp = fanID;
204  res->data = (void*) zf;
205  return FALSE;
206 }
208 {
209  bigintmat* permutations = (bigintmat*)v->Data();
210  int ambientDim = permutations->cols();
211  gfan::IntMatrix im = permutationIntMatrix(permutations);
212  if (!gfan::Permutation::arePermutations(im))
213  {
214  Werror("provided bigintmat contains invalid permutations of {1, ..., %d}", ambientDim);
215  return TRUE;
216  }
217  gfan::SymmetryGroup sg = gfan::SymmetryGroup(ambientDim);
218  sg.computeClosure(im);
219  gfan::ZFan* zf = new gfan::ZFan(gfan::ZFan::fullFan(sg));
220  res->rtyp = fanID;
221  res->data = (void*) zf;
222  return FALSE;
223 }
224 
226 {
227  leftv u = args;
228  if (u == NULL)
229  {
230  res->rtyp = fanID;
231  res->data = (void*) new gfan::ZFan(0);
232  return FALSE;
233  }
234  if ((u != NULL) && (u->Typ() == INT_CMD))
235  if (u->next == NULL) return jjFANFULL_I(res, u);
236  if ((u != NULL) && (u->Typ() == BIGINTMAT_CMD))
237  if (u->next == NULL) return jjFANFULL_IM(res, u);
238  WerrorS("fullFan: unexpected parameters");
239  return TRUE;
240 }
241 
242 int getAmbientDimension(gfan::ZFan* zf)
243 {
244  return zf->getAmbientDimension();
245 }
246 
247 int getCodimension(gfan::ZFan* zf)
248 {
249  return zf->getCodimension();
250 }
251 
252 int getDimension(gfan::ZFan* zf)
253 {
254  return zf->getDimension();
255 }
256 
257 int getLinealityDimension(gfan::ZFan* zf)
258 {
259  return zf->getLinealityDimension();
260 }
261 
263 {
264  leftv u=args;
265  if ((u != NULL) && (u->Typ() == fanID))
266  {
267  leftv v=u->next;
268  if ((v != NULL) && (v->Typ() == INT_CMD))
269  {
270  leftv w=v->next;
271  if ((w != NULL) && (w->Typ() == INT_CMD))
272  {
273  leftv x=w->next;
274  if ((x != NULL) && (x->Typ() == INT_CMD))
275  {
276  gfan::ZFan* zf = (gfan::ZFan*) u->Data();
277  int d = (int)(long)v->Data();
278  int o = (int)(long)w->Data();
279  int m = (int)(long)x->Data();
280  if ( (0<=d) && (d <= zf->getAmbientDimension())
281  && ((o == 0) || (o == 1))
282  && ((m == 0) || (m == 1)))
283  {
284  bool oo = (bool) o;
285  bool mm = (bool) m;
286  int ld = zf->getLinealityDimension();
287  if (d-ld>=0)
288  {
289  int n = zf->numberOfConesOfDimension(d-ld,oo,mm);
290  res->rtyp = INT_CMD;
291  res->data = (void*) (long) n;
292  return FALSE;
293  }
294  res->rtyp = INT_CMD;
295  res->data = (void*) (long) 0;
296  return FALSE;
297  }
298  }
299  }
300  }
301  }
302  WerrorS("numberOfConesOfDimension: unexpected parameters");
303  return TRUE;
304 }
305 
307 {
308  leftv u=args;
309  if ((u != NULL) && (u->Typ() == fanID))
310  {
311  gfan::ZFan* zf = (gfan::ZFan*)u->Data();
312  int d = zf->getAmbientDimension();
313  int n = 0;
314 
315  for (int i=0; i<=d; i++)
316  n = n + zf->numberOfConesOfDimension(i,0,0);
317 
318  res->rtyp = INT_CMD;
319  res->data = (void*) (long) n;
320  return FALSE;
321  }
322  WerrorS("ncones: unexpected parameters");
323  return TRUE;
324 }
325 
327 {
328  leftv u=args;
329  if ((u != NULL) && (u->Typ() == fanID))
330  {
331  gfan::ZFan* zf = (gfan::ZFan*)u->Data();
332 
333  int n = 0;
334  for (int d=0; d<=zf->getAmbientDimension(); d++)
335  n = n + zf->numberOfConesOfDimension(d,0,1);
336 
337  res->rtyp = INT_CMD;
338  res->data = (void*) (long) n;
339  return FALSE;
340  }
341  WerrorS("nmaxcones: unexpected parameters");
342  return TRUE;
343 }
344 
345 bool isCompatible(const gfan::ZFan* zf, const gfan::ZCone* zc)
346 {
347  bool b = (zf->getAmbientDimension() == zc->ambientDimension());
348  if(b)
349  {
350  for (int d=0; d<=zf->getAmbientDimension(); d++)
351  {
352  for (int i=0; i<zf->numberOfConesOfDimension(d,0,1); i++)
353  {
354  gfan::ZCone zd = zf->getCone(d,i,0,1);
355  gfan::ZCone zt = gfan::intersection(*zc,zd);
356  zt.canonicalize();
357  b = b && zd.hasFace(zt);
358  }
359  }
360  }
361  return b;
362 }
363 
365 {
366  leftv u=args;
367  if ((u != NULL) && (u->Typ() == fanID))
368  {
369  leftv v=u->next;
370  if ((v != NULL) && (v->Typ() == coneID))
371  {
372  gfan::ZFan* zf = (gfan::ZFan*)u->Data();
373  gfan::ZCone* zc = (gfan::ZCone*)v->Data();
374  int b = isCompatible(zf,zc);
375  res->rtyp = INT_CMD;
376  res->data = (void*) (long) b;
377  return FALSE;
378  }
379  }
380  WerrorS("isCompatible: unexpected parameters");
381  return TRUE;
382 }
383 
385 {
386  leftv u=args;
387  if ((u != NULL) && (u->rtyp==IDHDL) && (u->e==NULL) && (u->Typ() == fanID))
388  {
389  leftv v=u->next;
390  if ((v != NULL) && (v->Typ() == coneID))
391  {
392  gfan::ZFan* zf = (gfan::ZFan*)u->Data();
393  gfan::ZCone* zc = (gfan::ZCone*)v->Data();
394  zc->canonicalize();
395 
396  leftv w=v->next;
397  int n;
398  if ((w != NULL) && (w->Typ() == INT_CMD))
399  n = (int)(long) w;
400 
401  if (n != 0)
402  {
403  if (!isCompatible(zf,zc))
404  {
405  WerrorS("insertCone: cone and fan not compatible");
406  return TRUE;
407  }
408  }
409 
410  zf->insert(*zc);
411  res->rtyp = NONE;
412  res->data = NULL;
413  IDDATA((idhdl)u->data) = (char*) zf;
414  return FALSE;
415  }
416  }
417  WerrorS("insertCone: unexpected parameters");
418  return TRUE;
419 }
420 
421 bool containsInCollection(gfan::ZFan* zf, gfan::ZCone* zc)
422 {
423  gfan::ZVector zv=zc->getRelativeInteriorPoint();
424  for (int d=0; d<=zf->getAmbientDimension(); d++)
425  {
426  for (int i=0; i<zf->numberOfConesOfDimension(d,0,1); i++)
427  {
428  gfan::ZCone zd = zf->getCone(d,i,0,1);
429  zd.canonicalize();
430  if (zd.containsRelatively(zv))
431  {
432  gfan::ZCone temp = *zc;
433  temp.canonicalize();
434  return (!(zd != temp));
435  }
436  }
437  }
438  return 0;
439 }
440 
442 {
443  leftv u=args;
444  if ((u != NULL) && (u->Typ() == fanID))
445  {
446  leftv v=u->next;
447  if ((v != NULL) && (v->Typ() == coneID))
448  {
449  gfan::ZFan* zf = (gfan::ZFan*)u->Data();
450  gfan::ZCone* zc = (gfan::ZCone*)v->Data();
451  if((zf->getAmbientDimension() == zc->ambientDimension()))
452  {
453  res->rtyp = INT_CMD;
454  res->data = (void*) (long) (int) containsInCollection(zf,zc);
455  return FALSE;
456  }
457  WerrorS("containsInCollection: mismatching ambient dimensions");
458  return TRUE;
459  }
460  }
461  WerrorS("containsInCollection: unexpected parameters");
462  return TRUE;
463 }
464 
465 // BOOLEAN coneContaining(leftv res, leftv args)
466 // {
467 // leftv u=args;
468 // if ((u != NULL) && (u->Typ() == fanID))
469 // {
470 // leftv v=u->next;
471 // if ((v != NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTVEC_CMD)))
472 // {
473 // gfan::ZFan* zf = (gfan::ZFan*)u->Data();
474 // gfan::ZVector* point;
475 // if (v->Typ() == INTVEC_CMD)
476 // {
477 // intvec* w0 = (intvec*) v->Data();
478 // bigintmat* w1 = iv2bim(w0,coeffs_BIGINT);
479 // w1->inpTranspose();
480 // point = bigintmatToZVector(*w1);
481 // delete w1;
482 // }
483 // else
484 // {
485 // bigintmat* w1 = (bigintmat*) v->Data();
486 // point = bigintmatToZVector(*w1);
487 // }
488 // lists L = (lists)omAllocBin(slists_bin);
489 // res->rtyp = LIST_CMD;
490 // res->data = (void*) L;
491 // delete point;
492 // return FALSE;
493 // }
494 // }
495 // WerrorS("coneContaining: unexpected parameters");
496 // return TRUE;
497 // }
498 
500 {
501  leftv u=args;
502  if ((u != NULL) && (u->Typ() == fanID))
503  {
504  leftv v=u->next;
505  if ((v != NULL) && (v->Typ() == coneID))
506  {
507  gfan::ZFan* zf = (gfan::ZFan*)u->Data();
508  gfan::ZCone* zc = (gfan::ZCone*)v->Data();
509  zc->canonicalize();
510 
511  leftv w=v->next; int n = 1;
512  if ((w != NULL) && (w->Typ() == INT_CMD))
513  n = (int)(long) w;
514 
515  if (n != 0)
516  {
517  if (!containsInCollection(zf,zc))
518  {
519  WerrorS("removeCone: cone not contained in fan");
520  return TRUE;
521  }
522  }
523 
524  zf->remove(*zc);
525  res->rtyp = NONE;
526  res->data = NULL;
527  IDDATA((idhdl)u->data) = (char*) zf;
528  return FALSE;
529  }
530  }
531  WerrorS("removeCone: unexpected parameters");
532  return TRUE;
533 }
534 
536 {
537  leftv u=args;
538  if ((u != NULL) && (u->Typ() == fanID))
539  {
540  leftv v=u->next;
541  if ((v != NULL) && (v->Typ() == INT_CMD))
542  {
543  leftv w=v->next;
544  if ((w != NULL) && (w->Typ() == INT_CMD))
545  {
546  gfan::ZFan* zf = (gfan::ZFan*) u->Data();
547  int d = (int)(long)v->Data();
548  int i = (int)(long)w->Data();
549  int o = -1;
550  int m = -1;
551  leftv x=w->next;
552  if ((x != NULL) && (x->Typ() == INT_CMD))
553  {
554  o = (int)(long)x->Data();
555  leftv y=x->next;
556  if ((y != NULL) && (y->Typ() == INT_CMD))
557  {
558  m = (int)(long)y->Data();
559  }
560  }
561  if (o == -1) o = 0;
562  if (m == -1) m = 0;
563  if (((o == 0) || (o == 1)) && ((m == 0) || (m == 1)))
564  {
565  bool oo = (bool) o;
566  bool mm = (bool) m;
567  if (0<=d && d<=zf->getAmbientDimension())
568  {
569  int ld = zf->getLinealityDimension();
570  if (0<i && i<=zf->numberOfConesOfDimension(d-ld,oo,mm))
571  {
572  i=i-1;
573  if (d-ld>=0)
574  {
575  gfan::ZCone zc = zf->getCone(d-ld,i,oo,mm);
576  res->rtyp = coneID;
577  res->data = (void*)new gfan::ZCone(zc);
578  return FALSE;
579  }
580  else
581  {
582  WerrorS("getCone: invalid dimension; no cones in this dimension");
583  return TRUE;
584  }
585  }
586  else
587  {
588  WerrorS("getCone: invalid index");
589  return TRUE;
590  }
591  }
592  else
593  {
594  WerrorS("getCone: invalid dimension");
595  return TRUE;
596  }
597  }
598  else
599  {
600  WerrorS("getCone: invalid specifier for orbit or maximal");
601  return TRUE;
602  }
603  }
604  }
605  }
606  WerrorS("getCone: unexpected parameters");
607  return TRUE;
608 }
609 
611 {
612  leftv u=args;
613  if ((u != NULL) && (u->Typ() == fanID))
614  {
615  leftv v=u->next;
616  if ((v != NULL) && (v->Typ() == INT_CMD))
617  {
618  gfan::ZFan* zf = (gfan::ZFan*) u->Data();
619  int d = (int)(long)v->Data();
620  int o = -1;
621  int m = -1;
622  leftv w=v->next;
623  if ((w != NULL) && (w->Typ() == INT_CMD))
624  {
625  o = (int)(long)w->Data();
626  leftv x=w->next;
627  if ((x != NULL) && (x->Typ() == INT_CMD))
628  {
629  m = (int)(long)x->Data();
630  }
631  }
632  if (o == -1) o = 0;
633  if (m == -1) m = 0;
634  if (((o == 0) || (o == 1)) && ((m == 0) || (m == 1)))
635  {
636  bool oo = (bool) o;
637  bool mm = (bool) m;
638  if (0<=d && d<=zf->getAmbientDimension())
639  {
640  int ld = zf->getLinealityDimension();
641  if (d-ld>=0)
642  {
644  int n = zf->numberOfConesOfDimension(d-ld,oo,mm);
645  L->Init(n);
646  for (int i=0; i<n; i++)
647  {
648  gfan::ZCone zc = zf->getCone(d-ld,i,oo,mm);
649  L->m[i].rtyp = coneID; L->m[i].data=(void*) new gfan::ZCone(zc);
650  }
651  res->rtyp = LIST_CMD;
652  res->data = (void*) L;
653  return FALSE;
654  }
655  else
656  {
657  WerrorS("getCones: invalid dimension; no cones in this dimension");
658  return TRUE;
659  }
660  }
661  else
662  {
663  WerrorS("getCones: invalid dimension");
664  return TRUE;
665  }
666  }
667  else
668  {
669  WerrorS("getCones: invalid specifier for orbit or maximal");
670  return TRUE;
671  }
672  }
673  }
674  WerrorS("getCones: unexpected parameters");
675  return TRUE;
676 }
677 
678 int isSimplicial(gfan::ZFan* zf)
679 {
680  int i = zf->isSimplicial() ? 1 : 0;
681  return i;
682 }
683 
685 {
686  leftv u=args;
687  if ((u != NULL) && (u->Typ() == fanID))
688  {
689  gfan::ZFan* zf = (gfan::ZFan*) u->Data();
690  int b = zf->isPure();
691  res->rtyp = INT_CMD;
692  res->data = (void*) (long) b;
693  return FALSE;
694  }
695  WerrorS("isPure: unexpected parameters");
696  return TRUE;
697 }
698 
699 // BOOLEAN isComplete(leftv res, leftv args)
700 // {
701 // leftv u=args;
702 // if ((u != NULL) && (u->Typ() == fanID))
703 // {
704 // gfan::ZFan* zf = (gfan::ZFan*) u->Data();
705 // int b = zf->isComplete();
706 // res->rtyp = INT_CMD;
707 // res->data = (void*) (long) b;
708 // return FALSE;
709 // }
710 // WerrorS("isComplete: unexpected parameters");
711 // return TRUE;
712 // }
713 
715 {
716  leftv u=args;
717  if ((u != NULL) && (u->Typ() == fanID))
718  {
719  gfan::ZFan* zf = (gfan::ZFan*) u->Data();
720  gfan::ZVector zv=zf->getFVector();
721  res->rtyp = BIGINTMAT_CMD;
722  res->data = (void*) zVectorToBigintmat(zv);
723  return FALSE;
724  }
725  WerrorS("fVector: unexpected parameters");
726  return TRUE;
727 }
728 
729 gfan::ZMatrix rays(const gfan::ZFan* const zf)
730 {
731  gfan::ZMatrix rays(0,zf->getAmbientDimension());
732  for (int i=0; i<zf->numberOfConesOfDimension(1,0,0); i++)
733  {
734  gfan::ZCone zc = zf->getCone(1, i, 0, 0);
735  rays.append(zc.extremeRays());
736  }
737  return rays;
738 }
739 
740 int numberOfConesWithVector(gfan::ZFan* zf, gfan::ZVector* v)
741 {
742  int count = 0;
743  int ambientDim = zf->getAmbientDimension();
744  for (int i=0; i<zf->numberOfConesOfDimension(ambientDim, 0, 0); i++)
745  {
746  gfan::ZCone zc = zf->getCone(ambientDim, i, 0, 0);
747  if (zc.contains(*v))
748  {
749  count = count +1;
750  if (count > 1)
751  return count;
752  }
753  }
754  return count;
755 }
756 
758 {
759  leftv u=args;
760  if ((u != NULL) && (u->Typ() == fanID))
761  {
762  leftv v=u->next;
763  if ((v != NULL) && (v->Typ() == BIGINTMAT_CMD))
764  {
765  gfan::ZFan* zf = (gfan::ZFan*) u->Data();
766  bigintmat* v0 = (bigintmat*) v->Data();
767  int ambientDim = zf->getAmbientDimension();
768  if (ambientDim != v0->cols())
769  {
770  WerrorS("numberOfConesWithVector: mismatching dimensions");
771  return TRUE;
772  }
773  gfan::ZVector* v1 = bigintmatToZVector(*v0);
774  int count = numberOfConesWithVector(zf, v1);
775  delete v1;
776  res->rtyp = INT_CMD;
777  res->data = (void*) (long) count;
778  return FALSE;
779  }
780  }
781  WerrorS("numberOfConesWithVector: unexpected parameters");
782  return TRUE;
783 }
784 
786 {
787  leftv u=args;
788  if ((u != NULL) && (u->Typ() == STRING_CMD))
789  {
790  std::string fanInString = (char*) u->Data();
791  std::istringstream s(fanInString);
792  gfan::ZFan* zf = new gfan::ZFan(s);
793  res->rtyp = fanID;
794  res->data = (void*) zf;
795  return FALSE;
796  }
797  WerrorS("fanFromString: unexpected parameters");
798  return TRUE;
799 }
800 
802 {
803  leftv u=args;
804  if ((u != NULL) && (u->Typ() == LIST_CMD))
805  {
806  lists L = (lists) u->Data();
807  if (lSize(L)>-1)
808  {
809  if (L->m[0].Typ() != coneID)
810  {
811  WerrorS("fanViaCones: list contains entries of wrong type");
812  return TRUE;
813  }
814  gfan::ZCone* zc = (gfan::ZCone*) L->m[0].Data();
815  gfan::ZFan* zf = new gfan::ZFan(zc->ambientDimension());
816  zf->insert(*zc);
817  for (int i=1; i<=lSize(L); i++)
818  {
819  if (L->m[i].Typ() != coneID)
820  {
821  WerrorS("fanViaCones: entries of wrong type in list");
822  return TRUE;
823  }
824  gfan::ZCone* zc = (gfan::ZCone*) L->m[i].Data();
825  if (zc->ambientDimension() != zf->getAmbientDimension())
826  {
827  WerrorS("fanViaCones: inconsistent ambient dimensions amongst cones in list");
828  return TRUE;
829  }
830  zf->insert(*zc);
831  }
832  res->rtyp = fanID;
833  res->data = (void*) zf;
834  return FALSE;
835  }
836  res->rtyp = fanID;
837  res->data = (void*) new gfan::ZFan(0);
838  return FALSE;
839  }
840  if ((u != NULL) && (u->Typ() == coneID))
841  {
842  gfan::ZCone* zc = (gfan::ZCone*) u->Data();
843  gfan::ZFan* zf = new gfan::ZFan(zc->ambientDimension());
844  zf->insert(*zc);
845  while (u->next != NULL)
846  {
847  u = u->next;
848  if (u->Typ() != coneID)
849  {
850  WerrorS("fanViaCones: arguments of wrong type");
851  return TRUE;
852  }
853  gfan::ZCone* zc = (gfan::ZCone*) u->Data();
854  if (zc->ambientDimension() != zf->getAmbientDimension())
855  {
856  WerrorS("fanViaCones: inconsistent ambient dimensions amongst input cones");
857  return TRUE;
858  }
859  zf->insert(*zc);
860  }
861  res->rtyp = fanID;
862  res->data = (void*) zf;
863  return FALSE;
864  }
865  if (u == NULL)
866  {
867  res->rtyp = fanID;
868  res->data = (void*) new gfan::ZFan(0);
869  return FALSE;
870  }
871  WerrorS("fanViaCones: unexpected parameters");
872  return TRUE;
873 }
874 
875 
876 // BOOLEAN tropicalVariety(leftv res, leftv args)
877 // {
878 // leftv u=args;
879 // if ((u != NULL) && (u->Typ() == POLY_CMD))
880 // {
881 // int n = rVar(currRing);
882 // gfan::ZFan* zf = new gfan::ZFan(n);
883 // int* expv1 = (int*)omAlloc((n+1)*sizeof(int));
884 // int* expv2 = (int*)omAlloc((n+1)*sizeof(int));
885 // int* expvr = (int*)omAlloc((n+1)*sizeof(int));
886 // gfan::ZVector expw1 = gfan::ZVector(n);
887 // gfan::ZVector expw2 = gfan::ZVector(n);
888 // gfan::ZVector expwr = gfan::ZVector(n);
889 // gfan::ZMatrix eq, ineq;
890 // for (poly s1=(poly)u->Data(); s1!=NULL; pIter(s1))
891 // {
892 // pGetExpV(s1,expv1);
893 // expw1 = intStar2ZVector(n,expv1);
894 // for (poly s2=pNext(s1); s2!=NULL; pIter(s2))
895 // {
896 // pGetExpV(s2,expv2);
897 // expw2 = intStar2ZVector(n,expv2);
898 // eq = gfan::ZMatrix(0,n);
899 // eq.appendRow(expw1-expw2);
900 // ineq = gfan::ZMatrix(0,n);
901 // for (poly r=(poly)u->Data(); r!=NULL; pIter(r))
902 // {
903 // pGetExpV(r,expvr);
904 // expwr = intStar2ZVector(n,expvr);
905 // if ((r!=s1) && (r!=s2))
906 // {
907 // ineq.appendRow(expw1-expwr);
908 // }
909 // }
910 // gfan::ZCone zc = gfan::ZCone(ineq,eq);
911 // zf->insert(zc);
912 // }
913 // }
914 // omFreeSize(expv1,(n+1)*sizeof(int));
915 // omFreeSize(expv2,(n+1)*sizeof(int));
916 // omFreeSize(expvr,(n+1)*sizeof(int));
917 // res->rtyp = fanID;
918 // res->data = (void*) zf;
919 // return FALSE;
920 // }
921 // WerrorS("tropicalVariety: unexpected parameters");
922 // return TRUE;
923 // }
924 
925 gfan::ZFan commonRefinement(gfan::ZFan zf, gfan::ZFan zg)
926 {
927  assume(zf.getAmbientDimension() == zg.getAmbientDimension());
928 
929  // gather all maximal cones of f and g
930  std::list<gfan::ZCone> maximalConesOfF;
931  for (int d=0; d<=zf.getAmbientDimension(); d++)
932  for (int i=0; i<zf.numberOfConesOfDimension(d,0,1); i++)
933  maximalConesOfF.push_back(zf.getCone(d,i,0,1));
934 
935  std::list<gfan::ZCone> maximalConesOfG;
936  for (int d=0; d<=zg.getAmbientDimension(); d++)
937  for (int i=0; i<zg.numberOfConesOfDimension(d,0,1); i++)
938  maximalConesOfG.push_back(zg.getCone(d,i,0,1));
939 
940  // construct a new fan out of their intersections
941  gfan::ZFan zr = gfan::ZFan(zf.getAmbientDimension());
942  for (std::list<gfan::ZCone>::iterator itf=maximalConesOfF.begin();
943  itf != maximalConesOfF.end(); itf++)
944  for (std::list<gfan::ZCone>::iterator itg=maximalConesOfG.begin();
945  itg != maximalConesOfG.end(); itg++)
946  zr.insert(intersection(*itf,*itg));
947 
948  return zr;
949 }
950 
952 {
953  leftv u=args;
954  if ((u != NULL) && (u->Typ() == fanID))
955  {
956  leftv v=u->next;
957  if ((v != NULL) && (v->Typ() == fanID))
958  {
959  gfan::ZFan* zf = (gfan::ZFan*) u->Data();
960  gfan::ZFan* zg = (gfan::ZFan*) v->Data();
961  gfan::ZFan* zr = new gfan::ZFan(commonRefinement(*zf,*zg));
962  res->rtyp = fanID;
963  res->data = (void*) zr;
964  return FALSE;
965  }
966  }
967  WerrorS("commonRefinement: unexpected parameters");
968  return TRUE;
969 }
970 
971 // BOOLEAN grFan(leftv res, leftv h)
972 // {
973 // /*======== GFAN ==============*/
974 // /*
975 // WILL HAVE TO CHANGE RETURN TYPE TO LIST_CMD
976 // */
977 // /*
978 // heuristic:
979 // 0 = keep all Groebner bases in memory
980 // 1 = write all Groebner bases to disk and read whenever necessary
981 // 2 = use a mixed heuristic, based on length of Groebner bases
982 // */
983 // if( h!=NULL && h->Typ()==IDEAL_CMD && h->next!=NULL && h->next->Typ()==INT_CMD)
984 // {
985 // int heuristic;
986 // heuristic=(int)(long)h->next->Data();
987 // ideal I=((ideal)h->Data());
988 // #ifndef USE_ZFAN
989 // #define USE_ZFAN
990 // #endif
991 // #ifndef USE_ZFAN
992 // res->rtyp=LIST_CMD; //res->rtyp=coneID; res->data(void*)zcone;
993 // res->data=(lists) grfan(I,heuristic,FALSE);
994 // #else
995 // res->rtyp=fanID;
996 // res->data=(void*)(grfan(I,heuristic,FALSE));
997 // #endif
998 // return FALSE;
999 // }
1000 // else
1001 // {
1002 // WerrorS("Usage: grfan(<ideal>,<int>)");
1003 // return TRUE;
1004 // }
1005 // }
1006  //Possibility to have only one Groebner cone computed by specifying a weight vector FROM THE RELATIVE INTERIOR!
1007  //Needs wp as ordering!
1008 // if(strcmp(sys_cmd,"grcone")==0)
1009 // {
1010 // if(h!=NULL && h->Typ()==IDEAL_CMD && h->next!=NULL && h->next->Typ()==INT_CMD)
1011 // {
1012 // ideal I=((ideal)h->Data());
1013 // res->rtyp=LIST_CMD;
1014 // res->data=(lists)grcone_by_intvec(I);
1015 // }
1016 // }
1017 
1018 
1020 {
1021  blackbox *b=(blackbox*)omAlloc0(sizeof(blackbox));
1022  // all undefined entries will be set to default in setBlackboxStuff
1023  // the default Print is quite usefule,
1024  // all other are simply error messages
1025  b->blackbox_destroy=bbfan_destroy;
1026  b->blackbox_String=bbfan_String;
1027  //b->blackbox_Print=blackbox_default_Print;
1028  b->blackbox_Init=bbfan_Init;
1029  b->blackbox_Copy=bbfan_Copy;
1030  b->blackbox_Assign=bbfan_Assign;
1031  p->iiAddCproc("","emptyFan",FALSE,emptyFan);
1032  p->iiAddCproc("","fullFan",FALSE,fullFan);
1033  /* the following functions are implemented in bbcone.cc */
1034  // iiAddCproc("","containsInSupport",FALSE,containsInSupport);
1035  // iiAddCproc("","getAmbientDimension",FALSE,getAmbientDimension);
1036  // iiAddCproc("","getCodimension",FALSE,getDimension);
1037  // iiAddCproc("","getDimension",FALSE,getDimension);
1038  // iiAddCproc("","getLinealityDimension",FALSE,getLinealityDimension);
1039  // iiAddCproc("","isSimplicial",FALSE,isSimplicial);
1040  /********************************************************/
1041  p->iiAddCproc("","isCompatible",FALSE,isCompatible);
1042  p->iiAddCproc("","numberOfConesOfDimension",FALSE,numberOfConesOfDimension);
1043  p->iiAddCproc("","ncones",FALSE,ncones);
1044  p->iiAddCproc("","nmaxcones",FALSE,nmaxcones);
1045  p->iiAddCproc("","insertCone",FALSE,insertCone);
1046  p->iiAddCproc("","removeCone",FALSE,removeCone);
1047  p->iiAddCproc("","getCone",FALSE,getCone);
1048  p->iiAddCproc("","getCones",FALSE,getCones);
1049  p->iiAddCproc("","isPure",FALSE,isPure);
1050  p->iiAddCproc("","fanFromString",FALSE,fanFromString);
1051  p->iiAddCproc("","fanViaCones",FALSE,fanViaCones);
1052  p->iiAddCproc("","numberOfConesWithVector",FALSE,numberOfConesWithVector);
1053  // iiAddCproc("","isComplete",FALSE,isComplete); not working as expected, should leave this to polymake
1054  p->iiAddCproc("","fVector",FALSE,fVector);
1055  p->iiAddCproc("","containsInCollection",FALSE,containsInCollection);
1056  // p->iiAddCproc("","tropicalVariety",FALSE,tropicalVariety);
1057  p->iiAddCproc("","commonRefinement",FALSE,commonRefinement);
1058  // iiAddCproc("","grFan",FALSE,grFan);
1059  fanID=setBlackboxStuff(b,"fan");
1060  //Print("created type %d (fan)\n",fanID);
1061 }
1062 
1063 #endif
1064 // gfan::ZFan commonRefinementCompleteFans(const gfan::ZFan &zf, const gfan::ZFan &zg)
1065 // {
1066 // assume(zf->getAmbientDimension() == zg->getAmbientDimension());
1067 
1068 // gfan::ZFan zfg = gfan::ZFan(zf->getAmbientDimension());
1069 // int d = zf->getAmbientDimension();
1070 // for (int i=0; i<zf->numberOfConesOfDimension(d,0,1); i++)
1071 // for (int j=0; j<zg->numberOfConesOfDimension(d,0,1); j++)
1072 // {
1073 // gfan::ZCone zc = intersection(zf->getCone(d,i,0,1),zg->getCone(d,j,0,1));
1074 // if (zc.dimension()==d) zgf.insert(zc);
1075 // }
1076 
1077 // return zfg;
1078 // }
int status int void size_t count
Definition: si_signals.h:59
static FORCE_INLINE number n_Sub(number a, number b, const coeffs r)
return the difference of &#39;a&#39; and &#39;b&#39;, i.e., a-b
Definition: coeffs.h:668
char * bbfan_String(blackbox *, void *d)
Definition: bbfan.cc:34
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
const CanonicalForm int s
Definition: facAbsFact.cc:55
sleftv * m
Definition: lists.h:45
const CanonicalForm int const CFList const Variable & y
Definition: facAbsFact.cc:57
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
Definition: tok.h:85
Subexpr e
Definition: subexpr.h:106
Definition: lists.h:22
#define FALSE
Definition: auxiliary.h:140
BOOLEAN numberOfConesOfDimension(leftv res, leftv args)
Definition: bbfan.cc:262
return P p
Definition: myNF.cc:203
BOOLEAN nmaxcones(leftv res, leftv args)
Definition: bbfan.cc:326
Matrices of numbers.
Definition: bigintmat.h:51
bool isCompatible(const gfan::ZFan *zf, const gfan::ZCone *zc)
Definition: bbfan.cc:345
void * bbfan_Init(blackbox *)
Definition: bbfan.cc:20
BOOLEAN fullFan(leftv res, leftv args)
Definition: bbfan.cc:225
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
void bbfan_setup(SModulFunctions *p)
Definition: bbfan.cc:1019
#define string
Definition: libparse.cc:1250
intvec * ivCopy(const intvec *o)
Definition: intvec.h:141
#define TRUE
Definition: auxiliary.h:144
BOOLEAN bbfan_Assign(leftv l, leftv r)
Definition: bbfan.cc:68
BOOLEAN emptyFan(leftv res, leftv args)
Definition: bbfan.cc:173
void WerrorS(const char *s)
Definition: feFopen.cc:24
static BOOLEAN jjFANEMPTY_IM(leftv res, leftv v)
Definition: bbfan.cc:156
BOOLEAN fanViaCones(leftv res, leftv args)
Definition: bbfan.cc:801
bigintmat * zVectorToBigintmat(const gfan::ZVector &zv)
int fanID
Definition: bbfan.cc:18
coeffs coeffs_BIGINT
Definition: ipid.cc:54
int Typ()
Definition: subexpr.cc:969
Definition: idrec.h:34
int getAmbientDimension(gfan::ZFan *zf)
Definition: bbfan.cc:242
#define IDHDL
Definition: tok.h:35
void set(int i, int j, number n, const coeffs C=NULL)
replace an entry with a copy (delete old + copy new!). NOTE: starts at [1,1]
Definition: bigintmat.cc:93
void * bbfan_Copy(blackbox *, void *d)
Definition: bbfan.cc:61
void * data
Definition: subexpr.h:89
poly res
Definition: myNF.cc:322
const ring r
Definition: syzextra.cc:208
Coefficient rings, fields and other domains suitable for Singular polynomials.
int isSimplicial(gfan::ZFan *zf)
Definition: bbfan.cc:678
BOOLEAN getCone(leftv res, leftv args)
Definition: bbfan.cc:535
BOOLEAN fanFromString(leftv res, leftv args)
Definition: bbfan.cc:785
gfan::ZMatrix rays(const gfan::ZFan *const zf)
Definition: bbfan.cc:729
BOOLEAN ncones(leftv res, leftv args)
Definition: bbfan.cc:306
#define assume(x)
Definition: mod2.h:405
gfan::ZMatrix * bigintmatToZMatrix(const bigintmat &bim)
int numberOfConesWithVector(gfan::ZFan *zf, gfan::ZVector *v)
Definition: bbfan.cc:740
BOOLEAN insertCone(leftv res, leftv args)
Definition: bbfan.cc:384
BOOLEAN fVector(leftv res, leftv args)
Definition: bbfan.cc:714
static BOOLEAN jjFANEMPTY_I(leftv res, leftv v)
Definition: bbfan.cc:143
int m
Definition: cfEzgcd.cc:119
bool containsInCollection(gfan::ZFan *zf, gfan::ZCone *zc)
Definition: bbfan.cc:421
int coneID
Definition: bbcone.cc:24
int i
Definition: cfEzgcd.cc:123
int getCodimension(gfan::ZFan *zf)
Definition: bbfan.cc:247
int lSize(lists L)
Definition: lists.cc:25
int cols() const
Definition: bigintmat.h:147
leftv next
Definition: subexpr.h:87
BOOLEAN getCones(leftv res, leftv args)
Definition: bbfan.cc:610
INLINE_THIS void Init(int l=0)
Definition: lists.h:66
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
int rows() const
Definition: bigintmat.h:148
#define NULL
Definition: omList.c:10
slists * lists
Definition: mpr_numeric.h:146
BOOLEAN isPure(leftv res, leftv args)
Definition: bbfan.cc:684
static gfan::IntMatrix permutationIntMatrix(const bigintmat *iv)
Definition: bbfan.cc:124
const CanonicalForm & w
Definition: facAbsFact.cc:55
Variable x
Definition: cfModGcd.cc:4023
int rtyp
Definition: subexpr.h:92
gfan::ZFan commonRefinement(gfan::ZFan zf, gfan::ZFan zg)
Definition: bbfan.cc:925
void * Data()
Definition: subexpr.cc:1111
Definition: tok.h:96
int getLinealityDimension(gfan::ZFan *zf)
Definition: bbfan.cc:257
int getDimension(gfan::ZFan *zf)
Definition: bbfan.cc:252
omBin slists_bin
Definition: lists.cc:23
BOOLEAN removeCone(leftv res, leftv args)
Definition: bbfan.cc:499
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete &#39;p&#39;
Definition: coeffs.h:456
int(* iiAddCproc)(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition: ipid.h:73
static BOOLEAN jjFANFULL_IM(leftv res, leftv v)
Definition: bbfan.cc:207
#define IDDATA(a)
Definition: ipid.h:125
int setBlackboxStuff(blackbox *bb, const char *n)
define a new type
Definition: blackbox.cc:128
int BOOLEAN
Definition: auxiliary.h:131
#define IMATELEM(M, I, J)
Definition: intvec.h:77
const poly b
Definition: syzextra.cc:213
#define NONE
Definition: tok.h:173
void bbfan_destroy(blackbox *, void *d)
Definition: bbfan.cc:25
static BOOLEAN jjFANFULL_I(leftv res, leftv v)
Definition: bbfan.cc:194
void Werror(const char *fmt,...)
Definition: reporter.cc:199
void * CopyD(int t)
Definition: subexpr.cc:676
gfan::ZVector * bigintmatToZVector(const bigintmat &bim)
#define omAlloc0(size)
Definition: omAllocDecl.h:211
int l
Definition: cfEzgcd.cc:94
#define omStrDup(s)
Definition: omAllocDecl.h:263