bbcone.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 "misc/sirandom.h"
7 
8 #include "coeffs/bigintmat.h"
9 #include "coeffs/longrat.h"
10 
11 #include "Singular/ipid.h"
12 #include "Singular/ipshell.h"
13 #include "Singular/blackbox.h"
14 
15 #include "Singular/links/ssiLink.h"
16 
17 #include "callgfanlib_conversion.h"
18 
19 #include "gfanlib/gfanlib.h"
20 #include "gfanlib/gfanlib_q.h"
21 
22 #include "bbfan.h"
23 #include "bbpolytope.h"
24 
25 int coneID;
26 
27 std::string toString(const gfan::ZCone* const c)
28 {
29  std::stringstream s;
30  s<<"AMBIENT_DIM"<<std::endl;
31  s<<c->ambientDimension()<<std::endl;
32 
33  gfan::ZMatrix i=c->getInequalities();
34  char* ineqs = toString(i);
35  if (c->areFacetsKnown())
36  s<<"FACETS"<<std::endl;
37  else
38  s<<"INEQUALITIES"<<std::endl;
39  if (ineqs!=NULL)
40  {
41  s<<ineqs<<std::endl;
42  omFree(ineqs);
43  }
44 
45  gfan::ZMatrix e=c->getEquations();
46  char* eqs = toString(e);
47  if (c->areImpliedEquationsKnown())
48  s<<"LINEAR_SPAN"<<std::endl;
49  else
50  s<<"EQUATIONS"<<std::endl;
51  if (eqs!=NULL)
52  {
53  s<<eqs<<std::endl;
54  omFree(eqs);
55  }
56 
57  if (c->areExtremeRaysKnown())
58  {
59  gfan::ZMatrix r=c->extremeRays();
60  char* rs = toString(r);
61  s<<"RAYS"<<std::endl;
62  if (rs!=NULL)
63  {
64  s<<rs<<std::endl;
65  omFree(rs);
66  }
67  gfan::ZMatrix l=c->generatorsOfLinealitySpace();
68  char* ls = toString(l);
69  s<<"LINEALITY_SPACE"<<std::endl;
70  if (ls!=NULL)
71  {
72  s<<ls<<std::endl;
73  omFree(ls);
74  }
75  }
76 
77  return s.str();
78 }
79 
80 void* bbcone_Init(blackbox* /*b*/)
81 {
82  return (void*)(new gfan::ZCone());
83 }
84 
86 {
87  gfan::ZCone* newZc;
88  if (r==NULL)
89  {
90  if (l->Data()!=NULL)
91  {
92  gfan::ZCone* zd = (gfan::ZCone*)l->Data();
93  delete zd;
94  }
95  newZc = new gfan::ZCone();
96  }
97  else if (r->Typ()==l->Typ())
98  {
99  if (l->Data()!=NULL)
100  {
101  gfan::ZCone* zd = (gfan::ZCone*)l->Data();
102  delete zd;
103  }
104  newZc = (gfan::ZCone*)r->CopyD();
105  }
106  else if (r->Typ()==INT_CMD)
107  {
108  int ambientDim = (int)(long)r->Data();
109  if (ambientDim < 0)
110  {
111  Werror("expected an int >= 0, but got %d", ambientDim);
112  return TRUE;
113  }
114  if (l->Data()!=NULL)
115  {
116  gfan::ZCone* zd = (gfan::ZCone*)l->Data();
117  delete zd;
118  }
119  newZc = new gfan::ZCone(ambientDim);
120  }
121  else
122  {
123  Werror("assign Type(%d) = Type(%d) not implemented",l->Typ(),r->Typ());
124  return TRUE;
125  }
126 
127  if (l->rtyp==IDHDL)
128  {
129  IDDATA((idhdl)l->data)=(char*) newZc;
130  }
131  else
132  {
133  l->data=(void *)newZc;
134  }
135  return FALSE;
136 }
137 
138 char* bbcone_String(blackbox* /*b*/, void *d)
139 {
140  if (d==NULL) return omStrDup("invalid object");
141  else
142  {
143  std::string s=toString((gfan::ZCone*) d);
144  return omStrDup(s.c_str());
145  }
146 }
147 
148 void bbcone_destroy(blackbox* /*b*/, void *d)
149 {
150  if (d!=NULL)
151  {
152  gfan::ZCone* zc = (gfan::ZCone*) d;
153  delete zc;
154  }
155 }
156 
157 void* bbcone_Copy(blackbox* /*b*/, void *d)
158 {
159  gfan::ZCone* zc = (gfan::ZCone*)d;
160  gfan::ZCone* newZc = new gfan::ZCone(*zc);
161  return newZc;
162 }
163 
164 static BOOLEAN bbcone_Op2(int op, leftv res, leftv i1, leftv i2)
165 {
166  gfan::ZCone* zp = (gfan::ZCone*) i1->Data();
167  switch(op)
168  {
169  case '&':
170  {
171  if (i2->Typ()==coneID)
172  {
173  gfan::ZCone* zq = (gfan::ZCone*) i2->Data();
174  int d1 = zp->ambientDimension();
175  int d2 = zq->ambientDimension();
176  if (d1 != d2)
177  {
178  WerrorS("mismatching ambient dimensions");
179  return TRUE;
180  }
181  gfan::ZCone* zs = new gfan::ZCone();
182  *zs = gfan::intersection(*zp, *zq);
183  zs->canonicalize();
184  res->rtyp = coneID;
185  res->data = (void*) zs;
186  return FALSE;
187  }
188  return blackboxDefaultOp2(op,res,i1,i2);
189  }
190  case '|':
191  {
192  if(i2->Typ()==coneID)
193  {
194  gfan::ZCone* zq = (gfan::ZCone*) i2->Data();
195  int d1 = zp->ambientDimension();
196  int d2 = zq->ambientDimension();
197  if (d1 != d2)
198  {
199  WerrorS("mismatching ambient dimensions");
200  return TRUE;
201  }
202  gfan::ZMatrix rays = zp->extremeRays();
203  rays.append(zq->extremeRays());
204  gfan::ZMatrix lineality = zp->generatorsOfLinealitySpace();
205  lineality.append(zq->generatorsOfLinealitySpace());
206  gfan::ZCone* zs = new gfan::ZCone();
207  *zs = gfan::ZCone::givenByRays(rays,lineality);
208  zs->canonicalize();
209  res->rtyp = coneID;
210  res->data = (void*) zs;
211  return FALSE;
212  }
213  return blackboxDefaultOp2(op,res,i1,i2);
214  }
215  case EQUAL_EQUAL:
216  {
217  if(i2->Typ()==coneID)
218  {
219  gfan::ZCone* zq = (gfan::ZCone*) i2->Data();
220  zp->canonicalize();
221  zq->canonicalize();
222  bool b = !((*zp)!=(*zq));
223  res->rtyp = INT_CMD;
224  res->data = (void*) b;
225  return FALSE;
226  }
227  return blackboxDefaultOp2(op,res,i1,i2);
228  }
229  default:
230  return blackboxDefaultOp2(op,res,i1,i2);
231  }
232  return blackboxDefaultOp2(op,res,i1,i2);
233 }
234 
235 
236 /* singular wrapper for gfanlib functions */
238 {
239  /* method for generating a cone object from inequalities;
240  valid parametrizations: (intmat) */
241  bigintmat* ineq = NULL;
242  if (v->Typ() == INTMAT_CMD)
243  {
244  intvec* ineq0 = (intvec*) v->Data();
245  ineq = iv2bim(ineq0,coeffs_BIGINT);
246  }
247  else
248  ineq = (bigintmat*) v->Data();
249  gfan::ZMatrix* zm = bigintmatToZMatrix(ineq);
250  gfan::ZCone* zc = new gfan::ZCone(*zm, gfan::ZMatrix(0, zm->getWidth()));
251  delete zm;
252  if (v->Typ() == INTMAT_CMD)
253  delete ineq;
254  res->rtyp = coneID;
255  res->data = (void*) zc;
256  return FALSE;
257 }
258 
260 {
261  /* method for generating a cone object from iequalities,
262  and equations (...)
263  valid parametrizations: (intmat, intmat)
264  Errors will be invoked in the following cases:
265  - u and v have different numbers of columns */
266  bigintmat* ineq = NULL; bigintmat* eq = NULL;
267  if (u->Typ() == INTMAT_CMD)
268  {
269  intvec* ineq0 = (intvec*) u->Data();
270  ineq = iv2bim(ineq0,coeffs_BIGINT);
271  }
272  else
273  ineq = (bigintmat*) u->Data();
274  if (v->Typ() == INTMAT_CMD)
275  {
276  intvec* eq0 = (intvec*) v->Data();
277  eq = iv2bim(eq0,coeffs_BIGINT);
278  }
279  else
280  eq = (bigintmat*) v->Data();
281 
282  if (ineq->cols() != eq->cols())
283  {
284  Werror("expected same number of columns but got %d vs. %d",
285  ineq->cols(), eq->cols());
286  return TRUE;
287  }
288  gfan::ZMatrix* zm1 = bigintmatToZMatrix(ineq);
289  gfan::ZMatrix* zm2 = bigintmatToZMatrix(eq);
290  gfan::ZCone* zc = new gfan::ZCone(*zm1, *zm2);
291  delete zm1;
292  delete zm2;
293  if (u->Typ() == INTMAT_CMD)
294  delete ineq;
295  if (v->Typ() == INTMAT_CMD)
296  delete eq;
297  res->rtyp = coneID;
298  res->data = (void*) zc;
299  return FALSE;
300 }
301 
303 {
304  /* method for generating a cone object from inequalities, equations,
305  and an integer k;
306  valid parametrizations: (intmat, intmat, int);
307  Errors will be invoked in the following cases:
308  - u and v have different numbers of columns,
309  - k not in [0..3];
310  if the 2^0-bit of k is set, then ... */
311  bigintmat* ineq = NULL; bigintmat* eq = NULL;
312  if (u->Typ() == INTMAT_CMD)
313  {
314  intvec* ineq0 = (intvec*) u->Data();
315  ineq = iv2bim(ineq0,coeffs_BIGINT);
316  }
317  else
318  ineq = (bigintmat*) u->Data();
319  if (v->Typ() == INTMAT_CMD)
320  {
321  intvec* eq0 = (intvec*) v->Data();
322  eq = iv2bim(eq0,coeffs_BIGINT);
323  }
324  else
325  eq = (bigintmat*) v->Data();
326  if (ineq->cols() != eq->cols())
327  {
328  Werror("expected same number of columns but got %d vs. %d",
329  ineq->cols(), eq->cols());
330  return TRUE;
331  }
332  int k = (int)(long)w->Data();
333  if ((k < 0) || (k > 3))
334  {
335  WerrorS("expected int argument in [0..3]");
336  return TRUE;
337  }
338  gfan::ZMatrix* zm1 = bigintmatToZMatrix(ineq);
339  gfan::ZMatrix* zm2 = bigintmatToZMatrix(eq);
340  gfan::ZCone* zc = new gfan::ZCone(*zm1, *zm2, k);
341  delete zm1;
342  delete zm2;
343  if (u->Typ() == INTMAT_CMD)
344  delete ineq;
345  if (v->Typ() == INTMAT_CMD)
346  delete eq;
347  res->rtyp = coneID;
348  res->data = (void*) zc;
349  return FALSE;
350 }
351 
353 {
354  gfan::initializeCddlibIfRequired();
355  leftv u = args;
356  if ((u != NULL) && ((u->Typ() == BIGINTMAT_CMD) || (u->Typ() == INTMAT_CMD)))
357  {
358  if (u->next == NULL)
359  {
360  BOOLEAN bo = jjCONENORMALS1(res, u);
361  gfan::deinitializeCddlibIfRequired();
362  return bo;
363  }
364  }
365  leftv v = u->next;
366  if ((v != NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTMAT_CMD)))
367  {
368  if (v->next == NULL)
369  {
370  BOOLEAN bo = jjCONENORMALS2(res, u, v);
371  gfan::deinitializeCddlibIfRequired();
372  return bo;
373  }
374  }
375  leftv w = v->next;
376  if ((w != NULL) && (w->Typ() == INT_CMD))
377  {
378  if (w->next == NULL)
379  {
380  BOOLEAN bo = jjCONENORMALS3(res, u, v, w);
381  gfan::deinitializeCddlibIfRequired();
382  return bo;
383  }
384  }
385  WerrorS("coneViaInequalities: unexpected parameters");
386  return TRUE;
387 }
388 
390 {
391  /* method for generating a cone object from half-lines
392  (cone = convex hull of the half-lines; note: there may be
393  entire lines in the cone);
394  valid parametrizations: (intmat) */
395  bigintmat* rays = NULL;
396  if (v->Typ() == INTMAT_CMD)
397  {
398  intvec* rays0 = (intvec*) v->Data();
399  rays = iv2bim(rays0,coeffs_BIGINT);
400  }
401  else
402  rays = (bigintmat*) v->Data();
403 
404  gfan::ZMatrix* zm = bigintmatToZMatrix(rays);
405  gfan::ZCone* zc = new gfan::ZCone();
406  *zc = gfan::ZCone::givenByRays(*zm, gfan::ZMatrix(0, zm->getWidth()));
407  res->rtyp = coneID;
408  res->data = (void*) zc;
409 
410  delete zm;
411  if (v->Typ() == INTMAT_CMD)
412  delete rays;
413  return FALSE;
414 }
415 
417 {
418  /* method for generating a cone object from half-lines,
419  and lines (any point in the cone being the sum of a point
420  in the convex hull of the half-lines and a point in the span
421  of the lines; the second argument may contain or entirely consist
422  of zero rows);
423  valid parametrizations: (intmat, intmat)
424  Errors will be invoked in the following cases:
425  - u and v have different numbers of columns */
426  bigintmat* rays = NULL; bigintmat* linSpace = NULL;
427  if (u->Typ() == INTMAT_CMD)
428  {
429  intvec* rays0 = (intvec*) u->Data();
430  rays = iv2bim(rays0,coeffs_BIGINT);
431  }
432  else
433  rays = (bigintmat*) u->Data();
434  if (v->Typ() == INTMAT_CMD)
435  {
436  intvec* linSpace0 = (intvec*) v->Data();
437  linSpace = iv2bim(linSpace0,coeffs_BIGINT);
438  }
439  else
440  linSpace = (bigintmat*) v->Data();
441 
442  if (rays->cols() != linSpace->cols())
443  {
444  Werror("expected same number of columns but got %d vs. %d",
445  rays->cols(), linSpace->cols());
446  return TRUE;
447  }
448  gfan::ZMatrix* zm1 = bigintmatToZMatrix(rays);
449  gfan::ZMatrix* zm2 = bigintmatToZMatrix(linSpace);
450  gfan::ZCone* zc = new gfan::ZCone();
451  *zc = gfan::ZCone::givenByRays(*zm1, *zm2);
452  res->rtyp = coneID;
453  res->data = (void*) zc;
454 
455  delete zm1;
456  delete zm2;
457  if (u->Typ() == INTMAT_CMD)
458  delete rays;
459  if (v->Typ() == INTMAT_CMD)
460  delete linSpace;
461  return FALSE;
462 }
463 
465 {
466  /* method for generating a cone object from half-lines,
467  and lines (any point in the cone being the sum of a point
468  in the convex hull of the half-lines and a point in the span
469  of the lines), and an integer k;
470  valid parametrizations: (intmat, intmat, int);
471  Errors will be invoked in the following cases:
472  - u and v have different numbers of columns,
473  - k not in [0..3];
474  if the 2^0-bit of k is set, then the lineality space is known
475  to be the span of the provided lines;
476  if the 2^1-bit of k is set, then the extreme rays are known:
477  each half-line spans a (different) extreme ray */
478  bigintmat* rays = NULL; bigintmat* linSpace = NULL;
479  if (u->Typ() == INTMAT_CMD)
480  {
481  intvec* rays0 = (intvec*) u->Data();
482  rays = iv2bim(rays0,coeffs_BIGINT);
483  }
484  else
485  rays = (bigintmat*) u->Data();
486  if (v->Typ() == INTMAT_CMD)
487  {
488  intvec* linSpace0 = (intvec*) v->Data();
489  linSpace = iv2bim(linSpace0,coeffs_BIGINT);
490  }
491  else
492  linSpace = (bigintmat*) v->Data();
493 
494  if (rays->cols() != linSpace->cols())
495  {
496  Werror("expected same number of columns but got %d vs. %d",
497  rays->cols(), linSpace->cols());
498  return TRUE;
499  }
500  int k = (int)(long)w->Data();
501  if ((k < 0) || (k > 3))
502  {
503  WerrorS("expected int argument in [0..3]");
504  return TRUE;
505  }
506  gfan::ZMatrix* zm1 = bigintmatToZMatrix(rays);
507  gfan::ZMatrix* zm2 = bigintmatToZMatrix(linSpace);
508  gfan::ZCone* zc = new gfan::ZCone();
509  *zc = gfan::ZCone::givenByRays(*zm1, *zm2);
510  //k should be passed on to zc; not available yet
511  res->rtyp = coneID;
512  res->data = (void*) zc;
513 
514  delete zm1;
515  delete zm2;
516  if (u->Typ() == INTMAT_CMD)
517  delete rays;
518  if (v->Typ() == INTMAT_CMD)
519  delete linSpace;
520  return FALSE;
521 }
522 
524 {
525  gfan::initializeCddlibIfRequired();
526  leftv u = args;
527  if ((u != NULL) && ((u->Typ() == BIGINTMAT_CMD) || (u->Typ() == INTMAT_CMD)))
528  {
529  if (u->next == NULL)
530  {
531  BOOLEAN bo = jjCONERAYS1(res, u);
532  gfan::deinitializeCddlibIfRequired();
533  return bo;
534  }
535  leftv v = u->next;
536  if ((v != NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTMAT_CMD)))
537  {
538  if (v->next == NULL)
539  {
540  BOOLEAN bo = jjCONERAYS2(res, u, v);
541  gfan::deinitializeCddlibIfRequired();
542  return bo;
543  }
544  leftv w = v->next;
545  if ((w != NULL) && (w->Typ() == INT_CMD))
546  {
547  if (w->next == NULL)
548  {
549  BOOLEAN bo = jjCONERAYS3(res, u, v, w);
550  gfan::deinitializeCddlibIfRequired();
551  return bo;
552  }
553  }
554  }
555  }
556  WerrorS("coneViaPoints: unexpected parameters");
557  return TRUE;
558 }
559 
561 {
562  leftv u = args;
563  if ((u != NULL) && (u->Typ() == coneID || u->Typ() == polytopeID))
564  {
565  gfan::initializeCddlibIfRequired();
566  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
567  gfan::ZMatrix zmat = zc->getInequalities();
568  res->rtyp = BIGINTMAT_CMD;
569  res->data = (void*) zMatrixToBigintmat(zmat);
570  gfan::deinitializeCddlibIfRequired();
571  return FALSE;
572  }
573  WerrorS("inequalities: unexpected parameters");
574  return TRUE;
575 }
576 
578 {
579  leftv u = args;
580  if ((u != NULL) && (u->Typ() == coneID || u->Typ() == polytopeID))
581  {
582  gfan::initializeCddlibIfRequired();
583  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
584  gfan::ZMatrix zmat = zc->getEquations();
585  res->rtyp = BIGINTMAT_CMD;
586  res->data = (void*) zMatrixToBigintmat(zmat);
587  gfan::deinitializeCddlibIfRequired();
588  return FALSE;
589  }
590  WerrorS("equations: unexpected parameters");
591  return TRUE;
592 }
593 
595 {
596  leftv u = args;
597  if ((u != NULL) && (u->Typ() == coneID || u->Typ() == polytopeID))
598  {
599  gfan::initializeCddlibIfRequired();
600  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
601  gfan::ZMatrix zm = zc->getFacets();
602  res->rtyp = BIGINTMAT_CMD;
603  res->data = (void*) zMatrixToBigintmat(zm);
604  gfan::deinitializeCddlibIfRequired();
605  return FALSE;
606  }
607  WerrorS("facets: unexpected parameters");
608  return TRUE;
609 }
610 
612 {
613  leftv u = args;
614  if ((u != NULL) && (u->Typ() == coneID || u->Typ() == polytopeID))
615  {
616  gfan::initializeCddlibIfRequired();
617  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
618  gfan::ZMatrix zmat = zc->getImpliedEquations();
619  res->rtyp = BIGINTMAT_CMD;
620  res->data = (void*) zMatrixToBigintmat(zmat);
621  gfan::deinitializeCddlibIfRequired();
622  return FALSE;
623  }
624  WerrorS("span: unexpected parameters");
625  return TRUE;
626 }
627 
629 {
630  leftv u = args;
631  if ((u != NULL) && (u->Typ() == coneID || u->Typ() == polytopeID))
632  {
633  gfan::initializeCddlibIfRequired();
634  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
635  gfan::ZMatrix zmat = zc->generatorsOfSpan();
636  res->rtyp = BIGINTMAT_CMD;
637  res->data = (void*) zMatrixToBigintmat(zmat);
638  gfan::deinitializeCddlibIfRequired();
639  return FALSE;
640  }
641  WerrorS("generatorsOfSpan: unexpected parameters");
642  return TRUE;
643 }
644 
646 {
647  leftv u = args;
648  if ((u != NULL) && (u->Typ() == coneID || u->Typ() == polytopeID))
649  {
650  gfan::initializeCddlibIfRequired();
651  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
652  gfan::ZMatrix zmat = zc->generatorsOfLinealitySpace();
653  res->rtyp = BIGINTMAT_CMD;
654  res->data = (void*) zMatrixToBigintmat(zmat);
655  gfan::deinitializeCddlibIfRequired();
656  return FALSE;
657  }
658  WerrorS("generatorsOfLinealitySpace: unexpected parameters");
659  return TRUE;
660 }
661 
663 {
664  leftv u = args;
665  if ((u != NULL) && (u->Typ() == coneID))
666  {
667  gfan::initializeCddlibIfRequired();
668  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
669  gfan::ZMatrix zm = zc->extremeRays();
670  res->rtyp = BIGINTMAT_CMD;
671  res->data = (void*)zMatrixToBigintmat(zm);
672  gfan::deinitializeCddlibIfRequired();
673  return FALSE;
674  }
675  if ((u != NULL) && (u->Typ() == fanID))
676  {
677  gfan::initializeCddlibIfRequired();
678  gfan::ZFan* zf = (gfan::ZFan*)u->Data();
679  gfan::ZMatrix zmat = rays(zf);
680  res->rtyp = BIGINTMAT_CMD;
681  res->data = (void*) zMatrixToBigintmat(zmat);
682  gfan::deinitializeCddlibIfRequired();
683  return FALSE;
684  }
685  WerrorS("rays: unexpected parameters");
686  return TRUE;
687 }
688 
690 {
691  leftv u = args;
692  if ((u != NULL) && (u->Typ() == coneID))
693  {
694  gfan::initializeCddlibIfRequired();
695  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
696  gfan::ZMatrix zmat = zc->quotientLatticeBasis();
697  res->rtyp = BIGINTMAT_CMD;
698  res->data = (void*) zMatrixToBigintmat(zmat);
699  gfan::deinitializeCddlibIfRequired();
700  return FALSE;
701  }
702  WerrorS("quotientLatticeBasis: unexpected parameters");
703  return TRUE;
704 }
705 
707 {
708  leftv u = args;
709  if ((u != NULL) && (u->Typ() == coneID))
710  {
711  gfan::initializeCddlibIfRequired();
712  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
713  gfan::ZMatrix zmat = zc->getLinearForms();
714  res->rtyp = BIGINTMAT_CMD;
715  res->data = (void*) zMatrixToBigintmat(zmat);
716  gfan::deinitializeCddlibIfRequired();
717  return FALSE;
718  }
719  WerrorS("getLinearForms: unexpected parameters");
720  return TRUE;
721 }
722 
724 {
725  leftv u=args;
726  if ((u != NULL) && (u->Typ() == coneID))
727  {
728  gfan::initializeCddlibIfRequired();
729  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
730  res->rtyp = INT_CMD;
731  res->data = (void*) (long) zc->ambientDimension();
732  gfan::deinitializeCddlibIfRequired();
733  return FALSE;
734  }
735  if ((u != NULL) && (u->Typ() == fanID))
736  {
737  gfan::initializeCddlibIfRequired();
738  gfan::ZFan* zf = (gfan::ZFan*)u->Data();
739  res->rtyp = INT_CMD;
740  res->data = (void*) (long) getAmbientDimension(zf);
741  gfan::deinitializeCddlibIfRequired();
742  return FALSE;
743  }
744  if ((u != NULL) && (u->Typ() == polytopeID))
745  {
746  gfan::initializeCddlibIfRequired();
747  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
748  res->rtyp = INT_CMD;
749  res->data = (void*) (long) getAmbientDimension(zc);
750  gfan::deinitializeCddlibIfRequired();
751  return FALSE;
752  }
753  WerrorS("ambientDimension: unexpected parameters");
754  return TRUE;
755 }
756 
758 {
759  leftv u=args;
760  if ((u != NULL) && (u->Typ() == coneID))
761  {
762  gfan::initializeCddlibIfRequired();
763  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
764  res->rtyp = INT_CMD;
765  res->data = (void*) (long) zc->dimension();
766  gfan::deinitializeCddlibIfRequired();
767  return FALSE;
768  }
769  if ((u != NULL) && (u->Typ() == fanID))
770  {
771  gfan::initializeCddlibIfRequired();
772  gfan::ZFan* zf = (gfan::ZFan*)u->Data();
773  res->rtyp = INT_CMD;
774  res->data = (void*) (long) getDimension(zf);
775  gfan::deinitializeCddlibIfRequired();
776  return FALSE;
777  }
778  if ((u != NULL) && (u->Typ() == polytopeID))
779  {
780  gfan::initializeCddlibIfRequired();
781  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
782  res->rtyp = INT_CMD;
783  res->data = (void*) (long) getDimension(zc);
784  gfan::deinitializeCddlibIfRequired();
785  return FALSE;
786  }
787  WerrorS("dimension: unexpected parameters");
788  return TRUE;
789 }
790 
792 {
793  leftv u=args;
794  if ((u != NULL) && (u->Typ() == coneID))
795  {
796  gfan::initializeCddlibIfRequired();
797  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
798  res->rtyp = INT_CMD;
799  res->data = (void*) (long) zc->codimension();
800  gfan::deinitializeCddlibIfRequired();
801  return FALSE;
802  }
803  if ((u != NULL) && (u->Typ() == fanID))
804  {
805  gfan::initializeCddlibIfRequired();
806  gfan::ZFan* zf = (gfan::ZFan*)u->Data();
807  res->rtyp = INT_CMD;
808  res->data = (void*) (long) getCodimension(zf);
809  gfan::deinitializeCddlibIfRequired();
810  return FALSE;
811  }
812  if ((u != NULL) && (u->Typ() == polytopeID))
813  {
814  gfan::initializeCddlibIfRequired();
815  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
816  res->rtyp = INT_CMD;
817  res->data = (void*) (long) getCodimension(zc);
818  gfan::deinitializeCddlibIfRequired();
819  return FALSE;
820  }
821  WerrorS("getCodimension: unexpected parameters");
822  return TRUE;
823 }
824 
826 {
827  leftv u=args;
828  if ((u != NULL) && (u->Typ() == coneID))
829  {
830  gfan::initializeCddlibIfRequired();
831  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
832  res->rtyp = INT_CMD;
833  res->data = (void*) (long) zc->dimensionOfLinealitySpace();
834  gfan::deinitializeCddlibIfRequired();
835  return FALSE;
836  }
837  if ((u != NULL) && (u->Typ() == fanID))
838  {
839  gfan::initializeCddlibIfRequired();
840  gfan::ZFan* zf = (gfan::ZFan*)u->Data();
841  res->rtyp = INT_CMD;
842  res->data = (void*) (long) getLinealityDimension(zf);
843  gfan::deinitializeCddlibIfRequired();
844  return FALSE;
845  }
846  WerrorS("linealityDimension: unexpected parameters");
847  return TRUE;
848 }
849 
851 {
852  leftv u = args;
853  if ((u != NULL) && (u->Typ() == coneID))
854  {
855  gfan::initializeCddlibIfRequired();
856  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
857  number i = integerToNumber(zc->getMultiplicity());
858  res->rtyp = BIGINT_CMD;
859  res->data = (void*) i;
860  gfan::deinitializeCddlibIfRequired();
861  return FALSE;
862  }
863  WerrorS("getMultiplicity: unexpected parameters");
864  return TRUE;
865 }
866 
868 {
869  leftv u = args;
870  if ((u != NULL) && (u->Typ() == coneID))
871  {
872  gfan::initializeCddlibIfRequired();
873  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
874  int i = zc->isOrigin();
875  res->rtyp = INT_CMD;
876  res->data = (void*) (long) i;
877  gfan::deinitializeCddlibIfRequired();
878  return FALSE;
879  }
880  WerrorS("isOrigin: unexpected parameters");
881  return TRUE;
882 }
883 
885 {
886  leftv u = args;
887  if ((u != NULL) && (u->Typ() == coneID))
888  {
889  gfan::initializeCddlibIfRequired();
890  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
891  int i = zc->isFullSpace();
892  res->rtyp = INT_CMD;
893  res->data = (void*) (long) i;
894  gfan::deinitializeCddlibIfRequired();
895  return FALSE;
896  }
897  WerrorS("isFullSpace: unexpected parameters");
898  return TRUE;
899 }
900 
902 {
903  leftv u=args;
904  if ((u != NULL) && (u->Typ() == coneID))
905  {
906  gfan::initializeCddlibIfRequired();
907  gfan::ZCone* zc = (gfan::ZCone*) u->Data();
908  int b = zc->isSimplicial();
909  res->rtyp = INT_CMD;
910  res->data = (void*) (long) b;
911  gfan::deinitializeCddlibIfRequired();
912  return FALSE;
913  }
914  if ((u != NULL) && (u->Typ() == fanID))
915  {
916  gfan::initializeCddlibIfRequired();
917  gfan::ZFan* zf = (gfan::ZFan*) u->Data();
918  bool b = isSimplicial(zf);
919  res->rtyp = INT_CMD;
920  res->data = (void*) (long) b;
921  gfan::deinitializeCddlibIfRequired();
922  return FALSE;
923  }
924  WerrorS("isSimplicial: unexpected parameters");
925  return TRUE;
926 }
927 
929 {
930  leftv u = args;
931  if ((u != NULL) && (u->Typ() == coneID))
932  {
933  gfan::initializeCddlibIfRequired();
934  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
935  int i = zc->containsPositiveVector();
936  res->rtyp = INT_CMD;
937  res->data = (void*) (long) i;
938  gfan::deinitializeCddlibIfRequired();
939  return FALSE;
940  }
941  WerrorS("containsPositiveVector: unexpected parameters");
942  return TRUE;
943 }
944 
946 {
947  leftv u = args;
948  if ((u != NULL) && (u->Typ() == coneID))
949  {
950  gfan::initializeCddlibIfRequired();
951  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
952  gfan::ZCone* zd = new gfan::ZCone(zc->linealitySpace());
953  res->rtyp = coneID;
954  res->data = (void*) zd;
955  gfan::deinitializeCddlibIfRequired();
956  return FALSE;
957  }
958  WerrorS("linealitySpace: unexpected parameters");
959  return TRUE;
960 }
961 
963 {
964  leftv u = args;
965  if ((u != NULL) && (u->Typ() == coneID))
966  {
967  gfan::initializeCddlibIfRequired();
968  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
969  gfan::ZCone* zd = new gfan::ZCone(zc->dualCone());
970  res->rtyp = coneID;
971  res->data = (void*) zd;
972  gfan::deinitializeCddlibIfRequired();
973  return FALSE;
974  }
975  WerrorS("dual: unexpected parameters");
976  return TRUE;
977 }
978 
980 {
981  leftv u = args;
982  if ((u != NULL) && (u->Typ() == coneID))
983  {
984  gfan::initializeCddlibIfRequired();
985  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
986  gfan::ZCone* zd = new gfan::ZCone(zc->negated());
987  res->rtyp = coneID;
988  res->data = (void*) zd;
989  gfan::deinitializeCddlibIfRequired();
990  return FALSE;
991  }
992  WerrorS("negatedCone: unexpected parameters");
993  return TRUE;
994 }
995 
997 {
998  leftv u = args;
999  if ((u != NULL) && (u->Typ() == coneID))
1000  {
1001  gfan::initializeCddlibIfRequired();
1002  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
1003  int d = zc->dimension();
1004  int dLS = zc->dimensionOfLinealitySpace();
1005  if (d == dLS + 1)
1006  {
1007  gfan::ZVector zv = zc->semiGroupGeneratorOfRay();
1008  res->rtyp = BIGINTMAT_CMD;
1009  res->data = (void*) zVectorToBigintmat(zv);
1010  gfan::deinitializeCddlibIfRequired();
1011  return FALSE;
1012  }
1013  gfan::deinitializeCddlibIfRequired();
1014  Werror("expected dim of cone one larger than dim of lin space\n"
1015  "but got dimensions %d and %d", d, dLS);
1016  }
1017  WerrorS("semigroupGenerator: unexpected parameters");
1018  return TRUE;
1019 }
1020 
1022 {
1023  leftv u = args;
1024  if ((u != NULL) && (u->Typ() == coneID))
1025  {
1026  gfan::initializeCddlibIfRequired();
1027  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
1028  gfan::ZVector zv = zc->getRelativeInteriorPoint();
1029  res->rtyp = BIGINTMAT_CMD;
1030  res->data = (void*) zVectorToBigintmat(zv);
1031  gfan::deinitializeCddlibIfRequired();
1032  return FALSE;
1033  }
1034  WerrorS("relativeInteriorPoint: unexpected parameters");
1035  return TRUE;
1036 }
1037 
1039 {
1040  leftv u = args;
1041  if ((u != NULL) && (u->Typ() == coneID))
1042  {
1043  gfan::initializeCddlibIfRequired();
1044  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
1045  gfan::ZVector zv = zc->getUniquePoint();
1046  res->rtyp = BIGINTMAT_CMD;
1047  res->data = (void*) zVectorToBigintmat(zv);
1048  gfan::deinitializeCddlibIfRequired();
1049  return FALSE;
1050  }
1051  WerrorS("uniquePoint: unexpected parameters");
1052  return TRUE;
1053 }
1054 
1055 gfan::ZVector randomPoint(const gfan::ZCone* zc)
1056 {
1057  gfan::ZVector rp = gfan::ZVector(zc->ambientDimension());
1058 
1059  gfan::ZMatrix rays = zc->extremeRays();
1060  for (int i=0; i<rays.getHeight(); i++)
1061  {
1062  int n = siRand();
1063  rp = rp + n * rays[i].toVector();
1064  }
1065 
1066  gfan::ZMatrix lins = zc->generatorsOfLinealitySpace();
1067  for (int i=0; i<lins.getHeight(); i++)
1068  {
1069  int n = siRand();
1070  rp = rp + n * lins[i].toVector();
1071  }
1072 
1073  return rp;
1074 }
1075 
1077 {
1078  leftv u = args;
1079  if ((u != NULL) && (u->Typ() == coneID))
1080  {
1081  gfan::initializeCddlibIfRequired();
1082  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
1083  gfan::ZVector zv = randomPoint(zc);
1084  res->rtyp = BIGINTMAT_CMD;
1085  res->data = (void*) zVectorToBigintmat(zv);
1086  gfan::deinitializeCddlibIfRequired();
1087  return FALSE;
1088  }
1089  WerrorS("randomPoint: unexpected parameters");
1090  return TRUE;
1091 }
1092 
1094 {
1095  leftv u = args;
1096  if ((u != NULL) && (u->Typ() == coneID))
1097  {
1098  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
1099  leftv v = u->next;
1100  if ((v != NULL) && (v->Typ() == INT_CMD))
1101  {
1102  gfan::initializeCddlibIfRequired();
1103  int val = (int)(long)v->Data();
1104  zc->setMultiplicity(gfan::Integer(val));
1105  res->rtyp = NONE;
1106  res->data = NULL;
1107  gfan::deinitializeCddlibIfRequired();
1108  return FALSE;
1109  }
1110  }
1111  WerrorS("setMultiplicity: unexpected parameters");
1112  return TRUE;
1113 }
1114 
1116 {
1117  leftv u = args;
1118  if ((u != NULL) && (u->Typ() == coneID))
1119  {
1120  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
1121  leftv v = u->next;
1122  if ((v != NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTVEC_CMD)))
1123  {
1124  gfan::initializeCddlibIfRequired();
1125  bigintmat* mat=NULL;
1126  if (v->Typ() == INTVEC_CMD)
1127  {
1128  intvec* mat0 = (intvec*) v->Data();
1129  mat = iv2bim(mat0,coeffs_BIGINT)->transpose();
1130  }
1131  else
1132  mat = (bigintmat*) v->Data();
1133  gfan::ZMatrix* zm = bigintmatToZMatrix(mat);
1134  zc->setLinearForms(*zm);
1135  res->rtyp = NONE;
1136  res->data = NULL;
1137 
1138  delete zm;
1139  if (v->Typ() == INTVEC_CMD)
1140  delete mat;
1141  gfan::deinitializeCddlibIfRequired();
1142  return FALSE;
1143  }
1144  }
1145  WerrorS("setLinearForms: unexpected parameters");
1146  return TRUE;
1147 }
1148 
1149 gfan::ZMatrix liftUp(const gfan::ZMatrix &zm)
1150 {
1151  int r=zm.getHeight();
1152  int c=zm.getWidth();
1153  gfan::ZMatrix zn(r+1,c+1);
1154  zn[1][1]=1;
1155  for (int i=0; i<r; i++)
1156  for (int j=0; j<c; j++)
1157  zn[i+1][j+1]=zm[i][j];
1158  return zn;
1159 }
1160 
1161 gfan::ZCone liftUp(const gfan::ZCone &zc)
1162 {
1163  gfan::ZMatrix ineq=zc.getInequalities();
1164  gfan::ZMatrix eq=zc.getEquations();
1165  gfan::ZCone zd(liftUp(ineq),liftUp(eq));
1166  return zd;
1167 }
1168 
1170 {
1171  leftv u = args;
1172  if ((u != NULL) && (u->Typ() == coneID))
1173  {
1174  gfan::initializeCddlibIfRequired();
1175  gfan::ZCone* zc = (gfan::ZCone*) u->Data();
1176  gfan::ZMatrix ineq=zc->getInequalities();
1177  gfan::ZMatrix eq=zc->getEquations();
1178  gfan::ZCone* zd = new gfan::ZCone(liftUp(ineq),liftUp(eq));
1179  res->rtyp = polytopeID;
1180  res->data = (void*) zd;
1181  gfan::deinitializeCddlibIfRequired();
1182  return FALSE;
1183  }
1184  WerrorS("makePolytope: unexpected parameters");
1185  return TRUE;
1186 }
1187 
1189 {
1190  leftv u = args;
1191  if ((u != NULL) && (u->Typ() == coneID))
1192  {
1193  leftv v = u->next;
1194  if ((v != NULL) && (v->Typ() == coneID))
1195  {
1196  gfan::initializeCddlibIfRequired();
1197  gfan::ZCone* zc1 = (gfan::ZCone*)u->Data();
1198  gfan::ZCone* zc2 = (gfan::ZCone*)v->Data();
1199  int d1 = zc1->ambientDimension();
1200  int d2 = zc2->ambientDimension();
1201  if (d1 != d2)
1202  {
1203  Werror("expected ambient dims of both cones to coincide\n"
1204  "but got %d and %d", d1, d2);
1205  gfan::deinitializeCddlibIfRequired();
1206  return TRUE;
1207  }
1208  gfan::ZCone zc3 = gfan::intersection(*zc1, *zc2);
1209  zc3.canonicalize();
1210  res->rtyp = coneID;
1211  res->data = (void *)new gfan::ZCone(zc3);
1212  gfan::deinitializeCddlibIfRequired();
1213  return FALSE;
1214  }
1215  if ((v != NULL) && (v->Typ() == polytopeID))
1216  {
1217  gfan::initializeCddlibIfRequired();
1218  gfan::ZCone* zc11 = (gfan::ZCone*)u->Data();
1219  gfan::ZCone zc1 = liftUp(*zc11);
1220  gfan::ZCone* zc2 = (gfan::ZCone*)v->Data();
1221  int d1 = zc1.ambientDimension();
1222  int d2 = zc2->ambientDimension();
1223  if (d1 != d2)
1224  {
1225  Werror("expected ambient dims of both cones to coincide\n"
1226  "but got %d and %d", d1, d2);
1227  gfan::deinitializeCddlibIfRequired();
1228  return TRUE;
1229  }
1230  gfan::ZCone zc3 = gfan::intersection(zc1, *zc2);
1231  zc3.canonicalize();
1232  res->rtyp = polytopeID;
1233  res->data = (void *)new gfan::ZCone(zc3);
1234  gfan::deinitializeCddlibIfRequired();
1235  return FALSE;
1236  }
1237  }
1238  if ((u != NULL) && (u->Typ() == LIST_CMD))
1239  {
1240  if (u->next == NULL)
1241  {
1242  lists l = (lists) u->Data();
1243 
1244  // find the total number of inequalities and equations
1245  int r1=0; // total number of inequalities
1246  int r2=0; // total number of equations
1247  int c=0; // ambient dimension
1248  for (int i=0; i<=lSize(l); i++)
1249  {
1250  if (l->m[i].Typ() != coneID)
1251  {
1252  WerrorS("convexIntersection: entries of wrong type in list");
1253  return TRUE;
1254  }
1255  gfan::ZCone* ll = (gfan::ZCone*) l->m[i].Data();
1256  r1 = r1 + ll->getInequalities().getHeight();
1257  r2 = r2 + ll->getEquations().getHeight();
1258  }
1259  if (lSize(l)>=0)
1260  {
1261  gfan::ZCone* ll = (gfan::ZCone*) l->m[0].Data();
1262  c = ll->getInequalities().getWidth();
1263  }
1264  gfan::ZMatrix totalIneqs(r1,c);
1265  gfan::ZMatrix totalEqs(r2,c);
1266 
1267  // concat all inequalities and equations
1268  r1=0; // counter for inequalities
1269  r2=0; // counter for equations
1270  for (int i=0; i<=lSize(l); i++)
1271  {
1272  gfan::ZCone* ll = (gfan::ZCone*) l->m[i].Data();
1273  gfan::ZMatrix ineqs = ll->getInequalities();
1274  for (int j=0; j<ineqs.getHeight(); j++)
1275  {
1276  totalIneqs[r1]=ineqs[j];
1277  r1 = r1+1;
1278  }
1279  gfan::ZMatrix eqs = ll->getEquations();
1280  for (int j=0; j<eqs.getHeight(); j++)
1281  {
1282  totalEqs[r2]=eqs[j];
1283  r2 = r2+1;
1284  }
1285  }
1286 
1287  gfan::ZCone* zc = new gfan::ZCone(totalIneqs,totalEqs);
1288  zc->canonicalize();
1289  res->rtyp = coneID;
1290  res->data = (void *) zc;
1291  return FALSE;
1292  }
1293  }
1294  if ((u != NULL) && (u->Typ() == polytopeID))
1295  {
1296  leftv v = u->next;
1297  if ((v != NULL) && (v->Typ() == coneID))
1298  {
1299  gfan::initializeCddlibIfRequired();
1300  gfan::ZCone* zc1 = (gfan::ZCone*)u->Data();
1301  gfan::ZCone* zc22 = (gfan::ZCone*)v->Data();
1302  gfan::ZCone zc2 = liftUp(*zc22);
1303  int d1 = zc1->ambientDimension();
1304  int d2 = zc2.ambientDimension();
1305  if (d1 != d2)
1306  {
1307  Werror("expected ambient dims of both cones to coincide\n"
1308  "but got %d and %d", d1, d2);
1309  gfan::deinitializeCddlibIfRequired();
1310  return TRUE;
1311  }
1312  gfan::ZCone zc3 = gfan::intersection(*zc1, zc2);
1313  zc3.canonicalize();
1314  res->rtyp = polytopeID;
1315  res->data = (void *)new gfan::ZCone(zc3);
1316  gfan::deinitializeCddlibIfRequired();
1317  return FALSE;
1318  }
1319  if ((v != NULL) && (v->Typ() == polytopeID))
1320  {
1321  gfan::initializeCddlibIfRequired();
1322  gfan::ZCone* zc1 = (gfan::ZCone*)u->Data();
1323  gfan::ZCone* zc2 = (gfan::ZCone*)v->Data();
1324  int d1 = zc1->ambientDimension();
1325  int d2 = zc2->ambientDimension();
1326  if (d1 != d2)
1327  {
1328  Werror("expected ambient dims of both cones to coincide\n"
1329  "but got %d and %d", d1, d2);
1330  gfan::deinitializeCddlibIfRequired();
1331  return TRUE;
1332  }
1333  gfan::ZCone zc3 = gfan::intersection(*zc1, *zc2);
1334  zc3.canonicalize();
1335  res->rtyp = polytopeID;
1336  res->data = (void *)new gfan::ZCone(zc3);
1337  gfan::deinitializeCddlibIfRequired();
1338  return FALSE;
1339  }
1340  }
1341  WerrorS("convexIntersection: unexpected parameters");
1342  return TRUE;
1343 }
1344 
1346 {
1347  leftv u = args;
1348  if ((u != NULL) && (u->Typ() == coneID))
1349  {
1350  leftv v = u->next;
1351  if ((v != NULL) && (v->Typ() == coneID))
1352  {
1353  gfan::initializeCddlibIfRequired();
1354  gfan::ZCone* zc1 = (gfan::ZCone*)u->Data();
1355  gfan::ZCone* zc2 = (gfan::ZCone*)v->Data();
1356  int d1 = zc1->ambientDimension();
1357  int d2 = zc2->ambientDimension();
1358  if (d1 != d2)
1359  {
1360  Werror("expected ambient dims of both cones to coincide\n"
1361  "but got %d and %d", d1, d2);
1362  gfan::deinitializeCddlibIfRequired();
1363  return TRUE;
1364  }
1365  gfan::ZMatrix zm1 = zc1->extremeRays();
1366  gfan::ZMatrix zm2 = zc2->extremeRays();
1367  gfan::ZMatrix zn1 = zc1->generatorsOfLinealitySpace();
1368  gfan::ZMatrix zn2 = zc2->generatorsOfLinealitySpace();
1369  gfan::ZMatrix zm = combineOnTop(zm1,zm2);
1370  gfan::ZMatrix zn = combineOnTop(zn1,zn2);
1371  gfan::ZCone* zc = new gfan::ZCone();
1372  *zc = gfan::ZCone::givenByRays(zm, zn);
1373  res->rtyp = coneID;
1374  res->data = (void*) zc;
1375  gfan::deinitializeCddlibIfRequired();
1376  return FALSE;
1377  }
1378  if ((v != NULL) && (v->Typ() == polytopeID))
1379  {
1380  gfan::initializeCddlibIfRequired();
1381  gfan::ZCone* zc11 = (gfan::ZCone*)u->Data();
1382  gfan::ZCone zc1 = liftUp(*zc11);
1383  gfan::ZCone* zc2 = (gfan::ZCone*)v->Data();
1384  int d1 = zc1.ambientDimension()-1;
1385  int d2 = zc2->ambientDimension()-1;
1386  if (d1 != d2)
1387  {
1388  Werror("expected ambient dims of both cones to coincide\n"
1389  "but got %d and %d", d1, d2);
1390  gfan::deinitializeCddlibIfRequired();
1391  return TRUE;
1392  }
1393  gfan::ZMatrix zm1 = zc1.extremeRays();
1394  gfan::ZMatrix zm2 = zc2->extremeRays();
1395  gfan::ZMatrix zn = zc1.generatorsOfLinealitySpace();
1396  gfan::ZMatrix zm = combineOnTop(zm1,zm2);
1397  gfan::ZCone* zc = new gfan::ZCone();
1398  *zc = gfan::ZCone::givenByRays(zm, zn);
1399  res->rtyp = polytopeID;
1400  res->data = (void*) zc;
1401  gfan::deinitializeCddlibIfRequired();
1402  return FALSE;
1403  }
1404  }
1405  if ((u != NULL) && (u->Typ() == polytopeID))
1406  {
1407  leftv v = u->next;
1408  if ((v != NULL) && (v->Typ() == coneID))
1409  {
1410  gfan::initializeCddlibIfRequired();
1411  gfan::ZCone* zc1 = (gfan::ZCone*)u->Data();
1412  gfan::ZCone* zc22 = (gfan::ZCone*)v->Data();
1413  gfan::ZCone zc2 = liftUp(*zc22);
1414  int d1 = zc1->ambientDimension()-1;
1415  int d2 = zc2.ambientDimension()-1;
1416  if (d1 != d2)
1417  {
1418  Werror("expected ambient dims of both cones to coincide\n"
1419  "but got %d and %d", d1, d2);
1420  gfan::deinitializeCddlibIfRequired();
1421  return TRUE;
1422  }
1423  gfan::ZMatrix zm1 = zc1->extremeRays();
1424  gfan::ZMatrix zm2 = zc2.extremeRays();
1425  gfan::ZMatrix zn = zc2.generatorsOfLinealitySpace();
1426  gfan::ZMatrix zm = combineOnTop(zm1,zm2);
1427  gfan::ZCone* zc = new gfan::ZCone();
1428  *zc = gfan::ZCone::givenByRays(zm,gfan::ZMatrix(0, zm.getWidth()));
1429  res->rtyp = polytopeID;
1430  res->data = (void*) zc;
1431  gfan::deinitializeCddlibIfRequired();
1432  return FALSE;
1433  }
1434  if ((v != NULL) && (v->Typ() == polytopeID))
1435  {
1436  gfan::initializeCddlibIfRequired();
1437  gfan::ZCone* zc1 = (gfan::ZCone*)u->Data();
1438  gfan::ZCone* zc2 = (gfan::ZCone*)v->Data();
1439  int d1 = zc1->ambientDimension()-1;
1440  int d2 = zc2->ambientDimension()-1;
1441  if (d1 != d2)
1442  {
1443  Werror("expected ambient dims of both cones to coincide\n"
1444  "but got %d and %d", d1, d2);
1445  gfan::deinitializeCddlibIfRequired();
1446  return TRUE;
1447  }
1448  gfan::ZMatrix zm1 = zc1->extremeRays();
1449  gfan::ZMatrix zm2 = zc2->extremeRays();
1450  gfan::ZMatrix zm = combineOnTop(zm1,zm2);
1451  gfan::ZCone* zc = new gfan::ZCone();
1452  *zc = gfan::ZCone::givenByRays(zm,gfan::ZMatrix(0, zm.getWidth()));
1453  res->rtyp = polytopeID;
1454  res->data = (void*) zc;
1455  gfan::deinitializeCddlibIfRequired();
1456  return FALSE;
1457  }
1458  }
1459  WerrorS("convexHull: unexpected parameters");
1460  return TRUE;
1461 }
1462 
1464 {
1465  leftv u = args;
1466  if ((u != NULL) && (u->Typ() == coneID))
1467  {
1468  leftv v = u->next;
1469  if ((v != NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTVEC_CMD)))
1470  {
1471  gfan::initializeCddlibIfRequired();
1472  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
1473  bigintmat* iv = NULL;
1474  if (v->Typ() == INTVEC_CMD)
1475  {
1476  intvec* iv0 = (intvec*) v->Data();
1477  iv = iv2bim(iv0,coeffs_BIGINT)->transpose();
1478  }
1479  else
1480  iv = (bigintmat*)v->Data();
1481  gfan::ZVector* zv = bigintmatToZVector(iv);
1482  int d1 = zc->ambientDimension();
1483  int d2 = zv->size();
1484  if (d1 != d2)
1485  {
1486  Werror("expected ambient dim of cone and size of vector\n"
1487  " to be equal but got %d and %d", d1, d2);
1488  gfan::deinitializeCddlibIfRequired();
1489  return TRUE;
1490  }
1491  if(!zc->contains(*zv))
1492  {
1493  WerrorS("the provided intvec does not lie in the cone");
1494  gfan::deinitializeCddlibIfRequired();
1495  return TRUE;
1496  }
1497  gfan::ZCone* zd = new gfan::ZCone(zc->link(*zv));
1498  res->rtyp = coneID;
1499  res->data = (void *) zd;
1500 
1501  delete zv;
1502  if (v->Typ() == INTVEC_CMD)
1503  delete iv;
1504  gfan::deinitializeCddlibIfRequired();
1505  return FALSE;
1506  }
1507  }
1508  WerrorS("coneLink: unexpected parameters");
1509  return TRUE;
1510 }
1511 
1513 {
1514  leftv u=args;
1515  if ((u != NULL) && (u->Typ() == coneID))
1516  {
1517  leftv v=u->next;
1518  if ((v != NULL) && (v->Typ() == coneID))
1519  {
1520  gfan::initializeCddlibIfRequired();
1521  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
1522  gfan::ZCone* zd = (gfan::ZCone*)v->Data();
1523  int d1 = zc->ambientDimension();
1524  int d2 = zd->ambientDimension();
1525  if (d1 != d2)
1526  {
1527  Werror("expected cones with same ambient dimensions\n but got"
1528  " dimensions %d and %d", d1, d2);
1529  gfan::deinitializeCddlibIfRequired();
1530  return TRUE;
1531  }
1532  bool b = (zc->contains(*zd) ? 1 : 0);
1533  res->rtyp = INT_CMD;
1534  res->data = (void*) (long) b;
1535  gfan::deinitializeCddlibIfRequired();
1536  return FALSE;
1537  }
1538  if ((v != NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTVEC_CMD)))
1539  {
1540  gfan::initializeCddlibIfRequired();
1541  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
1542  bigintmat* iv = NULL;
1543  if (v->Typ() == INTVEC_CMD)
1544  {
1545  intvec* iv0 = (intvec*) v->Data();
1546  iv = iv2bim(iv0,coeffs_BIGINT)->transpose();
1547  }
1548  else
1549  iv = (bigintmat*)v->Data();
1550 
1551  gfan::ZVector* zv = bigintmatToZVector(iv);
1552  int d1 = zc->ambientDimension();
1553  int d2 = zv->size();
1554  if (d1 != d2)
1555  {
1556  Werror("expected cones with same ambient dimensions\n but got"
1557  " dimensions %d and %d", d1, d2);
1558  gfan::deinitializeCddlibIfRequired();
1559  return TRUE;
1560  }
1561  int b = zc->contains(*zv);
1562  res->rtyp = INT_CMD;
1563  res->data = (void*) (long) b;
1564 
1565  delete zv;
1566  if (v->Typ() == INTVEC_CMD)
1567  delete iv;
1568  gfan::deinitializeCddlibIfRequired();
1569  return FALSE;
1570  }
1571  }
1572  WerrorS("containsInSupport: unexpected parameters");
1573  return TRUE;
1574 }
1575 
1577 {
1578  gfan::initializeCddlibIfRequired();
1579  leftv u = args;
1580  if ((u != NULL) && (u->Typ() == coneID))
1581  {
1582  leftv v = u->next;
1583  if ((v != NULL) && (v->Typ() == coneID))
1584  {
1585  gfan::ZCone* zc1 = (gfan::ZCone*)u->Data();
1586  gfan::ZCone* zc2 = (gfan::ZCone*)v->Data();
1587  int d1 = zc1->ambientDimension();
1588  int d2 = zc2->ambientDimension();
1589  if (d1 != d2)
1590  {
1591  Werror("expected ambient dims of both cones to coincide\n"
1592  "but got %d and %d", d1, d2);
1593  return TRUE;
1594  }
1595  gfan::ZCone zc3 = gfan::intersection(*zc1, *zc2);
1596  zc3.canonicalize();
1597  res->rtyp = coneID;
1598  res->data = (void *)new gfan::ZCone(zc3);
1599  return FALSE;
1600  }
1601  if ((v != NULL) && (v->Typ() == polytopeID))
1602  {
1603  gfan::ZCone* zc11 = (gfan::ZCone*)u->Data();
1604  gfan::ZCone zc1 = liftUp(*zc11);
1605  gfan::ZCone* zc2 = (gfan::ZCone*)v->Data();
1606  int d1 = zc1.ambientDimension();
1607  int d2 = zc2->ambientDimension();
1608  if (d1 != d2)
1609  {
1610  Werror("expected ambient dims of both cones to coincide\n"
1611  "but got %d and %d", d1, d2);
1612  return TRUE;
1613  }
1614  gfan::ZCone zc3 = gfan::intersection(zc1, *zc2);
1615  zc3.canonicalize();
1616  res->rtyp = polytopeID;
1617  res->data = (void *)new gfan::ZCone(zc3);
1618  return FALSE;
1619  }
1620  }
1621  if ((u != NULL) && (u->Typ() == polytopeID))
1622  {
1623  leftv v = u->next;
1624  if ((v != NULL) && (v->Typ() == coneID))
1625  {
1626  gfan::ZCone* zc1 = (gfan::ZCone*)u->Data();
1627  gfan::ZCone* zc22 = (gfan::ZCone*)v->Data();
1628  gfan::ZCone zc2 = liftUp(*zc22);
1629  int d1 = zc1->ambientDimension();
1630  int d2 = zc2.ambientDimension();
1631  if (d1 != d2)
1632  {
1633  Werror("expected ambient dims of both cones to coincide\n"
1634  "but got %d and %d", d1, d2);
1635  return TRUE;
1636  }
1637  gfan::ZCone zc3 = gfan::intersection(*zc1, zc2);
1638  zc3.canonicalize();
1639  res->rtyp = polytopeID;
1640  res->data = (void *)new gfan::ZCone(zc3);
1641  return FALSE;
1642  }
1643  if ((v != NULL) && (v->Typ() == polytopeID))
1644  {
1645  gfan::ZCone* zc1 = (gfan::ZCone*)u->Data();
1646  gfan::ZCone* zc2 = (gfan::ZCone*)v->Data();
1647  int d1 = zc1->ambientDimension();
1648  int d2 = zc2->ambientDimension();
1649  if (d1 != d2)
1650  {
1651  Werror("expected ambient dims of both cones to coincide\n"
1652  "but got %d and %d", d1, d2);
1653  return TRUE;
1654  }
1655  gfan::ZCone zc3 = gfan::intersection(*zc1, *zc2);
1656  zc3.canonicalize();
1657  res->rtyp = polytopeID;
1658  res->data = (void *)new gfan::ZCone(zc3);
1659  return FALSE;
1660  }
1661  }
1662  WerrorS("convexIntersectionOld: unexpected parameters");
1663  return TRUE;
1664 }
1665 
1667 {
1668  leftv u = args;
1669  if ((u != NULL) && (u->Typ() == coneID))
1670  {
1671  leftv v = u->next;
1672  if ((v != NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTVEC_CMD)))
1673  {
1674  gfan::initializeCddlibIfRequired();
1675  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
1676  bigintmat* iv = NULL;
1677  if (v->Typ() == INTVEC_CMD)
1678  {
1679  intvec* iv0 = (intvec*) v->Data();
1680  iv = iv2bim(iv0,coeffs_BIGINT)->transpose();
1681  }
1682  else
1683  iv = (bigintmat*)v->Data();
1684  gfan::ZVector* zv = bigintmatToZVector(iv);
1685  int d1 = zc->ambientDimension();
1686  int d2 = zv->size();
1687  if (d1 == d2)
1688  {
1689  bool b = (zc->containsRelatively(*zv) ? 1 : 0);
1690  res->rtyp = INT_CMD;
1691  res->data = (void *) b;
1692  delete zv;
1693  if (v->Typ() == INTVEC_CMD)
1694  delete iv;
1695  gfan::deinitializeCddlibIfRequired();
1696  return FALSE;
1697  }
1698  delete zv;
1699  if (v->Typ() == INTVEC_CMD)
1700  delete iv;
1701  gfan::deinitializeCddlibIfRequired();
1702  Werror("expected ambient dim of cone and size of vector\n"
1703  "to be equal but got %d and %d", d1, d2);
1704  }
1705  }
1706  WerrorS("containsRelatively: unexpected parameters");
1707  return TRUE;
1708 }
1709 
1711 {
1712  leftv u=args;
1713  if ((u != NULL) && (u->Typ() == coneID))
1714  {
1715  leftv v=u->next;
1716  if ((v != NULL) && (v->Typ() == coneID))
1717  {
1718  gfan::initializeCddlibIfRequired();
1719  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
1720  gfan::ZCone* zd = (gfan::ZCone*)v->Data();
1721  bool b = zc->hasFace(*zd);
1722  res->rtyp = INT_CMD;
1723  res->data = (void*) (long) b;
1724  gfan::deinitializeCddlibIfRequired();
1725  return FALSE;
1726  }
1727  }
1728  if ((u != NULL) && (u->Typ() == polytopeID))
1729  {
1730  leftv v=u->next;
1731  if ((v != NULL) && (v->Typ() == polytopeID))
1732  {
1733  gfan::initializeCddlibIfRequired();
1734  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
1735  gfan::ZCone* zd = (gfan::ZCone*)v->Data();
1736  bool b = zc->hasFace(*zd);
1737  res->rtyp = INT_CMD;
1738  res->data = (void*) (long) b;
1739  gfan::deinitializeCddlibIfRequired();
1740  return FALSE;
1741  }
1742  }
1743  WerrorS("containsAsFace: unexpected parameters");
1744  return TRUE;
1745 }
1746 
1748 {
1749  leftv u=args;
1750  if ((u != NULL) && (u->Typ() == coneID))
1751  {
1752  gfan::initializeCddlibIfRequired();
1753  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
1754  gfan::ZCone* zd = new gfan::ZCone(*zc);
1755  zd->canonicalize();
1756  res->rtyp = coneID;
1757  res->data = (void*) zd;
1758  gfan::deinitializeCddlibIfRequired();
1759  return FALSE;
1760  }
1761  WerrorS("canonicalizeCone: unexpected parameters");
1762  return TRUE;
1763 }
1764 
1766 {
1767  leftv u=args;
1768  if ((u != NULL) && (u->Typ() == LIST_CMD))
1769  {
1770  leftv v=u->next;
1771  if ((v != NULL) && (v->Typ() == coneID))
1772  {
1773  gfan::initializeCddlibIfRequired();
1774  lists l = (lists) u->Data();
1775  gfan::ZCone* zc = (gfan::ZCone*) v->Data();
1776  zc->canonicalize();
1777  int b = 0;
1778  for (int i=0; i<=lSize(l); i++)
1779  {
1780  if (l->m[i].Typ() != coneID)
1781  {
1782  WerrorS("containsCone: entries of wrong type in list");
1783  gfan::deinitializeCddlibIfRequired();
1784  return TRUE;
1785  }
1786  gfan::ZCone* ll = (gfan::ZCone*) l->m[i].Data();
1787  ll->canonicalize();
1788  if (!((*ll) != (*zc)))
1789  {
1790  b = 1;
1791  break;
1792  }
1793  }
1794  res->rtyp = INT_CMD;
1795  res->data = (char*) (long) b;
1796  gfan::deinitializeCddlibIfRequired();
1797  return FALSE;
1798  }
1799  }
1800  WerrorS("containsCone: unexpected parameters");
1801  return TRUE;
1802 }
1803 
1805 {
1806  leftv u = args;
1807  if ((u != NULL) && (u->Typ() == coneID))
1808  {
1809  leftv v = u->next;
1810  if ((v != NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTVEC_CMD)))
1811  {
1812  gfan::initializeCddlibIfRequired();
1813  gfan::ZCone* zc = (gfan::ZCone*) u->Data();
1814 
1815  bigintmat* point1;
1816  if (v->Typ() == INTVEC_CMD)
1817  {
1818  intvec* point0 = (intvec*) v->Data();
1819  point1 = iv2bim(point0,coeffs_BIGINT)->transpose();
1820  }
1821  else
1822  point1 = (bigintmat*) v->Data();
1823  gfan::ZVector* point = bigintmatToZVector(*point1);
1824 
1825  if (!zc->contains(*point))
1826  {
1827  WerrorS("faceContaining: point not in cone");
1828  return TRUE;
1829  }
1830  res->rtyp = coneID;
1831  res->data = (void*) new gfan::ZCone(zc->faceContaining(*point));
1832 
1833  delete point;
1834  if (v->Typ() == INTVEC_CMD)
1835  delete point1;
1836  gfan::deinitializeCddlibIfRequired();
1837  return FALSE;
1838  }
1839  }
1840  WerrorS("faceContaining: unexpected parameters");
1841  return TRUE;
1842 }
1843 
1844 
1845 /***
1846  * Computes a relative interior point for each facet of zc
1847  **/
1848 gfan::ZMatrix interiorPointsOfFacets(const gfan::ZCone &zc, const std::set<gfan::ZVector> &exceptThese)
1849 {
1850  gfan::ZMatrix inequalities = zc.getFacets();
1851  gfan::ZMatrix equations = zc.getImpliedEquations();
1852  int r = inequalities.getHeight();
1853  int c = inequalities.getWidth();
1854 
1855  /* our cone has r facets, if r==0 return empty matrices */
1856  gfan::ZMatrix relativeInteriorPoints = gfan::ZMatrix(0,c);
1857  if (r==0) return relativeInteriorPoints;
1858 
1859  /* next we iterate over each of the r facets,
1860  * build the respective cone and add it to the list
1861  * this is the i=0 case */
1862  gfan::ZMatrix newInequalities = inequalities.submatrix(1,0,r,c);
1863  gfan::ZMatrix newEquations = equations;
1864  newEquations.appendRow(inequalities[0]);
1865  gfan::ZCone facet = gfan::ZCone(newInequalities,newEquations);
1866  facet.canonicalize();
1867  gfan::ZVector interiorPoint = facet.getRelativeInteriorPoint();
1868  if (exceptThese.count(interiorPoint)==0)
1869  relativeInteriorPoints.appendRow(interiorPoint);
1870 
1871  /* these are the cases i=1,...,r-2 */
1872  for (int i=1; i<r-1; i++)
1873  {
1874  newInequalities = inequalities.submatrix(0,0,i,c);
1875  newInequalities.append(inequalities.submatrix(i+1,0,r,c));
1876  newEquations = equations;
1877  newEquations.appendRow(inequalities[i]);
1878  facet = gfan::ZCone(newInequalities,newEquations);
1879  facet.canonicalize();
1880  interiorPoint = facet.getRelativeInteriorPoint();
1881  if (exceptThese.count(interiorPoint)==0)
1882  relativeInteriorPoints.appendRow(interiorPoint);
1883  }
1884 
1885  /* this is the i=r-1 case */
1886  newInequalities = inequalities.submatrix(0,0,r-1,c);
1887  newEquations = equations;
1888  newEquations.appendRow(inequalities[r-1]);
1889  facet = gfan::ZCone(newInequalities,newEquations);
1890  facet.canonicalize();
1891  interiorPoint = facet.getRelativeInteriorPoint();
1892  if (exceptThese.count(interiorPoint)==0)
1893  relativeInteriorPoints.appendRow(interiorPoint);
1894 
1895  return relativeInteriorPoints;
1896 }
1897 
1898 
1899 /***
1900  * Computes a relative interior point and an outer normal vector for each facet of zc
1901  **/
1902 std::pair<gfan::ZMatrix,gfan::ZMatrix> interiorPointsAndNormalsOfFacets(const gfan::ZCone zc, const std::set<gfan::ZVector> &exceptThesePoints, const bool onlyLowerHalfSpace)
1903 {
1904  gfan::ZMatrix inequalities = zc.getFacets();
1905  gfan::ZMatrix equations = zc.getImpliedEquations();
1906  int r = inequalities.getHeight();
1907  int c = inequalities.getWidth();
1908 
1909  /* our cone has r facets, if r==0 return empty matrices */
1910  gfan::ZMatrix relativeInteriorPoints = gfan::ZMatrix(0,c);
1911  gfan::ZMatrix outerFacetNormals = gfan::ZMatrix(0,c);
1912  if (r==0)
1913  return std::make_pair(relativeInteriorPoints,outerFacetNormals);
1914 
1915  /* next we iterate over each of the r facets,
1916  * build the respective cone and add it to the list
1917  * this is the i=0 case */
1918  gfan::ZMatrix newInequalities = inequalities.submatrix(1,0,r,c);
1919  gfan::ZMatrix newEquations = equations;
1920  newEquations.appendRow(inequalities[0]);
1921  gfan::ZCone facet = gfan::ZCone(newInequalities,newEquations);
1922  gfan::ZVector interiorPoint = facet.getRelativeInteriorPoint();
1923  if (onlyLowerHalfSpace==false || interiorPoint[0].sign()<0)
1924  {
1925  if (exceptThesePoints.count(interiorPoint)==0)
1926  {
1927  relativeInteriorPoints.appendRow(interiorPoint);
1928  outerFacetNormals.appendRow(-inequalities[0].toVector());
1929  }
1930  }
1931 
1932  /* these are the cases i=1,...,r-2 */
1933  for (int i=1; i<r-1; i++)
1934  {
1935  newInequalities = inequalities.submatrix(0,0,i,c);
1936  newInequalities.append(inequalities.submatrix(i+1,0,r,c));
1937  newEquations = equations;
1938  newEquations.appendRow(inequalities[i]);
1939  facet = gfan::ZCone(newInequalities,newEquations);
1940  interiorPoint = facet.getRelativeInteriorPoint();
1941  if (onlyLowerHalfSpace==false || interiorPoint[0].sign()<0)
1942  {
1943  if (exceptThesePoints.count(interiorPoint)==0)
1944  {
1945  relativeInteriorPoints.appendRow(interiorPoint);
1946  outerFacetNormals.appendRow(-inequalities[i].toVector());
1947  }
1948  }
1949  }
1950 
1951  /* this is the i=r-1 case */
1952  newInequalities = inequalities.submatrix(0,0,r-1,c);
1953  newEquations = equations;
1954  newEquations.appendRow(inequalities[r-1]);
1955  facet = gfan::ZCone(newInequalities,newEquations);
1956  interiorPoint = facet.getRelativeInteriorPoint();
1957  if (onlyLowerHalfSpace==false || interiorPoint[0].sign()<0)
1958  {
1959  if (exceptThesePoints.count(interiorPoint)==0)
1960  {
1961  relativeInteriorPoints.appendRow(interiorPoint);
1962  outerFacetNormals.appendRow(-inequalities[r-1].toVector());
1963  }
1964  }
1965 
1966  return std::make_pair(relativeInteriorPoints,outerFacetNormals);
1967 }
1968 
1969 
1970 static void gfanIntegerWriteFd(gfan::Integer n, ssiInfo* dd)
1971 {
1972  mpz_t tmp;
1973  mpz_init(tmp);
1974  n.setGmp(tmp);
1975  mpz_out_str (dd->f_write,SSI_BASE, tmp);
1976  mpz_clear(tmp);
1977  fputc(' ',dd->f_write);
1978 }
1979 
1980 static void gfanZMatrixWriteFd(gfan::ZMatrix M, ssiInfo* dd)
1981 {
1982  fprintf(dd->f_write,"%d %d ",M.getHeight(),M.getWidth());
1983 
1984  for (int i=0; i<M.getHeight(); i++)
1985  {
1986  for (int j=0; j<M.getWidth(); j++)
1987  {
1988  gfanIntegerWriteFd(M[i][j],dd);
1989  }
1990  }
1991 }
1992 
1993 BOOLEAN bbcone_serialize(blackbox *b, void *d, si_link f)
1994 {
1995  ssiInfo *dd = (ssiInfo *)f->data;
1996 
1997  sleftv l;
1998  memset(&l,0,sizeof(l));
1999  l.rtyp=STRING_CMD;
2000  l.data=(void*)"cone";
2001  f->m->Write(f, &l);
2002 
2003  gfan::ZCone *Z = (gfan::ZCone*) d;
2004  fprintf(dd->f_write,"%d ",Z->areImpliedEquationsKnown()+Z->areFacetsKnown()*2);
2005 
2006  gfan::ZMatrix i=Z->getInequalities();
2007  gfanZMatrixWriteFd(i,dd);
2008 
2009  gfan::ZMatrix e=Z->getEquations();
2010  gfanZMatrixWriteFd(e,dd);
2011 
2012  // assert(i.getWidth() == e.getWidth());
2013  return FALSE;
2014 }
2015 
2016 static gfan::Integer gfanIntegerReadFd(ssiInfo* dd)
2017 {
2018  mpz_t tmp;
2019  mpz_init(tmp);
2020  s_readmpz_base(dd->f_read,tmp,SSI_BASE);
2021  gfan::Integer n(tmp);
2022  mpz_clear(tmp);
2023  return n;
2024 }
2025 
2026 static gfan::ZMatrix gfanZMatrixReadFd(ssiInfo* dd)
2027 {
2028  int r=s_readint(dd->f_read);
2029  int c=s_readint(dd->f_read);
2030 
2031  gfan::ZMatrix M(r,c);
2032  for (int i=0; i<r; i++)
2033  {
2034  for (int j=0; j<c; j++)
2035  {
2036  M[i][j] = gfanIntegerReadFd(dd);
2037  }
2038  }
2039  return M;
2040 }
2041 
2042 BOOLEAN bbcone_deserialize(blackbox **b, void **d, si_link f)
2043 {
2044  ssiInfo *dd = (ssiInfo *)f->data;
2045  int preassumptions = s_readint(dd->f_read);
2046 
2047  gfan::ZMatrix i = gfanZMatrixReadFd(dd);
2048  gfan::ZMatrix e = gfanZMatrixReadFd(dd);
2049 
2050  // if (e.getHeight()==0) // why is e sometimes 0x0 and sometimex 0xn???
2051  // e = gfan::ZMatrix(0,i.getWidth());
2052 
2053  gfan::ZCone* Z = new gfan::ZCone(i,e,preassumptions);
2054 
2055  *d=Z;
2056  return FALSE;
2057 }
2058 
2060 {
2061  blackbox *b=(blackbox*)omAlloc0(sizeof(blackbox));
2062  // all undefined entries will be set to default in setBlackboxStuff
2063  // the default Print is quite usefull,
2064  // all other are simply error messages
2065  b->blackbox_destroy=bbcone_destroy;
2066  b->blackbox_String=bbcone_String;
2067  // b->blackbox_Print=blackbox_default_Print;
2068  b->blackbox_Init=bbcone_Init;
2069  b->blackbox_Copy=bbcone_Copy;
2070  b->blackbox_Assign=bbcone_Assign;
2071  b->blackbox_Op2=bbcone_Op2;
2072  b->blackbox_serialize=bbcone_serialize;
2073  b->blackbox_deserialize=bbcone_deserialize;
2074  p->iiAddCproc("gfan.lib","coneViaInequalities",FALSE,coneViaNormals);
2075  p->iiAddCproc("gfan.lib","coneViaPoints",FALSE,coneViaRays);
2076  p->iiAddCproc("","listContainsCone",FALSE,containsCone);
2077  // iiAddCproc("gfan.lib","makePolytope",FALSE,coneToPolytope);
2078  p->iiAddCproc("gfan.lib","ambientDimension",FALSE,ambientDimension);
2079  p->iiAddCproc("gfan.lib","canonicalizeCone",FALSE,canonicalizeCone);
2080  p->iiAddCproc("gfan.lib","codimension",FALSE,codimension);
2081  p->iiAddCproc("gfan.lib","coneLink",FALSE,coneLink);
2082  p->iiAddCproc("gfan.lib","containsAsFace",FALSE,hasFace);
2083  p->iiAddCproc("gfan.lib","containsInSupport",FALSE,containsInSupport);
2084  p->iiAddCproc("gfan.lib","containsPositiveVector",FALSE,containsPositiveVector);
2085  p->iiAddCproc("gfan.lib","containsRelatively",FALSE,containsRelatively);
2086  p->iiAddCproc("gfan.lib","convexHull",FALSE,convexHull);
2087  p->iiAddCproc("gfan.lib","convexIntersection",FALSE,intersectCones);
2088  p->iiAddCproc("gfan.lib","convexIntersectionOld",FALSE,convexIntersectionOld);
2089  p->iiAddCproc("gfan.lib","dimension",FALSE,dimension);
2090  p->iiAddCproc("gfan.lib","dualCone",FALSE,dualCone);
2091  p->iiAddCproc("gfan.lib","equations",FALSE,equations);
2092  p->iiAddCproc("gfan.lib","facets",FALSE,facets);
2093  p->iiAddCproc("gfan.lib","generatorsOfLinealitySpace",FALSE,generatorsOfLinealitySpace);
2094  p->iiAddCproc("gfan.lib","generatorsOfSpan",FALSE,generatorsOfSpan);
2095  p->iiAddCproc("gfan.lib","getLinearForms",FALSE,getLinearForms);
2096  p->iiAddCproc("gfan.lib","getMultiplicity",FALSE,getMultiplicity);
2097  p->iiAddCproc("gfan.lib","inequalities",FALSE,inequalities);
2098  p->iiAddCproc("gfan.lib","isFullSpace",FALSE,isFullSpace);
2099  p->iiAddCproc("gfan.lib","isOrigin",FALSE,isOrigin);
2100  p->iiAddCproc("gfan.lib","isSimplicial",FALSE,isSimplicial);
2101  p->iiAddCproc("gfan.lib","linealityDimension",FALSE,linealityDimension);
2102  p->iiAddCproc("gfan.lib","linealitySpace",FALSE,linealitySpace);
2103  p->iiAddCproc("gfan.lib","negatedCone",FALSE,negatedCone);
2104  p->iiAddCproc("gfan.lib","quotientLatticeBasis",FALSE,quotientLatticeBasis);
2105  p->iiAddCproc("gfan.lib","randomPoint",FALSE,randomPoint);
2106  p->iiAddCproc("gfan.lib","rays",FALSE,rays);
2107  p->iiAddCproc("gfan.lib","relativeInteriorPoint",FALSE,relativeInteriorPoint);
2108  p->iiAddCproc("gfan.lib","semigroupGenerator",FALSE,semigroupGenerator);
2109  p->iiAddCproc("gfan.lib","setLinearForms",FALSE,setLinearForms);
2110  p->iiAddCproc("gfan.lib","setMultiplicity",FALSE,setMultiplicity);
2111  p->iiAddCproc("gfan.lib","span",FALSE,impliedEquations);
2112  p->iiAddCproc("gfan.lib","uniquePoint",FALSE,uniquePoint);
2113  p->iiAddCproc("gfan.lib","faceContaining",FALSE,faceContaining);
2114  coneID=setBlackboxStuff(b,"cone");
2115 }
2116 
2117 #endif
bigintmat * transpose()
Definition: bigintmat.cc:37
BOOLEAN isFullSpace(leftv res, leftv args)
Definition: bbcone.cc:884
const CanonicalForm int s
Definition: facAbsFact.cc:55
sleftv * m
Definition: lists.h:45
int j
Definition: facHensel.cc:105
BOOLEAN coneViaNormals(leftv res, leftv args)
Definition: bbcone.cc:352
Class used for (list of) interpreter objects.
Definition: subexpr.h:82
BOOLEAN getMultiplicity(leftv res, leftv args)
Definition: bbcone.cc:850
BOOLEAN dualCone(leftv res, leftv args)
Definition: bbcone.cc:962
Definition: tok.h:96
BOOLEAN containsPositiveVector(leftv res, leftv args)
Definition: bbcone.cc:928
gfan::ZMatrix liftUp(const gfan::ZMatrix &zm)
Definition: bbcone.cc:1149
BOOLEAN containsRelatively(leftv res, leftv args)
Definition: bbcone.cc:1666
Definition: lists.h:22
BOOLEAN canonicalizeCone(leftv res, leftv args)
Definition: bbcone.cc:1747
BOOLEAN bbcone_deserialize(blackbox **b, void **d, si_link f)
Definition: bbcone.cc:2042
#define FALSE
Definition: auxiliary.h:94
BOOLEAN quotientLatticeBasis(leftv res, leftv args)
Definition: bbcone.cc:689
Definition: tok.h:38
Matrices of numbers.
Definition: bigintmat.h:51
BOOLEAN coneToPolytope(leftv res, leftv args)
Definition: bbcone.cc:1169
BOOLEAN generatorsOfSpan(leftv res, leftv args)
Definition: bbcone.cc:628
bigintmat * iv2bim(intvec *b, const coeffs C)
Definition: bigintmat.cc:349
Definition: gfan.h:44
bigintmat * zMatrixToBigintmat(const gfan::ZMatrix &zm)
#define string
Definition: libparse.cc:1250
BOOLEAN coneViaRays(leftv res, leftv args)
Definition: bbcone.cc:523
#define TRUE
Definition: auxiliary.h:98
void WerrorS(const char *s)
Definition: feFopen.cc:24
int k
Definition: cfEzgcd.cc:92
void s_readmpz_base(s_buff F, mpz_ptr a, int base)
Definition: s_buff.cc:207
bigintmat * zVectorToBigintmat(const gfan::ZVector &zv)
BOOLEAN containsInSupport(leftv res, leftv args)
Definition: bbcone.cc:1512
int fanID
Definition: bbfan.cc:19
BOOLEAN blackboxDefaultOp2(int, leftv, leftv, leftv)
default procedure blackboxDefaultOp2, to be called as "default:" branch
Definition: blackbox.cc:81
std::pair< gfan::ZMatrix, gfan::ZMatrix > interiorPointsAndNormalsOfFacets(const gfan::ZCone zc, const std::set< gfan::ZVector > &exceptThesePoints, const bool onlyLowerHalfSpace)
Definition: bbcone.cc:1902
static gfan::ZMatrix gfanZMatrixReadFd(ssiInfo *dd)
Definition: bbcone.cc:2026
coeffs coeffs_BIGINT
Definition: ipid.cc:52
int Typ()
Definition: subexpr.cc:992
BOOLEAN convexIntersectionOld(leftv res, leftv args)
Definition: bbcone.cc:1576
static BOOLEAN bbcone_Op2(int op, leftv res, leftv i1, leftv i2)
Definition: bbcone.cc:164
gfan::ZVector randomPoint(const gfan::ZCone *zc)
Definition: bbcone.cc:1055
Definition: idrec.h:34
int getAmbientDimension(gfan::ZFan *zf)
Definition: bbfan.cc:246
#define IDHDL
Definition: tok.h:31
BOOLEAN bbcone_serialize(blackbox *b, void *d, si_link f)
Definition: bbcone.cc:1993
void * data
Definition: subexpr.h:88
#define M
Definition: sirandom.c:24
CanonicalForm b
Definition: cfModGcd.cc:4044
BOOLEAN inequalities(leftv res, leftv args)
Definition: bbcone.cc:560
BOOLEAN linealitySpace(leftv res, leftv args)
Definition: bbcone.cc:945
int polytopeID
Definition: bbpolytope.cc:16
BOOLEAN relativeInteriorPoint(leftv res, leftv args)
Definition: bbcone.cc:1021
Definition: intvec.h:17
static BOOLEAN jjCONERAYS1(leftv res, leftv v)
Definition: bbcone.cc:389
BOOLEAN semigroupGenerator(leftv res, leftv args)
Definition: bbcone.cc:996
CanonicalForm res
Definition: facAbsFact.cc:64
int s_readint(s_buff F)
Definition: s_buff.cc:110
#define omFree(addr)
Definition: omAllocDecl.h:261
gfan::ZMatrix * bigintmatToZMatrix(const bigintmat &bim)
BOOLEAN isSimplicial(leftv res, leftv args)
Definition: bbcone.cc:901
BOOLEAN codimension(leftv res, leftv args)
Definition: bbcone.cc:791
BOOLEAN coneLink(leftv res, leftv args)
Definition: bbcone.cc:1463
BOOLEAN negatedCone(leftv res, leftv args)
Definition: bbcone.cc:979
BOOLEAN getLinearForms(leftv res, leftv args)
Definition: bbcone.cc:706
int cols() const
Definition: bigintmat.h:145
static BOOLEAN jjCONERAYS2(leftv res, leftv u, leftv v)
Definition: bbcone.cc:416
int coneID
Definition: bbcone.cc:25
#define SSI_BASE
Definition: auxiliary.h:149
number integerToNumber(const gfan::Integer &I)
FILE * f
Definition: checklibs.c:9
int i
Definition: cfEzgcd.cc:125
int getCodimension(gfan::ZFan *zf)
Definition: bbfan.cc:251
int lSize(lists L)
Definition: lists.cc:25
leftv next
Definition: subexpr.h:86
static BOOLEAN jjCONENORMALS2(leftv res, leftv u, leftv v)
Definition: bbcone.cc:259
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
BOOLEAN rays(leftv res, leftv args)
Definition: bbcone.cc:662
void bbcone_destroy(blackbox *, void *d)
Definition: bbcone.cc:148
BOOLEAN dimension(leftv res, leftv args)
Definition: bbcone.cc:757
void bbcone_setup(SModulFunctions *p)
Definition: bbcone.cc:2059
#define NULL
Definition: omList.c:10
slists * lists
Definition: mpr_numeric.h:146
void * bbcone_Init(blackbox *)
Definition: bbcone.cc:80
BOOLEAN containsCone(leftv res, leftv args)
Definition: bbcone.cc:1765
static BOOLEAN jjCONERAYS3(leftv res, leftv u, leftv v, leftv w)
Definition: bbcone.cc:464
static BOOLEAN jjCONENORMALS3(leftv res, leftv u, leftv v, leftv w)
Definition: bbcone.cc:302
BOOLEAN uniquePoint(leftv res, leftv args)
Definition: bbcone.cc:1038
BOOLEAN equations(leftv res, leftv args)
Definition: bbcone.cc:577
const CanonicalForm & w
Definition: facAbsFact.cc:55
static void gfanIntegerWriteFd(gfan::Integer n, ssiInfo *dd)
Definition: bbcone.cc:1970
static void gfanZMatrixWriteFd(gfan::ZMatrix M, ssiInfo *dd)
Definition: bbcone.cc:1980
BOOLEAN facets(leftv res, leftv args)
Definition: bbcone.cc:594
int rtyp
Definition: subexpr.h:91
BOOLEAN setLinearForms(leftv res, leftv args)
Definition: bbcone.cc:1115
BOOLEAN ambientDimension(leftv res, leftv args)
Definition: bbcone.cc:723
void * Data()
Definition: subexpr.cc:1134
char * bbcone_String(blackbox *, void *d)
Definition: bbcone.cc:138
Definition: tok.h:118
BOOLEAN isOrigin(leftv res, leftv args)
Definition: bbcone.cc:867
int getLinealityDimension(gfan::ZFan *zf)
Definition: bbfan.cc:261
int getDimension(gfan::ZFan *zf)
Definition: bbfan.cc:256
BOOLEAN bbcone_Assign(leftv l, leftv r)
Definition: bbcone.cc:85
BOOLEAN faceContaining(leftv res, leftv args)
Definition: bbcone.cc:1804
BOOLEAN linealityDimension(leftv res, leftv args)
Definition: bbcone.cc:825
std::string toString(const gfan::ZCone *const c)
Definition: bbcone.cc:27
static BOOLEAN jjCONENORMALS1(leftv res, leftv v)
Definition: bbcone.cc:237
BOOLEAN convexHull(leftv res, leftv args)
Definition: bbcone.cc:1345
int(* iiAddCproc)(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition: ipid.h:69
int p
Definition: cfModGcd.cc:4019
BOOLEAN generatorsOfLinealitySpace(leftv res, leftv args)
Definition: bbcone.cc:645
BOOLEAN impliedEquations(leftv res, leftv args)
Definition: bbcone.cc:611
#define IDDATA(a)
Definition: ipid.h:121
BOOLEAN hasFace(leftv res, leftv args)
Definition: bbcone.cc:1710
BOOLEAN intersectCones(leftv res, leftv args)
Definition: bbcone.cc:1188
int setBlackboxStuff(blackbox *bb, const char *n)
define a new type
Definition: blackbox.cc:126
int BOOLEAN
Definition: auxiliary.h:85
#define NONE
Definition: tok.h:218
void * bbcone_Copy(blackbox *, void *d)
Definition: bbcone.cc:157
static int sign(int x)
Definition: ring.cc:3328
void Werror(const char *fmt,...)
Definition: reporter.cc:189
void * CopyD(int t)
Definition: subexpr.cc:703
gfan::ZMatrix interiorPointsOfFacets(const gfan::ZCone &zc, const std::set< gfan::ZVector > &exceptThese)
Definition: bbcone.cc:1848
gfan::ZVector * bigintmatToZVector(const bigintmat &bim)
int siRand()
Definition: sirandom.c:41
#define omAlloc0(size)
Definition: omAllocDecl.h:211
int l
Definition: cfEzgcd.cc:93
BOOLEAN setMultiplicity(leftv res, leftv args)
Definition: bbcone.cc:1093
static gfan::Integer gfanIntegerReadFd(ssiInfo *dd)
Definition: bbcone.cc:2016
#define omStrDup(s)
Definition: omAllocDecl.h:263