[81384b] | 1 | #include <kernel/mod2.h> |
---|
| 2 | |
---|
| 3 | #include <gfanlib/gfanlib.h> |
---|
| 4 | #include <gfanlib/gfanlib_q.h> |
---|
| 5 | |
---|
| 6 | #include <Singular/ipid.h> |
---|
| 7 | #include <Singular/ipshell.h> |
---|
| 8 | #include <Singular/blackbox.h> |
---|
| 9 | #include <libpolys/misc/intvec.h> |
---|
| 10 | #include <libpolys/coeffs/longrat.h> |
---|
| 11 | #include <libpolys/coeffs/bigintmat.h> |
---|
| 12 | |
---|
| 13 | #include <bbfan.h> |
---|
| 14 | #include <bbpolytope.h> |
---|
| 15 | #include <sstream> |
---|
| 16 | |
---|
[58b407] | 17 | #include "Singular/ipid.h" |
---|
| 18 | |
---|
[81384b] | 19 | // #include <omalloc/omalloc.h> |
---|
| 20 | // #include <kernel/febase.h> |
---|
| 21 | // #include <kernel/intvec.h> |
---|
| 22 | // #include <kernel/longrat.h> |
---|
| 23 | // #include <Singular/lists.h> |
---|
| 24 | // #include <Singular/subexpr.h> |
---|
| 25 | |
---|
| 26 | int coneID; |
---|
| 27 | |
---|
| 28 | number integerToNumber(const gfan::Integer &I) |
---|
| 29 | { |
---|
| 30 | mpz_t i; |
---|
| 31 | mpz_init(i); |
---|
| 32 | I.setGmp(i); |
---|
| 33 | long m = 268435456; |
---|
| 34 | if(mpz_cmp_si(i,m)) |
---|
| 35 | { |
---|
| 36 | int temp = (int) mpz_get_si(i); |
---|
| 37 | return n_Init(temp,coeffs_BIGINT); |
---|
| 38 | } |
---|
| 39 | else |
---|
| 40 | return n_InitMPZ(i,coeffs_BIGINT); |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | bigintmat* zVectorToBigintmat(const gfan::ZVector &zv) |
---|
| 44 | { |
---|
| 45 | int d=zv.size(); |
---|
| 46 | bigintmat* bim = new bigintmat(1,d,coeffs_BIGINT); |
---|
| 47 | for(int i=1;i<=d;i++) |
---|
| 48 | { |
---|
| 49 | number temp = integerToNumber(zv[i-1]); |
---|
| 50 | bim->set(1,i,temp); |
---|
| 51 | n_Delete(&temp,coeffs_BIGINT); |
---|
| 52 | } |
---|
| 53 | return bim; |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | bigintmat* zMatrixToBigintmat(const gfan::ZMatrix &zm) |
---|
| 57 | { |
---|
| 58 | int d=zm.getHeight(); |
---|
| 59 | int n=zm.getWidth(); |
---|
| 60 | bigintmat* bim = new bigintmat(d,n,coeffs_BIGINT); |
---|
| 61 | for(int i=1;i<=d;i++) |
---|
| 62 | for(int j=1; j<=n; j++) |
---|
| 63 | { |
---|
| 64 | number temp = integerToNumber(zm[i-1][j-1]); |
---|
| 65 | bim->set(i,j,temp); |
---|
| 66 | n_Delete(&temp,coeffs_BIGINT); |
---|
| 67 | } |
---|
| 68 | return bim; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | gfan::Integer* numberToInteger(const number &n) |
---|
| 72 | { |
---|
| 73 | if (SR_HDL(n) & SR_INT) |
---|
| 74 | return new gfan::Integer(SR_TO_INT(n)); |
---|
| 75 | else |
---|
| 76 | return new gfan::Integer(n->z); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | gfan::ZMatrix* bigintmatToZMatrix(const bigintmat &bim) |
---|
| 80 | { |
---|
| 81 | int d=bim.rows(); |
---|
| 82 | int n=bim.cols(); |
---|
| 83 | gfan::ZMatrix* zm = new gfan::ZMatrix(d,n); |
---|
| 84 | for(int i=0;i<d;i++) |
---|
| 85 | for(int j=0;j<n;j++) |
---|
| 86 | { |
---|
| 87 | number temp = BIMATELEM(bim, i+1, j+1); |
---|
| 88 | gfan::Integer* gi = numberToInteger(temp); |
---|
| 89 | (*zm)[i][j] = *gi; |
---|
| 90 | delete gi; |
---|
| 91 | } |
---|
| 92 | return zm; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | gfan::ZVector* bigintmatToZVector(const bigintmat &bim) |
---|
| 96 | { |
---|
| 97 | gfan::ZVector* zv=new gfan::ZVector(bim.cols()); |
---|
| 98 | for(int j=0; j<bim.cols(); j++) |
---|
| 99 | { |
---|
| 100 | number temp = BIMATELEM(bim, 1, j+1); |
---|
| 101 | gfan::Integer* gi = numberToInteger(temp); |
---|
| 102 | (*zv)[j] = *gi; |
---|
| 103 | n_Delete(&temp,coeffs_BIGINT); |
---|
| 104 | delete gi; |
---|
| 105 | } |
---|
| 106 | return zv; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | char* toString(gfan::ZMatrix const &zm) |
---|
| 110 | { |
---|
| 111 | bigintmat* bim = zMatrixToBigintmat(zm); |
---|
| 112 | char* s = bim->StringAsPrinted(); |
---|
| 113 | delete bim; |
---|
| 114 | return s; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | std::string toString(const gfan::ZCone* const c) |
---|
| 118 | { |
---|
| 119 | std::stringstream s; |
---|
| 120 | gfan::ZMatrix i=c->getInequalities(); |
---|
| 121 | gfan::ZMatrix e=c->getEquations(); |
---|
| 122 | s<<"AMBIENT_DIM"<<std::endl; |
---|
| 123 | s<<c->ambientDimension()<<std::endl; |
---|
| 124 | if (c->areFacetsKnown()) |
---|
| 125 | s<<"FACETS"<<std::endl; |
---|
| 126 | else |
---|
| 127 | s<<"INEQUALITIES"<<std::endl; |
---|
| 128 | s<<toString(i)<<std::endl; |
---|
| 129 | if (c->areImpliedEquationsKnown()) |
---|
| 130 | s<<"LINEAR_SPAN"<<std::endl; |
---|
| 131 | else |
---|
| 132 | s<<"EQUATIONS"<<std::endl; |
---|
| 133 | s<<toString(e)<<std::endl; |
---|
| 134 | return s.str(); |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | void* bbcone_Init(blackbox *b) |
---|
| 138 | { |
---|
| 139 | return (void*)(new gfan::ZCone()); |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | BOOLEAN bbcone_Assign(leftv l, leftv r) |
---|
| 143 | { |
---|
| 144 | gfan::ZCone* newZc; |
---|
| 145 | if (r==NULL) |
---|
| 146 | { |
---|
| 147 | if (l->Data()!=NULL) |
---|
| 148 | { |
---|
| 149 | gfan::ZCone* zd = (gfan::ZCone*)l->Data(); |
---|
| 150 | delete zd; |
---|
| 151 | } |
---|
| 152 | newZc = new gfan::ZCone(); |
---|
| 153 | } |
---|
| 154 | else if (r->Typ()==l->Typ()) |
---|
| 155 | { |
---|
| 156 | if (l->Data()!=NULL) |
---|
| 157 | { |
---|
| 158 | gfan::ZCone* zd = (gfan::ZCone*)l->Data(); |
---|
| 159 | delete zd; |
---|
| 160 | } |
---|
| 161 | gfan::ZCone* zc = (gfan::ZCone*)r->Data(); |
---|
| 162 | newZc = new gfan::ZCone(*zc); |
---|
| 163 | } |
---|
| 164 | else if (r->Typ()==INT_CMD) |
---|
| 165 | { |
---|
| 166 | int ambientDim = (int)(long)r->Data(); |
---|
| 167 | if (ambientDim < 0) |
---|
| 168 | { |
---|
| 169 | Werror("expected an int >= 0, but got %d", ambientDim); |
---|
| 170 | return TRUE; |
---|
| 171 | } |
---|
| 172 | if (l->Data()!=NULL) |
---|
| 173 | { |
---|
| 174 | gfan::ZCone* zd = (gfan::ZCone*)l->Data(); |
---|
| 175 | delete zd; |
---|
| 176 | } |
---|
| 177 | newZc = new gfan::ZCone(ambientDim); |
---|
| 178 | } |
---|
| 179 | else |
---|
| 180 | { |
---|
| 181 | Werror("assign Type(%d) = Type(%d) not implemented",l->Typ(),r->Typ()); |
---|
| 182 | return TRUE; |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | if (l->rtyp==IDHDL) |
---|
| 186 | { |
---|
| 187 | IDDATA((idhdl)l->data)=(char*) newZc; |
---|
| 188 | } |
---|
| 189 | else |
---|
| 190 | { |
---|
| 191 | l->data=(void *)newZc; |
---|
| 192 | } |
---|
| 193 | return FALSE; |
---|
| 194 | } |
---|
| 195 | |
---|
| 196 | char * bbcone_String(blackbox *b, void *d) |
---|
| 197 | { |
---|
| 198 | if (d==NULL) return omStrDup("invalid object"); |
---|
| 199 | else |
---|
| 200 | { |
---|
| 201 | std::string s=toString((gfan::ZCone*) d); |
---|
| 202 | return omStrDup(s.c_str()); |
---|
| 203 | } |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | void bbcone_destroy(blackbox *b, void *d) |
---|
| 207 | { |
---|
| 208 | if (d!=NULL) |
---|
| 209 | { |
---|
| 210 | gfan::ZCone* zc = (gfan::ZCone*) d; |
---|
| 211 | delete zc; |
---|
| 212 | } |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | void* bbcone_Copy(blackbox*b, void *d) |
---|
| 216 | { |
---|
| 217 | gfan::ZCone* zc = (gfan::ZCone*)d; |
---|
| 218 | gfan::ZCone* newZc = new gfan::ZCone(*zc); |
---|
| 219 | return newZc; |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | static BOOLEAN bbcone_Op2(int op, leftv res, leftv i1, leftv i2) |
---|
| 223 | { |
---|
| 224 | gfan::ZCone* zp = (gfan::ZCone*) i1->Data(); |
---|
| 225 | switch(op) |
---|
| 226 | { |
---|
| 227 | case '&': |
---|
| 228 | { |
---|
| 229 | if (i2->Typ()==coneID) |
---|
| 230 | { |
---|
| 231 | gfan::ZCone* zq = (gfan::ZCone*) i2->Data(); |
---|
| 232 | int d1 = zp->ambientDimension(); |
---|
| 233 | int d2 = zq->ambientDimension(); |
---|
| 234 | if (d1 != d2) |
---|
| 235 | { |
---|
| 236 | WerrorS("mismatching ambient dimensions"); |
---|
| 237 | return TRUE; |
---|
| 238 | } |
---|
| 239 | gfan::ZCone* zs = new gfan::ZCone(); |
---|
| 240 | *zs = gfan::intersection(*zp, *zq); |
---|
| 241 | zs->canonicalize(); |
---|
| 242 | res->rtyp = coneID; |
---|
| 243 | res->data = (void*) zs; |
---|
| 244 | return FALSE; |
---|
| 245 | } |
---|
| 246 | return blackboxDefaultOp2(op,res,i1,i2); |
---|
| 247 | } |
---|
| 248 | case '|': |
---|
| 249 | { |
---|
| 250 | if(i2->Typ()==coneID) |
---|
| 251 | { |
---|
| 252 | gfan::ZCone* zq = (gfan::ZCone*) i2->Data(); |
---|
| 253 | int d1 = zp->ambientDimension(); |
---|
| 254 | int d2 = zq->ambientDimension(); |
---|
| 255 | if (d1 != d2) |
---|
| 256 | { |
---|
| 257 | WerrorS("mismatching ambient dimensions"); |
---|
| 258 | return TRUE; |
---|
| 259 | } |
---|
| 260 | gfan::ZMatrix rays = zp->extremeRays(); |
---|
| 261 | rays.append(zq->extremeRays()); |
---|
| 262 | gfan::ZMatrix lineality = zp->generatorsOfLinealitySpace(); |
---|
| 263 | lineality.append(zq->generatorsOfLinealitySpace()); |
---|
| 264 | gfan::ZCone* zs = new gfan::ZCone(); |
---|
| 265 | *zs = gfan::ZCone::givenByRays(rays,lineality); |
---|
| 266 | zs->canonicalize(); |
---|
| 267 | res->rtyp = coneID; |
---|
| 268 | res->data = (void*) zs; |
---|
| 269 | return FALSE; |
---|
| 270 | } |
---|
| 271 | return blackboxDefaultOp2(op,res,i1,i2); |
---|
| 272 | } |
---|
| 273 | case EQUAL_EQUAL: |
---|
| 274 | { |
---|
| 275 | if(i2->Typ()==coneID) |
---|
| 276 | { |
---|
| 277 | gfan::ZCone* zq = (gfan::ZCone*) i2->Data(); |
---|
| 278 | zp->canonicalize(); |
---|
| 279 | zq->canonicalize(); |
---|
| 280 | bool b = !((*zp)!=(*zq)); |
---|
| 281 | res->rtyp = INT_CMD; |
---|
| 282 | res->data = (void*) b; |
---|
| 283 | return FALSE; |
---|
| 284 | } |
---|
| 285 | return blackboxDefaultOp2(op,res,i1,i2); |
---|
| 286 | } |
---|
| 287 | default: |
---|
| 288 | return blackboxDefaultOp2(op,res,i1,i2); |
---|
| 289 | } |
---|
| 290 | return blackboxDefaultOp2(op,res,i1,i2); |
---|
| 291 | } |
---|
| 292 | |
---|
| 293 | |
---|
| 294 | /* singular wrapper for gfanlib functions */ |
---|
| 295 | static BOOLEAN jjCONENORMALS1(leftv res, leftv v) |
---|
| 296 | { |
---|
| 297 | /* method for generating a cone object from inequalities; |
---|
| 298 | valid parametrizations: (intmat) */ |
---|
| 299 | bigintmat* ineq = NULL; |
---|
| 300 | if (v->Typ() == INTMAT_CMD) |
---|
| 301 | { |
---|
| 302 | intvec* ineq0 = (intvec*) v->Data(); |
---|
| 303 | ineq = iv2bim(ineq0,coeffs_BIGINT); |
---|
| 304 | } |
---|
| 305 | else |
---|
| 306 | ineq = (bigintmat*) v->Data(); |
---|
| 307 | gfan::ZMatrix* zm = bigintmatToZMatrix(ineq); |
---|
| 308 | gfan::ZCone* zc = new gfan::ZCone(*zm, gfan::ZMatrix(0, zm->getWidth())); |
---|
| 309 | delete zm; |
---|
| 310 | if (v->Typ() == INTMAT_CMD) |
---|
| 311 | delete ineq; |
---|
| 312 | res->rtyp = coneID; |
---|
| 313 | res->data = (void*) zc; |
---|
| 314 | return FALSE; |
---|
| 315 | } |
---|
| 316 | |
---|
| 317 | static BOOLEAN jjCONENORMALS2(leftv res, leftv u, leftv v) |
---|
| 318 | { |
---|
| 319 | /* method for generating a cone object from iequalities, |
---|
| 320 | and equations (...) |
---|
| 321 | valid parametrizations: (intmat, intmat) |
---|
| 322 | Errors will be invoked in the following cases: |
---|
| 323 | - u and v have different numbers of columns */ |
---|
| 324 | bigintmat* ineq = NULL; bigintmat* eq = NULL; |
---|
| 325 | if (u->Typ() == INTMAT_CMD) |
---|
| 326 | { |
---|
| 327 | intvec* ineq0 = (intvec*) u->Data(); |
---|
| 328 | ineq = iv2bim(ineq0,coeffs_BIGINT); |
---|
| 329 | } |
---|
| 330 | else |
---|
| 331 | ineq = (bigintmat*) u->Data(); |
---|
| 332 | if (v->Typ() == INTMAT_CMD) |
---|
| 333 | { |
---|
| 334 | intvec* eq0 = (intvec*) v->Data(); |
---|
| 335 | eq = iv2bim(eq0,coeffs_BIGINT); |
---|
| 336 | } |
---|
| 337 | else |
---|
| 338 | eq = (bigintmat*) v->Data(); |
---|
| 339 | |
---|
| 340 | if (ineq->cols() != eq->cols()) |
---|
| 341 | { |
---|
| 342 | Werror("expected same number of columns but got %d vs. %d", |
---|
| 343 | ineq->cols(), eq->cols()); |
---|
| 344 | return TRUE; |
---|
| 345 | } |
---|
| 346 | gfan::ZMatrix* zm1 = bigintmatToZMatrix(ineq); |
---|
| 347 | gfan::ZMatrix* zm2 = bigintmatToZMatrix(eq); |
---|
| 348 | gfan::ZCone* zc = new gfan::ZCone(*zm1, *zm2); |
---|
| 349 | delete zm1; |
---|
| 350 | delete zm2; |
---|
| 351 | if (u->Typ() == INTMAT_CMD) |
---|
| 352 | delete ineq; |
---|
| 353 | if (v->Typ() == INTMAT_CMD) |
---|
| 354 | delete eq; |
---|
| 355 | res->rtyp = coneID; |
---|
| 356 | res->data = (void*) zc; |
---|
| 357 | return FALSE; |
---|
| 358 | } |
---|
| 359 | |
---|
| 360 | static BOOLEAN jjCONENORMALS3(leftv res, leftv u, leftv v, leftv w) |
---|
| 361 | { |
---|
| 362 | /* method for generating a cone object from inequalities, equations, |
---|
| 363 | and an integer k; |
---|
| 364 | valid parametrizations: (intmat, intmat, int); |
---|
| 365 | Errors will be invoked in the following cases: |
---|
| 366 | - u and v have different numbers of columns, |
---|
| 367 | - k not in [0..3]; |
---|
| 368 | if the 2^0-bit of k is set, then ... */ |
---|
| 369 | bigintmat* ineq = NULL; bigintmat* eq = NULL; |
---|
| 370 | if (u->Typ() == INTMAT_CMD) |
---|
| 371 | { |
---|
| 372 | intvec* ineq0 = (intvec*) u->Data(); |
---|
| 373 | ineq = iv2bim(ineq0,coeffs_BIGINT); |
---|
| 374 | } |
---|
| 375 | else |
---|
| 376 | ineq = (bigintmat*) u->Data(); |
---|
| 377 | if (v->Typ() == INTMAT_CMD) |
---|
| 378 | { |
---|
| 379 | intvec* eq0 = (intvec*) v->Data(); |
---|
| 380 | eq = iv2bim(eq0,coeffs_BIGINT); |
---|
| 381 | } |
---|
| 382 | else |
---|
| 383 | eq = (bigintmat*) v->Data(); |
---|
| 384 | if (ineq->cols() != eq->cols()) |
---|
| 385 | { |
---|
| 386 | Werror("expected same number of columns but got %d vs. %d", |
---|
| 387 | ineq->cols(), eq->cols()); |
---|
| 388 | return TRUE; |
---|
| 389 | } |
---|
| 390 | int k = (int)(long)w->Data(); |
---|
| 391 | if ((k < 0) || (k > 3)) |
---|
| 392 | { |
---|
| 393 | WerrorS("expected int argument in [0..3]"); |
---|
| 394 | return TRUE; |
---|
| 395 | } |
---|
| 396 | gfan::ZMatrix* zm1 = bigintmatToZMatrix(ineq); |
---|
| 397 | gfan::ZMatrix* zm2 = bigintmatToZMatrix(eq); |
---|
| 398 | gfan::ZCone* zc = new gfan::ZCone(*zm1, *zm2, k); |
---|
| 399 | delete zm1; |
---|
| 400 | delete zm2; |
---|
| 401 | if (u->Typ() == INTMAT_CMD) |
---|
| 402 | delete ineq; |
---|
| 403 | if (v->Typ() == INTMAT_CMD) |
---|
| 404 | delete eq; |
---|
| 405 | res->rtyp = coneID; |
---|
| 406 | res->data = (void*) zc; |
---|
| 407 | return FALSE; |
---|
| 408 | } |
---|
| 409 | |
---|
| 410 | BOOLEAN coneViaNormals(leftv res, leftv args) |
---|
| 411 | { |
---|
| 412 | leftv u = args; |
---|
| 413 | if ((u != NULL) && ((u->Typ() == BIGINTMAT_CMD) || (u->Typ() == INTMAT_CMD))) |
---|
| 414 | { |
---|
| 415 | if (u->next == NULL) return jjCONENORMALS1(res, u); |
---|
| 416 | } |
---|
| 417 | leftv v = u->next; |
---|
| 418 | if ((v != NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTMAT_CMD))) |
---|
| 419 | { |
---|
| 420 | if (v->next == NULL) return jjCONENORMALS2(res, u, v); |
---|
| 421 | } |
---|
| 422 | leftv w = v->next; |
---|
| 423 | if ((w != NULL) && (w->Typ() == INT_CMD)) |
---|
| 424 | { |
---|
| 425 | if (w->next == NULL) return jjCONENORMALS3(res, u, v, w); |
---|
| 426 | } |
---|
| 427 | WerrorS("coneViaInequalities: unexpected parameters"); |
---|
| 428 | return TRUE; |
---|
| 429 | } |
---|
| 430 | |
---|
| 431 | static BOOLEAN jjCONERAYS1(leftv res, leftv v) |
---|
| 432 | { |
---|
| 433 | /* method for generating a cone object from half-lines |
---|
| 434 | (cone = convex hull of the half-lines; note: there may be |
---|
| 435 | entire lines in the cone); |
---|
| 436 | valid parametrizations: (intmat) */ |
---|
| 437 | bigintmat* rays = NULL; |
---|
| 438 | if (v->Typ() == INTMAT_CMD) |
---|
| 439 | { |
---|
| 440 | intvec* rays0 = (intvec*) v->Data(); |
---|
| 441 | rays = iv2bim(rays0,coeffs_BIGINT); |
---|
| 442 | } |
---|
| 443 | else |
---|
| 444 | rays = (bigintmat*) v->Data(); |
---|
| 445 | |
---|
| 446 | gfan::ZMatrix* zm = bigintmatToZMatrix(rays); |
---|
| 447 | gfan::ZCone* zc = new gfan::ZCone(); |
---|
| 448 | *zc = gfan::ZCone::givenByRays(*zm, gfan::ZMatrix(0, zm->getWidth())); |
---|
| 449 | res->rtyp = coneID; |
---|
| 450 | res->data = (void*) zc; |
---|
| 451 | |
---|
| 452 | delete zm; |
---|
| 453 | if (v->Typ() == INTMAT_CMD) |
---|
| 454 | delete rays; |
---|
| 455 | return FALSE; |
---|
| 456 | } |
---|
| 457 | |
---|
| 458 | static BOOLEAN jjCONERAYS2(leftv res, leftv u, leftv v) |
---|
| 459 | { |
---|
| 460 | /* method for generating a cone object from half-lines, |
---|
| 461 | and lines (any point in the cone being the sum of a point |
---|
| 462 | in the convex hull of the half-lines and a point in the span |
---|
| 463 | of the lines; the second argument may contain or entirely consist |
---|
| 464 | of zero rows); |
---|
| 465 | valid parametrizations: (intmat, intmat) |
---|
| 466 | Errors will be invoked in the following cases: |
---|
| 467 | - u and v have different numbers of columns */ |
---|
| 468 | bigintmat* rays = NULL; bigintmat* linSpace = NULL; |
---|
| 469 | if (u->Typ() == INTMAT_CMD) |
---|
| 470 | { |
---|
| 471 | intvec* rays0 = (intvec*) u->Data(); |
---|
| 472 | rays = iv2bim(rays0,coeffs_BIGINT); |
---|
| 473 | } |
---|
| 474 | else |
---|
| 475 | rays = (bigintmat*) u->Data(); |
---|
| 476 | if (v->Typ() == INTMAT_CMD) |
---|
| 477 | { |
---|
| 478 | intvec* linSpace0 = (intvec*) v->Data(); |
---|
| 479 | linSpace = iv2bim(linSpace0,coeffs_BIGINT); |
---|
| 480 | } |
---|
| 481 | else |
---|
| 482 | linSpace = (bigintmat*) v->Data(); |
---|
| 483 | |
---|
| 484 | if (rays->cols() != linSpace->cols()) |
---|
| 485 | { |
---|
| 486 | Werror("expected same number of columns but got %d vs. %d", |
---|
| 487 | rays->cols(), linSpace->cols()); |
---|
| 488 | return TRUE; |
---|
| 489 | } |
---|
| 490 | gfan::ZMatrix* zm1 = bigintmatToZMatrix(rays); |
---|
| 491 | gfan::ZMatrix* zm2 = bigintmatToZMatrix(linSpace); |
---|
| 492 | gfan::ZCone* zc = new gfan::ZCone(); |
---|
| 493 | *zc = gfan::ZCone::givenByRays(*zm1, *zm2); |
---|
| 494 | res->rtyp = coneID; |
---|
| 495 | res->data = (void*) zc; |
---|
| 496 | |
---|
| 497 | delete zm1; |
---|
| 498 | delete zm2; |
---|
| 499 | if (u->Typ() == INTMAT_CMD) |
---|
| 500 | delete rays; |
---|
| 501 | if (v->Typ() == INTMAT_CMD) |
---|
| 502 | delete linSpace; |
---|
| 503 | return FALSE; |
---|
| 504 | } |
---|
| 505 | |
---|
| 506 | static BOOLEAN jjCONERAYS3(leftv res, leftv u, leftv v, leftv w) |
---|
| 507 | { |
---|
| 508 | /* method for generating a cone object from half-lines, |
---|
| 509 | and lines (any point in the cone being the sum of a point |
---|
| 510 | in the convex hull of the half-lines and a point in the span |
---|
| 511 | of the lines), and an integer k; |
---|
| 512 | valid parametrizations: (intmat, intmat, int); |
---|
| 513 | Errors will be invoked in the following cases: |
---|
| 514 | - u and v have different numbers of columns, |
---|
| 515 | - k not in [0..3]; |
---|
| 516 | if the 2^0-bit of k is set, then the lineality space is known |
---|
| 517 | to be the span of the provided lines; |
---|
| 518 | if the 2^1-bit of k is set, then the extreme rays are known: |
---|
| 519 | each half-line spans a (different) extreme ray */ |
---|
| 520 | bigintmat* rays = NULL; bigintmat* linSpace = NULL; |
---|
| 521 | if (u->Typ() == INTMAT_CMD) |
---|
| 522 | { |
---|
| 523 | intvec* rays0 = (intvec*) u->Data(); |
---|
| 524 | rays = iv2bim(rays0,coeffs_BIGINT); |
---|
| 525 | } |
---|
| 526 | else |
---|
| 527 | rays = (bigintmat*) u->Data(); |
---|
| 528 | if (v->Typ() == INTMAT_CMD) |
---|
| 529 | { |
---|
| 530 | intvec* linSpace0 = (intvec*) v->Data(); |
---|
| 531 | linSpace = iv2bim(linSpace0,coeffs_BIGINT); |
---|
| 532 | } |
---|
| 533 | else |
---|
| 534 | linSpace = (bigintmat*) v->Data(); |
---|
| 535 | |
---|
| 536 | if (rays->cols() != linSpace->cols()) |
---|
| 537 | { |
---|
| 538 | Werror("expected same number of columns but got %d vs. %d", |
---|
| 539 | rays->cols(), linSpace->cols()); |
---|
| 540 | return TRUE; |
---|
| 541 | } |
---|
| 542 | int k = (int)(long)w->Data(); |
---|
| 543 | if ((k < 0) || (k > 3)) |
---|
| 544 | { |
---|
| 545 | WerrorS("expected int argument in [0..3]"); |
---|
| 546 | return TRUE; |
---|
| 547 | } |
---|
| 548 | gfan::ZMatrix* zm1 = bigintmatToZMatrix(rays); |
---|
| 549 | gfan::ZMatrix* zm2 = bigintmatToZMatrix(linSpace); |
---|
| 550 | gfan::ZCone* zc = new gfan::ZCone(); |
---|
| 551 | *zc = gfan::ZCone::givenByRays(*zm1, *zm2); |
---|
| 552 | //k should be passed on to zc; not available yet |
---|
| 553 | res->rtyp = coneID; |
---|
| 554 | res->data = (void*) zc; |
---|
| 555 | |
---|
| 556 | delete zm1; |
---|
| 557 | delete zm2; |
---|
| 558 | if (u->Typ() == INTMAT_CMD) |
---|
| 559 | delete rays; |
---|
| 560 | if (v->Typ() == INTMAT_CMD) |
---|
| 561 | delete linSpace; |
---|
| 562 | return FALSE; |
---|
| 563 | } |
---|
| 564 | |
---|
| 565 | BOOLEAN coneViaRays(leftv res, leftv args) |
---|
| 566 | { |
---|
| 567 | leftv u = args; |
---|
| 568 | if ((u != NULL) && ((u->Typ() == BIGINTMAT_CMD) || (u->Typ() == INTMAT_CMD))) |
---|
| 569 | { |
---|
| 570 | if (u->next == NULL) return jjCONERAYS1(res, u); |
---|
| 571 | leftv v = u->next; |
---|
| 572 | if ((v != NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTMAT_CMD))) |
---|
| 573 | { |
---|
| 574 | if (v->next == NULL) return jjCONERAYS2(res, u, v); |
---|
| 575 | leftv w = v->next; |
---|
| 576 | if ((w != NULL) && (w->Typ() == INT_CMD)) |
---|
| 577 | { |
---|
| 578 | if (w->next == NULL) return jjCONERAYS3(res, u, v, w); |
---|
| 579 | } |
---|
| 580 | } |
---|
| 581 | } |
---|
| 582 | WerrorS("coneViaPoints: unexpected parameters"); |
---|
| 583 | return TRUE; |
---|
| 584 | } |
---|
| 585 | |
---|
| 586 | BOOLEAN inequalities(leftv res, leftv args) |
---|
| 587 | { |
---|
| 588 | leftv u = args; |
---|
| 589 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 590 | { |
---|
| 591 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 592 | |
---|
| 593 | gfan::ZMatrix zmat = zc->getInequalities(); |
---|
| 594 | res->rtyp = BIGINTMAT_CMD; |
---|
| 595 | res->data = (void*) zMatrixToBigintmat(zmat); |
---|
| 596 | return FALSE; |
---|
| 597 | } |
---|
| 598 | WerrorS("inequalities: unexpected parameters"); |
---|
| 599 | return TRUE; |
---|
| 600 | } |
---|
| 601 | |
---|
| 602 | BOOLEAN equations(leftv res, leftv args) |
---|
| 603 | { |
---|
| 604 | leftv u = args; |
---|
| 605 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 606 | { |
---|
| 607 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 608 | gfan::ZMatrix zmat = zc->getEquations(); |
---|
| 609 | res->rtyp = BIGINTMAT_CMD; |
---|
| 610 | res->data = (void*) zMatrixToBigintmat(zmat); |
---|
| 611 | return FALSE; |
---|
| 612 | } |
---|
| 613 | WerrorS("equations: unexpected parameters"); |
---|
| 614 | return TRUE; |
---|
| 615 | } |
---|
| 616 | |
---|
| 617 | BOOLEAN facets(leftv res, leftv args) |
---|
| 618 | { |
---|
| 619 | leftv u = args; |
---|
| 620 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 621 | { |
---|
| 622 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 623 | gfan::ZMatrix zm = zc->getFacets(); |
---|
| 624 | res->rtyp = BIGINTMAT_CMD; |
---|
| 625 | res->data = (void*) zMatrixToBigintmat(zm); |
---|
| 626 | return FALSE; |
---|
| 627 | } |
---|
| 628 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
| 629 | { |
---|
| 630 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 631 | res->rtyp = BIGINTMAT_CMD; |
---|
| 632 | res->data = (void*) getFacetNormals(zc); |
---|
| 633 | return FALSE; |
---|
| 634 | } |
---|
| 635 | WerrorS("facets: unexpected parameters"); |
---|
| 636 | return TRUE; |
---|
| 637 | } |
---|
| 638 | |
---|
| 639 | BOOLEAN impliedEquations(leftv res, leftv args) |
---|
| 640 | { |
---|
| 641 | leftv u = args; |
---|
| 642 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 643 | { |
---|
| 644 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 645 | gfan::ZMatrix zmat = zc->getImpliedEquations(); |
---|
| 646 | res->rtyp = BIGINTMAT_CMD; |
---|
| 647 | res->data = (void*) zMatrixToBigintmat(zmat); |
---|
| 648 | return FALSE; |
---|
| 649 | } |
---|
| 650 | WerrorS("span: unexpected parameters"); |
---|
| 651 | return TRUE; |
---|
| 652 | } |
---|
| 653 | |
---|
| 654 | BOOLEAN generatorsOfSpan(leftv res, leftv args) |
---|
| 655 | { |
---|
| 656 | leftv u = args; |
---|
| 657 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 658 | { |
---|
| 659 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 660 | gfan::ZMatrix zmat = zc->generatorsOfSpan(); |
---|
| 661 | res->rtyp = BIGINTMAT_CMD; |
---|
| 662 | res->data = (void*) zMatrixToBigintmat(zmat); |
---|
| 663 | return FALSE; |
---|
| 664 | } |
---|
| 665 | WerrorS("generatorsOfSpan: unexpected parameters"); |
---|
| 666 | return TRUE; |
---|
| 667 | } |
---|
| 668 | |
---|
| 669 | BOOLEAN generatorsOfLinealitySpace(leftv res, leftv args) |
---|
| 670 | { |
---|
| 671 | leftv u = args; |
---|
| 672 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 673 | { |
---|
| 674 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 675 | gfan::ZMatrix zmat = zc->generatorsOfLinealitySpace(); |
---|
| 676 | res->rtyp = BIGINTMAT_CMD; |
---|
| 677 | res->data = (void*) zMatrixToBigintmat(zmat); |
---|
| 678 | return FALSE; |
---|
| 679 | } |
---|
| 680 | WerrorS("generatorsOfLinealitySpace: unexpected parameters"); |
---|
| 681 | return TRUE; |
---|
| 682 | } |
---|
| 683 | |
---|
| 684 | BOOLEAN rays(leftv res, leftv args) |
---|
| 685 | { |
---|
| 686 | leftv u = args; |
---|
| 687 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 688 | { |
---|
| 689 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 690 | gfan::ZMatrix zm = zc->extremeRays(); |
---|
| 691 | res->rtyp = BIGINTMAT_CMD; |
---|
| 692 | res->data = (void*)zMatrixToBigintmat(zm); |
---|
| 693 | return FALSE; |
---|
| 694 | } |
---|
| 695 | if ((u != NULL) && (u->Typ() == fanID)) |
---|
| 696 | { |
---|
| 697 | gfan::ZFan* zf = (gfan::ZFan*)u->Data(); |
---|
| 698 | gfan::ZMatrix zmat = rays(zf); |
---|
| 699 | res->rtyp = BIGINTMAT_CMD; |
---|
| 700 | res->data = (void*) zMatrixToBigintmat(zmat); |
---|
| 701 | return FALSE; |
---|
| 702 | } |
---|
| 703 | WerrorS("rays: unexpected parameters"); |
---|
| 704 | return TRUE; |
---|
| 705 | } |
---|
| 706 | |
---|
| 707 | BOOLEAN quotientLatticeBasis(leftv res, leftv args) |
---|
| 708 | { |
---|
| 709 | leftv u = args; |
---|
| 710 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 711 | { |
---|
| 712 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 713 | gfan::ZMatrix zmat = zc->quotientLatticeBasis(); |
---|
| 714 | res->rtyp = BIGINTMAT_CMD; |
---|
| 715 | res->data = (void*) zMatrixToBigintmat(zmat); |
---|
| 716 | return FALSE; |
---|
| 717 | } |
---|
| 718 | WerrorS("quotientLatticeBasis: unexpected parameters"); |
---|
| 719 | return TRUE; |
---|
| 720 | } |
---|
| 721 | |
---|
| 722 | BOOLEAN getLinearForms(leftv res, leftv args) |
---|
| 723 | { |
---|
| 724 | leftv u = args; |
---|
| 725 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 726 | { |
---|
| 727 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 728 | gfan::ZMatrix zmat = zc->getLinearForms(); |
---|
| 729 | res->rtyp = BIGINTMAT_CMD; |
---|
| 730 | res->data = (void*) zMatrixToBigintmat(zmat); |
---|
| 731 | return FALSE; |
---|
| 732 | } |
---|
| 733 | WerrorS("getLinearForms: unexpected parameters"); |
---|
| 734 | return TRUE; |
---|
| 735 | } |
---|
| 736 | |
---|
| 737 | BOOLEAN ambientDimension(leftv res, leftv args) |
---|
| 738 | { |
---|
| 739 | leftv u=args; |
---|
| 740 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 741 | { |
---|
| 742 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 743 | res->rtyp = INT_CMD; |
---|
| 744 | res->data = (void*) (long) zc->ambientDimension(); |
---|
| 745 | return FALSE; |
---|
| 746 | } |
---|
| 747 | if ((u != NULL) && (u->Typ() == fanID)) |
---|
| 748 | { |
---|
| 749 | gfan::ZFan* zf = (gfan::ZFan*)u->Data(); |
---|
| 750 | res->rtyp = INT_CMD; |
---|
| 751 | res->data = (void*) (long) getAmbientDimension(zf); |
---|
| 752 | return FALSE; |
---|
| 753 | } |
---|
| 754 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
| 755 | { |
---|
| 756 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 757 | res->rtyp = INT_CMD; |
---|
| 758 | res->data = (void*) (long) getAmbientDimension(zc); |
---|
| 759 | return FALSE; |
---|
| 760 | } |
---|
| 761 | WerrorS("ambientDimension: unexpected parameters"); |
---|
| 762 | return TRUE; |
---|
| 763 | } |
---|
| 764 | |
---|
| 765 | BOOLEAN dimension(leftv res, leftv args) |
---|
| 766 | { |
---|
| 767 | leftv u=args; |
---|
| 768 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 769 | { |
---|
| 770 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 771 | res->rtyp = INT_CMD; |
---|
| 772 | res->data = (void*) (long) zc->dimension(); |
---|
| 773 | return FALSE; |
---|
| 774 | } |
---|
| 775 | if ((u != NULL) && (u->Typ() == fanID)) |
---|
| 776 | { |
---|
| 777 | gfan::ZFan* zf = (gfan::ZFan*)u->Data(); |
---|
| 778 | res->rtyp = INT_CMD; |
---|
| 779 | res->data = (void*) (long) getDimension(zf); |
---|
| 780 | return FALSE; |
---|
| 781 | } |
---|
| 782 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
| 783 | { |
---|
| 784 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 785 | res->rtyp = INT_CMD; |
---|
| 786 | res->data = (void*) (long) getDimension(zc); |
---|
| 787 | return FALSE; |
---|
| 788 | } |
---|
| 789 | WerrorS("dimension: unexpected parameters"); |
---|
| 790 | return TRUE; |
---|
| 791 | } |
---|
| 792 | |
---|
| 793 | BOOLEAN codimension(leftv res, leftv args) |
---|
| 794 | { |
---|
| 795 | leftv u=args; |
---|
| 796 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 797 | { |
---|
| 798 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 799 | res->rtyp = INT_CMD; |
---|
| 800 | res->data = (void*) (long) zc->codimension(); |
---|
| 801 | return FALSE; |
---|
| 802 | } |
---|
| 803 | if ((u != NULL) && (u->Typ() == fanID)) |
---|
| 804 | { |
---|
| 805 | gfan::ZFan* zf = (gfan::ZFan*)u->Data(); |
---|
| 806 | res->rtyp = INT_CMD; |
---|
| 807 | res->data = (void*) (long) getCodimension(zf); |
---|
| 808 | return FALSE; |
---|
| 809 | } |
---|
| 810 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
| 811 | { |
---|
| 812 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 813 | res->rtyp = INT_CMD; |
---|
| 814 | res->data = (void*) (long) getCodimension(zc); |
---|
| 815 | return FALSE; |
---|
| 816 | } |
---|
| 817 | WerrorS("getCodimension: unexpected parameters"); |
---|
| 818 | return TRUE; |
---|
| 819 | } |
---|
| 820 | |
---|
| 821 | BOOLEAN linealityDimension(leftv res, leftv args) |
---|
| 822 | { |
---|
| 823 | leftv u=args; |
---|
| 824 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 825 | { |
---|
| 826 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 827 | res->rtyp = INT_CMD; |
---|
| 828 | res->data = (void*) (long) zc->dimensionOfLinealitySpace(); |
---|
| 829 | return FALSE; |
---|
| 830 | } |
---|
| 831 | if ((u != NULL) && (u->Typ() == fanID)) |
---|
| 832 | { |
---|
| 833 | gfan::ZFan* zf = (gfan::ZFan*)u->Data(); |
---|
| 834 | res->rtyp = INT_CMD; |
---|
| 835 | res->data = (void*) (long) getLinealityDimension(zf); |
---|
| 836 | return FALSE; |
---|
| 837 | } |
---|
| 838 | WerrorS("linealityDimension: unexpected parameters"); |
---|
| 839 | return TRUE; |
---|
| 840 | } |
---|
| 841 | |
---|
| 842 | BOOLEAN getMultiplicity(leftv res, leftv args) |
---|
| 843 | { |
---|
| 844 | leftv u = args; |
---|
| 845 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 846 | { |
---|
| 847 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 848 | number i = integerToNumber(zc->getMultiplicity()); |
---|
| 849 | res->rtyp = BIGINT_CMD; |
---|
| 850 | res->data = (void*) i; |
---|
| 851 | return FALSE; |
---|
| 852 | } |
---|
| 853 | WerrorS("getMultiplicity: unexpected parameters"); |
---|
| 854 | return TRUE; |
---|
| 855 | } |
---|
| 856 | |
---|
| 857 | BOOLEAN isOrigin(leftv res, leftv args) |
---|
| 858 | { |
---|
| 859 | leftv u = args; |
---|
| 860 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 861 | { |
---|
| 862 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 863 | int i = zc->isOrigin(); |
---|
| 864 | res->rtyp = INT_CMD; |
---|
| 865 | res->data = (void*) (long) i; |
---|
| 866 | return FALSE; |
---|
| 867 | } |
---|
| 868 | WerrorS("isOrigin: unexpected parameters"); |
---|
| 869 | return TRUE; |
---|
| 870 | } |
---|
| 871 | |
---|
| 872 | BOOLEAN isFullSpace(leftv res, leftv args) |
---|
| 873 | { |
---|
| 874 | leftv u = args; |
---|
| 875 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 876 | { |
---|
| 877 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 878 | int i = zc->isFullSpace(); |
---|
| 879 | res->rtyp = INT_CMD; |
---|
| 880 | res->data = (void*) (long) i; |
---|
| 881 | return FALSE; |
---|
| 882 | } |
---|
| 883 | WerrorS("isFullSpace: unexpected parameters"); |
---|
| 884 | return TRUE; |
---|
| 885 | } |
---|
| 886 | |
---|
| 887 | BOOLEAN isSimplicial(leftv res, leftv args) |
---|
| 888 | { |
---|
| 889 | leftv u=args; |
---|
| 890 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 891 | { |
---|
| 892 | gfan::ZCone* zc = (gfan::ZCone*) u->Data(); |
---|
| 893 | int b = zc->isSimplicial(); |
---|
| 894 | res->rtyp = INT_CMD; |
---|
| 895 | res->data = (void*) (long) b; |
---|
| 896 | return FALSE; |
---|
| 897 | } |
---|
| 898 | if ((u != NULL) && (u->Typ() == fanID)) |
---|
| 899 | { |
---|
| 900 | gfan::ZFan* zf = (gfan::ZFan*) u->Data(); |
---|
| 901 | bool b = isSimplicial(zf); |
---|
| 902 | res->rtyp = INT_CMD; |
---|
| 903 | res->data = (void*) (long) b; |
---|
| 904 | return FALSE; |
---|
| 905 | } |
---|
| 906 | WerrorS("isSimplicial: unexpected parameters"); |
---|
| 907 | return TRUE; |
---|
| 908 | } |
---|
| 909 | |
---|
| 910 | BOOLEAN containsPositiveVector(leftv res, leftv args) |
---|
| 911 | { |
---|
| 912 | leftv u = args; |
---|
| 913 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 914 | { |
---|
| 915 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 916 | int i = zc->containsPositiveVector(); |
---|
| 917 | res->rtyp = INT_CMD; |
---|
| 918 | res->data = (void*) (long) i; |
---|
| 919 | return FALSE; |
---|
| 920 | } |
---|
| 921 | WerrorS("containsPositiveVector: unexpected parameters"); |
---|
| 922 | return TRUE; |
---|
| 923 | } |
---|
| 924 | |
---|
| 925 | BOOLEAN linealitySpace(leftv res, leftv args) |
---|
| 926 | { |
---|
| 927 | leftv u = args; |
---|
| 928 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 929 | { |
---|
| 930 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 931 | gfan::ZCone* zd = new gfan::ZCone(zc->linealitySpace()); |
---|
| 932 | res->rtyp = coneID; |
---|
| 933 | res->data = (void*) zd; |
---|
| 934 | return FALSE; |
---|
| 935 | } |
---|
| 936 | WerrorS("linealitySpace: unexpected parameters"); |
---|
| 937 | return TRUE; |
---|
| 938 | } |
---|
| 939 | |
---|
| 940 | BOOLEAN dualCone(leftv res, leftv args) |
---|
| 941 | { |
---|
| 942 | leftv u = args; |
---|
| 943 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 944 | { |
---|
| 945 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 946 | gfan::ZCone* zd = new gfan::ZCone(zc->dualCone()); |
---|
| 947 | res->rtyp = coneID; |
---|
| 948 | res->data = (void*) zd; |
---|
| 949 | return FALSE; |
---|
| 950 | } |
---|
| 951 | WerrorS("dual: unexpected parameters"); |
---|
| 952 | return TRUE; |
---|
| 953 | } |
---|
| 954 | |
---|
| 955 | BOOLEAN negatedCone(leftv res, leftv args) |
---|
| 956 | { |
---|
| 957 | leftv u = args; |
---|
| 958 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 959 | { |
---|
| 960 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 961 | gfan::ZCone* zd = new gfan::ZCone(zc->negated()); |
---|
| 962 | res->rtyp = coneID; |
---|
| 963 | res->data = (void*) zd; |
---|
| 964 | return FALSE; |
---|
| 965 | } |
---|
| 966 | WerrorS("negatedCone: unexpected parameters"); |
---|
| 967 | return TRUE; |
---|
| 968 | } |
---|
| 969 | |
---|
| 970 | BOOLEAN semigroupGenerator(leftv res, leftv args) |
---|
| 971 | { |
---|
| 972 | leftv u = args; |
---|
| 973 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 974 | { |
---|
| 975 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 976 | int d = zc->dimension(); |
---|
| 977 | int dLS = zc->dimensionOfLinealitySpace(); |
---|
| 978 | if (d == dLS + 1) |
---|
| 979 | { |
---|
| 980 | gfan::ZVector zv = zc->semiGroupGeneratorOfRay(); |
---|
| 981 | res->rtyp = BIGINTMAT_CMD; |
---|
| 982 | res->data = (void*) zVectorToBigintmat(zv); |
---|
| 983 | return FALSE; |
---|
| 984 | } |
---|
| 985 | Werror("expected dim of cone one larger than dim of lin space\n" |
---|
| 986 | "but got dimensions %d and %d", d, dLS); |
---|
| 987 | } |
---|
| 988 | WerrorS("semigroupGenerator: unexpected parameters"); |
---|
| 989 | return TRUE; |
---|
| 990 | } |
---|
| 991 | |
---|
| 992 | BOOLEAN relativeInteriorPoint(leftv res, leftv args) |
---|
| 993 | { |
---|
| 994 | leftv u = args; |
---|
| 995 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 996 | { |
---|
| 997 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 998 | gfan::ZVector zv = zc->getRelativeInteriorPoint(); |
---|
| 999 | res->rtyp = BIGINTMAT_CMD; |
---|
| 1000 | res->data = (void*) zVectorToBigintmat(zv); |
---|
| 1001 | return FALSE; |
---|
| 1002 | } |
---|
| 1003 | WerrorS("relativeInteriorPoint: unexpected parameters"); |
---|
| 1004 | return TRUE; |
---|
| 1005 | } |
---|
| 1006 | |
---|
| 1007 | BOOLEAN uniquePoint(leftv res, leftv args) |
---|
| 1008 | { |
---|
| 1009 | leftv u = args; |
---|
| 1010 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 1011 | { |
---|
| 1012 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 1013 | gfan::ZVector zv = zc->getUniquePoint(); |
---|
| 1014 | res->rtyp = BIGINTMAT_CMD; |
---|
| 1015 | res->data = (void*) zVectorToBigintmat(zv); |
---|
| 1016 | return FALSE; |
---|
| 1017 | } |
---|
| 1018 | WerrorS("uniquePoint: unexpected parameters"); |
---|
| 1019 | return TRUE; |
---|
| 1020 | } |
---|
| 1021 | |
---|
| 1022 | gfan::ZVector randomPoint(const gfan::ZCone* zc) |
---|
| 1023 | { |
---|
| 1024 | gfan::ZMatrix rays = zc->extremeRays(); |
---|
| 1025 | gfan::ZVector rp = gfan::ZVector(zc->ambientDimension()); |
---|
| 1026 | for (int i=0; i<rays.getHeight(); i++) |
---|
| 1027 | { |
---|
| 1028 | int n = siRand(); |
---|
| 1029 | rp = rp + n * rays[i]; |
---|
| 1030 | } |
---|
| 1031 | return rp; |
---|
| 1032 | } |
---|
| 1033 | |
---|
| 1034 | BOOLEAN randomPoint(leftv res, leftv args) |
---|
| 1035 | { |
---|
| 1036 | leftv u = args; |
---|
| 1037 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 1038 | { |
---|
| 1039 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 1040 | gfan::ZVector zv = randomPoint(zc); |
---|
| 1041 | res->rtyp = BIGINTMAT_CMD; |
---|
| 1042 | res->data = (void*) zVectorToBigintmat(zv); |
---|
| 1043 | return FALSE; |
---|
| 1044 | } |
---|
| 1045 | WerrorS("randomPoint: unexpected parameters"); |
---|
| 1046 | return TRUE; |
---|
| 1047 | } |
---|
| 1048 | |
---|
| 1049 | BOOLEAN setMultiplicity(leftv res, leftv args) |
---|
| 1050 | { |
---|
| 1051 | leftv u = args; |
---|
| 1052 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 1053 | { |
---|
| 1054 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 1055 | leftv v = u->next; |
---|
| 1056 | if ((v != NULL) && (v->Typ() == INT_CMD)) |
---|
| 1057 | { |
---|
| 1058 | int val = (int)(long)v->Data(); |
---|
| 1059 | zc->setMultiplicity(gfan::Integer(val)); |
---|
| 1060 | res->rtyp = NONE; |
---|
| 1061 | res->data = NULL; |
---|
| 1062 | return FALSE; |
---|
| 1063 | } |
---|
| 1064 | } |
---|
| 1065 | WerrorS("setMultiplicity: unexpected parameters"); |
---|
| 1066 | return TRUE; |
---|
| 1067 | } |
---|
| 1068 | |
---|
| 1069 | BOOLEAN setLinearForms(leftv res, leftv args) |
---|
| 1070 | { |
---|
| 1071 | leftv u = args; |
---|
| 1072 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 1073 | { |
---|
| 1074 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 1075 | leftv v = u->next; |
---|
| 1076 | if ((v != NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTVEC_CMD))) |
---|
| 1077 | { |
---|
| 1078 | bigintmat* mat=NULL; |
---|
| 1079 | if (v->Typ() == INTVEC_CMD) |
---|
| 1080 | { |
---|
| 1081 | intvec* mat0 = (intvec*) v->Data(); |
---|
| 1082 | mat = iv2bim(mat0,coeffs_BIGINT)->transpose(); |
---|
| 1083 | } |
---|
| 1084 | else |
---|
| 1085 | mat = (bigintmat*) v->Data(); |
---|
| 1086 | gfan::ZMatrix* zm = bigintmatToZMatrix(mat); |
---|
| 1087 | zc->setLinearForms(*zm); |
---|
| 1088 | res->rtyp = NONE; |
---|
| 1089 | res->data = NULL; |
---|
| 1090 | |
---|
| 1091 | delete zm; |
---|
| 1092 | if (v->Typ() == INTVEC_CMD) |
---|
| 1093 | delete mat; |
---|
| 1094 | return FALSE; |
---|
| 1095 | } |
---|
| 1096 | } |
---|
| 1097 | WerrorS("setLinearForms: unexpected parameters"); |
---|
| 1098 | return TRUE; |
---|
| 1099 | } |
---|
| 1100 | |
---|
| 1101 | gfan::ZMatrix liftUp(const gfan::ZMatrix &zm) |
---|
| 1102 | { |
---|
| 1103 | int r=zm.getHeight(); |
---|
| 1104 | int c=zm.getWidth(); |
---|
| 1105 | gfan::ZMatrix zn(r+1,c+1); |
---|
| 1106 | zn[1][1]=1; |
---|
| 1107 | for (int i=0; i<r; i++) |
---|
| 1108 | for (int j=0; j<c; j++) |
---|
| 1109 | zn[i+1][j+1]=zm[i][j]; |
---|
| 1110 | return zn; |
---|
| 1111 | } |
---|
| 1112 | |
---|
| 1113 | gfan::ZCone liftUp(const gfan::ZCone &zc) |
---|
| 1114 | { |
---|
| 1115 | gfan::ZMatrix ineq=zc.getInequalities(); |
---|
| 1116 | gfan::ZMatrix eq=zc.getEquations(); |
---|
| 1117 | gfan::ZCone zd(liftUp(ineq),liftUp(eq)); |
---|
| 1118 | return zd; |
---|
| 1119 | } |
---|
| 1120 | |
---|
| 1121 | BOOLEAN coneToPolytope(leftv res, leftv args) |
---|
| 1122 | { |
---|
| 1123 | leftv u = args; |
---|
| 1124 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 1125 | { |
---|
| 1126 | gfan::ZCone* zc = (gfan::ZCone*) u->Data(); |
---|
| 1127 | gfan::ZMatrix ineq=zc->getInequalities(); |
---|
| 1128 | gfan::ZMatrix eq=zc->getEquations(); |
---|
| 1129 | gfan::ZCone* zd = new gfan::ZCone(liftUp(ineq),liftUp(eq)); |
---|
| 1130 | res->rtyp = polytopeID; |
---|
| 1131 | res->data = (void*) zd; |
---|
| 1132 | return FALSE; |
---|
| 1133 | } |
---|
| 1134 | WerrorS("makePolytope: unexpected parameters"); |
---|
| 1135 | return TRUE; |
---|
| 1136 | } |
---|
| 1137 | |
---|
| 1138 | BOOLEAN intersectCones(leftv res, leftv args) |
---|
| 1139 | { |
---|
| 1140 | leftv u = args; |
---|
| 1141 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 1142 | { |
---|
| 1143 | leftv v = u->next; |
---|
| 1144 | if ((v != NULL) && (v->Typ() == coneID)) |
---|
| 1145 | { |
---|
| 1146 | gfan::ZCone* zc1 = (gfan::ZCone*)u->Data(); |
---|
| 1147 | gfan::ZCone* zc2 = (gfan::ZCone*)v->Data(); |
---|
| 1148 | int d1 = zc1->ambientDimension(); |
---|
| 1149 | int d2 = zc2->ambientDimension(); |
---|
| 1150 | if (d1 != d2) |
---|
| 1151 | { |
---|
| 1152 | Werror("expected ambient dims of both cones to coincide\n" |
---|
| 1153 | "but got %d and %d", d1, d2); |
---|
| 1154 | return TRUE; |
---|
| 1155 | } |
---|
| 1156 | gfan::ZCone zc3 = gfan::intersection(*zc1, *zc2); |
---|
| 1157 | zc3.canonicalize(); |
---|
| 1158 | res->rtyp = coneID; |
---|
| 1159 | res->data = (void *)new gfan::ZCone(zc3); |
---|
| 1160 | return FALSE; |
---|
| 1161 | } |
---|
| 1162 | if ((v != NULL) && (v->Typ() == polytopeID)) |
---|
| 1163 | { |
---|
| 1164 | gfan::ZCone* zc11 = (gfan::ZCone*)u->Data(); |
---|
| 1165 | gfan::ZCone zc1 = liftUp(*zc11); |
---|
| 1166 | gfan::ZCone* zc2 = (gfan::ZCone*)v->Data(); |
---|
| 1167 | int d1 = zc1.ambientDimension(); |
---|
| 1168 | int d2 = zc2->ambientDimension(); |
---|
| 1169 | if (d1 != d2) |
---|
| 1170 | { |
---|
| 1171 | Werror("expected ambient dims of both cones to coincide\n" |
---|
| 1172 | "but got %d and %d", d1, d2); |
---|
| 1173 | return TRUE; |
---|
| 1174 | } |
---|
| 1175 | gfan::ZCone zc3 = gfan::intersection(zc1, *zc2); |
---|
| 1176 | zc3.canonicalize(); |
---|
| 1177 | res->rtyp = polytopeID; |
---|
| 1178 | res->data = (void *)new gfan::ZCone(zc3); |
---|
| 1179 | return FALSE; |
---|
| 1180 | } |
---|
| 1181 | } |
---|
| 1182 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
| 1183 | { |
---|
| 1184 | leftv v = u->next; |
---|
| 1185 | if ((v != NULL) && (v->Typ() == coneID)) |
---|
| 1186 | { |
---|
| 1187 | gfan::ZCone* zc1 = (gfan::ZCone*)u->Data(); |
---|
| 1188 | gfan::ZCone* zc22 = (gfan::ZCone*)v->Data(); |
---|
| 1189 | gfan::ZCone zc2 = liftUp(*zc22); |
---|
| 1190 | int d1 = zc1->ambientDimension(); |
---|
| 1191 | int d2 = zc2.ambientDimension(); |
---|
| 1192 | if (d1 != d2) |
---|
| 1193 | { |
---|
| 1194 | Werror("expected ambient dims of both cones to coincide\n" |
---|
| 1195 | "but got %d and %d", d1, d2); |
---|
| 1196 | return TRUE; |
---|
| 1197 | } |
---|
| 1198 | gfan::ZCone zc3 = gfan::intersection(*zc1, zc2); |
---|
| 1199 | zc3.canonicalize(); |
---|
| 1200 | res->rtyp = polytopeID; |
---|
| 1201 | res->data = (void *)new gfan::ZCone(zc3); |
---|
| 1202 | return FALSE; |
---|
| 1203 | } |
---|
| 1204 | if ((v != NULL) && (v->Typ() == polytopeID)) |
---|
| 1205 | { |
---|
| 1206 | gfan::ZCone* zc1 = (gfan::ZCone*)u->Data(); |
---|
| 1207 | gfan::ZCone* zc2 = (gfan::ZCone*)v->Data(); |
---|
| 1208 | int d1 = zc1->ambientDimension(); |
---|
| 1209 | int d2 = zc2->ambientDimension(); |
---|
| 1210 | if (d1 != d2) |
---|
| 1211 | { |
---|
| 1212 | Werror("expected ambient dims of both cones to coincide\n" |
---|
| 1213 | "but got %d and %d", d1, d2); |
---|
| 1214 | return TRUE; |
---|
| 1215 | } |
---|
| 1216 | gfan::ZCone zc3 = gfan::intersection(*zc1, *zc2); |
---|
| 1217 | zc3.canonicalize(); |
---|
| 1218 | res->rtyp = polytopeID; |
---|
| 1219 | res->data = (void *)new gfan::ZCone(zc3); |
---|
| 1220 | return FALSE; |
---|
| 1221 | } |
---|
| 1222 | } |
---|
| 1223 | WerrorS("convexIntersection: unexpected parameters"); |
---|
| 1224 | return TRUE; |
---|
| 1225 | } |
---|
| 1226 | |
---|
| 1227 | BOOLEAN convexHull(leftv res, leftv args) |
---|
| 1228 | { |
---|
| 1229 | leftv u = args; |
---|
| 1230 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 1231 | { |
---|
| 1232 | leftv v = u->next; |
---|
| 1233 | if ((v != NULL) && (v->Typ() == coneID)) |
---|
| 1234 | { |
---|
| 1235 | gfan::ZCone* zc1 = (gfan::ZCone*)u->Data(); |
---|
| 1236 | gfan::ZCone* zc2 = (gfan::ZCone*)v->Data(); |
---|
| 1237 | int d1 = zc1->ambientDimension(); |
---|
| 1238 | int d2 = zc2->ambientDimension(); |
---|
| 1239 | if (d1 != d2) |
---|
| 1240 | { |
---|
| 1241 | Werror("expected ambient dims of both cones to coincide\n" |
---|
| 1242 | "but got %d and %d", d1, d2); |
---|
| 1243 | return TRUE; |
---|
| 1244 | } |
---|
| 1245 | gfan::ZMatrix zm1 = zc1->extremeRays(); |
---|
| 1246 | gfan::ZMatrix zm2 = zc2->extremeRays(); |
---|
| 1247 | gfan::ZMatrix zn1 = zc1->generatorsOfLinealitySpace(); |
---|
| 1248 | gfan::ZMatrix zn2 = zc2->generatorsOfLinealitySpace(); |
---|
| 1249 | gfan::ZMatrix zm = combineOnTop(zm1,zm2); |
---|
| 1250 | gfan::ZMatrix zn = combineOnTop(zn1,zn2); |
---|
| 1251 | gfan::ZCone* zc = new gfan::ZCone(); |
---|
| 1252 | *zc = gfan::ZCone::givenByRays(zm, zn); |
---|
| 1253 | res->rtyp = coneID; |
---|
| 1254 | res->data = (void*) zc; |
---|
| 1255 | return FALSE; |
---|
| 1256 | } |
---|
| 1257 | if ((v != NULL) && (v->Typ() == polytopeID)) |
---|
| 1258 | { |
---|
| 1259 | gfan::ZCone* zc11 = (gfan::ZCone*)u->Data(); |
---|
| 1260 | gfan::ZCone zc1 = liftUp(*zc11); |
---|
| 1261 | gfan::ZCone* zc2 = (gfan::ZCone*)v->Data(); |
---|
| 1262 | int d1 = zc1.ambientDimension()-1; |
---|
| 1263 | int d2 = zc2->ambientDimension()-1; |
---|
| 1264 | if (d1 != d2) |
---|
| 1265 | { |
---|
| 1266 | Werror("expected ambient dims of both cones to coincide\n" |
---|
| 1267 | "but got %d and %d", d1, d2); |
---|
| 1268 | return TRUE; |
---|
| 1269 | } |
---|
| 1270 | gfan::ZMatrix zm1 = zc1.extremeRays(); |
---|
| 1271 | gfan::ZMatrix zm2 = zc2->extremeRays(); |
---|
| 1272 | gfan::ZMatrix zn = zc1.generatorsOfLinealitySpace(); |
---|
| 1273 | gfan::ZMatrix zm = combineOnTop(zm1,zm2); |
---|
| 1274 | gfan::ZCone* zc = new gfan::ZCone(); |
---|
| 1275 | *zc = gfan::ZCone::givenByRays(zm, zn); |
---|
| 1276 | res->rtyp = polytopeID; |
---|
| 1277 | res->data = (void*) zc; |
---|
| 1278 | return FALSE; |
---|
| 1279 | } |
---|
| 1280 | } |
---|
| 1281 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
| 1282 | { |
---|
| 1283 | leftv v = u->next; |
---|
| 1284 | if ((v != NULL) && (v->Typ() == coneID)) |
---|
| 1285 | { |
---|
| 1286 | gfan::ZCone* zc1 = (gfan::ZCone*)u->Data(); |
---|
| 1287 | gfan::ZCone* zc22 = (gfan::ZCone*)v->Data(); |
---|
| 1288 | gfan::ZCone zc2 = liftUp(*zc22); |
---|
| 1289 | int d1 = zc1->ambientDimension()-1; |
---|
| 1290 | int d2 = zc2.ambientDimension()-1; |
---|
| 1291 | if (d1 != d2) |
---|
| 1292 | { |
---|
| 1293 | Werror("expected ambient dims of both cones to coincide\n" |
---|
| 1294 | "but got %d and %d", d1, d2); |
---|
| 1295 | return TRUE; |
---|
| 1296 | } |
---|
| 1297 | gfan::ZMatrix zm1 = zc1->extremeRays(); |
---|
| 1298 | gfan::ZMatrix zm2 = zc2.extremeRays(); |
---|
| 1299 | gfan::ZMatrix zn = zc2.generatorsOfLinealitySpace(); |
---|
| 1300 | gfan::ZMatrix zm = combineOnTop(zm1,zm2); |
---|
| 1301 | gfan::ZCone* zc = new gfan::ZCone(); |
---|
| 1302 | *zc = gfan::ZCone::givenByRays(zm,gfan::ZMatrix(0, zm.getWidth())); |
---|
| 1303 | res->rtyp = polytopeID; |
---|
| 1304 | res->data = (void*) zc; |
---|
| 1305 | return FALSE; |
---|
| 1306 | } |
---|
| 1307 | if ((v != NULL) && (v->Typ() == polytopeID)) |
---|
| 1308 | { |
---|
| 1309 | gfan::ZCone* zc1 = (gfan::ZCone*)u->Data(); |
---|
| 1310 | gfan::ZCone* zc2 = (gfan::ZCone*)v->Data(); |
---|
| 1311 | int d1 = zc1->ambientDimension()-1; |
---|
| 1312 | int d2 = zc2->ambientDimension()-1; |
---|
| 1313 | if (d1 != d2) |
---|
| 1314 | { |
---|
| 1315 | Werror("expected ambient dims of both cones to coincide\n" |
---|
| 1316 | "but got %d and %d", d1, d2); |
---|
| 1317 | return TRUE; |
---|
| 1318 | } |
---|
| 1319 | gfan::ZMatrix zm1 = zc1->extremeRays(); |
---|
| 1320 | gfan::ZMatrix zm2 = zc2->extremeRays(); |
---|
| 1321 | gfan::ZMatrix zm = combineOnTop(zm1,zm2); |
---|
| 1322 | gfan::ZCone* zc = new gfan::ZCone(); |
---|
| 1323 | *zc = gfan::ZCone::givenByRays(zm,gfan::ZMatrix(0, zm.getWidth())); |
---|
| 1324 | res->rtyp = polytopeID; |
---|
| 1325 | res->data = (void*) zc; |
---|
| 1326 | return FALSE; |
---|
| 1327 | } |
---|
| 1328 | } |
---|
| 1329 | WerrorS("convexHull: unexpected parameters"); |
---|
| 1330 | return TRUE; |
---|
| 1331 | } |
---|
| 1332 | |
---|
| 1333 | BOOLEAN coneLink(leftv res, leftv args) |
---|
| 1334 | { |
---|
| 1335 | leftv u = args; |
---|
| 1336 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 1337 | { |
---|
| 1338 | leftv v = u->next; |
---|
| 1339 | if ((v != NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTVEC_CMD))) |
---|
| 1340 | { |
---|
| 1341 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 1342 | bigintmat* iv = NULL; |
---|
| 1343 | if (v->Typ() == INTVEC_CMD) |
---|
| 1344 | { |
---|
| 1345 | intvec* iv0 = (intvec*) v->Data(); |
---|
| 1346 | iv = iv2bim(iv0,coeffs_BIGINT)->transpose(); |
---|
| 1347 | } |
---|
| 1348 | else |
---|
| 1349 | iv = (bigintmat*)v->Data(); |
---|
| 1350 | gfan::ZVector* zv = bigintmatToZVector(iv); |
---|
| 1351 | int d1 = zc->ambientDimension(); |
---|
| 1352 | int d2 = zv->size(); |
---|
| 1353 | if (d1 != d2) |
---|
| 1354 | { |
---|
| 1355 | Werror("expected ambient dim of cone and size of vector\n" |
---|
| 1356 | " to be equal but got %d and %d", d1, d2); |
---|
| 1357 | return TRUE; |
---|
| 1358 | } |
---|
| 1359 | if(!zc->contains(*zv)) |
---|
| 1360 | { |
---|
| 1361 | WerrorS("the provided intvec does not lie in the cone"); |
---|
| 1362 | return TRUE; |
---|
| 1363 | } |
---|
| 1364 | gfan::ZCone* zd = new gfan::ZCone(zc->link(*zv)); |
---|
| 1365 | res->rtyp = coneID; |
---|
| 1366 | res->data = (void *) zd; |
---|
| 1367 | |
---|
| 1368 | delete zv; |
---|
| 1369 | if (v->Typ() == INTMAT_CMD) |
---|
| 1370 | delete iv; |
---|
| 1371 | return FALSE; |
---|
| 1372 | } |
---|
| 1373 | } |
---|
| 1374 | WerrorS("coneLink: unexpected parameters"); |
---|
| 1375 | return TRUE; |
---|
| 1376 | } |
---|
| 1377 | |
---|
| 1378 | BOOLEAN containsInSupport(leftv res, leftv args) |
---|
| 1379 | { |
---|
| 1380 | leftv u=args; |
---|
| 1381 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 1382 | { |
---|
| 1383 | leftv v=u->next; |
---|
| 1384 | if ((v != NULL) && (v->Typ() == coneID)) |
---|
| 1385 | { |
---|
| 1386 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 1387 | gfan::ZCone* zd = (gfan::ZCone*)v->Data(); |
---|
| 1388 | int d1 = zc->ambientDimension(); |
---|
| 1389 | int d2 = zd->ambientDimension(); |
---|
| 1390 | if (d1 != d2) |
---|
| 1391 | { |
---|
| 1392 | Werror("expected cones with same ambient dimensions\n but got" |
---|
| 1393 | " dimensions %d and %d", d1, d2); |
---|
| 1394 | return TRUE; |
---|
| 1395 | } |
---|
| 1396 | bool b = (zc->contains(*zd) ? 1 : 0); |
---|
| 1397 | res->rtyp = INT_CMD; |
---|
| 1398 | res->data = (void*) (long) b; |
---|
| 1399 | return FALSE; |
---|
| 1400 | } |
---|
| 1401 | if ((v != NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTVEC_CMD))) |
---|
| 1402 | { |
---|
| 1403 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 1404 | bigintmat* iv = NULL; |
---|
| 1405 | if (v->Typ() == INTVEC_CMD) |
---|
| 1406 | { |
---|
| 1407 | intvec* iv0 = (intvec*) v->Data(); |
---|
| 1408 | iv = iv2bim(iv0,coeffs_BIGINT)->transpose(); |
---|
| 1409 | } |
---|
| 1410 | else |
---|
| 1411 | iv = (bigintmat*)v->Data(); |
---|
| 1412 | |
---|
| 1413 | gfan::ZVector* zv = bigintmatToZVector(iv); |
---|
| 1414 | int d1 = zc->ambientDimension(); |
---|
| 1415 | int d2 = zv->size(); |
---|
| 1416 | if (d1 != d2) |
---|
| 1417 | { |
---|
| 1418 | Werror("expected cones with same ambient dimensions\n but got" |
---|
| 1419 | " dimensions %d and %d", d1, d2); |
---|
| 1420 | return TRUE; |
---|
| 1421 | } |
---|
| 1422 | int b = zc->contains(*zv); |
---|
| 1423 | res->rtyp = INT_CMD; |
---|
| 1424 | res->data = (void*) (long) b; |
---|
| 1425 | |
---|
| 1426 | delete zv; |
---|
| 1427 | if (v->Typ() == INTMAT_CMD) |
---|
| 1428 | delete iv; |
---|
| 1429 | return FALSE; |
---|
| 1430 | } |
---|
| 1431 | } |
---|
| 1432 | WerrorS("containsInSupport: unexpected parameters"); |
---|
| 1433 | return TRUE; |
---|
| 1434 | } |
---|
| 1435 | |
---|
| 1436 | BOOLEAN containsRelatively(leftv res, leftv args) |
---|
| 1437 | { |
---|
| 1438 | leftv u = args; |
---|
| 1439 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 1440 | { |
---|
| 1441 | leftv v = u->next; |
---|
| 1442 | if ((v != NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTVEC_CMD))) |
---|
| 1443 | { |
---|
| 1444 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 1445 | bigintmat* iv = NULL; |
---|
| 1446 | if (v->Typ() == INTVEC_CMD) |
---|
| 1447 | { |
---|
| 1448 | intvec* iv0 = (intvec*) v->Data(); |
---|
| 1449 | iv = iv2bim(iv0,coeffs_BIGINT)->transpose(); |
---|
| 1450 | } |
---|
| 1451 | else |
---|
| 1452 | iv = (bigintmat*)v->Data(); |
---|
| 1453 | gfan::ZVector* zv = bigintmatToZVector(iv); |
---|
| 1454 | int d1 = zc->ambientDimension(); |
---|
| 1455 | int d2 = zv->size(); |
---|
| 1456 | if (d1 == d2) |
---|
| 1457 | { |
---|
| 1458 | bool b = (zc->containsRelatively(*zv) ? 1 : 0); |
---|
| 1459 | res->rtyp = INT_CMD; |
---|
| 1460 | res->data = (void *) b; |
---|
| 1461 | delete zv; |
---|
| 1462 | if (v->Typ() == INTMAT_CMD) |
---|
| 1463 | delete iv; |
---|
| 1464 | return FALSE; |
---|
| 1465 | } |
---|
| 1466 | delete zv; |
---|
| 1467 | if (v->Typ() == INTMAT_CMD) |
---|
| 1468 | delete iv; |
---|
| 1469 | Werror("expected ambient dim of cone and size of vector\n" |
---|
| 1470 | "to be equal but got %d and %d", d1, d2); |
---|
| 1471 | } |
---|
| 1472 | } |
---|
| 1473 | WerrorS("containsRelatively: unexpected parameters"); |
---|
| 1474 | return TRUE; |
---|
| 1475 | } |
---|
| 1476 | |
---|
| 1477 | BOOLEAN hasFace(leftv res, leftv args) |
---|
| 1478 | { |
---|
| 1479 | leftv u=args; |
---|
| 1480 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 1481 | { |
---|
| 1482 | leftv v=u->next; |
---|
| 1483 | if ((v != NULL) && (v->Typ() == coneID)) |
---|
| 1484 | { |
---|
| 1485 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 1486 | gfan::ZCone* zd = (gfan::ZCone*)v->Data(); |
---|
| 1487 | bool b = zc->hasFace(*zd); |
---|
| 1488 | res->rtyp = INT_CMD; |
---|
| 1489 | res->data = (void*) (long) b; |
---|
| 1490 | return FALSE; |
---|
| 1491 | } |
---|
| 1492 | } |
---|
| 1493 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
| 1494 | { |
---|
| 1495 | leftv v=u->next; |
---|
| 1496 | if ((v != NULL) && (v->Typ() == polytopeID)) |
---|
| 1497 | { |
---|
| 1498 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 1499 | gfan::ZCone* zd = (gfan::ZCone*)v->Data(); |
---|
| 1500 | bool b = zc->hasFace(*zd); |
---|
| 1501 | res->rtyp = INT_CMD; |
---|
| 1502 | res->data = (void*) (long) b; |
---|
| 1503 | return FALSE; |
---|
| 1504 | } |
---|
| 1505 | } |
---|
| 1506 | WerrorS("containsAsFace: unexpected parameters"); |
---|
| 1507 | return TRUE; |
---|
| 1508 | } |
---|
| 1509 | |
---|
| 1510 | BOOLEAN canonicalizeCone(leftv res, leftv args) |
---|
| 1511 | { |
---|
| 1512 | leftv u=args; |
---|
| 1513 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
| 1514 | { |
---|
| 1515 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
| 1516 | gfan::ZCone* zd = new gfan::ZCone(*zc); |
---|
| 1517 | zd->canonicalize(); |
---|
| 1518 | res->rtyp = coneID; |
---|
| 1519 | res->data = (void*) zd; |
---|
| 1520 | return FALSE; |
---|
| 1521 | } |
---|
| 1522 | WerrorS("canonicalizeCone: unexpected parameters"); |
---|
| 1523 | return TRUE; |
---|
| 1524 | } |
---|
| 1525 | |
---|
| 1526 | BOOLEAN containsCone(leftv res, leftv args) |
---|
| 1527 | { |
---|
| 1528 | leftv u=args; |
---|
| 1529 | if ((u != NULL) && (u->Typ() == LIST_CMD)) |
---|
| 1530 | { |
---|
| 1531 | leftv v=u->next; |
---|
| 1532 | if ((v != NULL) && (v->Typ() == coneID)) |
---|
| 1533 | { |
---|
| 1534 | lists l = (lists) u->Data(); |
---|
| 1535 | gfan::ZCone* zc = (gfan::ZCone*) v->Data(); |
---|
| 1536 | zc->canonicalize(); |
---|
| 1537 | int b = 0; |
---|
| 1538 | for (int i=0; i<=lSize(l); i++) |
---|
| 1539 | { |
---|
| 1540 | if (l->m[i].Typ() != coneID) |
---|
| 1541 | { |
---|
| 1542 | WerrorS("containsCone: entries of wrong type in list"); |
---|
| 1543 | return TRUE; |
---|
| 1544 | } |
---|
| 1545 | gfan::ZCone* ll = (gfan::ZCone*) l->m[i].Data(); |
---|
| 1546 | ll->canonicalize(); |
---|
| 1547 | if (!((*ll) != (*zc))) |
---|
| 1548 | { |
---|
| 1549 | b = 1; |
---|
| 1550 | break; |
---|
| 1551 | } |
---|
| 1552 | } |
---|
| 1553 | res->rtyp = INT_CMD; |
---|
| 1554 | res->data = (char*) (long) b; |
---|
| 1555 | return FALSE; |
---|
| 1556 | } |
---|
| 1557 | } |
---|
| 1558 | WerrorS("containsCone: unexpected parameters"); |
---|
| 1559 | return TRUE; |
---|
| 1560 | } |
---|
| 1561 | |
---|
[58b407] | 1562 | void bbcone_setup(SModulFunctions* p) |
---|
[81384b] | 1563 | { |
---|
| 1564 | blackbox *b=(blackbox*)omAlloc0(sizeof(blackbox)); |
---|
| 1565 | // all undefined entries will be set to default in setBlackboxStuff |
---|
| 1566 | // the default Print is quite usefull, |
---|
| 1567 | // all other are simply error messages |
---|
| 1568 | b->blackbox_destroy=bbcone_destroy; |
---|
| 1569 | b->blackbox_String=bbcone_String; |
---|
| 1570 | // b->blackbox_Print=blackbox_default_Print; |
---|
| 1571 | b->blackbox_Init=bbcone_Init; |
---|
| 1572 | b->blackbox_Copy=bbcone_Copy; |
---|
| 1573 | b->blackbox_Assign=bbcone_Assign; |
---|
| 1574 | b->blackbox_Op2=bbcone_Op2; |
---|
[58b407] | 1575 | p->iiAddCproc("","coneViaInequalities",FALSE,coneViaNormals); |
---|
| 1576 | p->iiAddCproc("","coneViaPoints",FALSE,coneViaRays); |
---|
[81384b] | 1577 | |
---|
| 1578 | // iiAddCproc("","makePolytope",FALSE,coneToPolytope); |
---|
[58b407] | 1579 | p->iiAddCproc("","ambientDimension",FALSE,ambientDimension); |
---|
| 1580 | p->iiAddCproc("","canonicalizeCone",FALSE,canonicalizeCone); |
---|
| 1581 | p->iiAddCproc("","codimension",FALSE,codimension); |
---|
| 1582 | p->iiAddCproc("","coneLink",FALSE,coneLink); |
---|
| 1583 | p->iiAddCproc("","containsAsFace",FALSE,hasFace); |
---|
| 1584 | p->iiAddCproc("","containsInSupport",FALSE,containsInSupport); |
---|
| 1585 | p->iiAddCproc("","containsPositiveVector",FALSE,containsPositiveVector); |
---|
| 1586 | p->iiAddCproc("","containsRelatively",FALSE,containsRelatively); |
---|
| 1587 | p->iiAddCproc("","convexHull",FALSE,convexHull); |
---|
| 1588 | p->iiAddCproc("","convexIntersection",FALSE,intersectCones); |
---|
| 1589 | p->iiAddCproc("","dimension",FALSE,dimension); |
---|
| 1590 | p->iiAddCproc("","dualCone",FALSE,dualCone); |
---|
| 1591 | p->iiAddCproc("","equations",FALSE,equations); |
---|
| 1592 | p->iiAddCproc("","facets",FALSE,facets); |
---|
| 1593 | p->iiAddCproc("","generatorsOfLinealitySpace",FALSE,generatorsOfLinealitySpace); |
---|
| 1594 | p->iiAddCproc("","generatorsOfSpan",FALSE,generatorsOfSpan); |
---|
| 1595 | p->iiAddCproc("","getLinearForms",FALSE,getLinearForms); |
---|
| 1596 | p->iiAddCproc("","getMultiplicity",FALSE,getMultiplicity); |
---|
| 1597 | p->iiAddCproc("","inequalities",FALSE,inequalities); |
---|
| 1598 | p->iiAddCproc("","isFullSpace",FALSE,isFullSpace); |
---|
| 1599 | p->iiAddCproc("","isOrigin",FALSE,isOrigin); |
---|
| 1600 | p->iiAddCproc("","isSimplicial",FALSE,isSimplicial); |
---|
| 1601 | p->iiAddCproc("","linealityDimension",FALSE,linealityDimension); |
---|
| 1602 | p->iiAddCproc("","linealitySpace",FALSE,linealitySpace); |
---|
| 1603 | p->iiAddCproc("","negatedCone",FALSE,negatedCone); |
---|
| 1604 | p->iiAddCproc("","quotientLatticeBasis",FALSE,quotientLatticeBasis); |
---|
| 1605 | p->iiAddCproc("","randomPoint",FALSE,randomPoint); |
---|
| 1606 | p->iiAddCproc("","rays",FALSE,rays); |
---|
| 1607 | p->iiAddCproc("","relativeInteriorPoint",FALSE,relativeInteriorPoint); |
---|
| 1608 | p->iiAddCproc("","semigroupGenerator",FALSE,semigroupGenerator); |
---|
| 1609 | p->iiAddCproc("","setLinearForms",FALSE,setLinearForms); |
---|
| 1610 | p->iiAddCproc("","setMultiplicity",FALSE,setMultiplicity); |
---|
| 1611 | p->iiAddCproc("","span",FALSE,impliedEquations); |
---|
| 1612 | p->iiAddCproc("","uniquePoint",FALSE,uniquePoint); |
---|
| 1613 | p->iiAddCproc("","listContainsCone",FALSE,containsCone); |
---|
[81384b] | 1614 | coneID=setBlackboxStuff(b,"cone"); |
---|
| 1615 | } |
---|