This file is indexed.

/usr/share/singular/LIB/schubert.lib is in singular-data 4.0.3+ds-1.

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
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
////////////////////////////////////////////////////////////////////////////////
version="version schubert.lib 4.0.0.0 Nov_2013 "; // $Id: 3716882c59cbc1ea84c159503bd3b822962311a4 $
category="Algebraic Geometry";
info="
LIBRARY:    schubert.lib    Proceduces for Intersection Theory

AUTHOR:     Hiep Dang,          email: hiep@mathematik.uni-kl.de

OVERVIEW:

    We implement new classes (variety, sheaf, stack, graph) and methods for
    computing with them. An abstract variety is represented by a nonnegative
    integer which is its dimension and a graded ring which is its Chow ring.
    An abstract sheaf is represented by a variety and a polynomial which is its
    Chern character. In particular, we implement the concrete varieties such as
    projective spaces, Grassmannians, and projective bundles.

    An important task of this library is related to the computation of
    Gromov-Witten invariants. In particular, we implement new tools for the
    computation in equivariant intersection theory. These tools are based on the
    localization of moduli spaces of stable maps and Bott's formula. They are
    useful for the computation of Gromov-Witten invariants. In order to do this,
    we have to deal with moduli spaces of stable maps, which were introduced by
    Kontsevich, and the graphs corresponding to the fixed point components of a
    torus action on the moduli spaces of stable maps.

    As an insightful example, the numbers of rational curves on general complete
    intersection Calabi-Yau threefolds in projective spaces are computed up to
    degree 6. The results are all in agreement with predictions made from mirror
    symmetry computations.

REFERENCES:

    Hiep Dang,  Intersection theory with applications to the computation of
                Gromov-Witten invariants, Ph.D thesis, TU Kaiserslautern, 2013.

    Sheldon Katz and Stein A. Stromme, Schubert-A Maple package for intersection
                theory and enumerative geometry, 1992.

    Daniel R. Grayson, Michael E. Stillman, Stein A. Stromme, David Eisenbud and
    Charley Crissman, Schubert2-A Macaulay2 package for computation in
                intersection theory, 2010.

    Maxim Kontsevich, Enumeration of rational curves via torus actions, 1995.

PROCEDURES:
    mod_init()                          create new objects in this library
    makeVariety(int,ideal)              create a variety
    printVariety(variety)               print procedure for a variety
    productVariety(variety,variety)     make the product of two varieties
    ChowRing(variety)                   create the Chow ring of a variety
    Grassmannian(int,int)               create a Grassmannian as a variety
    projectiveSpace(int)                create a projective space as a variety
    projectiveBundle(sheaf)             create a projective bundle as a variety
    integral(variety,poly)              degree of a 0-cycle on a variety
    makeSheaf(variety,poly)             create a sheaf
    printSheaf(sheaf)                   print procedure for sheaves
    rankSheaf(sheaf)                    return the rank of a sheaf
    totalChernClass(sheaf)              compute the total Chern class of a sheaf
    ChernClass(sheaf,int)               compute the k-th Chern class of a sheaf
    topChernClass(sheaf)                compute the top Chern class of a sheaf
    totalSegreClass(sheaf)              compute the total Segre class of a sheaf
    dualSheaf(sheaf)                    make the dual of a sheaf
    tensorSheaf(sheaf,sheaf)            make the tensor of two sheaves
    symmetricPowerSheaf(sheaf,int)      make the k-th symmetric power of a sheaf
    quotSheaf(sheaf,sheaf)              make the quotient of two sheaves
    addSheaf(sheaf,sheaf)               make the direct sum of two sheaves
    makeGraph(list,list)                create a graph from a list of vertices
                                        and a list of edges
    printGraph(graph)                   print procedure for graphs
    moduliSpace(variety,int)            create a moduli space of stable maps as
                                        an algebraic stack
    printStack(stack)                   print procedure for stacks
    dimStack(stack)                     compute the dimension of a stack
    fixedPoints(stack)                  compute the list of graphs corresponding
                                        the fixed point components of a torus
                                        action on the stack
    contributionBundle(stack,graph)     compute the contribution bundle on a
                                        stack at a graph
    normalBundle(stack,graph)           compute the normal bundle on a stack at
                                        a graph
    multipleCover(int)                  compute the contribution of multiple
                                        covers of a smooth rational curve as a
                                        Gromov-Witten invariant
    linesHypersurface(int)              compute the number of lines on a general
                                        hypersurface
    rationalCurve(int,list)             compute the Gromov-Witten invariant
                                        corresponding the number of rational
                                        curves on a general Calabi-Yau threefold
    sumofquotients(stack,list)          prepare a command for parallel
                                        computation
    part(poly,int)                      compute a homogeneous component of a
                                        polynomial.
    parts(poly,int,int)                 compute the sum of homogeneous
                                        components of a polynomial
    logg(poly,int)                      compute Chern characters from total
                                        Chern classes.
    expp(poly,int)                      compute total Chern classes from Chern
                                        characters
    SchubertClass(list)                 compute the Schubert classes on a
                                        Grassmannian
    dualPartition(list)                 compute the dual of a partition

KEYWORDS:       Intersection theory; Enumerative geometry; Schubert calculus;
                Bott's formula; Gromov-Witten invariants.

";

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

LIB "general.lib";
LIB "homolog.lib";
LIB "parallel.lib";

////////////////////////////////////////////////////////////////////////////////
/////////// create new objects in this library  ////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

proc mod_init()
"USAGE:     mod_init();
THEORY:     This is to create new objects in this library such as variety,
            sheaf, stack, and graph.
KEYWORDS:   variety, sheaf, stack, graph
EXAMPLE:    example mod_init(); shows an example
"
{
    newstruct("variety","int dimension, ring baseRing, ideal relations");
    newstruct("sheaf","variety currentVariety, poly ChernCharacter");
    newstruct("graph","list vertices, list edges");
    newstruct("stack","variety currentVariety, int degreeCurve");

    system("install","variety","print",printVariety,1);
    system("install","variety","*",productVariety,2);
    system("install","sheaf","print",printSheaf,1);
    system("install","sheaf","*",tensorSheaf,2);
    system("install","sheaf","+",addSheaf,2);
    system("install","sheaf","-",quotSheaf,2);
    system("install","sheaf","^",symmetricPowerSheaf,2);
    system("install","graph","print",printGraph,1);
    system("install","stack","print",printStack,1);
}
example
{
    "EXAMPLE:"; echo=2;
    mod_init();
}

////////////////////////////////////////////////////////////////////////////////
//////// Procedures concerned with moduli spaces of stable maps ////////////////
////////////////////////////////////////////////////////////////////////////////

proc printStack(stack M)
"USAGE:     printStack(M); M stack
ASSUME:     M is a moduli space of stable maps.
THEORY:     This is the print function used by Singular to print a stack.
KEYWORDS:   stack, moduli space of stable maps
EXAMPLE:    example printStack; shows an example
"
{
    "A moduli space of dimension", dimStack(M);
}
example
{
    "EXAMPLE:"; echo=2;
    ring r = 0,(x),dp;
    variety P = projectiveSpace(4);
    stack M = moduliSpace(P,2);
    M;
}

proc moduliSpace(variety V, int d)
"USAGE:     moduliSpace(V,d); V variety, d int
ASSUME:     V is a projective space and d is a positive integer.
THEORY:     This is the function used by Singular to create a moduli space of
            stable maps from a genus zero curve to a projective space.
KEYWORDS:   stack, moduli space of stable maps, rational curves
EXAMPLE:    example moduliSpace; shows an example
"
{
    stack M;
    M.currentVariety = V;
    M.degreeCurve = d;
    return(M);
}
example
{
    "EXAMPLE:"; echo=2;
    ring r = 0,(x),dp;
    variety P = projectiveSpace(4);
    stack M = moduliSpace(P,2);
    M;
}

proc dimStack(stack M)
"USAGE:     dimStack(M); M stack
RETURN:     int
INPUT:      M is a moduli space of stable maps.
OUTPUT:     the dimension of moduli space of stable maps.
KEYWORDS:   dimension, moduli space of stable maps, rational curves
EXAMPLE:    example dimStack; shows an example
"
{
    variety V = M.currentVariety;
    int n = V.dimension;
    int d = M.degreeCurve;
    return (n*d+n+d-3);
}
example
{
    "EXAMPLE:"; echo=2;
    ring r = 0,(x),dp;
    variety P = projectiveSpace(4);
    stack M = moduliSpace(P,2);
    dimStack(M);
}

proc fixedPoints(stack M)
"USAGE:     fixedPoints(M); M stack
RETURN:     list
INPUT:      M is a moduli space of stable maps.
OUTPUT:     a list of graphs corresponding the fixed point components of a torus
            action on a moduli space of stable maps.
KEYWORDS:   fixed points, moduli space of stable maps, graph
EXAMPLE:    example fixedPoints; shows an example
"
{
    int i,j,k,h,m,n,p,q;
    list l;
    int d = M.degreeCurve;
    variety V = M.currentVariety;
    int r = V.dimension;
    for (i=0;i<=r;i++)
    {
        for (j=0;j<=r;j++)
        {
            if (i <> j)
            {
                l[size(l)+1] = list(graph1(d,i,j),2*d);
            }
        }
    }
    if (d == 2)
    {
        for (i=0;i<=r;i++)
        {
            for (j=0;j<=r;j++)
            {
                for (k=0;k<=r;k++)
                {
                    if (i <> j and j <> k)
                    {
                        l[size(l)+1] = list(graph2(list(1,1),i,j,k),2);
                    }
                }
            }
        }
    }
    if (d == 3)
    {
        for (i=0;i<=r;i++)
        {
            for (j=0;j<=r;j++)
            {
                for (k=0;k<=r;k++)
                {
                    if (i <> j and j <> k)
                    {
                        l[size(l)+1] = list(graph2(list(2,1),i,j,k),2);
                        for (h=0;h<=r;h++)
                        {
                            if (h <> k)
                            {
                                l[size(l)+1] = list(graph31(list(1,1,1),i,j,k,h),2);
                            }
                            if (h <> j)
                            {
                                l[size(l)+1] = list(graph32(list(1,1,1),i,j,k,h),6);
                            }
                        }
                    }
                }
            }
        }
    }
    if (d == 4)
    {
        for (i=0;i<=r;i++)
        {
            for (j=0;j<=r;j++)
            {
                for (k=0;k<=r;k++)
                {
                    if (i <> j and j <> k)
                    {
                        l[size(l)+1] = list(graph2(list(3,1),i,j,k),3);
                        l[size(l)+1] = list(graph2(list(2,2),i,j,k),8);
                        for (h=0;h<=r;h++)
                        {
                            if (h <> k)
                            {
                                l[size(l)+1] = list(graph31(list(2,1,1),i,j,k,h),2);
                                l[size(l)+1] = list(graph31(list(1,2,1),i,j,k,h),4);
                            }
                            if (h <> j)
                            {
                                l[size(l)+1] = list(graph32(list(2,1,1),i,j,k,h),4);
                            }
                            for (m=0;m<=r;m++)
                            {
                                if (k <> h and m <> h)
                                {
                                    l[size(l)+1] = list(graph41(list(1,1,1,1),i,j,k,h,m),2);
                                }
                                if (k <> h and m <> k)
                                {
                                    l[size(l)+1] = list(graph42(list(1,1,1,1),i,j,k,h,m),2);
                                }
                                if (h <> j and m <> j)
                                {
                                    l[size(l)+1] = list(graph43(list(1,1,1,1),i,j,k,h,m),24);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (d == 5)
    {
        for (i=0;i<=r;i++)
        {
            for (j=0;j<=r;j++)
            {
                for (k=0;k<=r;k++)
                {
                    if (i <> j and j <> k)
                    {
                        l[size(l)+1] = list(graph2(list(4,1),i,j,k),4);
                        l[size(l)+1] = list(graph2(list(3,2),i,j,k),6);
                        for (h=0;h<=r;h++)
                        {
                            if (k <> h)
                            {
                                l[size(l)+1] = list(graph31(list(3,1,1),i,j,k,h),3);
                                l[size(l)+1] = list(graph31(list(1,3,1),i,j,k,h),6);
                                l[size(l)+1] = list(graph31(list(2,2,1),i,j,k,h),4);
                                l[size(l)+1] = list(graph31(list(2,1,2),i,j,k,h),8);
                            }
                            if (j <> h)
                            {
                                l[size(l)+1] = list(graph32(list(3,1,1),i,j,k,h),6);
                                l[size(l)+1] = list(graph32(list(2,2,1),i,j,k,h),8);
                            }
                            for (m=0;m<=r;m++)
                            {
                                if (k <> h and h <> m)
                                {
                                    l[size(l)+1] = list(graph41(list(2,1,1,1),i,j,k,h,m),2);
                                    l[size(l)+1] = list(graph41(list(1,2,1,1),i,j,k,h,m),2);
                                }
                                if (k <> h and k <> m)
                                {
                                    l[size(l)+1] = list(graph42(list(2,1,1,1),i,j,k,h,m),4);
                                    l[size(l)+1] = list(graph42(list(1,2,1,1),i,j,k,h,m),4);
                                    l[size(l)+1] = list(graph42(list(1,1,2,1),i,j,k,h,m),2);
                                }
                                if (j <> h and j <> m)
                                {
                                    l[size(l)+1] = list(graph43(list(2,1,1,1),i,j,k,h,m),12);
                                }
                                for (n=0;n<=r;n++)
                                {
                                    if (k <> h and h <> m and m <> n)
                                    {
                                        l[size(l)+1] = list(graph51(list(1,1,1,1,1),i,j,k,h,m,n),2);
                                    }
                                    if (k <> h and h <> m and h <> n)
                                    {
                                        l[size(l)+1] = list(graph52(list(1,1,1,1,1),i,j,k,h,m,n),2);
                                    }
                                    if (k <> h and k <> m and k <> n)
                                    {
                                        l[size(l)+1] = list(graph53(list(1,1,1,1,1),i,j,k,h,m,n),6);
                                    }
                                    if (j <> h and h <> m and h <> n)
                                    {
                                        l[size(l)+1] = list(graph54(list(1,1,1,1,1),i,j,k,h,m,n),8);
                                    }
                                    if (k <> h and k <> m and h <> n)
                                    {
                                        l[size(l)+1] = list(graph55(list(1,1,1,1,1),i,j,k,h,m,n),2);
                                    }
                                    if (j <> h and j <> m and j <> n)
                                    {
                                        l[size(l)+1] = list(graph56(list(1,1,1,1,1),i,j,k,h,m,n),120);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (d == 6)
    {
        for (i=0;i<=r;i++)
        {
            for (j=0;j<=r;j++)
            {
                for (k=0;k<=r;k++)
                {
                    if (i <> j and j <> k)
                    {
                        l[size(l)+1] = list(graph2(list(5,1),i,j,k),5);
                        l[size(l)+1] = list(graph2(list(4,2),i,j,k),8);
                        l[size(l)+1] = list(graph2(list(3,3),i,j,k),18);
                        for (h=0;h<=r;h++)
                        {
                            if (k <> h)
                            {
                                l[size(l)+1] = list(graph31(list(4,1,1),i,j,k,h),4);
                                l[size(l)+1] = list(graph31(list(1,4,1),i,j,k,h),8);
                                l[size(l)+1] = list(graph31(list(3,2,1),i,j,k,h),6);
                                l[size(l)+1] = list(graph31(list(3,1,2),i,j,k,h),6);
                                l[size(l)+1] = list(graph31(list(1,3,2),i,j,k,h),6);
                                l[size(l)+1] = list(graph31(list(2,2,2),i,j,k,h),16);
                            }
                            if (j <> h)
                            {
                                l[size(l)+1] = list(graph32(list(4,1,1),i,j,k,h),8);
                                l[size(l)+1] = list(graph32(list(3,2,1),i,j,k,h),6);
                                l[size(l)+1] = list(graph32(list(2,2,2),i,j,k,h),48);
                            }
                            for (m=0;m<=r;m++)
                            {
                                if (k <> h and h <> m)
                                {
                                    l[size(l)+1] = list(graph41(list(3,1,1,1),i,j,k,h,m),3);
                                    l[size(l)+1] = list(graph41(list(1,3,1,1),i,j,k,h,m),3);
                                    l[size(l)+1] = list(graph41(list(2,2,1,1),i,j,k,h,m),4);
                                    l[size(l)+1] = list(graph41(list(2,1,2,1),i,j,k,h,m),4);
                                    l[size(l)+1] = list(graph41(list(2,1,1,2),i,j,k,h,m),8);
                                    l[size(l)+1] = list(graph41(list(1,2,2,1),i,j,k,h,m),8);
                                }
                                if (k <> h and k <> m)
                                {
                                    l[size(l)+1] = list(graph42(list(3,1,1,1),i,j,k,h,m),6);
                                    l[size(l)+1] = list(graph42(list(1,3,1,1),i,j,k,h,m),6);
                                    l[size(l)+1] = list(graph42(list(1,1,3,1),i,j,k,h,m),3);
                                    l[size(l)+1] = list(graph42(list(2,2,1,1),i,j,k,h,m),8);
                                    l[size(l)+1] = list(graph42(list(1,1,2,2),i,j,k,h,m),8);
                                    l[size(l)+1] = list(graph42(list(2,1,2,1),i,j,k,h,m),4);
                                    l[size(l)+1] = list(graph42(list(1,2,2,1),i,j,k,h,m),4);
                                }
                                if (j <> h and j <> m)
                                {
                                    l[size(l)+1] = list(graph43(list(3,1,1,1),i,j,k,h,m),18);
                                    l[size(l)+1] = list(graph43(list(2,2,1,1),i,j,k,h,m),16);
                                }
                                for (n=0;n<=r;n++)
                                {
                                    if (k <> h and h <> m and m <> n)
                                    {
                                        l[size(l)+1] = list(graph51(list(2,1,1,1,1),i,j,k,h,m,n),2);
                                        l[size(l)+1] = list(graph51(list(1,2,1,1,1),i,j,k,h,m,n),2);
                                        l[size(l)+1] = list(graph51(list(1,1,2,1,1),i,j,k,h,m,n),4);
                                    }
                                    if (k <> h and h <> m and h <> n)
                                    {
                                        l[size(l)+1] = list(graph52(list(2,1,1,1,1),i,j,k,h,m,n),4);
                                        l[size(l)+1] = list(graph52(list(1,2,1,1,1),i,j,k,h,m,n),4);
                                        l[size(l)+1] = list(graph52(list(1,1,2,1,1),i,j,k,h,m,n),4);
                                        l[size(l)+1] = list(graph52(list(1,1,1,2,1),i,j,k,h,m,n),2);
                                    }
                                    if (k <> h and k <> m and k <> n)
                                    {
                                        l[size(l)+1] = list(graph53(list(2,1,1,1,1),i,j,k,h,m,n),12);
                                        l[size(l)+1] = list(graph53(list(1,2,1,1,1),i,j,k,h,m,n),12);
                                        l[size(l)+1] = list(graph53(list(1,1,2,1,1),i,j,k,h,m,n),4);
                                    }
                                    if (j <> h and h <> m and h <> n)
                                    {
                                        l[size(l)+1] = list(graph54(list(2,1,1,1,1),i,j,k,h,m,n),4);
                                        l[size(l)+1] = list(graph54(list(1,1,2,1,1),i,j,k,h,m,n),16);
                                    }
                                    if (k <> h and k <> m and h <> n)
                                    {
                                        l[size(l)+1] = list(graph55(list(2,1,1,1,1),i,j,k,h,m,n),2);
                                        l[size(l)+1] = list(graph55(list(1,2,1,1,1),i,j,k,h,m,n),2);
                                        l[size(l)+1] = list(graph55(list(1,1,1,2,1),i,j,k,h,m,n),4);
                                    }
                                    if (j <> h and j <> m and j <> n)
                                    {
                                        l[size(l)+1] = list(graph56(list(2,1,1,1,1),i,j,k,h,m,n),48);
                                    }
                                    for (p=0;p<=r;p++)
                                    {
                                        if (k <> h and h <> m and m <> n and n <> p)
                                        {
                                            l[size(l)+1] = list(graph61(list(1,1,1,1,1,1),i,j,k,h,m,n,p),2);
                                        }
                                        if (k <> h and h <> m and m <> n and m <> p)
                                        {
                                            l[size(l)+1] = list(graph62(list(1,1,1,1,1,1),i,j,k,h,m,n,p),2);
                                        }
                                        if (k <> h and h <> m and h <> n and n <> p)
                                        {
                                            l[size(l)+1] = list(graph63(list(1,1,1,1,1,1),i,j,k,h,m,n,p),1);
                                        }
                                        if (k <> h and h <> m and h <> n and h <> p)
                                        {
                                            l[size(l)+1] = list(graph64(list(1,1,1,1,1,1),i,j,k,h,m,n,p),6);
                                        }
                                        if (k <> h and k <> m and k <> n and n <> p)
                                        {
                                            l[size(l)+1] = list(graph65(list(1,1,1,1,1,1),i,j,k,h,m,n,p),4);
                                        }
                                        if (k <> h and k <> m and m <> p and h <> n)
                                        {
                                            l[size(l)+1] = list(graph66(list(1,1,1,1,1,1),i,j,k,h,m,n,p),6);
                                        }
                                        if (j <> h and h <> m and m <> n and m <> p)
                                        {
                                            l[size(l)+1] = list(graph67(list(1,1,1,1,1,1),i,j,k,h,m,n,p),8);
                                        }
                                        if (j <> h and h <> m and h <> n and h <> p)
                                        {
                                            l[size(l)+1] = list(graph68(list(1,1,1,1,1,1),i,j,k,h,m,n,p),12);
                                        }
                                        if (j <> h and h <> m and h <> n and n <> p)
                                        {
                                            l[size(l)+1] = list(graph69(list(1,1,1,1,1,1),i,j,k,h,m,n,p),2);
                                        }
                                        if (k <> h and k <> m and k <> n and k <> p)
                                        {
                                            l[size(l)+1] = list(graph610(list(1,1,1,1,1,1),i,j,k,h,m,n,p),24);
                                        }
                                        if (j <> h and j <> m and j <> n and j <> p)
                                        {
                                            l[size(l)+1] = list(graph611(list(1,1,1,1,1,1),i,j,k,h,m,n,p),720);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return (l);
}
example
{
    "EXAMPLE:"; echo=2;
    ring r = 0,x,dp;
    variety P = projectiveSpace(4);
    stack M = moduliSpace(P,2);
    def F = fixedPoints(M);
    size(F);
    typeof(F[1]) == "list";
    typeof(F[1][1]) == "graph";
    typeof(F[1][2]) == "int";
}

static proc torusList(variety P)
"USAGE:     torusList(P); P variety
RETURN:     list
INPUT:      P is a projective space
OUTPUT:     a list of numbers
THEORY:     This is a procedure concerning the enumeration of rational curves.
KEYWORDS:   torus action
EXAMPLE:    example torusList; shows an example
"
{
    int i;
    int n = P.dimension;
    list l;
    for (i=0;i<=n;i++)
    {
        l = insert(l,number(10^i),size(l));
    }
    return (l);
}
example
{
    "EXAMPLE:"; echo=2;
    ring r = 0,x,dp;
    variety P = projectiveSpace(4);
    def L = torusList(P);
    L;
}

proc contributionBundle(stack M, graph G, list #)
"USAGE:     contributionBundle(M,G,#); M stack, G graph, # list
RETURN:     number
INPUT:      M is a moduli space of stable maps, G is a graph, # is a list.
OUTPUT:     a number corresponding to the contribution bundle on a moduli space
            of stable maps at a fixed point component (graph)
KEYWORDS:   contribution bundle, graph, multiple cover, rational curve,
SEE ALSO:   normalBundle
EXAMPLE:    example contributionBundle; shows an example
"
{
    def R = basering;
    setring R;
    int i,j,a;
    variety P = M.currentVariety;
    def L = torusList(P);
    int r = P.dimension;
    int d;
    if (size(#)==0) {d = 2*r - 3;}
    else
    {
        if (typeof(#[1]) == "int") {d = #[1];}
        else {Error("invalid optional argument");}
    }
    list e = G.edges;
    list v = G.vertices;
    number E = 1;
    number V = 1;
    if (r == 1)
    {
        for (i=1;i<=size(v);i++)
        {
            V = V*(-L[v[i][1]+1])^(v[i][2]-1);
        }
        for (j=1;j<=size(e);j++)
        {
            number f = 1;
            if (e[j][3]<>1)
            {
                for (a=1;a<e[j][3];a++)
                {
                    f=f*(-a*L[e[j][1]+1]-(e[j][3]-a)*L[e[j][2]+1])/e[j][3];
                }
            }
            E = E*f;
            kill f;
        }
        return ((E*V)^2);
    }
    else
    {
        for (i=1;i<=size(v);i++)
        {
            V = V*((d*L[v[i][1]+1])^(v[i][2]-1));
        }
        for (j=1;j<=size(e);j++)
        {
            number f = 1;
            for (a=0;a<=d*e[j][3];a++)
            {
                f = f*((a*L[e[j][1]+1]+(d*e[j][3]-a)*L[e[j][2]+1])/e[j][3]);
            }
            E = E*f;
            kill f;
        }
        return (E/V);
    }
}
example
{
    "EXAMPLE:"; echo=2;
    ring r = 0,x,dp;
    variety P = projectiveSpace(4);
    stack M = moduliSpace(P,2);
    def F = fixedPoints(M);
    graph G = F[1][1];
    number f = contributionBundle(M,G);
    number g = contributionBundle(M,G,5);
    f == g;
}

proc normalBundle(stack M, graph G)
"USAGE:     normalBundle(M,G); M stack, G graph
RETURN:     number
INPUT:      M is a moduli space of stable maps, G is a graph
OUTPUT:     a number corresponding to the normal bundle on a moduli space of
            stable maps at a graph
KEYWORDS:   normal bundle, graph, rational curves, mutiple covers, lines on
            hypersurfaces
SEE ALSO:   contributionBundle
EXAMPLE:    example normalBundle; shows an example
{
    def R = basering;
    setring R;
    variety P = M.currentVariety;
    def L = torusList(P);
    int n = P.dimension;
    list e = G.edges;
    list v = G.vertices;
    int i,j,k,h,b,m,a;
    number N = 1;
    for (j=1;j<=size(e);j++)
    {
        int d = e[j][3];
        number c = (-1)^d*factorial(d)^2;
        number y = c*(L[e[j][1]+1]-L[e[j][2]+1])^(2*d)/(number(d)^(2*d));
        for (k=0;k<=n;k++)
        {
            if (k <> e[j][1] and k <> e[j][2])
            {
                for (a=0;a<=d;a++)
                {
                    y=y*((a*L[e[j][1]+1]+(d-a)*L[e[j][2]+1])/d - L[k+1]);
                }
            }
        }
        N = N*y;
        kill y,d,c;
    }
    for (i=1;i<=size(v);i++)
    {
        number F = 1;
        for (h=3;h<=size(v[i]);h++)
        {
            F = F*(L[v[i][h][1]+1]-L[v[i][h][2]+1])/v[i][h][3];
        }
        if (v[i][2] == 1)
        {
            N = N/F;
            kill F;
        }
        else
        {
            number z = 1;
            for (m=0;m<=n;m++)
            {
                if (m<>v[i][1])
                {
                    z = z*(L[v[i][1]+1]-L[m+1]);
                }
            }
            if (v[i][2] == 3)
            {
                N = N*F/z^2;
                kill F,z;
            }
            else
            {
                number g = 0;
                for (b=3;b<=size(v[i]);b++)
                {
                    g = g + v[i][b][3]/(L[v[i][b][1]+1]-L[v[i][b][2]+1]);
                }
                N = N*F*g^(3-v[i][2])/(z^(v[i][2]-1));
                kill g,F,z;
            }
        }
    }
    return (N);
}
example
{
    "EXAMPLE:"; echo=2;
    ring r = 0,x,dp;
    variety P = projectiveSpace(4);
    stack M = moduliSpace(P,2);
    def F = fixedPoints(M);
    graph G = F[1][1];
    number f = normalBundle(M,G);
    f <> 0;
}

proc multipleCover(int d)
"USAGE:     multipleCover(d); d int
RETURN:     number
THEORY:     This is the contribution of degree d multiple covers of a smooth
            rational curve as a Gromov-Witten invariant.
KEYWORDS:   Gromov-Witten invariants, multiple covers
SEE ALSO:   rationalCurve, linesHypersurface
EXAMPLE:    example multipleCover; shows an example
"
{
    def R = basering;
    setring R;
    variety P = projectiveSpace(1);
    stack M = moduliSpace(P,d);
    def F = fixedPoints(M);
    int i;
    number r = 0;
    for (i=1;i<=size(F);i++)
    {
        graph G = F[i][1];
        number s = contributionBundle(M,G);
        number t = F[i][2]*normalBundle(M,G);
        r = r + s/t;
        kill s,t,G;
    }
    return (r);
}
example
{
    "EXAMPLE:"; echo=2;
    ring r = 0,x,dp;
    multipleCover(1);
    multipleCover(2);
    multipleCover(3);
    multipleCover(4);
    multipleCover(5);
    multipleCover(6);
}

proc linesHypersurface(int n)
"USAGE:     linesHypersurface(n); n int
RETURN:     number
THEORY:     This is the number of lines on a general hypersurface of degree
            d = 2n-3 in an n-dimensional projective space.
KEYWORDS:   Gromov-Witten invariants, lines on hypersurfaces
SEE ALSO:   linesHypersurface, multipleCover
EXAMPLE:    example linesHypersurface; shows an example
"
{
    def R = basering;
    setring R;
    variety P = projectiveSpace(n);
    stack M = moduliSpace(P,1);
    def F = fixedPoints(M);
    int i;
    number r = 0;
    for (i=1;i<=size(F);i++)
    {
        graph G = F[i][1];
        number s = contributionBundle(M,G);
        number t = F[i][2]*normalBundle(M,G);
        r = r + s/t;
        kill s,t,G;
    }
    return (r);
}
example
{
    "EXAMPLE:"; echo=2;
    ring r = 0,x,dp;
    linesHypersurface(2);
    linesHypersurface(3);
    linesHypersurface(4);
    linesHypersurface(5);
    linesHypersurface(6);
    linesHypersurface(7);
    linesHypersurface(8);
    linesHypersurface(9);
    linesHypersurface(10);
}

proc sumofquotients(stack M, list F, list #)
"USAGE:     sumofquotient(M,F,#); M stack, F list, # list
RETURN:     number
THEORY:     This is useful for the parallel computation of rationalCurve.
KEYWORDS:   Gromov-Witten invariants, rational curves on Calabi-Yau threefolds
EXAMPLE:    example sumofquotients; shows an example
"
{
    if (size(#) == 0) {list l = 5;}
    else {list l = #;}
    number sum = 0;
    number s, t;
    int i,j;
    for (i = size(F); i > 0; i--)
    {
        s = 1;
        for (j=1;j<=size(l);j++)
        {
            s = s*contributionBundle(M,F[i][1],list(l[j]));
        }
        t = F[i][2]*normalBundle(M,F[i][1]);
        sum = sum + s/t;
    }
    return(sum);
}
example
{
    "EXAMPLE:"; echo=2;
    ring r = 0,x,dp;
    variety P = projectiveSpace(4);
    stack M = moduliSpace(P,2);
    list F = fixedPoints(M);
    sumofquotients(M,F);
    sumofquotients(M,F,list(5));
}

proc rationalCurve(int d, list #)
"USAGE:     rationalCurve(d,#); d int, # list
RETURN:     number
THEORY:     This is the Gromov-Witten invariant corresponding the number of
            rational curves on a general Calabi-Yau threefold.
KEYWORDS:   Gromov-Witten invariants, rational curves on Calabi-Yau threefolds
SEE ALSO:   linesHypersurface, multipleCover
EXAMPLE:    example rationalCurve; shows an example
"
{
    def R = basering;
    setring R;
    int n,i;
    if (size(#) == 0) {n = 4; list l = 5;}
    else {n = size(#)+3; list l = #;}
    variety P = projectiveSpace(n);
    stack M = moduliSpace(P,d);
    def F = fixedPoints(M);
    int ncpus = system("--cpus");
    int sizeF = size(F);
    list args;
    int from = 1;
    int to;
    for (i = 1; i <= ncpus; i++)
    {
        to = (sizeF*i) div ncpus;
        args[i] = list(M, list(F[from..to]), l);
        from = to+1;
    }
    list results = parallelWaitAll("sumofquotients", args);
    number r = 0;
    for (i = 1; i <= ncpus; i++)
    {
        r = r + results[i];
    }
    return (r);
}
example
{
    "EXAMPLE:"; echo=2;
    ring r = 0,x,dp;
    rationalCurve(1);
    /*
    rationalCurve(2);
    rationalCurve(3);
    rationalCurve(4);
    rationalCurve(1,list(4,2));
    rationalCurve(1,list(3,3));
    rationalCurve(1,list(3,2,2));
    rationalCurve(1,list(2,2,2,2));
    rationalCurve(2,list(4,2));
    rationalCurve(2,list(3,3));
    rationalCurve(2,list(3,2,2));
    rationalCurve(2,list(2,2,2,2));
    rationalCurve(3,list(4,2));
    rationalCurve(3,list(3,3));
    rationalCurve(3,list(3,2,2));
    rationalCurve(3,list(2,2,2,2));
    rationalCurve(4,list(4,2));
    rationalCurve(4,list(3,3));
    rationalCurve(4,list(3,2,2));
    rationalCurve(4,list(2,2,2,2));
    */
}

////////////////////////////////////////////////////////////////////////////////
/////////// Procedures concerned with graphs ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

proc printGraph(graph G)
"USAGE:     printGraph(G); G graph
ASSUME:     G is a graph.
THEORY:     This is the print function used by Singular to print a graph.
KEYWORDS:   graph
EXAMPLE:    example printGraph; shows an example
"
{
    "A graph with", size(G.vertices), "vertices and", size(G.edges), "edges";
}
example
{
    "EXAMPLE:"; echo=2;
    ring r = 0,x,dp;
    graph G = makeGraph(list(list(0,1,list(0,1,2)),list(1,1,list(1,0,2))),
    list(list(0,1,2)));
    G;
}

proc makeGraph(list v, list e)
"USAGE:     makeGraph(v,e); v list, e list
ASSUME:     v is a list of vertices, e is a list of edges.
RETURN:     graph with vertices v and edges e.
THEORY:     Creates a graph from a list of vertices and edges.
KEYWORDS:   graph
EXAMPLE:    example makeGraph; shows an example
{
    graph G;
    G.vertices = v;
    G.edges = e;
    return(G);
}
example
{
    "EXAMPLE:"; echo=2;
    ring r = 0,x,dp;
    graph G = makeGraph(list(list(0,1,list(0,1,2)),list(1,1,list(1,0,2))),
    list(list(0,1,2)));
    G;
}

static proc graph1(int d, int i, int j)
{
    graph G;
    list f1 = i,j,d;
    list f2 = j,i,d;
    list v1 = i,1,f1;
    list v2 = j,1,f2;
    G.vertices = v1,v2;
    G.edges = list(f1);
    return (G);
}

static proc graph2(list d, int i, int j, int k)
{
    graph G;
    list f1 = i,j,d[1];
    list f2 = j,i,d[1];
    list f3 = j,k,d[2];
    list f4 = k,j,d[2];
    list v1 = i,1,f1;
    list v2 = j,2,f2,f3;
    list v3 = k,1,f4;
    G.vertices = v1,v2,v3;
    G.edges = f1,f3;
    return (G);
}

static proc graph31(list d, int i, int j, int k, int h)
{
    graph G;
    list f1 = i,j,d[1];
    list f2 = j,i,d[1];
    list f3 = j,k,d[2];
    list f4 = k,j,d[2];
    list f5 = k,h,d[3];
    list f6 = h,k,d[3];
    list v1 = i,1,f1;
    list v2 = j,2,f2,f3;
    list v3 = k,2,f4,f5;
    list v4 = h,1,f6;
    G.vertices = v1,v2,v3,v4;
    G.edges = f1,f3,f5;
    return (G);
}

static proc graph32(list d, int i, int j, int k, int h)
{
    graph G;
    list f1 = i,j,d[1];
    list f2 = j,i,d[1];
    list f3 = j,k,d[2];
    list f4 = j,h,d[3];
    list f5 = k,j,d[2];
    list f6 = h,j,d[3];
    list v1 = i,1,f1;
    list v2 = j,3,f2,f3,f4;
    list v3 = k,1,f5;
    list v4 = h,1,f6;
    G.vertices = v1,v2,v3,v4;
    G.edges = f1,f3,f4;
    return (G);
}

static proc graph41(list d, int i, int j, int k, int h, int l)
{
    graph G;
    list f1 = i,j,d[1];
    list f2 = j,i,d[1];
    list f3 = j,k,d[2];
    list f4 = k,j,d[2];
    list f5 = k,h,d[3];
    list f6 = h,k,d[3];
    list f7 = h,l,d[4];
    list f8 = l,h,d[4];
    list v1 = i,1,f1;
    list v2 = j,2,f2,f3;
    list v3 = k,2,f4,f5;
    list v4 = h,2,f6,f7;
    list v5 = l,1,f8;
    G.vertices = v1,v2,v3,v4,v5;
    G.edges = f1,f3,f5,f7;
    return (G);
}

static proc graph42(list d, int i, int j, int k, int h, int l)
{
    graph G;
    list f1 = i,j,d[1];
    list f2 = j,i,d[1];
    list f3 = j,k,d[2];
    list f4 = k,j,d[2];
    list f5 = k,h,d[3];
    list f6 = k,l,d[4];
    list f7 = h,k,d[3];
    list f8 = l,k,d[4];
    list v1 = i,1,f1;
    list v2 = j,2,f2,f3;
    list v3 = k,3,f4,f5,f6;
    list v4 = h,1,f7;
    list v5 = l,1,f8;
    G.vertices = v1,v2,v3,v4,v5;
    G.edges = f1,f3,f5,f6;
    return (G);
}

static proc graph43(list d, int i, int j, int k, int h, int l)
{
    graph G;
    list f1 = i,j,d[1];
    list f2 = j,i,d[1];
    list f3 = j,k,d[2];
    list f4 = j,h,d[3];
    list f5 = j,l,d[4];
    list f6 = k,j,d[2];
    list f7 = h,j,d[3];
    list f8 = l,j,d[4];
    list v1 = i,1,f1;
    list v2 = j,4,f2,f3,f4,f5;
    list v3 = k,1,f6;
    list v4 = h,1,f7;
    list v5 = l,1,f8;
    G.vertices = v1,v2,v3,v4,v5;
    G.edges = f1,f3,f4,f5;
    return (G);
}

static proc graph51(list d, int i, int j, int k, int h, int m, int n)
{
    graph G;
    list f1 = i,j,d[1];
    list f2 = j,i,d[1];
    list f3 = j,k,d[2];
    list f4 = k,j,d[2];
    list f5 = k,h,d[3];
    list f6 = h,k,d[3];
    list f7 = h,m,d[4];
    list f8 = m,h,d[4];
    list f9 = m,n,d[5];
    list f10 = n,m,d[5];
    list v1 = i,1,f1;
    list v2 = j,2,f2,f3;
    list v3 = k,2,f4,f5;
    list v4 = h,2,f6,f7;
    list v5 = m,2,f8,f9;
    list v6 = n,1,f10;
    G.vertices = v1,v2,v3,v4,v5,v6;
    G.edges = f1,f3,f5,f7,f9;
    return (G);
}

static proc graph52(list d, int i, int j, int k, int h, int m, int n)
{
    graph G;
    list f1 = i,j,d[1];
    list f2 = j,i,d[1];
    list f3 = j,k,d[2];
    list f4 = k,j,d[2];
    list f5 = k,h,d[3];
    list f6 = h,k,d[3];
    list f7 = h,m,d[4];
    list f8 = m,h,d[4];
    list f9 = h,n,d[5];
    list f10 = n,h,d[5];
    list v1 = i,1,f1;
    list v2 = j,2,f2,f3;
    list v3 = k,2,f4,f5;
    list v4 = h,3,f6,f7,f9;
    list v5 = m,1,f8;
    list v6 = n,1,f10;
    G.vertices = v1,v2,v3,v4,v5,v6;
    G.edges = f1,f3,f5,f7,f9;
    return (G);
}

static proc graph53(list d, int i, int j, int k, int h, int m, int n)
{
    graph G;
    list f1 = i,j,d[1];
    list f2 = j,i,d[1];
    list f3 = j,k,d[2];
    list f4 = k,j,d[2];
    list f5 = k,h,d[3];
    list f6 = h,k,d[3];
    list f7 = k,m,d[4];
    list f8 = m,k,d[4];
    list f9 = k,n,d[5];
    list f10 = n,k,d[5];
    list v1 = i,1,f1;
    list v2 = j,2,f2,f3;
    list v3 = k,4,f4,f5,f7,f9;
    list v4 = h,1,f6;
    list v5 = m,1,f8;
    list v6 = n,1,f10;
    G.vertices = v1,v2,v3,v4,v5,v6;
    G.edges = f1,f3,f5,f7,f9;
    return (G);
}

static proc graph54(list d, int i, int j, int k, int h, int m, int n)
{
    graph G;
    list f1 = i,j,d[1];
    list f2 = j,i,d[1];
    list f3 = j,k,d[2];
    list f4 = k,j,d[2];
    list f5 = j,h,d[3];
    list f6 = h,j,d[3];
    list f7 = h,m,d[4];
    list f8 = m,h,d[4];
    list f9 = h,n,d[5];
    list f10 = n,h,d[5];
    list v1 = i,1,f1;
    list v2 = j,3,f2,f3,f5;
    list v3 = k,1,f4;
    list v4 = h,3,f6,f7,f9;
    list v5 = m,1,f8;
    list v6 = n,1,f10;
    G.vertices = v1,v2,v3,v4,v5,v6;
    G.edges = f1,f3,f5,f7,f9;
    return (G);
}

static proc graph55(list d, int i, int j, int k, int h, int m, int n)
{
    graph G;
    list f1 = i,j,d[1];
    list f2 = j,i,d[1];
    list f3 = j,k,d[2];
    list f4 = k,j,d[2];
    list f5 = k,h,d[3];
    list f6 = h,k,d[3];
    list f7 = k,m,d[4];
    list f8 = m,k,d[4];
    list f9 = h,n,d[5];
    list f10 = n,h,d[5];
    list v1 = i,1,f1;
    list v2 = j,2,f2,f3;
    list v3 = k,3,f4,f5,f7;
    list v4 = h,2,f6,f9;
    list v5 = m,1,f8;
    list v6 = n,1,f10;
    G.vertices = v1,v2,v3,v4,v5,v6;
    G.edges = f1,f3,f5,f7,f9;
    return (G);
}

static proc graph56(list d, int i, int j, int k, int h, int m, int n)
{
    graph G;
    list f1 = i,j,d[1];
    list f2 = j,i,d[1];
    list f3 = j,k,d[2];
    list f4 = k,j,d[2];
    list f5 = j,h,d[3];
    list f6 = h,j,d[3];
    list f7 = j,m,d[4];
    list f8 = m,j,d[4];
    list f9 = j,n,d[5];
    list f10 = n,j,d[5];
    list v1 = i,1,f1;
    list v2 = j,5,f2,f3,f5,f7,f9;
    list v3 = k,1,f4;
    list v4 = h,1,f6;
    list v5 = m,1,f8;
    list v6 = n,1,f10;
    G.vertices = v1,v2,v3,v4,v5,v6;
    G.edges = f1,f3,f5,f7,f9;
    return (G);
}

static proc graph61(list d, int i, int j, int k, int h, int m, int n, int p)
{
    graph G;
    list f1 = i,j,d[1];
    list f2 = j,i,d[1];
    list f3 = j,k,d[2];
    list f4 = k,j,d[2];
    list f5 = k,h,d[3];
    list f6 = h,k,d[3];
    list f7 = h,m,d[4];
    list f8 = m,h,d[4];
    list f9 = m,n,d[5];
    list f10 = n,m,d[5];
    list f11 = n,p,d[6];
    list f12 = p,n,d[6];
    list v1 = i,1,f1;
    list v2 = j,2,f2,f3;
    list v3 = k,2,f4,f5;
    list v4 = h,2,f6,f7;
    list v5 = m,2,f8,f9;
    list v6 = n,2,f10,f11;
    list v7 = p,1,f12;
    G.vertices = v1,v2,v3,v4,v5,v6,v7;
    G.edges = f1,f3,f5,f7,f9,f11;
    return (G);
}

static proc graph62(list d, int i, int j, int k, int h, int m, int n, int p)
{
    graph G;
    list f1 = i,j,d[1];
    list f2 = j,i,d[1];
    list f3 = j,k,d[2];
    list f4 = k,j,d[2];
    list f5 = k,h,d[3];
    list f6 = h,k,d[3];
    list f7 = h,m,d[4];
    list f8 = m,h,d[4];
    list f9 = m,n,d[5];
    list f10 = n,m,d[5];
    list f11 = m,p,d[6];
    list f12 = p,m,d[6];
    list v1 = i,1,f1;
    list v2 = j,2,f2,f3;
    list v3 = k,2,f4,f5;
    list v4 = h,2,f6,f7;
    list v5 = m,3,f8,f9,f11;
    list v6 = n,1,f10;
    list v7 = p,1,f12;
    G.vertices = v1,v2,v3,v4,v5,v6,v7;
    G.edges = f1,f3,f5,f7,f9,f11;
    return (G);
}

static proc graph63(list d, int i, int j, int k, int h, int m, int n, int p)
{
    graph G;
    list f1 = i,j,d[1];
    list f2 = j,i,d[1];
    list f3 = j,k,d[2];
    list f4 = k,j,d[2];
    list f5 = k,h,d[3];
    list f6 = h,k,d[3];
    list f7 = h,m,d[4];
    list f8 = m,h,d[4];
    list f9 = h,n,d[5];
    list f10 = n,h,d[5];
    list f11 = n,p,d[6];
    list f12 = p,n,d[6];
    list v1 = i,1,f1;
    list v2 = j,2,f2,f3;
    list v3 = k,2,f4,f5;
    list v4 = h,3,f6,f7,f9;
    list v5 = m,1,f8;
    list v6 = n,2,f10,f11;
    list v7 = p,1,f12;
    G.vertices = v1,v2,v3,v4,v5,v6,v7;
    G.edges = f1,f3,f5,f7,f9,f11;
    return (G);
}

static proc graph64(list d, int i, int j, int k, int h, int m, int n, int p)
{
    graph G;
    list f1 = i,j,d[1];
    list f2 = j,i,d[1];
    list f3 = j,k,d[2];
    list f4 = k,j,d[2];
    list f5 = k,h,d[3];
    list f6 = h,k,d[3];
    list f7 = h,m,d[4];
    list f8 = m,h,d[4];
    list f9 = h,n,d[5];
    list f10 = n,h,d[5];
    list f11 = h,p,d[6];
    list f12 = p,h,d[6];
    list v1 = i,1,f1;
    list v2 = j,2,f2,f3;
    list v3 = k,2,f4,f5;
    list v4 = h,4,f6,f7,f9,f11;
    list v5 = m,1,f8;
    list v6 = n,1,f10;
    list v7 = p,1,f12;
    G.vertices = v1,v2,v3,v4,v5,v6,v7;
    G.edges = f1,f3,f5,f7,f9,f11;
    return (G);
}

static proc graph65(list d, int i, int j, int k, int h, int m, int n, int p)
{
    graph G;
    list f1 = i,j,d[1];
    list f2 = j,i,d[1];
    list f3 = j,k,d[2];
    list f4 = k,j,d[2];
    list f5 = k,h,d[3];
    list f6 = h,k,d[3];
    list f7 = k,m,d[4];
    list f8 = m,k,d[4];
    list f9 = k,n,d[5];
    list f10 = n,k,d[5];
    list f11 = n,p,d[6];
    list f12 = p,n,d[6];
    list v1 = i,1,f1;
    list v2 = j,2,f2,f3;
    list v3 = k,4,f4,f5,f7,f9;
    list v4 = h,1,f6;
    list v5 = m,1,f8;
    list v6 = n,2,f10,f11;
    list v7 = p,1,f12;
    G.vertices = v1,v2,v3,v4,v5,v6,v7;
    G.edges = f1,f3,f5,f7,f9,f11;
    return (G);
}

static proc graph66(list d, int i, int j, int k, int h, int m, int n, int p)
{
    graph G;
    list f1 = i,j,d[1];
    list f2 = j,i,d[1];
    list f3 = j,k,d[2];
    list f4 = k,j,d[2];
    list f5 = k,h,d[3];
    list f6 = h,k,d[3];
    list f7 = k,m,d[4];
    list f8 = m,k,d[4];
    list f9 = h,n,d[5];
    list f10 = n,h,d[5];
    list f11 = m,p,d[6];
    list f12 = p,m,d[6];
    list v1 = i,1,f1;
    list v2 = j,2,f2,f3;
    list v3 = k,3,f4,f5,f7;
    list v4 = h,2,f6,f9;
    list v5 = m,2,f8,f11;
    list v6 = n,1,f10;
    list v7 = p,1,f12;
    G.vertices = v1,v2,v3,v4,v5,v6,v7;
    G.edges = f1,f3,f5,f7,f9,f11;
    return (G);
}

static proc graph67(list d, int i, int j, int k, int h, int m, int n, int p)
{
    graph G;
    list f1 = i,j,d[1];
    list f2 = j,i,d[1];
    list f3 = j,k,d[2];
    list f4 = k,j,d[2];
    list f5 = j,h,d[3];
    list f6 = h,j,d[3];
    list f7 = h,m,d[4];
    list f8 = m,h,d[4];
    list f9 = m,n,d[5];
    list f10 = n,m,d[5];
    list f11 = m,p,d[6];
    list f12 = p,m,d[6];
    list v1 = i,1,f1;
    list v2 = j,3,f2,f3,f5;
    list v3 = k,1,f4;
    list v4 = h,2,f6,f7;
    list v5 = m,3,f8,f9,f11;
    list v6 = n,1,f10;
    list v7 = p,1,f12;
    G.vertices = v1,v2,v3,v4,v5,v6,v7;
    G.edges = f1,f3,f5,f7,f9,f11;
    return (G);
}

static proc graph68(list d, int i, int j, int k, int h, int m, int n, int p)
{
    graph G;
    list f1 = i,j,d[1];
    list f2 = j,i,d[1];
    list f3 = j,k,d[2];
    list f4 = k,j,d[2];
    list f5 = j,h,d[3];
    list f6 = h,j,d[3];
    list f7 = h,m,d[4];
    list f8 = m,h,d[4];
    list f9 = h,n,d[5];
    list f10 = n,h,d[5];
    list f11 = h,p,d[6];
    list f12 = p,h,d[6];
    list v1 = i,1,f1;
    list v2 = j,3,f2,f3,f5;
    list v3 = k,1,f4;
    list v4 = h,4,f6,f7,f9,f11;
    list v5 = m,1,f8;
    list v6 = n,1,f10;
    list v7 = p,1,f12;
    G.vertices = v1,v2,v3,v4,v5,v6,v7;
    G.edges = f1,f3,f5,f7,f9,f11;
    return (G);
}

static proc graph69(list d, int i, int j, int k, int h, int m, int n, int p)
{
    graph G;
    list f1 = i,j,d[1];
    list f2 = j,i,d[1];
    list f3 = j,k,d[2];
    list f4 = k,j,d[2];
    list f5 = j,h,d[3];
    list f6 = h,j,d[3];
    list f7 = h,m,d[4];
    list f8 = m,h,d[4];
    list f9 = h,n,d[5];
    list f10 = n,h,d[5];
    list f11 = n,p,d[6];
    list f12 = p,n,d[6];
    list v1 = i,1,f1;
    list v2 = j,3,f2,f3,f5;
    list v3 = k,1,f4;
    list v4 = h,3,f6,f7,f9;
    list v5 = m,1,f8;
    list v6 = n,2,f10,f11;
    list v7 = p,1,f12;
    G.vertices = v1,v2,v3,v4,v5,v6,v7;
    G.edges = f1,f3,f5,f7,f9,f11;
    return (G);
}

static proc graph610(list d, int i, int j, int k, int h, int m, int n, int p)
{
    graph G;
    list f1 = i,j,d[1];
    list f2 = j,i,d[1];
    list f3 = j,k,d[2];
    list f4 = k,j,d[2];
    list f5 = k,h,d[3];
    list f6 = h,k,d[3];
    list f7 = k,m,d[4];
    list f8 = m,k,d[4];
    list f9 = k,n,d[5];
    list f10 = n,k,d[5];
    list f11 = k,p,d[6];
    list f12 = p,k,d[6];
    list v1 = i,1,f1;
    list v2 = j,2,f2,f3;
    list v3 = k,5,f4,f5,f7,f9,f11;
    list v4 = h,1,f6;
    list v5 = m,1,f8;
    list v6 = n,1,f10;
    list v7 = p,1,f12;
    G.vertices = v1,v2,v3,v4,v5,v6,v7;
    G.edges = f1,f3,f5,f7,f9,f11;
    return (G);
}

static proc graph611(list d, int i, int j, int k, int h, int m, int n, int p)
{
    graph G;
    list f1 = i,j,d[1];
    list f2 = j,i,d[1];
    list f3 = j,k,d[2];
    list f4 = k,j,d[2];
    list f5 = j,h,d[3];
    list f6 = h,j,d[3];
    list f7 = j,m,d[4];
    list f8 = m,j,d[4];
    list f9 = j,n,d[5];
    list f10 = n,j,d[5];
    list f11 = j,p,d[6];
    list f12 = p,j,d[6];
    list v1 = i,1,f1;
    list v2 = j,6,f2,f3,f5,f7,f9,f11;
    list v3 = k,1,f4;
    list v4 = h,1,f6;
    list v5 = m,1,f8;
    list v6 = n,1,f10;
    list v7 = p,1,f12;
    G.vertices = v1,v2,v3,v4,v5,v6,v7;
    G.edges = f1,f3,f5,f7,f9,f11;
    return (G);
}

proc part(poly f, int n)
"USAGE:     part(f,n); f poly, n int
RETURN:     poly
PURPOSE:    computing the homogeneous component of a polynomial.
EXAMPLE:    example part; shows examples
"
{
    int i;
    poly p;
    for (i=1;i<=size(f);i++)
    {
        if (deg(f[i])==n) {p=p+f[i];}
    }
    return (p);
}
example
{
    "EXAMPLE:"; echo=2;
    ring r = 0,(x,y,z),wp(1,2,3);
    poly f = 1+x+x2+x3+x4+y+y2+y3+z+z2+xy+xz+yz+xyz;
    part(f,0);
    part(f,1);
    part(f,2);
    part(f,3);
    part(f,4);
    part(f,5);
    part(f,6);
}

proc parts(poly f, int i, int j)
"USAGE:     parts(f,i,j); f poly, i int, j int
RETURN:     poly
THEORY:     computing a polynomial which is the sum of the homogeneous
            components of a polynomial.
EXAMPLE:    example parts; shows examples
"
{
    int k;
    poly p;
    for (k=i;k<=j;k++)
    {
        p=p+part(f,k);
    }
    return (p);
}
example
{
    "EXAMPLE:"; echo=2;
    ring r = 0,(x,y,z),wp(1,2,3);
    poly f = 1+x+x2+x3+x4+y+y2+y3+z+z2+xy+xz+yz+xyz;
    parts(f,2,4);
}

proc logg(poly f, int n)
"USAGE:     logg(f,n); f poly, n int
RETURN:     poly
THEORY:     computing Chern characters from total Chern classes.
EXAMPLE:    example logg; shows examples
"
{
    poly p;
    int i,j,k,m;
    if (n==0) {p=0;}
    if (n==1) {p=part(f,1);}
    else
    {
        list l=-part(f,1);
        for (j=2;j<=n;j++)
        {
            poly q;
            for (k=1;k<j;k++)
            {
                q=q+part(f,k)*l[j-k];
            }
            q=-j*part(f,j)-q;
            l=insert(l,q,size(l));
            kill q;
        }
        for (m=1;m<=n;m++)
        {
            p=p+1/factorial(m)*(-1)^m*l[m];
        }
    }
    return (p);
}
example
{
    "EXAMPLE:"; echo=2;
    ring r = 0,(x,y),wp(1,2);
    poly f = 1+x+y;
    logg(f,4);
}

proc expp(poly f, int n)
"USAGE:     expp(f,n); f poly, n int
RETURN:     poly
PURPOSE:    computing total Chern classes from Chern characters.
EXAMPLE:    example expp; shows examples
"
{
    poly p;
    int i,j,k;
    if (deg(f)==0) {p=1;}
    else
    {
        list l=1;
        for (i=1;i<=n;i++)
        {
            poly q;
            for (j=1;j<=i;j++)
            {
                q=q+factorial(j)*(-1)^(j-1)*l[i-j+1]*part(f,j)/i;
            }
            l=insert(l,q,size(l));
            kill q;
        }
        for (k=1;k<=size(l);k++)
        {
            p=p+l[k];
        }
    }
    return (p);
}
example
{
    "EXAMPLE:"; echo=2;
    ring r = 0,x,dp;
    poly f = 3+x;
    expp(f,3);
}

static proc adams(poly f, int n)
{
    poly p;
    int i;
    for (i=0;i<=deg(f);i++)
    {
        p=p+n^i*part(f,i);
    }
    return (p);
}

static proc wedges(int n, poly f, int d)
{
    int i,j;
    list l;
    if (n==0) {l=1;}
    if (n==1) {l=1,f;}
    else
    {
        l=1,f;
        for (i=2;i<=n;i++)
        {
            poly q;
            for (j=1;j<=i;j++)
            {
                q=q+((-1)^(i-j))*parts(l[j]*adams(f,i-j+1),0,d)/i;
            }
            l=insert(l,q,size(l));
            kill q;
        }
    }
    return (l);
}

static proc schur(list p, poly f)
{
    int i,j;
    int n = size(p);
    matrix M[n][n];
    for (i=1;i<=n;i++)
    {
        for (j=1;j<=n;j++)
        {
            M[i,j] = part(f,p[i]+j-i);
        }
    }
    return (det(M));
}

////////////////////////////////////////////////////////////////////////////////
//////// Procedures concerned with abstract varieties //////////////////////////
////////////////////////////////////////////////////////////////////////////////

proc printVariety(variety V)
"USAGE:     printVariety(V); V variety
ASSUME:     V is an abstract variety
THEORY:     This is the print function used by Singular to print an abstract
            variety.
KEYWORDS:   abstract variety, projective space, Grassmannian
EXAMPLE:    example printVariety; shows an example
"
{
    "A variety of dimension", V.dimension;
}
example
{
    "EXAMPLE:"; echo=2;
    ring r = 0,(h,e),wp(1,1);
    ideal rels = he,h2+e2;
    variety V = makeVariety(2,rels);
    V;
}

proc makeVariety(int d, ideal i)
"USAGE:     makeVariety(d,i); d int, i ideal
ASSUME:     d is a nonnegative integer, i is an ideal
RETURN:     variety
THEORY:     create an abstract variety which has dimension d, and its Chow ring
            should be a quotient ring
KEYWORDS:   abstract variety, projective space, Grassmannian
EXAMPLE:    example makeVariety; shows an example
"
{
    def R = basering;
    variety V;
    V.dimension = d;
    V.baseRing = R;
    V.relations = i;
    return(V);
}
example
{
    "EXAMPLE:"; echo=2;
    ring r = 0,(h,e),wp(1,1);
    ideal rels = he,h2+e2;
    variety V = makeVariety(2,rels);
    V;
    V.dimension;
    V.relations;
}

proc ChowRing(variety V)
"USAGE:     ChowRing(V); V variety
ASSUME:     V is an abstract variety
RETURN:     qring
KEYWORDS:   Chow ring, abstract variety, projective space, Grassmannian
EXAMPLE:    example makeVariety; shows an example
"
{
    def R = V.baseRing;
    setring R;
    ideal rels = V.relations;
    qring CR = std(rels);
    return (CR);
}
example
{
    "EXAMPLE:"; echo=2;
    ring r = 0,(h,e),wp(1,1);
    ideal rels = he,h2+e2;
    int d = 2;
    variety V = makeVariety(2,rels);
    ChowRing(V);
}

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

proc Grassmannian(int k, int n, list #)
"USAGE:     Grassmannian(k,n); k int, n int
RETURN:     variety
THEORY:     create a Grassmannian G(k,n) as an abstract variety. This abstract
            variety has diemnsion k(n-k) and its Chow ring is the quotient ring
            of a polynomial ring in n-k variables q(1),...,q(n-k), which are the
            Chern classes of tautological quotient bundle on G(k,n), modulo some
            ideal generated by n-k polynomials which come from the Giambelli
            formula. The monomial ordering of this Chow ring is 'wp' with vector
            (1..k,1..n-k). Moreover, we export the Chern characters of
            tautological subbundle and quotient bundle on G(k,n)
            (say 'subBundle' and 'quotientBundle').
KEYWORDS:   Grassmannian, abstract variety, Schubert calculus
SEE ALSO:   projectiveSpace, projectiveBundle
EXAMPLE:    example Grassmannian; shows examples
"
{
    string q;
    if (size(#)==0) {q = "q";}
    else
    {
        if (typeof(#[1]) == "string") {q = #[1];}
        else {Error("invalid optional argument");}
    }
    variety G;
    G.dimension = k*(n-k);
    execute("ring r = 0,("+q+"(1..n-k)),wp(1..n-k);");
    setring r;
    G.baseRing = r;
    int i,j;
    poly v = 1;
    poly u = 1;
    for (j=1;j<=n-k;j++) {v=v+q(j);}
    list l;
    for (i=1;i<=k;i++)
    {
        l=insert(l,1,size(l));
        u=u+(-1)^i*schur(l,v);
    }
    l=insert(l,1,size(l));
    ideal rels = schur(l,v);
    int h = k+2;
    while (h<=n)
    {
        l=insert(l,1,size(l));
        rels = rels,schur(l,v);
        h++;
    }
    G.relations = rels;
    int d = k*(n-k);
    poly subBundle = reduce(logg(u,d)+k,std(rels));
    poly quotientBundle = reduce(logg(v,d)+n-k,std(rels));
    export (subBundle,quotientBundle);
    kill u,v,d,l,rels;
    return (G);
}
example
{
    "EXAMPLE:"; echo=2;
    variety G24 = Grassmannian(2,4);
    G24;
    def r = G24.baseRing;
    setring r;
    subBundle;
    quotientBundle;
    G24.dimension;
    G24.relations;
    ChowRing(G24);
}

proc projectiveSpace(int n, list #)
"USAGE:     projectiveSpace(n); n int
RETURN:     variety
THEORY:     create a projective space of dimension n as an abstract variety. Its
            Chow ring is a quotient ring in one variable h modulo the ideal
            generated by h^(n+1).
KEYWORDS:   projective space, abstract variety
SEE ALSO:   Grassmannian, projectiveBundle
EXAMPLE:    example projectiveSpace; shows examples
"
{
    string h;
    if (size(#)==0) {h = "h";}
    else
    {
        if (typeof(#[1]) == "string") {h = #[1];}
        else {Error("invalid optional argument");}
    }
    variety P;
    P.dimension = n;
    execute("ring r = 0, ("+h+"), wp(1);");
    setring r;
    P.baseRing = r;
    ideal rels = var(1)^(n+1);
    P.relations = rels;
    poly u = 1;
    poly v = 1 + var(1);
    list l;
    int i;
    for (i=1;i<=n;i++)
    {
        l=insert(l,1,size(l));
        u=u+(-1)^i*schur(l,v);
    }
    poly subBundle = reduce(logg(u,n)+n,std(rels));
    poly quotientBundle = reduce(logg(v,n)+1,std(rels));
    export(subBundle,quotientBundle);
    kill rels,u,v,l;
    return (P);
}
example
{
    "EXAMPLE:"; echo=2;
    variety P = projectiveSpace(3);
    P;
    P.dimension;
    def r = P.baseRing;
    setring r;
    P.relations;
    ChowRing(P);
}

proc projectiveBundle(sheaf S, list #)
"USAGE:     projectiveBundle(S); S sheaf
INPUT:      a sheaf on an abstract variety
RETURN:     variety
THEORY:     create a projective bundle as an abstract variety. This is related
            to the enumeration of conics.
KEYWORDS:   projective bundle, abstract variety, sheaf, enumeration of conics
SEE ALSO:   projectiveSpace, Grassmannian
EXAMPLE:    example projectiveBundle; shows examples
"
{
    string z;
    if (size(#)==0) {z = "z";}
    else
    {
        if (typeof(#[1]) == "string") {z = #[1];}
        else {Error("invalid optional argument");}
    }
    variety A;
    def B = S.currentVariety;
    def R = B.baseRing;
    setring R;
    ideal rels = B.relations;
    int r = rankSheaf(S);
    A.dimension = r - 1 + B.dimension;
    poly c = totalChernClass(S);
    execute("ring P = 0, ("+z+"), wp(1);");
    def CR = P + R;
    setring CR;
    A.baseRing = CR;
    poly c = imap(R,c);
    ideal rels = imap(R,rels);
    poly g = var(1)^r;
    int i;
    for (i=1;i<=r;i++) {g=g+var(1)^(r-i)*part(c,i);}
    A.relations = rels,g;
    poly u = 1 + var(1);
    poly f = logg(u,A.dimension)+1;
    poly QuotientBundle = reduce(f,std(A.relations));
    export (QuotientBundle);
    kill f,rels;
    return (A);
}
example
{
    "EXAMPLE:"; echo=2;
    variety G = Grassmannian(3,5);
    def r = G.baseRing;
    setring r;
    sheaf S = makeSheaf(G,subBundle);
    sheaf B = dualSheaf(S)^2;
    variety PB = projectiveBundle(B);
    PB;
    def R = PB.baseRing;
    setring R;
    QuotientBundle;
    ChowRing(PB);
}

proc productVariety(variety U, variety V)
"USAGE:     productVariety(U,V); U variety, V variety
INPUT:      two abstract varieties
OUTPUT:     a product variety as an abstract variety
RETURN:     variety
KEYWORDS:   product variety, abstract variety
SEE ALSO:   projectiveSpace, Grassmannian, projectiveBundle
EXAMPLE:    example productVariety; shows examples
"
{
    //def br = basering;
    def ur = U.baseRing; setring ur;
    ideal ii1 = U.relations;
    def vr = V.baseRing; setring vr;
    ideal ii2 = V.relations;
    variety W;
    W.dimension = U.dimension + V.dimension;
    def temp = ringtensor(ur,vr);
    setring temp;
    W.baseRing = temp;
    ideal i1 = imap(ur,ii1);
    ideal i2 = imap(vr,ii2);
    W.relations = i1 + i2;
    setring ur;
    kill ii1;
    setring vr;
    kill ii2;
    //setring br;
    return (W);
}
example
{
    "EXAMPLE:"; echo=2;
    variety P = projectiveSpace(3);
    variety G = Grassmannian(2,4);
    variety W = productVariety(P,G);
    W;
    W.dimension == P.dimension + G.dimension;
    def r = W.baseRing;
    setring r;
    W.relations;
}

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

proc integral(variety V, poly f)
"USAGE:     integral(V,f); V variety, f poly
INPUT:      a abstract variety and a polynomial
RETURN:     int
PURPOSE:    computing intersection numbers.
EXAMPLE:    example integral; shows an example
"
{
    def R = V.baseRing;
    setring R;
    ideal rels = V.relations;
    return (leadcoef(reduce(f,std(rels))));
}
example
{
    "EXAMPLE:"; echo=2;
    variety G = Grassmannian(2,4);
    def r = G.baseRing;
    setring r;
    integral(G,q(1)^4);
}

proc SchubertClass(list p)
"USAGE:     SchubertClass(p); p list
INPUT:      a list of integers which is a partition
RETURN:     poly
PURPOSE:    compute the Schubert classes on a Grassmannian.
EXAMPLE:    example SchubertClass; shows an example
"
{
    def R = basering;
    setring R;
    poly f = 1;
    if (size(p) == 0) {return (f);}
    int i;
    for (i=1;i<=nvars(R);i++)
    {
        f = f + var(i);
    }
    return (schur(p,f));
}
example
{
    "EXAMPLE:"; echo=2;
    variety G = Grassmannian(2,4);
    def r = G.baseRing;
    setring r;
    list p = 1,1;
    SchubertClass(p);
}

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

proc dualPartition(int k, int n, list p)
"USAGE:     dualPartition(k,n,p); k int, n int, p list
INPUT:      two integers and a partition
RETURN:     list
PURPOSE:    compute the dual of a partition.
SEE ALSO:   SchubertClass
EXAMPLE:    example dualPartition; shows an example
"
{
    while (size(p) < k)
    {
        p = insert(p,0,size(p));
    }
    int i;
    list l;
    for (i=1;i<=size(p);i++)
    {
        l[i] = n-k-p[size(p)-i+1];
    }
    return (l);
}
example
{
    "EXAMPLE:"; echo=2;
    ring r = 0,(x),dp;
    dualPartition(2,4,list(2,1));
}

////////////////////////////////////////////////////////////////////////////////
////////// Procedures concerned with abstract sheaves ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

proc printSheaf(sheaf S)
"USAGE:     printSheaf(S); S sheaf
RETURN:     string
INPUT:      a sheaf
THEORY:     This is the print function used by Singular to print a sheaf.
SEE ALSO:   makeSheaf, rankSheaf
EXAMPLE:    example printSheaf; shows an example
"
{
    "A sheaf of rank ", rankSheaf(S);
}
example
{
    "EXAMPLE:"; echo=2;
    variety X;
    X.dimension = 4;
    ring r = 0,(c(1..2),d(1..3)),wp(1..2,1..3);
    setring r;
    X.baseRing = r;
    poly c = 1 + c(1) + c(2);
    poly ch = 2 + logg(c,4);
    sheaf S = makeSheaf(X,ch);
    S;
}

proc makeSheaf(variety V, poly ch)
"USAGE:     makeSheaf(V,ch); V variety, ch poly
RETURN:     sheaf
THEORY:     create a sheaf on an abstract variety, and its Chern character is
            the polynomial ch.
SEE ALSO:   printSheaf, rankSheaf
EXAMPLE:    example makeSheaf; shows an example
"
{
    def R = basering;
    sheaf S;
    S.currentVariety = V;
    S.ChernCharacter = ch;
    return(S);
}
example
{
    "EXAMPLE:"; echo=2;
    variety X;
    X.dimension = 4;
    ring r = 0,(c(1..2),d(1..3)),wp(1..2,1..3);
    setring r;
    X.baseRing = r;
    poly c = 1 + c(1) + c(2);
    poly ch = 2 + logg(c,4);
    sheaf S = makeSheaf(X,ch);
    S;
}

proc rankSheaf(sheaf S)
"USAGE:     rankSheaf(S); S sheaf
RETURN:     int
INPUT:      S is a sheaf
OUTPUT:     a positive integer which is the rank of a sheaf.
SEE ALSO:   makeSheaf, printSheaf
EXAMPLE:    example rankSheaf; shows an example
"
{
    variety V = S.currentVariety;
    def R = V.baseRing;
    setring R;
    poly f = S.ChernCharacter;
    return (int(part(f,0)));
}
example
{
    "EXAMPLE:"; echo=2;
    variety G = Grassmannian(2,4);
    def R = G.baseRing;
    setring R;
    sheaf S = makeSheaf(G,subBundle);
    rankSheaf(S);
}

proc totalChernClass(sheaf S)
"USAGE:     totalChernClass(S); S sheaf
RETURN:     poly
INPUT:      S is a sheaf
OUTPUT:     a polynomial which is the total Chern class of a sheaf
SEE ALSO:   totalSegreClass, topChernClass, ChernClass
EXAMPLE:    example totalChernClass; shows an example
"
{
    variety V = S.currentVariety;
    int d = V.dimension;
    def R = V.baseRing;
    setring R;
    poly ch = S.ChernCharacter;
    poly f = expp(ch,d);
    ideal rels = std(V.relations);
    return (reduce(f,rels));
}
example
{
    "EXAMPLE:"; echo=2;
    variety X;
    X.dimension = 4;
    ring r = 0,(c(1..2),d(1..3)),wp(1..2,1..3);
    setring r;
    X.baseRing = r;
    poly c = 1 + c(1) + c(2);
    poly ch = 2 + logg(c,4);
    sheaf E = makeSheaf(X,ch);
    sheaf S = E^3;
    totalChernClass(S);
}

proc ChernClass(sheaf S, int i)
"USAGE:     ChernClass(S,i); S sheaf, i int
INPUT:      S is a sheaf, i is a nonnegative integer
RETURN:     poly
THEORY:     This is the i-th Chern class of a sheaf
SEE ALSO:   topChernClass, totalChernClass
EXAMPLE:    example ChernClass; shows an example
"
{
    return (part(totalChernClass(S),i));
}
example
{
    "EXAMPLE:"; echo=2;
    variety X;
    X.dimension = 4;
    ring r = 0,(c(1..2),d(1..3)),wp(1..2,1..3);
    setring r;
    X.baseRing = r;
    poly c = 1 + c(1) + c(2);
    poly ch = 2 + logg(c,4);
    sheaf E = makeSheaf(X,ch);
    sheaf S = E^3;
    ChernClass(S,1);
    ChernClass(S,2);
    ChernClass(S,3);
    ChernClass(S,4);
}

proc topChernClass(sheaf S)
"USAGE:     topChernClass(S); S sheaf
RETURN:     poly
INPUT:      S is a sheaf
THEORY:     This is the top Chern class of a sheaf
SEE ALSO:   ChernClass, totalChernClass
EXAMPLE:    example topChernClass; shows an example
"
{
    return (ChernClass(S,rankSheaf(S)));
}
example
{
    "EXAMPLE:"; echo=2;
    variety G = Grassmannian(2,4);
    def R = G.baseRing;
    setring R;
    sheaf S = makeSheaf(G,quotientBundle);
    sheaf B = S^3;
    topChernClass(B);
}

proc totalSegreClass(sheaf S)
"USAGE:     totalSegreClass(S); S sheaf
RETURN:     poly
INPUT:      S is a sheaf
THEORY:     This is the total Segre class of a sheaf.
SEE AlSO:   totalChernClass
EXAMPLE:    example totalSegreClass; shows an example
"
{
    //def D = dualSheaf(S);
    variety V = S.currentVariety;
    def R = V.baseRing;
    setring R;
    poly f = totalChernClass(S);
    poly g;
    int d = V.dimension;
    ideal rels = std(V.relations);
    if (f == 1) {return (1);}
    else
    {
        poly t,h;
        int i,j;
        for (i=0;i<=d;i++) {t = t + (1-f)^i;}
        for (j=0;j<=d;j++) {h = h + part(t,j);}
        return (reduce(h,rels));
    }
}
example
{
    "EXAMPLE:"; echo=2;
    variety G = Grassmannian(2,4);
    def R = G.baseRing;
    setring R;
    sheaf S = makeSheaf(G,subBundle);
    totalSegreClass(S);
}

proc dualSheaf(sheaf S)
"USAGE:     dualSheaf(S); S sheaf
RETURN:     sheaf
THEORY:     This is the dual of a sheaf
SEE ALSO:   addSheaf, symmetricPowerSheaf, tensorSheaf, quotSheaf
EXAMPLE:    example dualSheaf; shows examples
"
{
    variety V = S.currentVariety;
    int d = V.dimension;
    def R = V.baseRing;
    setring R;
    poly ch = S.ChernCharacter;
    poly f = adams(ch,-1);
    sheaf D;
    D.currentVariety = V;
    D.ChernCharacter = f;
    return (D);
}
example
{
    "EXAMPLE:"; echo=2;
    variety G = Grassmannian(2,4);
    def R = G.baseRing;
    setring R;
    sheaf S = makeSheaf(G,subBundle);
    sheaf D = dualSheaf(S);
    D;
}

proc tensorSheaf(sheaf A, sheaf B)
"USAGE:     tensorSheaf(A,B); A sheaf, B sheaf
RETURN:     sheaf
THEORY:     This is the tensor product of two sheaves
SEE ALSO:   addSheaf, symmetricPowerSheaf, quotSheaf, dualSheaf
EXAMPLE:    example tensorSheaf; shows examples
"
{
    sheaf S;
    variety V1 = A.currentVariety;
    variety V2 = B.currentVariety;
    def R1 = V1.baseRing;
    setring R1;
    poly c1 = A.ChernCharacter;
    def R2 = V2.baseRing;
    setring R2;
    poly c2 = B.ChernCharacter;
    if (nvars(R1) < nvars(R2))
    {
        S.currentVariety = V2;
        poly c = imap(R1,c1);
        poly f = parts(c*c2,0,V2.dimension);
        S.ChernCharacter = f;
        return (S);
    }
    else
    {
        setring R1;
        S.currentVariety = V1;
        poly c = imap(R2,c2);
        poly f = parts(c1*c,0,V1.dimension);
        S.ChernCharacter = f;
        return (S);
    }
}
example
{
    "EXAMPLE:"; echo=2;
    variety G = Grassmannian(3,4);
    def R = G.baseRing;
    setring R;
    sheaf S = makeSheaf(G,subBundle);
    sheaf Q = makeSheaf(G,quotientBundle);
    sheaf T = S*Q;
    T;
}

proc symmetricPowerSheaf(sheaf S, int n)
"USAGE:     symmetricPowerSheaf(S,n); S sheaf, n int
RETURN:     sheaf
THEORY:     This is the n-th symmetric power of a sheaf
SEE ALSO:   quotSheaf, addSheaf, tensorSheaf, dualSheaf
EXAMPLE:    example symmetricPowerSheaf; shows examples
"
{
    variety V = S.currentVariety;
    def R = V.baseRing;
    setring R;
    int r = rankSheaf(S);
    int d = V.dimension;
    int i,j,m;
    poly f = S.ChernCharacter;
    poly result;
    list s,w;
    if (n==0) {result=1;}
    if (n==1) {result=f;}
    else
    {
        s = 1,f;
        w = wedges(n,f,d);
        for (i=2;i<=n;i++)
        {
            if (i<=r) {m=i;}
            else {m=r;}
            poly q;
            for (j=1;j<=m;j++)
            {
                q = q + ((-1)^(j+1))*parts(w[j+1]*s[i-j+1],0,d);
            }
            s = insert(s,q,size(s));
            kill q;
        }
        result = s[n+1];
    }
    sheaf A;
    A.currentVariety = V;
    A.ChernCharacter = result;
    return (A);
}
example
{
    "EXAMPLE:"; echo=2;
    variety G = Grassmannian(2,4);
    def R = G.baseRing;
    setring R;
    sheaf S = makeSheaf(G,quotientBundle);
    sheaf B = symmetricPowerSheaf(S,3);
    B;
    sheaf A = S^3;
    A;
    A.ChernCharacter == B.ChernCharacter;
}

proc quotSheaf(sheaf A, sheaf B)
"USAGE:     quotSheaf(A,B); A sheaf, B sheaf
RETURN:     sheaf
THEORY:     This is the quotient of two sheaves
SEE ALSO:   addSheaf, symmetricPowerSheaf, tensorSheaf, dualSheaf
EXAMPLE:    example quotSheaf; shows an example
"
{
    sheaf S;
    variety V1 = A.currentVariety;
    variety V2 = B.currentVariety;
    def R1 = V1.baseRing;
    setring R1;
    poly c1 = A.ChernCharacter;
    def R2 = V2.baseRing;
    setring R2;
    poly c2 = B.ChernCharacter;
    if (nvars(R1) < nvars(R2))
    {
        S.currentVariety = V2;
        poly c = imap(R1,c1);
        S.ChernCharacter = c - c2;
        return (S);
    }
    else
    {
        setring R1;
        S.currentVariety = V1;
        poly c = imap(R2,c2);
        S.ChernCharacter = c1 - c;
        return (S);
    }
}
example
{
    "EXAMPLE:"; echo=2;
    variety G = Grassmannian(3,5);
    def r = G.baseRing;
    setring r;
    sheaf S = makeSheaf(G,subBundle);
    sheaf B = dualSheaf(S)^2;
    sheaf B3 = dualSheaf(S)^3;
    sheaf B5 = dualSheaf(S)^5;
    variety PB = projectiveBundle(B);
    def R = PB.baseRing;
    setring R;
    sheaf Q = makeSheaf(PB,QuotientBundle);
    sheaf V = dualSheaf(Q)*B3;
    sheaf A = B5 - V;
    A;
}

proc addSheaf(sheaf A, sheaf B)
"USAGE:     addSheaf(A,B); A sheaf, B sheaf
RETURN:     sheaf
THEORY:     This is the direct sum of two sheaves.
SEE ALSO:   quotSheaf, symmetricPowerSheaf, tensorSheaf, dualSheaf
EXAMPLE:    example addSheaf; shows an example
"
{
    sheaf S;
    variety V1 = A.currentVariety;
    variety V2 = B.currentVariety;
    def R1 = V1.baseRing;
    setring R1;
    poly c1 = A.ChernCharacter;
    def R2 = V2.baseRing;
    setring R2;
    poly c2 = B.ChernCharacter;
    if (nvars(R1) < nvars(R2))
    {
        S.currentVariety = V2;
        poly c = imap(R1,c1);
        S.ChernCharacter = c + c2;
        return (S);
    }
    else
    {
        setring R1;
        S.currentVariety = V1;
        poly c = imap(R2,c2);
        S.ChernCharacter = c1 + c;
        return (S);
    }
}
example
{
    "EXAMPLE:"; echo=2;
    variety G = Grassmannian(3,5);
    def r = G.baseRing;
    setring r;
    sheaf S = makeSheaf(G,subBundle);
    sheaf Q = makeSheaf(G,quotientBundle);
    sheaf D = S + Q;
    D;
    D.ChernCharacter == rankSheaf(D);
    totalChernClass(D) == 1;
}