This file is indexed.

/usr/share/singular/LIB/gfan.lib is in singular-data 1:4.1.0-p3+ds-2build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
///////////////////////////////////////////////////////////////////////////////
version="version gfan.lib 4.0.3.3 Oct_2016 ";
category = "Convex Geometry";
info="
LIBRARY:  gfan.lib   Interface to gfanlib to enable computations in convex geometry
AUTHORS:  Anders N. Jensen, email: jensen@imf.au.dk
          Yue Ren,          email: ren@mathematik.uni-kl.de
          Frank Seelisch

PROCEDURES:
       fullSpace(n);       cone, the ambient space of dimension n
       origin(n);          cone, the origin in an ambient space of dimension n
       positiveOrthant(n); cone, the positive orthant of dimension n
       ambientDimension(c); the dimension of the ambient space the input lives in
       canonicalizeCone(c); a unique representation of the cone c
       codimension(c);      the codimension of the input
       coneViaPoints();     define a cone
       coneViaInequalities(); define a cone
       coneLink(c,w);       the link of c around w
       containsAsFace(c,d); is d a face of c
       containsInSupport(c,d); is d contained in c
       containsPositiveVector(c); contains a vector with only positive entries?
       containsRelatively(c,p); p in c?
       convexHull(c1,c2);   convex hull
       convexIntersection(c1,c2); convex hull
       dimension(c);         diemsion
       dualCone(c);          the dual of c
       equations(c);         defining equations of c
       faceContaining(c,w);  the face of c containing w in its relative interior
       facets(c);            the facets of c
       generatorsOfLinealitySpace(c); generators of the lineality space of c
       generatorsOfSpan(c);  generators of the span of c
       getLinearForms(c);    linear forms previously stored in c
       getMultiplicity(c);   multiplicity previously stored in c
       inequalities(c);      inequalities of c
       isFullSpace(c);       is the entire ambient space?
       isOrigin(c);          is the origin?
       isSimplicial(c);      is simplicial?
       linealityDimension(c); the dimension of the lineality space of c
       linealitySpace(c);    the lineality space of c
       negatedCone(c);       the negative of c
       polytopeViaInequalities();
       polytopeViaPoints();
       quotientLatticeBasis(c);  basis of Z^n intersected with the span of c modulo Z^n intersected with the lineality space of c
       randomPoint(c);       a random point in the relative interior of c
       rays(c);              generators of the rays of c
       relativeInteriorPoint(c); point in the relative interior of c
       semigroupGenerator(c); generator of Z^n intersected with c modulo Z^n intersected with the lineality space of c
       setLinearForms(c);    stores linear forms in c
       setMultiplicity(c);   stores a multiplicity in c
       span(c);              unique irredundant equations of c
       uniquePoint(c);       a unique point in c stable under reflections at coordinate hyperplanes
       containsInCollection(f,c); f contains c?
       emptyFan(n);           empty fan in ambient dimension n
       fanViaCones(L);        fan generated by the cones in L
       fullFan(n);            full fan in ambient dimension n
       fVector(f);            the f-Vector of f
       getCone(f,d,i[,o,m]);  the i-th cone in dimensiond in f
       insertCone(f,c[,b]);   inserts the cone c into f
       isCompatible(f,c);     f and c live in the same ambient space
       isPure(f);             all maximal cones of f are of the same dimension
       nmaxcones(f);          number of maximal cones in f
       ncones(f);             number of cones in f
       numberOfConesOfDimension(f,d[,o,m]); the number of cones in dimension d
       removeCone(f,c[,b]);   removes the cone c
       dualPolytope(p);       the dual of p
       newtonPolytope(f);     convex hull of all exponent vectors of f
       vertices(p);           vertices of p
";

///////////////////////////////////////////////////////////////////////////////

/////
// non gfanlib.so functions
/////

proc fullSpace(int n)
"USAGE:   fullSpace(n);  n int
RETURN:  cone, the ambient space of dimension n
EXAMPLE: example positiveOrthant; shows an example
"
{
  cone c = n;
  return (c);
}
example
{
  "EXAMPLE:"; echo = 2;
  cone c = fullSpace(2);
  generatorsOfLinealitySpace(c);
}

proc origin(int n)
"USAGE:   origin(n);  n int
RETURN:  cone, the origin in an ambient space of dimension n
EXAMPLE: example origin; shows an example
"
{
  bigintmat ineq[0][n];
  bigintmat eq[n][n];
  for (int i=1; i<=n; i++)
  {
    eq[i,i]=1;
  }
  cone o = coneViaInequalities(ineq,eq);
  return (o);
}
example
{
  "EXAMPLE:"; echo = 2;
  cone c = origin(2);
  equations(c);
}

proc positiveOrthant(int n)
"USAGE:   positiveOrthant(n);  n int
RETURN:  cone, the positive orthant of dimension n
EXAMPLE: example positiveOrthant; shows an example
"
{
  bigintmat ineq[n][n];
  for (int i=1; i<=n; i++)
  {
    ineq[i,i]=1;
  }
  cone posOrthant = coneViaInequalities(ineq);
  return (posOrthant);
}
example
{
  "EXAMPLE:"; echo = 2;
  cone c = positiveOrthant(2);
  rays(c);
}


/////
// cone related functions
/////

proc ambientDimension()
"USAGE:   ambientDimension(c);  c cone
         ambientDimension(f);  f fan
         ambientDimension(p);  p polytope
RETURN:  int, the dimension of the ambient space the input lives in
EXAMPLE: example ambientDimension; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M1[2][2]=
    1,0,
    0,1;
  cone c1=coneViaPoints(M1);
  ambientDimension(c1);
  intmat M2[2][3]=
    1,0,0,
    0,1,0;
  cone c2=coneViaPoints(M2);
  ambientDimension(c2);

  fan f = emptyFan(3);
  ambientDimension(f);
}

proc canonicalizeCone()
"USAGE:   canonicalizeCone(c);  c cone
RETURN:  cone, a unique representation of the cone c
EXAMPLE: example canonicalizeCone; shows an example
"
{
}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M[5][3]=
    8,1,9,
    9,2,4,
    0,6,2,
    8,8,8,
    0,9,5;
  cone c=coneViaInequalities(M);
  c;
  cone cc=canonicalizeCone(c);
  cc;
  // computes a unique representation of c
  c == cc;
  // some procedures work with the known inequalities and equations
  // in order to obtain a unique output,
  // bring the cone in canonical form beforehand
  relativeInteriorPoint(c);
  relativeInteriorPoint(cc);
}

proc codimension()
"USAGE:   codimension(c);  c cone
         codimension(f);  f fan
         codimension(p);  p polytope
RETURN:  int, the codimension of the input
EXAMPLE: example codimension; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M1[1][2]=
    1,0;
  cone c1=coneViaPoints(M1);
  codimension(c1);
  intmat M2[2][2]=
    1,0,
    0,1;
  cone c2=coneViaPoints(M2);
  codimension(c2);

  fan f = emptyFan(2);
  codimension(f);
  insertCone(f,c1);
  codimension(f);
  insertCone(f,c2);
  codimension(f);
}

proc coneViaPoints()
"USAGE:   coneViaPoints(HL); intmat HL
          coneViaPoints(HL,L); intmat HL, intmat L
          coneViaPoints(HL,L,flags); intmat HL, intmat L, int flags
RETURN:  cone
PURPOSE: cone generated by half lines generated by the row vectors of HL
  and (if stated) by lines generated by the row vectors of L;
  flags may range between 0,..,3 defining an upper and lower bit
  (0=0*2+0, 1=0*2+1, 2=1*2+0, 3=1*2+1),
  if upper bit is 1, then program assumes that each row vector in HL
  generates a ray of the cone,
  if lower bit is 1, then program assumes that the span of the row
  vectors of L is the lineality space of the cone,
  if either bit is 0, then program computes the information itself.
EXAMPLE: example coneViaPoints; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  // Let's define a cone in R^3 generated by the following half lines:
  intmat HL[5][3]=
   1,0, 0,
  -1,0, 0,
   0,1, 1,
   0,1,-1,
   0,0, 1;
  cone c=coneViaPoints(HL);
  c;
  kill HL,c;
  // Note that (1,0,0) and (-1,0,0) form a line, hence also possible:
  intmat HL[3][3]=
  0,1, 1,
  0,1,-1,
  0,0, 1;
  intmat L[1][3]=
  1,0,0;
  cone c=coneViaPoints(HL,L);
  c;
  kill HL,L,c;
  // lineality space is exactly Lin(1,0,0)
  intmat HL[3][3]=
  0,1, 1,
  0,1,-1,
  0,0, 1;
  intmat L[1][3]=
  1,0,0;
  cone c=coneViaPoints(HL,L,1);
  c;
  kill HL,L,c;
  // and that (0,1,-1), (0,1,1) generate rays
  intmat HL[3][3]=
  0,1, 1,
  0,1,-1;
  intmat L[1][3]=
  1,0,0;
  cone c=coneViaPoints(HL,L,1);
  c;
  kill HL,L,c;
  // and that (0,1,-1), (0,1,1) generate rays
  intmat HL[3][3]=
  0,1, 1,
  0,1,-1;
  intmat L[1][3]=
  1,0,0;
  cone c=coneViaPoints(HL,L,3);
  c;
}

proc coneViaInequalities()
"USAGE:   coneViaInequalities(IE); intmat IE
          coneViaInequalities(IE,E); intmat IE, intmat E
          coneViaInequalities(IE,E,flags); intmat IE, intmat E, int flags
RETURN:  cone
PURPOSE: cone consisting of all points x, such that IE*x >= 0 in each component
  and (if stated) E*x = 0;
  inequalities and (if stated) equations will be transformed, getting rid of
  redundancies;
  flags may range between 0,..,3 defining an upper and lower bit
  (0=0*2+0, 1=0*2+1, 2=1*2+0, 3=1*2+1),
  if higher bit is 1, then program assumes each inequality yields a facet,
  if lower bit is 1, then program assumes the kernel of E is the span of the cone,
  if either bit is 0, then program computes the information itself.
EXAMPLE: example coneViaInequalities; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  // Let's define a cone in R^3 given by the following inequalities:
  intmat IE[6][3]=
  1,3,5,
  1,5,3,
  0,1,-1,
  0,1,1,
  1,0,0,
  -1,0,0;
  cone c=coneViaInequalities(IE);
  c;
  // Note that the last two inequalities yield x1 = 0, hence also possible:
  intmat IE[4][3]=
  0,1,-1,
  0,1,1;
  intmat E[1][3]=
  1,0,0;
  cone c=coneViaInequalities(IE,E);
  c;
  // each inequalities gives rise to a facet
  intmat IE[2][3]=
  0,1,-1,
  0,1,1;
  intmat E[1][3]=
  1,0,0;
  cone c=coneViaInequalities(IE,E,1);
  c;
  // and the kernel of E is the span of the cone
  intmat IE[2][3]=
  0,1,-1,
  0,1,1;
  intmat E[1][3]=
  1,0,0;
  cone c=coneViaInequalities(IE,E,3);
  c;
}

proc coneLink()
"USAGE:   coneLink(c,w);  c cone, w intvec/bigintmat
RETURN:  cone, the link of c around w
EXAMPLE: example coneLink; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M[3][3]=
    1,0,0,
    0,1,0,
    0,0,1;
  cone c=coneViaPoints(M);
  intvec v=1,0,0;
  cone cv=coneLink(c,v);
  rays(cv);
  generatorsOfLinealitySpace(cv);
  intvec w=1,1,1;
  cone cw=coneLink(c,w);
  rays(cw);
  generatorsOfLinealitySpace(cw);
}

proc containsAsFace()
"USAGE:   containsAsFace(c,d);  c cone, d cone
RETURN:  1, if d is a face of c; 0 otherwise
EXAMPLE: example containsAsFace; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M[2][2]=
    1,0,
    0,1;
  cone c=coneViaPoints(M);
  intmat N1[1][2]=
    1,1;
  cone d1=coneViaPoints(N1);
  containsInSupport(c,d1);
  containsAsFace(c,d1);
  intmat N2[1][2]=
    0,1;
  cone d2=coneViaPoints(N2);
  containsInSupport(c,d2);
  containsAsFace(c,d2);
}

proc containsRelatively()
"USAGE:   containsRelatively(c,p);  c cone, intvec p
RETURN:  1 iff the given cone contains the given point in its relative interior; 0 otherwise
EXAMPLE: example containsRelatively; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M[2][2]=
  1,0,
  0,1;
  cone c=coneViaPoints(M);
  intvec p1=1,1;
  containsRelatively(c,p1);
  intvec p2=0,1;
  containsRelatively(c,p2);
}

proc containsInSupport()
"USAGE:   containsInSupport(c,d);  c cone, d cone
         containsInSupport(c,p);   c cone, p intvec/bigintmat
RETURN:  1, if d resp. p is contained in c; 0 otherwise
EXAMPLE: example containsInSupport; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M[2][2]=
    1,0,
    0,1;
  cone c=coneViaPoints(M);
  containsInSupport(c,c);
  intmat N1[2][2]=
    1,1,
    0,1;
  cone d1=coneViaPoints(N1);
  containsInSupport(c,d1);
  intmat N2[2][2]=
    1,1,
    1,-1;
  cone d2=coneViaPoints(N2);
  containsInSupport(c,d2);
  intvec p1=0,1;
  containsInSupport(c,p1);
  intvec p2=1,-1;
  containsInSupport(c,p2);
}

proc containsPositiveVector()
"USAGE:   containsPositiveVector(c);  c cone
RETURN:  1, if c contains a vector with only positive entries in its relative interior
EXAMPLE: example containsPositiveVector; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M1[2][2]=
    1,1,
    1,-1;
  cone c1=coneViaPoints(M1);
  containsPositiveVector(c1);
  intmat M2[2][2]=
    0,1,
    -1,0;
  cone c2=coneViaPoints(M2);
  containsPositiveVector(c2);
}

proc convexHull()
"USAGE:   convexHull(c1,c2);   c1 cone, c2 cone
         convexHull(c1,p1);   c1 cone, p1 polytope
         convexHull(p1,c1);   p1 cone, c1 polytope
         convexHull(p1,p2);   p1 polytope, p2 polytope
RETURN:  cone resp polytope, the convex hull of its two input objects
EXAMPLE: example convexHull; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M1[2][2]=
    1,0,
    0,1;
  cone c1=coneViaPoints(M1);
  intmat M2[2][2]=
    1,1,
    1,-1;
  cone c2=coneViaPoints(M2);
  intmat M3[2][2]=
    1,0,
    0,-1;
  cone c3=coneViaPoints(M3);
  cone c12=convexHull(c1,c2);
  c12;
  print(rays(c12));
  cone c23=convexHull(c2,c3);
  c23;
  print(rays(c23));
  cone c13=convexHull(c1,c3);
  c13;
  print(rays(c13));
}

proc convexIntersection()
"USAGE:   convexIntersection(c1,c2);   c1 cone, c2 cone
         convexIntersection(c1,p1);   c1 cone, p1 polytope
         convexIntersection(p1,c1);   p1 cone, c1 polytope
         convexIntersection(p1,p2);   p1 polytope, p2 polytope
RETURN:  cone resp polytope, the convex hull of its two input objects
EXAMPLE: example convexIntersection; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M1[2][2]=
    1,0,
    0,1;
  cone c1=coneViaPoints(M1);
  intmat M2[2][2]=
    1,1,
    1,-1;
  cone c2=coneViaPoints(M2);
  intmat M3[2][2]=
    1,0,
    0,-1;
  cone c3=coneViaPoints(M3);
  cone c12=convexIntersection(c1,c2);
  c12;
  print(rays(c12));
  cone c23=convexIntersection(c2,c3);
  c23;
  print(rays(c23));
  cone c13=convexIntersection(c1,c3);
  c13;
  print(rays(c13));
}

proc dimension()
"USAGE:   dimension(c);  c cone
         dimension(f);  f fan
         dimension(p);  p polytope
RETURN:  int, the dimension of the input
EXAMPLE: example dimension; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M1[1][2]=
    1,0;
  cone c1=coneViaPoints(M1);
  dimension(c1);
  intmat M2[2][2]=
    1,0,
    0,1;
  cone c2=coneViaPoints(M2);
  dimension(c2);

  fan f = emptyFan(2);
  dimension(f);
  insertCone(f,c1);
  dimension(f);
  insertCone(f,c2);
  dimension(f);
}

proc dualCone()
"USAGE:   dualCone(c);  c cone
RETURN:  cone, the dual of c
EXAMPLE: example dualCone; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M1[2][2]=
    1,0,
    0,1;
  cone c1=coneViaPoints(M1);
  cone d1=dualCone(c1);
  d1;
  print(rays(d1));
  intmat M2[2][2]=
    1,1,
    0,1;
  cone c2=coneViaPoints(M2);
  cone d2=dualCone(c2);
  d2;
  print(rays(d2));
}

proc equations()
"USAGE:   equations(c);  c cone
         equations(p);  p polytope
RETURN:  bigintmat, defining equations of c resp p
NOTE:    neither unique nor complete, unless c resp p in canonical form
EXAMPLE: example equations; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M1[2][2]=
    1,0,
    0,1;
  cone c1=coneViaPoints(M1);
  bigintmat E1=equations(c1);
  print(E1);
  intmat M2[1][2]=
    1,0;
  cone c2=coneViaPoints(M2);
  bigintmat E2=equations(c2);
  print(E2);
}

proc faceContaining()
"USAGE:   faceContaining(c,w);  c cone, w intvec/bigintmat
ASSUME:  containsInSupport(c,w)==1
RETURN:  cone, the face of c containing w in its relative interior
EXAMPLE: example faceContaining; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M[2][2]=
    1,0,
    0,1;
  cone c=coneViaPoints(M);
  faceContaining(c,intvec(1,0));
  faceContaining(c,intvec(0,1));
  faceContaining(c,intvec(1,1));
  faceContaining(c,intvec(0,0));
}

proc facets()
"USAGE:   facets(c);  c cone
         facets(p);  p polytope
RETURN:  bigintmat, the facets of c resp p
EXAMPLE: example facets; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M1[2][2]=
    1,0,
    0,1;
  cone c1=coneViaPoints(M1);
  bigintmat F1=facets(c1);
  print(F1);
  intmat M2[2][2]=
    1,1,
    0,-1;
  cone c2=coneViaPoints(M2);
  bigintmat F2=facets(c2);
  print(F2);
}

proc generatorsOfLinealitySpace()
"USAGE:   generatorsOfLinealitySpace(c);  c cone
RETURN:  bigintmat, generators of the lineality space of c
EXAMPLE: example generatorsOfLinealitySpace; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M[5][3]=
    1,0,0,
    0,1,0,
    0,0,1,
    -1,0,0,
    0,-1,0;
  cone c=coneViaPoints(M);
  bigintmat L=generatorsOfLinealitySpace(c);
  print(L);
}

proc generatorsOfSpan()
"USAGE:   generatorsOfSpan(c);  c cone
RETURN:  bigintmat, generators of the span of c
EXAMPLE: example generatorsOfSpan; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M[3][5]=
    1,0,0,0,0,
    0,1,0,0,0,
    0,0,1,0,0;
  cone c=coneViaPoints(M);
  bigintmat S=generatorsOfSpan(c);
  print(S);
}

proc getLinearForms()
"USAGE:   getLinearForms(c);  c cone
         getLinearForms(p);  p polytope
RETURN:  bigintmat, linear forms previously stored in c resp p
EXAMPLE: example getLinearForms; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M[2][3]=
    -1,0,0,
    0,-1,0;
  cone c=coneViaPoints(M);
  getLinearForms(c);
  intvec v=1,1,1;
  setLinearForms(c,v);
  getLinearForms(c);
}

proc getMultiplicity()
"USAGE:   getMultiplicity(c);  c cone
         getMultiplicity(p);  p polytope
RETURN:  bigint, 1 or a multiplicity previously stored in c resp p
EXAMPLE: example getMultiplicity; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M[2][3]=
    -1,0,0,
    0,-1,0;
  cone c=coneViaPoints(M);
  getMultiplicity(c);
  setMultiplicity(c,3);
  getMultiplicity(c);
}

proc inequalities()
"USAGE:   inequalities(c);  c cone
         inequalities(p);  p polytope
RETURN:  bigintmat, the inequalities of c resp p
NOTE:    neither unique nor irredundant, unless c resp p in canonical form
EXAMPLE: example inequalities; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M1[2][2]=
    1,0,
    0,1;
  cone c1=coneViaPoints(M1);
  bigintmat I1=inequalities(c1);
  print(I1);
  intmat M2[2][2]=
    1,1,
    0,-1;
  cone c2=coneViaPoints(M2);
  bigintmat I2=inequalities(c2);
  print(I2);
}

proc isFullSpace()
"USAGE:   isFullSpace(c);  c cone
RETURN:  1, if c is the entire ambient space; 0 otherwise
EXAMPLE: example isFullSpace; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  cone c1;
  isFullSpace(c1);
  intmat M2[2][2]=
    1,0,
    0,1;
  cone c2=coneViaPoints(M2);
  isFullSpace(c2);
  intmat M3[4][2]=
    1,0,
    0,1,
    -1,0,
    0,-1;
  cone c3=coneViaPoints(M3);
  isFullSpace(c3);
}

proc isOrigin()
"USAGE:   isOrigin(c);  c cone
RETURN:  1, if c is the origin; 0 otherwise
EXAMPLE: example isOrigin; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  cone c1;
  isOrigin(c1);
  intmat M2[2][2]=
    1,0,
    0,1;
  cone c2=coneViaPoints(M2);
  isOrigin(c2);
  intmat M3[4][2]=
    1,0,
    0,1,
    -1,0,
    0,-1;
  cone c3=coneViaPoints(M3);
  isOrigin(c3);
}

proc isSimplicial()
"USAGE:   isSimplicial(c);  c cone
         isSimplicial(f);  f fan
RETURN:  1, if c resp f is simplicial; 0 otherwise
EXAMPLE: example isSimplicial; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M1[3][3]=
    1,0,0,
    0,1,0,
    0,0,1;
  cone c1=coneViaPoints(M1);
  isSimplicial(c1);
  intmat M2[4][3]=
    1,0,0,
    0,1,0,
    0,0,1,
    1,1,-1;
  cone c2=coneViaPoints(M2);
  isSimplicial(c2);
  /***********************/
  fan f=emptyFan(3);
  isSimplicial(f);
  intmat N1[3][3]=
    1,0,0,
    0,1,0,
    0,0,1;
  cone d1=coneViaPoints(N1);
  insertCone(f,d1);
  isSimplicial(f);
  intmat N2[4][3]=
    1,0,0,
    0,1,0,
    1,0,-1,
    0,1,-1;
  cone d2=coneViaPoints(N2);
  insertCone(f,d2);
  isSimplicial(f);
}

proc linealityDimension()
"USAGE:   linealityDimension(c);  c cone
         linealityDimension(f);  f fan
RETURN:  int, the dimension of the lineality space of c resp f
EXAMPLE: example linealityDimension; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M1[3][3]=
    1,0,0,
    0,1,0,
    0,0,1;
  cone c1=coneViaPoints(M1);
  linealityDimension(c1);
  intmat M2[4][3]=
    1,0,0,
    0,1,0,
    0,0,1,
    -1,0,0;
  cone c2=coneViaPoints(M2);
  linealityDimension(c2);
}

proc linealitySpace()
"USAGE:   linealitySpace(c);  c cone
RETURN:  cone, the lineality space of c
EXAMPLE: example linealitySpace; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M1[3][3]=
    1,0,0,
    0,1,0,
    0,0,1;
  cone c1=coneViaPoints(M1);
  cone l1=linealitySpace(c1);
  l1;
  intmat M2[4][3]=
    1,0,0,
    0,1,0,
    0,0,1,
    -1,0,0;
  cone c2=coneViaPoints(M2);
  cone l2=linealitySpace(c2);
  l2;
}

proc negatedCone()
"USAGE:   negatedCone(c);  c cone
RETURN:  cone, the negative of c
EXAMPLE: example negatedCone; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M[2][2]=
    1,0,
    0,1;
  cone c=coneViaPoints(M);
  cone cn=negatedCone(c);
  print(rays(cn));
}

proc quotientLatticeBasis()
"USAGE:   quotientLatticeBasis(c);  c cone
RETURN:  bigintmat, a basis of Z^n intersected with the span of c modulo Z^n intersected with the lineality space of c
EXAMPLE: example quotientLatticeBasis; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M[3][2]=
    1,0,
    0,1,
    -1,0;
  cone c=coneViaPoints(M);
  bigintmat Q=quotientLatticeBasis(c);
  print(Q);
}

proc randomPoint()
"USAGE:   randomPoint(c);  c cone
RETURN:  bigintmat, a random point in the relative interior of c
EXAMPLE: example randomPoint; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M[3][2]=
    1,0,
    0,1,
    -1,0;
  cone c=coneViaPoints(M);
  bigintmat Q=randomPoint(c);
  print(Q);
}

proc rays()
"USAGE:   rays(c);  c cone
RETURN:  bigintmat, generators of the rays of c, orthogonal to its lineality space
EXAMPLE: example rays; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M1[2][2]=
    1,0,
    0,1;
  cone c1=coneViaPoints(M1);
  bigintmat R1=rays(c1);
  print(R1);
  intmat M2[3][2]=
    1,0,
    0,1,
    -1,0;
  cone c2=coneViaPoints(M2);
  bigintmat R2=rays(c2);
  print(R2);
}

proc relativeInteriorPoint()
"USAGE:   relativeInteriorPoint(c);  c cone
RETURN:  bigintmat, a point in the relative interior of c
NOTE:    not unique, unless c is in its canonical form
EXAMPLE: example relativeInteriorPoint; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M1[2][2]=
    1,0,
    0,1;
  cone c1=coneViaPoints(M1);
  relativeInteriorPoint(c1);
  intmat M2[2][2]=
    1,0,
    1,1;
  cone c2=coneViaPoints(M2);
  relativeInteriorPoint(c2);
}

proc semigroupGenerator()
"USAGE:   semigroupGenerator(c);  c cone
RETURN:  bigintmat, the generator of Z^n intersected with c modulo Z^n intersected with the lineality space of c
ASSUME:  dimension(c) == linealityDimension(c)+1
EXAMPLE: example semigroupGenerator; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M[3][2]=
    1,0,
    0,1,
    -1,0;
  cone c=coneViaPoints(M);
  semigroupGenerator(c);
}

proc setLinearForms()
"USAGE:   setLinearForms(c);  c cone
         setLinearForms(p);  p polytope
RETURN:  none, stores linear forms in c resp p
EXAMPLE: example setLinearForms; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M[2][3]=
    -1,0,0,
    0,-1,0;
  cone c=coneViaPoints(M);
  getLinearForms(c);
  intvec v=1,1,1;
  setLinearForms(c,v);
  getLinearForms(c);
}

proc setMultiplicity()
"USAGE:   setMultiplicity(c);  c cone
         setMultiplicity(p);  p polytope
RETURN:  none, stores a multiplicity in c resp p
EXAMPLE: example setMultiplicity; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M[2][3]=
    -1,0,0,
    0,-1,0;
  cone c=coneViaPoints(M);
  getMultiplicity(c);
  setMultiplicity(c,3);
  getMultiplicity(c);
}

proc span()
"USAGE:   span(c);  c cone
RETURN:  bigintmat, unique irredundant equations of c
NOTE:    the name 'span' was chosen to be in line with polymake's nomenclature
EXAMPLE: example span; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M[3][5]=
    1,0,0,0,0,
    0,1,0,0,0,
    0,0,1,0,0;
  cone c=coneViaPoints(M);
  bigintmat Eq=span(c);
  print(Eq);
}


proc uniquePoint()
"USAGE:   uniquePoint(c);  c cone
RETURN:  bigintmat, a unique point in c stable under reflections at coordinate hyperplanes
EXAMPLE: example uniquePoint; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M1[2][2]=
    1,0,
    0,1;
  cone c1=coneViaPoints(M1);
  uniquePoint(c1);
  intmat M2[2][2]=
    -1,0,
    0,1;
  cone c2=coneViaPoints(M2);
  uniquePoint(c2);
}



/////
// fan related functions
/////

proc containsInCollection()
"USAGE:   containsInCollection(f,c);  f fan, c cone
RETURN:  1, if f contains c; 0 otherwise
EXAMPLE: example containsInCollection; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  fan f=emptyFan(2);
  intmat M[2][2]=
    1,0,
    0,1;
  cone c=coneViaPoints(M);
  containsInCollection(f,c);
  insertCone(f,c);
  containsInCollection(f,c);
}

proc emptyFan()
"USAGE:   emptyFan(n);  n int
RETURN:  fan, an empty fan in ambient dimension n
EXAMPLE: example emptyFan; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  fan f=emptyFan(2);
  f;
}

proc fanViaCones()
"USAGE:   fanViaCones(L);  L list
         fanViaCones(c1[,...,ck]);  c1,...,ck cones
RETURN:  fan, creates a fan generated by the cones in L resp c1,...,ck
EXAMPLE: example fanViaCones; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M[2][2]=1,0,0,1;
  cone c=coneViaPoints(M);
  intmat N[2][2]=1,0,0,-1;
  cone d=coneViaPoints(N);
  fan f=fanViaCones(c,d);
  f;
  list L=c,d;
  fan g=fanViaCones(L);
  g;
}

proc fullFan()
"USAGE:   fullFan(n);  n int
RETURN:  fan, an full fan in ambient dimension n
EXAMPLE: example fullFan; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  fan f=fullFan(2);
  f;
}

proc fVector()
"USAGE:   fVector(f);  f fan
RETURN:  bigintmat, the f-Vector of f
EXAMPLE: example fVector; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  fan f=emptyFan(2);
  fVector(f);
  intmat M[2][2]=1,0,0,1;
  cone c=coneViaPoints(M);
  insertCone(f,c);
  fVector(f);
}

proc getCone()
"USAGE:   getCone(f,d,i[,o,m]);  f fan, d int, i int, o int, m int
ASSUME:  d is between 0 and ambientDimension(f)
         i is between 1 and numberOfConesOfDimension(f,d,o,m)
RETURN:  cone, returns in the fan f of all cones in dimension d the i-th cone
         if o=1, it will enumerate over cone orbits (deactivated for now)
         if m=1, it will enumerate over maximal cones
EXAMPLE: example getCone; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M[3][3]=
    1,0,0,
    0,1,0,
    0,0,1;
  cone c=coneViaPoints(M);
  fan f=emptyFan(3);
  insertCone(f,c);
  getCone(f,2,1,0,0);
  getCone(f,2,2,0,0);
}

proc insertCone()
"USAGE:   insertCone(f,c[,b]);  f fan, c cone, b int
ASSUME:  isCompatible(f,c)=1
RETURN:  none, inserts the cone c into f
         if b=0, then skips check whether f and c are compatible
EXAMPLE: example insertCone; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  fan f=emptyFan(3);
  f;
  intmat M[3][3]=
    1,0,0,
    0,1,0,
    0,0,1;
  cone c=coneViaPoints(M);
  insertCone(f,c);
  f;
}

proc isCompatible()
"USAGE:   isCompatible(f,c);  f fan, c cone
RETURN:  1 if f and c live in the same ambient space and
           if the intersection of c with any cone of f is a face of each;
         0 otherwise
EXAMPLE: example isCompatible; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  fan f=emptyFan(3);
  intmat M1[3][3]=
    1,0,0,
    0,1,0,
    0,0,1;
  cone c1=coneViaPoints(M1);
  isCompatible(f,c1);
  insertCone(f,c1);
  intmat M2[3][3]=
    1,1,1,
    1,0,0,
    0,1,0;
  cone c2=coneViaPoints(M2);
  isCompatible(f,c2);
  intmat M3[3][3]=
    1,0,0,
    0,1,0,
    0,0,-1;
  cone c3=coneViaPoints(M3);
  isCompatible(f,c3);
}

proc isPure()
"USAGE:   isPure(f);  f fan
RETURN:  1 if all maximal cones of f are of the same dimension
         0 otherwise
EXAMPLE: example isPure; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  fan f=fullFan(2);
  isPure(f);
  fan g=emptyFan(2);
  intmat M1[2][2]=
    1,0,
    0,1;
  cone c1=coneViaPoints(M1);
  insertCone(g,c1);
  isPure(g);
  intmat M2[1][2]=
    0,-1;
  cone c2=coneViaPoints(M2);
  insertCone(g,c2);
  isPure(g,c2);
}

proc nmaxcones()
"USAGE:   nmaxcones(f);  f fan
RETURN:  int, the number of maximal cones in f
EXAMPLE: example nmaxcones; shows an example
"
{

}
example
{
  fan f=emptyFan(3);
  nmaxcones(f);
  intmat M1[3][3]=
    1,0,0,
    0,1,0,
    0,0,1;
  cone c1=coneViaPoints(M1);
  insertCone(f,c1);
  nmaxcones(f);
  intmat M2[2][3]=
    1,0,0,
    0,-1,0;
  cone c2=coneViaPoints(M2);
  insertCone(f,c2);
  nmaxcones(f);
}

proc ncones()
"USAGE:   ncones(f);  f fan
RETURN:  int, the number of cones in f
EXAMPLE: example ncones; shows an example
"
{

}
example
{
  fan f=emptyFan(3);
  ncones(f);
  intmat M1[3][3]=
    1,0,0,
    0,1,0,
    0,0,1;
  cone c1=coneViaPoints(M1);
  insertCone(f,c1);
  ncones(f);
  intmat M2[2][3]=
    1,0,0,
    0,-1,0;
  cone c2=coneViaPoints(M2);
  insertCone(f,c2);
  ncones(f);
}

proc numberOfConesOfDimension()
"USAGE:   numberOfConesOfDimension(f,d[,o,m]);  f fan, d int, o int, m int
ASSUME:  d is between 0 and ambientDimension(f)
RETURN:  cone, returns in the fan f the number of cones in dimension d
         if o=1, it will only count cone orbits (deactivated for now)
         if m=1, it will only count maximal cones
EXAMPLE: example numberOfConesOfDimension; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  fan f=emptyFan(3);
  ncones(f);
  intmat M[3][3]=
    1,0,0,
    0,1,0,
    0,0,1;
  cone c=coneViaPoints(M);
  insertCone(f,c);
  numberOfConesOfDimension(f,0,0,0);
  numberOfConesOfDimension(f,0,0,1);
  numberOfConesOfDimension(f,1,0,0);
  numberOfConesOfDimension(f,0,0,1);
  numberOfConesOfDimension(f,2,0,0);
  numberOfConesOfDimension(f,2,0,1);
  numberOfConesOfDimension(f,3,0,0);
  numberOfConesOfDimension(f,3,0,1);
}

proc removeCone()
"USAGE:   removeCone(f,c[,b]);  f fan, c cone, b int
ASSUME:  containsInCollection(f,c)=1
RETURN:  none, removes the cone c from f
         if b=0, skips the check whether c is contained in f
EXAMPLE: example removeCone; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M[2][2]=1,0,0,1;
  intmat N[2][2]=1,0,1,-1;
  cone c=coneViaPoints(M);
  cone d=coneViaPoints(N);
  fan f=emptyFan(2);
  insertCone(f,c);
  insertCone(f,d);
  f;
  removeCone(f,c);
  f;
}



/////
// polytope related functions
/////

proc dualPolytope()
"USAGE:   dualPolytope(p);  p polytope
RETURN:  polytope, the dual of p
EXAMPLE: example dualPolytope; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M[4][2]=
    0,0,
    1,0,
    0,1,
    1,1;
  polytope p=polytopeViaPoints(M);
  dualPolytope(p);
}


proc newtonPolytope()
"USAGE:   newtonPolytope(f);  f poly
RETURN:  polytope, the convex hull of all exponent vectors of f
EXAMPLE: example newtonPolytope; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  ring r;
  poly f=x+y+z;
  polytope p=newtonPolytope(f);
  p;
}

proc polytopeViaPoints()
"USAGE: polytopeViaPoints(V [, flags]);  intmat V, int flags
RETURN: polytope which is the intersection of the cone generated by the row vectors
of V with the hyperplane, in which the first coordinate equals 1;
flags may be 0 or 1,@*
if flags is 1, then program assumes that each row vector of M generates a ray in the cone,
if flags is 0, then program computes that information itself
EXAMPLE: example polytopeViaPoints; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  // This is a polytope in R^2 generated by (0,0), (1,0), (0,1), (0,0);
  intmat V[4][3]=
  1,0,0,
  1,1,0,
  1,0,1,
  1,1,1;
  polytope p1=polytopeViaPoints(V);
  p1;
  // This is a polytope in R^2 generated by (1/2,2/3), (3/4,4/5), (5/6,6/7):
  intmat V[3][3]=
  6,3,4,
  20,15,16,
  42,35,36;
  polytope p2=polytopeViaPoints(V);
  p2;
  // This polytope is the positive orthant in R^2:
  // (0,1,0) and (0,0,1) imply that the polytope is unbounded in that direction
  intmat V[3][3]=
  1,0,0,
  0,1,0,
  0,0,1;
  polytope p3=polytopeViaPoints(V);
  p3;
}

proc polytopeViaInequalities()
"USAGE: polytopeViaInequalities(EV [, E [, flags]]);  intmat EV,E, int flags
RETURN: polytope consisting of all points x, such that IE*x >= 0 in each component
and (if stated) E*x = 0;
flags may range between 0,..,3 defining an upper and lower bit
(0=0*2+0, 1=0*2+1, 2=1*2+0, 3=1*2+1),
if higher bit is 1, then program assumes each inequality yields a facet,
if lower bit is 1, then program assumes the kernel of E is the span of the cone,
if either bit is 0, then program computes the information itself.
EXAMPLE: example polytopeViaPoints; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat IE[2][3]=
  1,0,0,
  0,1,0;
  intmat E[1][3]=
  0,0,1;
  polytope p=polytopeViaInequalities(IE,E);
  p;
}

proc vertices()
"USAGE:   vertices(p);  p polytope
RETURN:  bigintmat, the vertices of p modulo its lineality space
EXAMPLE: example vertices; shows an example
"
{

}
example
{
  "EXAMPLE:"; echo = 2;
  intmat M[4][3]=
    1,0,0,
    1,2,0,
    1,0,2,
    1,2,2,
    1,1,1;
  polytope p=polytopeViaPoints(M);
  vertices(p);
}

static proc mod_init()
{
  intvec save=option(get);
  option(noredefine);
  LIB "customstd.so";
  LIB "gfanlib.so";
  option(set,save);
}