My Project
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 VAR 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 int siRandBound(const int b)
1056 {
1057  int n = 0;
1058  while (n==0)
1059  {
1060  n = siRand();
1061  if (b>1)
1062  {
1063  n = n % b;
1064  }
1065  }
1066  return n;
1067 }
1068 
1069 gfan::ZVector randomPoint(const gfan::ZCone* zc, const int b)
1070 {
1071  gfan::ZVector rp = gfan::ZVector(zc->ambientDimension());
1072 
1073  gfan::ZMatrix rays = zc->extremeRays();
1074  for (int i=0; i<rays.getHeight(); i++)
1075  rp += siRandBound(b) * rays[i].toVector();
1076 
1077  // gfan::ZMatrix lins = zc->generatorsOfLinealitySpace();
1078  // for (int i=0; i<lins.getHeight(); i++)
1079  // {
1080  // int n = siRandBound(b);
1081  // rp = rp + n * lins[i].toVector();
1082  // }
1083 
1084  return rp;
1085 }
1086 
1088 {
1089  leftv u = args;
1090  if ((u != NULL) && (u->Typ() == coneID))
1091  {
1092  gfan::initializeCddlibIfRequired();
1093 
1094  int b = 0;
1095  leftv v = u->next;
1096  if ((v != NULL) && (v->Typ() == INT_CMD))
1097  {
1098  b = (int) (long) v->Data();
1099  b = b+1;
1100  }
1101 
1102  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
1103  gfan::ZVector zv = randomPoint(zc,b);
1104 
1105  res->rtyp = BIGINTMAT_CMD;
1106  res->data = (void*) zVectorToBigintmat(zv);
1107  gfan::deinitializeCddlibIfRequired();
1108  return FALSE;
1109  }
1110  WerrorS("randomPoint: unexpected parameters");
1111  return TRUE;
1112 }
1113 
1115 {
1116  leftv u = args;
1117  if ((u != NULL) && (u->Typ() == coneID))
1118  {
1119  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
1120  leftv v = u->next;
1121  if ((v != NULL) && (v->Typ() == INT_CMD))
1122  {
1123  gfan::initializeCddlibIfRequired();
1124  int val = (int)(long)v->Data();
1125  zc->setMultiplicity(gfan::Integer(val));
1126  res->rtyp = NONE;
1127  res->data = NULL;
1128  gfan::deinitializeCddlibIfRequired();
1129  return FALSE;
1130  }
1131  }
1132  WerrorS("setMultiplicity: unexpected parameters");
1133  return TRUE;
1134 }
1135 
1137 {
1138  leftv u = args;
1139  if ((u != NULL) && (u->Typ() == coneID))
1140  {
1141  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
1142  leftv v = u->next;
1143  if ((v != NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTVEC_CMD)))
1144  {
1145  gfan::initializeCddlibIfRequired();
1146  bigintmat* mat=NULL;
1147  if (v->Typ() == INTVEC_CMD)
1148  {
1149  intvec* mat0 = (intvec*) v->Data();
1150  mat = iv2bim(mat0,coeffs_BIGINT)->transpose();
1151  }
1152  else
1153  mat = (bigintmat*) v->Data();
1154  gfan::ZMatrix* zm = bigintmatToZMatrix(mat);
1155  zc->setLinearForms(*zm);
1156  res->rtyp = NONE;
1157  res->data = NULL;
1158 
1159  delete zm;
1160  if (v->Typ() == INTVEC_CMD)
1161  delete mat;
1162  gfan::deinitializeCddlibIfRequired();
1163  return FALSE;
1164  }
1165  }
1166  WerrorS("setLinearForms: unexpected parameters");
1167  return TRUE;
1168 }
1169 
1170 gfan::ZMatrix liftUp(const gfan::ZMatrix &zm)
1171 {
1172  int r=zm.getHeight();
1173  int c=zm.getWidth();
1174  gfan::ZMatrix zn(r+1,c+1);
1175  zn[1][1]=1;
1176  for (int i=0; i<r; i++)
1177  for (int j=0; j<c; j++)
1178  zn[i+1][j+1]=zm[i][j];
1179  return zn;
1180 }
1181 
1182 gfan::ZCone liftUp(const gfan::ZCone &zc)
1183 {
1184  gfan::ZMatrix ineq=zc.getInequalities();
1185  gfan::ZMatrix eq=zc.getEquations();
1186  gfan::ZCone zd(liftUp(ineq),liftUp(eq));
1187  return zd;
1188 }
1189 
1191 {
1192  leftv u = args;
1193  if ((u != NULL) && (u->Typ() == coneID))
1194  {
1195  gfan::initializeCddlibIfRequired();
1196  gfan::ZCone* zc = (gfan::ZCone*) u->Data();
1197  gfan::ZMatrix ineq=zc->getInequalities();
1198  gfan::ZMatrix eq=zc->getEquations();
1199  gfan::ZCone* zd = new gfan::ZCone(liftUp(ineq),liftUp(eq));
1200  res->rtyp = polytopeID;
1201  res->data = (void*) zd;
1202  gfan::deinitializeCddlibIfRequired();
1203  return FALSE;
1204  }
1205  WerrorS("makePolytope: unexpected parameters");
1206  return TRUE;
1207 }
1208 
1210 {
1211  leftv u = args;
1212  if ((u != NULL) && (u->Typ() == coneID))
1213  {
1214  leftv v = u->next;
1215  if ((v != NULL) && (v->Typ() == coneID))
1216  {
1217  gfan::initializeCddlibIfRequired();
1218  gfan::ZCone* zc1 = (gfan::ZCone*)u->Data();
1219  gfan::ZCone* zc2 = (gfan::ZCone*)v->Data();
1220  int d1 = zc1->ambientDimension();
1221  int d2 = zc2->ambientDimension();
1222  if (d1 != d2)
1223  {
1224  Werror("expected ambient dims of both cones to coincide\n"
1225  "but got %d and %d", d1, d2);
1226  gfan::deinitializeCddlibIfRequired();
1227  return TRUE;
1228  }
1229  gfan::ZCone zc3 = gfan::intersection(*zc1, *zc2);
1230  zc3.canonicalize();
1231  res->rtyp = coneID;
1232  res->data = (void *)new gfan::ZCone(zc3);
1233  gfan::deinitializeCddlibIfRequired();
1234  return FALSE;
1235  }
1236  if ((v != NULL) && (v->Typ() == polytopeID))
1237  {
1238  gfan::initializeCddlibIfRequired();
1239  gfan::ZCone* zc11 = (gfan::ZCone*)u->Data();
1240  gfan::ZCone zc1 = liftUp(*zc11);
1241  gfan::ZCone* zc2 = (gfan::ZCone*)v->Data();
1242  int d1 = zc1.ambientDimension();
1243  int d2 = zc2->ambientDimension();
1244  if (d1 != d2)
1245  {
1246  Werror("expected ambient dims of both cones to coincide\n"
1247  "but got %d and %d", d1, d2);
1248  gfan::deinitializeCddlibIfRequired();
1249  return TRUE;
1250  }
1251  gfan::ZCone zc3 = gfan::intersection(zc1, *zc2);
1252  zc3.canonicalize();
1253  res->rtyp = polytopeID;
1254  res->data = (void *)new gfan::ZCone(zc3);
1255  gfan::deinitializeCddlibIfRequired();
1256  return FALSE;
1257  }
1258  }
1259  if ((u != NULL) && (u->Typ() == LIST_CMD))
1260  {
1261  if (u->next == NULL)
1262  {
1263  lists l = (lists) u->Data();
1264 
1265  // find the total number of inequalities and equations
1266  int r1=0; // total number of inequalities
1267  int r2=0; // total number of equations
1268  int c=0; // ambient dimension
1269  for (int i=0; i<=lSize(l); i++)
1270  {
1271  if (l->m[i].Typ() != coneID)
1272  {
1273  WerrorS("convexIntersection: entries of wrong type in list");
1274  return TRUE;
1275  }
1276  gfan::ZCone* ll = (gfan::ZCone*) l->m[i].Data();
1277  r1 = r1 + ll->getInequalities().getHeight();
1278  r2 = r2 + ll->getEquations().getHeight();
1279  }
1280  if (lSize(l)>=0)
1281  {
1282  gfan::ZCone* ll = (gfan::ZCone*) l->m[0].Data();
1283  c = ll->getInequalities().getWidth();
1284  }
1285  gfan::ZMatrix totalIneqs(r1,c);
1286  gfan::ZMatrix totalEqs(r2,c);
1287 
1288  // concat all inequalities and equations
1289  r1=0; // counter for inequalities
1290  r2=0; // counter for equations
1291  for (int i=0; i<=lSize(l); i++)
1292  {
1293  gfan::ZCone* ll = (gfan::ZCone*) l->m[i].Data();
1294  gfan::ZMatrix ineqs = ll->getInequalities();
1295  for (int j=0; j<ineqs.getHeight(); j++)
1296  {
1297  totalIneqs[r1]=ineqs[j];
1298  r1 = r1+1;
1299  }
1300  gfan::ZMatrix eqs = ll->getEquations();
1301  for (int j=0; j<eqs.getHeight(); j++)
1302  {
1303  totalEqs[r2]=eqs[j];
1304  r2 = r2+1;
1305  }
1306  }
1307 
1308  gfan::ZCone* zc = new gfan::ZCone(totalIneqs,totalEqs);
1309  zc->canonicalize();
1310  res->rtyp = coneID;
1311  res->data = (void *) zc;
1312  return FALSE;
1313  }
1314  }
1315  if ((u != NULL) && (u->Typ() == polytopeID))
1316  {
1317  leftv v = u->next;
1318  if ((v != NULL) && (v->Typ() == coneID))
1319  {
1320  gfan::initializeCddlibIfRequired();
1321  gfan::ZCone* zc1 = (gfan::ZCone*)u->Data();
1322  gfan::ZCone* zc22 = (gfan::ZCone*)v->Data();
1323  gfan::ZCone zc2 = liftUp(*zc22);
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  if ((v != NULL) && (v->Typ() == polytopeID))
1341  {
1342  gfan::initializeCddlibIfRequired();
1343  gfan::ZCone* zc1 = (gfan::ZCone*)u->Data();
1344  gfan::ZCone* zc2 = (gfan::ZCone*)v->Data();
1345  int d1 = zc1->ambientDimension();
1346  int d2 = zc2->ambientDimension();
1347  if (d1 != d2)
1348  {
1349  Werror("expected ambient dims of both cones to coincide\n"
1350  "but got %d and %d", d1, d2);
1351  gfan::deinitializeCddlibIfRequired();
1352  return TRUE;
1353  }
1354  gfan::ZCone zc3 = gfan::intersection(*zc1, *zc2);
1355  zc3.canonicalize();
1356  res->rtyp = polytopeID;
1357  res->data = (void *)new gfan::ZCone(zc3);
1358  gfan::deinitializeCddlibIfRequired();
1359  return FALSE;
1360  }
1361  }
1362  WerrorS("convexIntersection: unexpected parameters");
1363  return TRUE;
1364 }
1365 
1367 {
1368  leftv u = args;
1369  if ((u != NULL) && (u->Typ() == coneID))
1370  {
1371  leftv v = u->next;
1372  if ((v != NULL) && (v->Typ() == coneID))
1373  {
1374  gfan::initializeCddlibIfRequired();
1375  gfan::ZCone* zc1 = (gfan::ZCone*)u->Data();
1376  gfan::ZCone* zc2 = (gfan::ZCone*)v->Data();
1377  int d1 = zc1->ambientDimension();
1378  int d2 = zc2->ambientDimension();
1379  if (d1 != d2)
1380  {
1381  Werror("expected ambient dims of both cones to coincide\n"
1382  "but got %d and %d", d1, d2);
1383  gfan::deinitializeCddlibIfRequired();
1384  return TRUE;
1385  }
1386  gfan::ZMatrix zm1 = zc1->extremeRays();
1387  gfan::ZMatrix zm2 = zc2->extremeRays();
1388  gfan::ZMatrix zn1 = zc1->generatorsOfLinealitySpace();
1389  gfan::ZMatrix zn2 = zc2->generatorsOfLinealitySpace();
1390  gfan::ZMatrix zm = combineOnTop(zm1,zm2);
1391  gfan::ZMatrix zn = combineOnTop(zn1,zn2);
1392  gfan::ZCone* zc = new gfan::ZCone();
1393  *zc = gfan::ZCone::givenByRays(zm, zn);
1394  res->rtyp = coneID;
1395  res->data = (void*) zc;
1396  gfan::deinitializeCddlibIfRequired();
1397  return FALSE;
1398  }
1399  if ((v != NULL) && (v->Typ() == polytopeID))
1400  {
1401  gfan::initializeCddlibIfRequired();
1402  gfan::ZCone* zc11 = (gfan::ZCone*)u->Data();
1403  gfan::ZCone zc1 = liftUp(*zc11);
1404  gfan::ZCone* zc2 = (gfan::ZCone*)v->Data();
1405  int d1 = zc1.ambientDimension()-1;
1406  int d2 = zc2->ambientDimension()-1;
1407  if (d1 != d2)
1408  {
1409  Werror("expected ambient dims of both cones to coincide\n"
1410  "but got %d and %d", d1, d2);
1411  gfan::deinitializeCddlibIfRequired();
1412  return TRUE;
1413  }
1414  gfan::ZMatrix zm1 = zc1.extremeRays();
1415  gfan::ZMatrix zm2 = zc2->extremeRays();
1416  gfan::ZMatrix zn = zc1.generatorsOfLinealitySpace();
1417  gfan::ZMatrix zm = combineOnTop(zm1,zm2);
1418  gfan::ZCone* zc = new gfan::ZCone();
1419  *zc = gfan::ZCone::givenByRays(zm, zn);
1420  res->rtyp = polytopeID;
1421  res->data = (void*) zc;
1422  gfan::deinitializeCddlibIfRequired();
1423  return FALSE;
1424  }
1425  }
1426  if ((u != NULL) && (u->Typ() == polytopeID))
1427  {
1428  leftv v = u->next;
1429  if ((v != NULL) && (v->Typ() == coneID))
1430  {
1431  gfan::initializeCddlibIfRequired();
1432  gfan::ZCone* zc1 = (gfan::ZCone*)u->Data();
1433  gfan::ZCone* zc22 = (gfan::ZCone*)v->Data();
1434  gfan::ZCone zc2 = liftUp(*zc22);
1435  int d1 = zc1->ambientDimension()-1;
1436  int d2 = zc2.ambientDimension()-1;
1437  if (d1 != d2)
1438  {
1439  Werror("expected ambient dims of both cones to coincide\n"
1440  "but got %d and %d", d1, d2);
1441  gfan::deinitializeCddlibIfRequired();
1442  return TRUE;
1443  }
1444  gfan::ZMatrix zm1 = zc1->extremeRays();
1445  gfan::ZMatrix zm2 = zc2.extremeRays();
1446  gfan::ZMatrix zn = zc2.generatorsOfLinealitySpace();
1447  gfan::ZMatrix zm = combineOnTop(zm1,zm2);
1448  gfan::ZCone* zc = new gfan::ZCone();
1449  *zc = gfan::ZCone::givenByRays(zm,gfan::ZMatrix(0, zm.getWidth()));
1450  res->rtyp = polytopeID;
1451  res->data = (void*) zc;
1452  gfan::deinitializeCddlibIfRequired();
1453  return FALSE;
1454  }
1455  if ((v != NULL) && (v->Typ() == polytopeID))
1456  {
1457  gfan::initializeCddlibIfRequired();
1458  gfan::ZCone* zc1 = (gfan::ZCone*)u->Data();
1459  gfan::ZCone* zc2 = (gfan::ZCone*)v->Data();
1460  int d1 = zc1->ambientDimension()-1;
1461  int d2 = zc2->ambientDimension()-1;
1462  if (d1 != d2)
1463  {
1464  Werror("expected ambient dims of both cones to coincide\n"
1465  "but got %d and %d", d1, d2);
1466  gfan::deinitializeCddlibIfRequired();
1467  return TRUE;
1468  }
1469  gfan::ZMatrix zm1 = zc1->extremeRays();
1470  gfan::ZMatrix zm2 = zc2->extremeRays();
1471  gfan::ZMatrix zm = combineOnTop(zm1,zm2);
1472  gfan::ZCone* zc = new gfan::ZCone();
1473  *zc = gfan::ZCone::givenByRays(zm,gfan::ZMatrix(0, zm.getWidth()));
1474  res->rtyp = polytopeID;
1475  res->data = (void*) zc;
1476  gfan::deinitializeCddlibIfRequired();
1477  return FALSE;
1478  }
1479  }
1480  WerrorS("convexHull: unexpected parameters");
1481  return TRUE;
1482 }
1483 
1485 {
1486  leftv u = args;
1487  if ((u != NULL) && (u->Typ() == coneID))
1488  {
1489  leftv v = u->next;
1490  if ((v != NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTVEC_CMD)))
1491  {
1492  gfan::initializeCddlibIfRequired();
1493  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
1494  bigintmat* iv = NULL;
1495  if (v->Typ() == INTVEC_CMD)
1496  {
1497  intvec* iv0 = (intvec*) v->Data();
1498  iv = iv2bim(iv0,coeffs_BIGINT)->transpose();
1499  }
1500  else
1501  iv = (bigintmat*)v->Data();
1502  gfan::ZVector* zv = bigintmatToZVector(iv);
1503  int d1 = zc->ambientDimension();
1504  int d2 = zv->size();
1505  if (d1 != d2)
1506  {
1507  Werror("expected ambient dim of cone and size of vector\n"
1508  " to be equal but got %d and %d", d1, d2);
1509  gfan::deinitializeCddlibIfRequired();
1510  return TRUE;
1511  }
1512  if(!zc->contains(*zv))
1513  {
1514  WerrorS("the provided intvec does not lie in the cone");
1515  gfan::deinitializeCddlibIfRequired();
1516  return TRUE;
1517  }
1518  gfan::ZCone* zd = new gfan::ZCone(zc->link(*zv));
1519  res->rtyp = coneID;
1520  res->data = (void *) zd;
1521 
1522  delete zv;
1523  if (v->Typ() == INTVEC_CMD)
1524  delete iv;
1525  gfan::deinitializeCddlibIfRequired();
1526  return FALSE;
1527  }
1528  }
1529  WerrorS("coneLink: unexpected parameters");
1530  return TRUE;
1531 }
1532 
1534 {
1535  leftv u=args;
1536  if ((u != NULL) && (u->Typ() == coneID))
1537  {
1538  leftv v=u->next;
1539  if ((v != NULL) && (v->Typ() == coneID))
1540  {
1541  gfan::initializeCddlibIfRequired();
1542  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
1543  gfan::ZCone* zd = (gfan::ZCone*)v->Data();
1544  int d1 = zc->ambientDimension();
1545  int d2 = zd->ambientDimension();
1546  if (d1 != d2)
1547  {
1548  Werror("expected cones with same ambient dimensions\n but got"
1549  " dimensions %d and %d", d1, d2);
1550  gfan::deinitializeCddlibIfRequired();
1551  return TRUE;
1552  }
1553  bool b = (zc->contains(*zd) ? 1 : 0);
1554  res->rtyp = INT_CMD;
1555  res->data = (void*) (long) b;
1556  gfan::deinitializeCddlibIfRequired();
1557  return FALSE;
1558  }
1559  if ((v != NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTVEC_CMD)))
1560  {
1561  gfan::initializeCddlibIfRequired();
1562  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
1563  bigintmat* iv = NULL;
1564  if (v->Typ() == INTVEC_CMD)
1565  {
1566  intvec* iv0 = (intvec*) v->Data();
1567  iv = iv2bim(iv0,coeffs_BIGINT)->transpose();
1568  }
1569  else
1570  iv = (bigintmat*)v->Data();
1571 
1572  gfan::ZVector* zv = bigintmatToZVector(iv);
1573  int d1 = zc->ambientDimension();
1574  int d2 = zv->size();
1575  if (d1 != d2)
1576  {
1577  Werror("expected cones with same ambient dimensions\n but got"
1578  " dimensions %d and %d", d1, d2);
1579  gfan::deinitializeCddlibIfRequired();
1580  return TRUE;
1581  }
1582  int b = zc->contains(*zv);
1583  res->rtyp = INT_CMD;
1584  res->data = (void*) (long) b;
1585 
1586  delete zv;
1587  if (v->Typ() == INTVEC_CMD)
1588  delete iv;
1589  gfan::deinitializeCddlibIfRequired();
1590  return FALSE;
1591  }
1592  }
1593  WerrorS("containsInSupport: unexpected parameters");
1594  return TRUE;
1595 }
1596 
1598 {
1599  leftv u = args;
1600  if ((u != NULL) && (u->Typ() == coneID))
1601  {
1602  leftv v = u->next;
1603  if ((v != NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTVEC_CMD)))
1604  {
1605  gfan::initializeCddlibIfRequired();
1606  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
1607  bigintmat* iv = NULL;
1608  if (v->Typ() == INTVEC_CMD)
1609  {
1610  intvec* iv0 = (intvec*) v->Data();
1611  iv = iv2bim(iv0,coeffs_BIGINT)->transpose();
1612  }
1613  else
1614  iv = (bigintmat*)v->Data();
1615  gfan::ZVector* zv = bigintmatToZVector(iv);
1616  int d1 = zc->ambientDimension();
1617  int d2 = zv->size();
1618  if (d1 == d2)
1619  {
1620  bool b = (zc->containsRelatively(*zv) ? 1 : 0);
1621  res->rtyp = INT_CMD;
1622  res->data = (void *) b;
1623  delete zv;
1624  if (v->Typ() == INTVEC_CMD)
1625  delete iv;
1626  gfan::deinitializeCddlibIfRequired();
1627  return FALSE;
1628  }
1629  delete zv;
1630  if (v->Typ() == INTVEC_CMD)
1631  delete iv;
1632  gfan::deinitializeCddlibIfRequired();
1633  Werror("expected ambient dim of cone and size of vector\n"
1634  "to be equal but got %d and %d", d1, d2);
1635  }
1636  }
1637  WerrorS("containsRelatively: unexpected parameters");
1638  return TRUE;
1639 }
1640 
1642 {
1643  leftv u=args;
1644  if ((u != NULL) && (u->Typ() == coneID))
1645  {
1646  leftv v=u->next;
1647  if ((v != NULL) && (v->Typ() == coneID))
1648  {
1649  gfan::initializeCddlibIfRequired();
1650  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
1651  gfan::ZCone* zd = (gfan::ZCone*)v->Data();
1652  bool b = zc->hasFace(*zd);
1653  res->rtyp = INT_CMD;
1654  res->data = (void*) (long) b;
1655  gfan::deinitializeCddlibIfRequired();
1656  return FALSE;
1657  }
1658  }
1659  if ((u != NULL) && (u->Typ() == polytopeID))
1660  {
1661  leftv v=u->next;
1662  if ((v != NULL) && (v->Typ() == polytopeID))
1663  {
1664  gfan::initializeCddlibIfRequired();
1665  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
1666  gfan::ZCone* zd = (gfan::ZCone*)v->Data();
1667  bool b = zc->hasFace(*zd);
1668  res->rtyp = INT_CMD;
1669  res->data = (void*) (long) b;
1670  gfan::deinitializeCddlibIfRequired();
1671  return FALSE;
1672  }
1673  }
1674  WerrorS("containsAsFace: unexpected parameters");
1675  return TRUE;
1676 }
1677 
1679 {
1680  leftv u=args;
1681  if ((u != NULL) && (u->Typ() == coneID))
1682  {
1683  gfan::initializeCddlibIfRequired();
1684  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
1685  gfan::ZCone* zd = new gfan::ZCone(*zc);
1686  zd->canonicalize();
1687  res->rtyp = coneID;
1688  res->data = (void*) zd;
1689  gfan::deinitializeCddlibIfRequired();
1690  return FALSE;
1691  }
1692  WerrorS("canonicalizeCone: unexpected parameters");
1693  return TRUE;
1694 }
1695 
1697 {
1698  leftv u=args;
1699  if ((u != NULL) && (u->Typ() == LIST_CMD))
1700  {
1701  leftv v=u->next;
1702  if ((v != NULL) && (v->Typ() == coneID))
1703  {
1704  gfan::initializeCddlibIfRequired();
1705  lists l = (lists) u->Data();
1706  gfan::ZCone* zc = (gfan::ZCone*) v->Data();
1707  zc->canonicalize();
1708  int b = 0;
1709  for (int i=0; i<=lSize(l); i++)
1710  {
1711  if (l->m[i].Typ() != coneID)
1712  {
1713  WerrorS("containsCone: entries of wrong type in list");
1714  gfan::deinitializeCddlibIfRequired();
1715  return TRUE;
1716  }
1717  gfan::ZCone* ll = (gfan::ZCone*) l->m[i].Data();
1718  ll->canonicalize();
1719  if (!((*ll) != (*zc)))
1720  {
1721  b = 1;
1722  break;
1723  }
1724  }
1725  res->rtyp = INT_CMD;
1726  res->data = (char*) (long) b;
1727  gfan::deinitializeCddlibIfRequired();
1728  return FALSE;
1729  }
1730  }
1731  WerrorS("containsCone: unexpected parameters");
1732  return TRUE;
1733 }
1734 
1736 {
1737  leftv u = args;
1738  if ((u != NULL) && (u->Typ() == coneID))
1739  {
1740  leftv v = u->next;
1741  if ((v != NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTVEC_CMD)))
1742  {
1743  gfan::initializeCddlibIfRequired();
1744  gfan::ZCone* zc = (gfan::ZCone*) u->Data();
1745 
1746  bigintmat* point1;
1747  if (v->Typ() == INTVEC_CMD)
1748  {
1749  intvec* point0 = (intvec*) v->Data();
1750  point1 = iv2bim(point0,coeffs_BIGINT)->transpose();
1751  }
1752  else
1753  point1 = (bigintmat*) v->Data();
1754  gfan::ZVector* point = bigintmatToZVector(*point1);
1755 
1756  if (!zc->contains(*point))
1757  {
1758  WerrorS("faceContaining: point not in cone");
1759  return TRUE;
1760  }
1761  res->rtyp = coneID;
1762  res->data = (void*) new gfan::ZCone(zc->faceContaining(*point));
1763 
1764  delete point;
1765  if (v->Typ() == INTVEC_CMD)
1766  delete point1;
1767  gfan::deinitializeCddlibIfRequired();
1768  return FALSE;
1769  }
1770  }
1771  WerrorS("faceContaining: unexpected parameters");
1772  return TRUE;
1773 }
1774 
1775 
1777 {
1778  leftv u=args;
1779  if ((u != NULL) && (u->Typ() == INT_CMD))
1780  {
1781  int n = (int) (long) u->Data();
1782  if (n>0)
1783  {
1784  intvec* v = new intvec(n);
1785  for (int i=0; i<n; i++)
1786  (*v)[i]=1;
1787  res->rtyp = INTVEC_CMD;
1788  res->data = (void*) v;
1789  return FALSE;
1790  }
1791  }
1792  WerrorS("onesVector: unexpected parameters");
1793  return TRUE;
1794 }
1795 
1796 /***
1797  * Computes a relative interior point for each facet of zc
1798  **/
1799 gfan::ZMatrix interiorPointsOfFacets(const gfan::ZCone &zc, const std::set<gfan::ZVector> &exceptThese)
1800 {
1801  gfan::ZMatrix inequalities = zc.getFacets();
1802  gfan::ZMatrix equations = zc.getImpliedEquations();
1803  int r = inequalities.getHeight();
1804  int c = inequalities.getWidth();
1805 
1806  /* our cone has r facets, if r==0 return empty matrices */
1807  gfan::ZMatrix relativeInteriorPoints = gfan::ZMatrix(0,c);
1808  if (r==0) return relativeInteriorPoints;
1809 
1810  /* next we iterate over each of the r facets,
1811  * build the respective cone and add it to the list
1812  * this is the i=0 case */
1813  gfan::ZMatrix newInequalities = inequalities.submatrix(1,0,r,c);
1814  gfan::ZMatrix newEquations = equations;
1815  newEquations.appendRow(inequalities[0]);
1816  gfan::ZCone facet = gfan::ZCone(newInequalities,newEquations);
1817  facet.canonicalize();
1818  gfan::ZVector interiorPoint = facet.getRelativeInteriorPoint();
1819  if (exceptThese.count(interiorPoint)==0)
1820  relativeInteriorPoints.appendRow(interiorPoint);
1821 
1822  /* these are the cases i=1,...,r-2 */
1823  for (int i=1; i<r-1; i++)
1824  {
1825  newInequalities = inequalities.submatrix(0,0,i,c);
1826  newInequalities.append(inequalities.submatrix(i+1,0,r,c));
1827  newEquations = equations;
1828  newEquations.appendRow(inequalities[i]);
1829  facet = gfan::ZCone(newInequalities,newEquations);
1830  facet.canonicalize();
1831  interiorPoint = facet.getRelativeInteriorPoint();
1832  if (exceptThese.count(interiorPoint)==0)
1833  relativeInteriorPoints.appendRow(interiorPoint);
1834  }
1835 
1836  /* this is the i=r-1 case */
1837  newInequalities = inequalities.submatrix(0,0,r-1,c);
1838  newEquations = equations;
1839  newEquations.appendRow(inequalities[r-1]);
1840  facet = gfan::ZCone(newInequalities,newEquations);
1841  facet.canonicalize();
1842  interiorPoint = facet.getRelativeInteriorPoint();
1843  if (exceptThese.count(interiorPoint)==0)
1844  relativeInteriorPoints.appendRow(interiorPoint);
1845 
1846  return relativeInteriorPoints;
1847 }
1848 
1849 
1850 /***
1851  * Computes a relative interior point and an outer normal vector for each facet of zc
1852  **/
1853 std::pair<gfan::ZMatrix,gfan::ZMatrix> interiorPointsAndNormalsOfFacets(const gfan::ZCone zc, const std::set<gfan::ZVector> &exceptThesePoints, const bool onlyLowerHalfSpace)
1854 {
1855  gfan::ZMatrix inequalities = zc.getFacets();
1856  gfan::ZMatrix equations = zc.getImpliedEquations();
1857  int r = inequalities.getHeight();
1858  int c = inequalities.getWidth();
1859 
1860  /* our cone has r facets, if r==0 return empty matrices */
1861  gfan::ZMatrix relativeInteriorPoints = gfan::ZMatrix(0,c);
1862  gfan::ZMatrix outerFacetNormals = gfan::ZMatrix(0,c);
1863  if (r==0)
1864  return std::make_pair(relativeInteriorPoints,outerFacetNormals);
1865 
1866  /* next we iterate over each of the r facets,
1867  * build the respective cone and add it to the list
1868  * this is the i=0 case */
1869  gfan::ZMatrix newInequalities = inequalities.submatrix(1,0,r,c);
1870  gfan::ZMatrix newEquations = equations;
1871  newEquations.appendRow(inequalities[0]);
1872  gfan::ZCone facet = gfan::ZCone(newInequalities,newEquations);
1873  gfan::ZVector interiorPoint = facet.getRelativeInteriorPoint();
1874  if (onlyLowerHalfSpace==false || interiorPoint[0].sign()<0)
1875  {
1876  if (exceptThesePoints.count(interiorPoint)==0)
1877  {
1878  relativeInteriorPoints.appendRow(interiorPoint);
1879  outerFacetNormals.appendRow(-inequalities[0].toVector());
1880  }
1881  }
1882 
1883  /* these are the cases i=1,...,r-2 */
1884  for (int i=1; i<r-1; i++)
1885  {
1886  newInequalities = inequalities.submatrix(0,0,i,c);
1887  newInequalities.append(inequalities.submatrix(i+1,0,r,c));
1888  newEquations = equations;
1889  newEquations.appendRow(inequalities[i]);
1890  facet = gfan::ZCone(newInequalities,newEquations);
1891  interiorPoint = facet.getRelativeInteriorPoint();
1892  if (onlyLowerHalfSpace==false || interiorPoint[0].sign()<0)
1893  {
1894  if (exceptThesePoints.count(interiorPoint)==0)
1895  {
1896  relativeInteriorPoints.appendRow(interiorPoint);
1897  outerFacetNormals.appendRow(-inequalities[i].toVector());
1898  }
1899  }
1900  }
1901 
1902  /* this is the i=r-1 case */
1903  newInequalities = inequalities.submatrix(0,0,r-1,c);
1904  newEquations = equations;
1905  newEquations.appendRow(inequalities[r-1]);
1906  facet = gfan::ZCone(newInequalities,newEquations);
1907  interiorPoint = facet.getRelativeInteriorPoint();
1908  if (onlyLowerHalfSpace==false || interiorPoint[0].sign()<0)
1909  {
1910  if (exceptThesePoints.count(interiorPoint)==0)
1911  {
1912  relativeInteriorPoints.appendRow(interiorPoint);
1913  outerFacetNormals.appendRow(-inequalities[r-1].toVector());
1914  }
1915  }
1916 
1917  return std::make_pair(relativeInteriorPoints,outerFacetNormals);
1918 }
1919 
1920 
1921 static void gfanIntegerWriteFd(gfan::Integer n, ssiInfo* dd)
1922 {
1923  mpz_t tmp;
1924  mpz_init(tmp);
1925  n.setGmp(tmp);
1926  mpz_out_str (dd->f_write,SSI_BASE, tmp);
1927  mpz_clear(tmp);
1928  fputc(' ',dd->f_write);
1929 }
1930 
1931 static void gfanZMatrixWriteFd(gfan::ZMatrix M, ssiInfo* dd)
1932 {
1933  fprintf(dd->f_write,"%d %d ",M.getHeight(),M.getWidth());
1934 
1935  for (int i=0; i<M.getHeight(); i++)
1936  {
1937  for (int j=0; j<M.getWidth(); j++)
1938  {
1939  gfanIntegerWriteFd(M[i][j],dd);
1940  }
1941  }
1942 }
1943 
1944 BOOLEAN bbcone_serialize(blackbox *b, void *d, si_link f)
1945 {
1946  ssiInfo *dd = (ssiInfo *)f->data;
1947 
1948  sleftv l;
1949  memset(&l,0,sizeof(l));
1950  l.rtyp=STRING_CMD;
1951  l.data=(void*)"cone";
1952  f->m->Write(f, &l);
1953 
1954  gfan::ZCone *Z = (gfan::ZCone*) d;
1955  fprintf(dd->f_write,"%d ",Z->areImpliedEquationsKnown()+Z->areFacetsKnown()*2);
1956 
1957  gfan::ZMatrix i=Z->getInequalities();
1958  gfanZMatrixWriteFd(i,dd);
1959 
1960  gfan::ZMatrix e=Z->getEquations();
1961  gfanZMatrixWriteFd(e,dd);
1962 
1963  // assert(i.getWidth() == e.getWidth());
1964  return FALSE;
1965 }
1966 
1967 static gfan::Integer gfanIntegerReadFd(ssiInfo* dd)
1968 {
1969  mpz_t tmp;
1970  mpz_init(tmp);
1971  s_readmpz_base(dd->f_read,tmp,SSI_BASE);
1972  gfan::Integer n(tmp);
1973  mpz_clear(tmp);
1974  return n;
1975 }
1976 
1977 static gfan::ZMatrix gfanZMatrixReadFd(ssiInfo* dd)
1978 {
1979  int r=s_readint(dd->f_read);
1980  int c=s_readint(dd->f_read);
1981 
1982  gfan::ZMatrix M(r,c);
1983  for (int i=0; i<r; i++)
1984  {
1985  for (int j=0; j<c; j++)
1986  {
1987  M[i][j] = gfanIntegerReadFd(dd);
1988  }
1989  }
1990  return M;
1991 }
1992 
1993 BOOLEAN bbcone_deserialize(blackbox **b, void **d, si_link f)
1994 {
1995  ssiInfo *dd = (ssiInfo *)f->data;
1996  int preassumptions = s_readint(dd->f_read);
1997 
1998  gfan::ZMatrix i = gfanZMatrixReadFd(dd);
1999  gfan::ZMatrix e = gfanZMatrixReadFd(dd);
2000 
2001  // if (e.getHeight()==0) // why is e sometimes 0x0 and sometimex 0xn???
2002  // e = gfan::ZMatrix(0,i.getWidth());
2003 
2004  gfan::ZCone* Z = new gfan::ZCone(i,e,preassumptions);
2005 
2006  *d=Z;
2007  return FALSE;
2008 }
2009 
2011 {
2012  gfan::initializeCddlibIfRequired();
2013  leftv u = args;
2014  if ((u != NULL) && (u->Typ() == coneID))
2015  {
2016  leftv v = u->next;
2017  if ((v != NULL) && (v->Typ() == coneID))
2018  {
2019  gfan::ZCone* zc1 = (gfan::ZCone*)u->Data();
2020  gfan::ZCone* zc2 = (gfan::ZCone*)v->Data();
2021  int d1 = zc1->ambientDimension();
2022  int d2 = zc2->ambientDimension();
2023  if (d1 != d2)
2024  {
2025  Werror("expected ambient dims of both cones to coincide\n"
2026  "but got %d and %d", d1, d2);
2027  return TRUE;
2028  }
2029  gfan::ZCone zc3 = gfan::intersection(*zc1, *zc2);
2030  zc3.canonicalize();
2031  res->rtyp = coneID;
2032  res->data = (void *)new gfan::ZCone(zc3);
2033  return FALSE;
2034  }
2035  if ((v != NULL) && (v->Typ() == polytopeID))
2036  {
2037  gfan::ZCone* zc11 = (gfan::ZCone*)u->Data();
2038  gfan::ZCone zc1 = liftUp(*zc11);
2039  gfan::ZCone* zc2 = (gfan::ZCone*)v->Data();
2040  int d1 = zc1.ambientDimension();
2041  int d2 = zc2->ambientDimension();
2042  if (d1 != d2)
2043  {
2044  Werror("expected ambient dims of both cones to coincide\n"
2045  "but got %d and %d", d1, d2);
2046  return TRUE;
2047  }
2048  gfan::ZCone zc3 = gfan::intersection(zc1, *zc2);
2049  zc3.canonicalize();
2050  res->rtyp = polytopeID;
2051  res->data = (void *)new gfan::ZCone(zc3);
2052  return FALSE;
2053  }
2054  }
2055  if ((u != NULL) && (u->Typ() == polytopeID))
2056  {
2057  leftv v = u->next;
2058  if ((v != NULL) && (v->Typ() == coneID))
2059  {
2060  gfan::ZCone* zc1 = (gfan::ZCone*)u->Data();
2061  gfan::ZCone* zc22 = (gfan::ZCone*)v->Data();
2062  gfan::ZCone zc2 = liftUp(*zc22);
2063  int d1 = zc1->ambientDimension();
2064  int d2 = zc2.ambientDimension();
2065  if (d1 != d2)
2066  {
2067  Werror("expected ambient dims of both cones to coincide\n"
2068  "but got %d and %d", d1, d2);
2069  return TRUE;
2070  }
2071  gfan::ZCone zc3 = gfan::intersection(*zc1, zc2);
2072  zc3.canonicalize();
2073  res->rtyp = polytopeID;
2074  res->data = (void *)new gfan::ZCone(zc3);
2075  return FALSE;
2076  }
2077  if ((v != NULL) && (v->Typ() == polytopeID))
2078  {
2079  gfan::ZCone* zc1 = (gfan::ZCone*)u->Data();
2080  gfan::ZCone* zc2 = (gfan::ZCone*)v->Data();
2081  int d1 = zc1->ambientDimension();
2082  int d2 = zc2->ambientDimension();
2083  if (d1 != d2)
2084  {
2085  Werror("expected ambient dims of both cones to coincide\n"
2086  "but got %d and %d", d1, d2);
2087  return TRUE;
2088  }
2089  gfan::ZCone zc3 = gfan::intersection(*zc1, *zc2);
2090  zc3.canonicalize();
2091  res->rtyp = polytopeID;
2092  res->data = (void *)new gfan::ZCone(zc3);
2093  return FALSE;
2094  }
2095  }
2096  WerrorS("convexIntersectionOld: unexpected parameters");
2097  return TRUE;
2098 }
2099 
2100 
2102 {
2103  blackbox *b=(blackbox*)omAlloc0(sizeof(blackbox));
2104  // all undefined entries will be set to default in setBlackboxStuff
2105  // the default Print is quite usefull,
2106  // all other are simply error messages
2107  b->blackbox_destroy=bbcone_destroy;
2108  b->blackbox_String=bbcone_String;
2109  // b->blackbox_Print=blackbox_default_Print;
2110  b->blackbox_Init=bbcone_Init;
2111  b->blackbox_Copy=bbcone_Copy;
2112  b->blackbox_Assign=bbcone_Assign;
2113  b->blackbox_Op2=bbcone_Op2;
2114  b->blackbox_serialize=bbcone_serialize;
2115  b->blackbox_deserialize=bbcone_deserialize;
2116  p->iiAddCproc("gfan.lib","coneViaInequalities",FALSE,coneViaNormals);
2117  p->iiAddCproc("gfan.lib","coneViaPoints",FALSE,coneViaRays);
2118  p->iiAddCproc("","listContainsCone",FALSE,containsCone);
2119  // iiAddCproc("gfan.lib","makePolytope",FALSE,coneToPolytope);
2120  p->iiAddCproc("gfan.lib","ambientDimension",FALSE,ambientDimension);
2121  p->iiAddCproc("gfan.lib","canonicalizeCone",FALSE,canonicalizeCone);
2122  p->iiAddCproc("gfan.lib","codimension",FALSE,codimension);
2123  p->iiAddCproc("gfan.lib","coneLink",FALSE,coneLink);
2124  p->iiAddCproc("gfan.lib","containsAsFace",FALSE,hasFace);
2125  p->iiAddCproc("gfan.lib","containsInSupport",FALSE,containsInSupport);
2126  p->iiAddCproc("gfan.lib","containsPositiveVector",FALSE,containsPositiveVector);
2127  p->iiAddCproc("gfan.lib","containsRelatively",FALSE,containsRelatively);
2128  p->iiAddCproc("gfan.lib","convexHull",FALSE,convexHull);
2129  p->iiAddCproc("gfan.lib","convexIntersection",FALSE,intersectCones);
2130  p->iiAddCproc("gfan.lib","dimension",FALSE,dimension);
2131  p->iiAddCproc("gfan.lib","dualCone",FALSE,dualCone);
2132  p->iiAddCproc("gfan.lib","equations",FALSE,equations);
2133  p->iiAddCproc("gfan.lib","facets",FALSE,facets);
2134  p->iiAddCproc("gfan.lib","generatorsOfLinealitySpace",FALSE,generatorsOfLinealitySpace);
2135  p->iiAddCproc("gfan.lib","generatorsOfSpan",FALSE,generatorsOfSpan);
2136  p->iiAddCproc("gfan.lib","getLinearForms",FALSE,getLinearForms);
2137  p->iiAddCproc("gfan.lib","getMultiplicity",FALSE,getMultiplicity);
2138  p->iiAddCproc("gfan.lib","inequalities",FALSE,inequalities);
2139  p->iiAddCproc("gfan.lib","isFullSpace",FALSE,isFullSpace);
2140  p->iiAddCproc("gfan.lib","isOrigin",FALSE,isOrigin);
2141  p->iiAddCproc("gfan.lib","isSimplicial",FALSE,isSimplicial);
2142  p->iiAddCproc("gfan.lib","linealityDimension",FALSE,linealityDimension);
2143  p->iiAddCproc("gfan.lib","linealitySpace",FALSE,linealitySpace);
2144  p->iiAddCproc("gfan.lib","negatedCone",FALSE,negatedCone);
2145  p->iiAddCproc("gfan.lib","quotientLatticeBasis",FALSE,quotientLatticeBasis);
2146  p->iiAddCproc("gfan.lib","randomPoint",FALSE,randomPoint);
2147  p->iiAddCproc("gfan.lib","rays",FALSE,rays);
2148  p->iiAddCproc("gfan.lib","relativeInteriorPoint",FALSE,relativeInteriorPoint);
2149  p->iiAddCproc("gfan.lib","semigroupGenerator",FALSE,semigroupGenerator);
2150  p->iiAddCproc("gfan.lib","setLinearForms",FALSE,setLinearForms);
2151  p->iiAddCproc("gfan.lib","setMultiplicity",FALSE,setMultiplicity);
2152  p->iiAddCproc("gfan.lib","span",FALSE,impliedEquations);
2153  p->iiAddCproc("gfan.lib","uniquePoint",FALSE,uniquePoint);
2154  p->iiAddCproc("gfan.lib","faceContaining",FALSE,faceContaining);
2155  p->iiAddCproc("gfan.lib","onesVector",FALSE,onesVector);
2156  p->iiAddCproc("gfan.lib","convexIntersectionOld",FALSE,convexIntersectionOld);
2157  coneID=setBlackboxStuff(b,"cone");
2158 }
2159 
2160 #endif
#define SSI_BASE
Definition: auxiliary.h:135
int BOOLEAN
Definition: auxiliary.h:87
#define TRUE
Definition: auxiliary.h:100
#define FALSE
Definition: auxiliary.h:96
BOOLEAN getMultiplicity(leftv res, leftv args)
Definition: bbcone.cc:850
BOOLEAN convexHull(leftv res, leftv args)
Definition: bbcone.cc:1366
BOOLEAN isFullSpace(leftv res, leftv args)
Definition: bbcone.cc:884
BOOLEAN canonicalizeCone(leftv res, leftv args)
Definition: bbcone.cc:1678
BOOLEAN bbcone_deserialize(blackbox **b, void **d, si_link f)
Definition: bbcone.cc:1993
BOOLEAN quotientLatticeBasis(leftv res, leftv args)
Definition: bbcone.cc:689
BOOLEAN onesVector(leftv res, leftv args)
Definition: bbcone.cc:1776
BOOLEAN convexIntersectionOld(leftv res, leftv args)
Definition: bbcone.cc:2010
BOOLEAN getLinearForms(leftv res, leftv args)
Definition: bbcone.cc:706
BOOLEAN codimension(leftv res, leftv args)
Definition: bbcone.cc:791
int siRandBound(const int b)
Definition: bbcone.cc:1055
void bbcone_destroy(blackbox *, void *d)
Definition: bbcone.cc:148
BOOLEAN facets(leftv res, leftv args)
Definition: bbcone.cc:594
BOOLEAN impliedEquations(leftv res, leftv args)
Definition: bbcone.cc:611
BOOLEAN uniquePoint(leftv res, leftv args)
Definition: bbcone.cc:1038
BOOLEAN isSimplicial(leftv res, leftv args)
Definition: bbcone.cc:901
static BOOLEAN jjCONENORMALS1(leftv res, leftv v)
Definition: bbcone.cc:237
BOOLEAN ambientDimension(leftv res, leftv args)
Definition: bbcone.cc:723
static gfan::ZMatrix gfanZMatrixReadFd(ssiInfo *dd)
Definition: bbcone.cc:1977
void * bbcone_Init(blackbox *)
Definition: bbcone.cc:80
BOOLEAN bbcone_Assign(leftv l, leftv r)
Definition: bbcone.cc:85
BOOLEAN coneLink(leftv res, leftv args)
Definition: bbcone.cc:1484
BOOLEAN containsCone(leftv res, leftv args)
Definition: bbcone.cc:1696
void bbcone_setup(SModulFunctions *p)
Definition: bbcone.cc:2101
BOOLEAN negatedCone(leftv res, leftv args)
Definition: bbcone.cc:979
BOOLEAN generatorsOfSpan(leftv res, leftv args)
Definition: bbcone.cc:628
gfan::ZMatrix interiorPointsOfFacets(const gfan::ZCone &zc, const std::set< gfan::ZVector > &exceptThese)
Definition: bbcone.cc:1799
static void gfanZMatrixWriteFd(gfan::ZMatrix M, ssiInfo *dd)
Definition: bbcone.cc:1931
BOOLEAN equations(leftv res, leftv args)
Definition: bbcone.cc:577
static gfan::Integer gfanIntegerReadFd(ssiInfo *dd)
Definition: bbcone.cc:1967
BOOLEAN containsRelatively(leftv res, leftv args)
Definition: bbcone.cc:1597
static BOOLEAN jjCONERAYS3(leftv res, leftv u, leftv v, leftv w)
Definition: bbcone.cc:464
BOOLEAN containsPositiveVector(leftv res, leftv args)
Definition: bbcone.cc:928
static BOOLEAN jjCONERAYS1(leftv res, leftv v)
Definition: bbcone.cc:389
BOOLEAN semigroupGenerator(leftv res, leftv args)
Definition: bbcone.cc:996
BOOLEAN dimension(leftv res, leftv args)
Definition: bbcone.cc:757
BOOLEAN coneViaNormals(leftv res, leftv args)
Definition: bbcone.cc:352
BOOLEAN faceContaining(leftv res, leftv args)
Definition: bbcone.cc:1735
BOOLEAN setMultiplicity(leftv res, leftv args)
Definition: bbcone.cc:1114
BOOLEAN bbcone_serialize(blackbox *b, void *d, si_link f)
Definition: bbcone.cc:1944
static BOOLEAN jjCONENORMALS3(leftv res, leftv u, leftv v, leftv w)
Definition: bbcone.cc:302
BOOLEAN generatorsOfLinealitySpace(leftv res, leftv args)
Definition: bbcone.cc:645
char * bbcone_String(blackbox *, void *d)
Definition: bbcone.cc:138
BOOLEAN containsInSupport(leftv res, leftv args)
Definition: bbcone.cc:1533
BOOLEAN coneToPolytope(leftv res, leftv args)
Definition: bbcone.cc:1190
BOOLEAN dualCone(leftv res, leftv args)
Definition: bbcone.cc:962
BOOLEAN isOrigin(leftv res, leftv args)
Definition: bbcone.cc:867
gfan::ZVector randomPoint(const gfan::ZCone *zc, const int b)
Definition: bbcone.cc:1069
BOOLEAN inequalities(leftv res, leftv args)
Definition: bbcone.cc:560
BOOLEAN setLinearForms(leftv res, leftv args)
Definition: bbcone.cc:1136
VAR int coneID
Definition: bbcone.cc:25
BOOLEAN linealityDimension(leftv res, leftv args)
Definition: bbcone.cc:825
gfan::ZMatrix liftUp(const gfan::ZMatrix &zm)
Definition: bbcone.cc:1170
BOOLEAN hasFace(leftv res, leftv args)
Definition: bbcone.cc:1641
BOOLEAN relativeInteriorPoint(leftv res, leftv args)
Definition: bbcone.cc:1021
static void gfanIntegerWriteFd(gfan::Integer n, ssiInfo *dd)
Definition: bbcone.cc:1921
static BOOLEAN bbcone_Op2(int op, leftv res, leftv i1, leftv i2)
Definition: bbcone.cc:164
void * bbcone_Copy(blackbox *, void *d)
Definition: bbcone.cc:157
static BOOLEAN jjCONENORMALS2(leftv res, leftv u, leftv v)
Definition: bbcone.cc:259
BOOLEAN rays(leftv res, leftv args)
Definition: bbcone.cc:662
BOOLEAN linealitySpace(leftv res, leftv args)
Definition: bbcone.cc:945
BOOLEAN coneViaRays(leftv res, leftv args)
Definition: bbcone.cc:523
static BOOLEAN jjCONERAYS2(leftv res, leftv u, leftv v)
Definition: bbcone.cc:416
BOOLEAN intersectCones(leftv res, leftv args)
Definition: bbcone.cc:1209
std::string toString(const gfan::ZCone *const c)
Definition: bbcone.cc:27
std::pair< gfan::ZMatrix, gfan::ZMatrix > interiorPointsAndNormalsOfFacets(const gfan::ZCone zc, const std::set< gfan::ZVector > &exceptThesePoints, const bool onlyLowerHalfSpace)
Definition: bbcone.cc:1853
int getDimension(gfan::ZFan *zf)
Definition: bbfan.cc:256
int getCodimension(gfan::ZFan *zf)
Definition: bbfan.cc:251
VAR int fanID
Definition: bbfan.cc:19
int getLinealityDimension(gfan::ZFan *zf)
Definition: bbfan.cc:261
int getAmbientDimension(gfan::ZFan *zf)
Definition: bbfan.cc:246
VAR int polytopeID
Definition: bbpolytope.cc:16
bigintmat * iv2bim(intvec *b, const coeffs C)
Definition: bigintmat.cc:349
int setBlackboxStuff(blackbox *bb, const char *n)
define a new type
Definition: blackbox.cc:142
BOOLEAN blackboxDefaultOp2(int, leftv, leftv, leftv)
default procedure blackboxDefaultOp2, to be called as "default:" branch
Definition: blackbox.cc:97
number integerToNumber(const gfan::Integer &I)
gfan::ZMatrix * bigintmatToZMatrix(const bigintmat &bim)
bigintmat * zMatrixToBigintmat(const gfan::ZMatrix &zm)
gfan::ZVector * bigintmatToZVector(const bigintmat &bim)
bigintmat * zVectorToBigintmat(const gfan::ZVector &zv)
int l
Definition: cfEzgcd.cc:100
int i
Definition: cfEzgcd.cc:132
int k
Definition: cfEzgcd.cc:99
int p
Definition: cfModGcd.cc:4078
CanonicalForm b
Definition: cfModGcd.cc:4103
FILE * f
Definition: checklibs.c:9
Variable next() const
Definition: factory.h:146
Matrices of numbers.
Definition: bigintmat.h:51
int cols() const
Definition: bigintmat.h:144
bigintmat * transpose()
Definition: bigintmat.cc:37
Definition: gfan.h:47
Definition: idrec.h:35
Definition: intvec.h:23
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
void * CopyD(int t)
Definition: subexpr.cc:710
int Typ()
Definition: subexpr.cc:1011
void * Data()
Definition: subexpr.cc:1154
leftv next
Definition: subexpr.h:86
Definition: lists.h:24
const CanonicalForm int s
Definition: facAbsFact.cc:51
CanonicalForm res
Definition: facAbsFact.cc:60
const CanonicalForm & w
Definition: facAbsFact.cc:51
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:39
int j
Definition: facHensel.cc:110
void WerrorS(const char *s)
Definition: feFopen.cc:24
#define VAR
Definition: globaldefs.h:5
@ BIGINTMAT_CMD
Definition: grammar.cc:278
@ EQUAL_EQUAL
Definition: grammar.cc:268
@ INTMAT_CMD
Definition: grammar.cc:279
VAR coeffs coeffs_BIGINT
Definition: ipid.cc:50
#define IDDATA(a)
Definition: ipid.h:126
#define string
Definition: libparse.cc:1252
int lSize(lists L)
Definition: lists.cc:25
slists * lists
Definition: mpr_numeric.h:146
#define omStrDup(s)
Definition: omAllocDecl.h:263
#define omFree(addr)
Definition: omAllocDecl.h:261
#define omAlloc0(size)
Definition: omAllocDecl.h:211
#define NULL
Definition: omList.c:12
void Werror(const char *fmt,...)
Definition: reporter.cc:189
static int sign(int x)
Definition: ring.cc:3372
void s_readmpz_base(s_buff F, mpz_ptr a, int base)
Definition: s_buff.cc:209
int s_readint(s_buff F)
Definition: s_buff.cc:112
s_buff f_read
Definition: s_buff.h:22
FILE * f_write
Definition: s_buff.h:23
Definition: s_buff.h:21
int siRand()
Definition: sirandom.c:42
#define M
Definition: sirandom.c:25
#define IDHDL
Definition: tok.h:31
@ BIGINT_CMD
Definition: tok.h:38
@ LIST_CMD
Definition: tok.h:118
@ INTVEC_CMD
Definition: tok.h:101
@ STRING_CMD
Definition: tok.h:185
@ INT_CMD
Definition: tok.h:96
#define NONE
Definition: tok.h:221