File: OldToricVectorBundles.m2

package info (click to toggle)
macaulay2 1.21%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 133,096 kB
  • sloc: cpp: 110,377; ansic: 16,306; javascript: 4,193; makefile: 3,821; sh: 3,580; lisp: 764; yacc: 590; xml: 177; python: 140; perl: 114; lex: 65; awk: 3
file content (4357 lines) | stat: -rw-r--r-- 211,144 bytes parent folder | download
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
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
--*- coding: utf-8 -*-

---------------------------------------------------------------------------
-- PURPOSE: Computations with vector bundles on toric varieties 
-- PROGRAMMER : René Birkner 
-- UPDATE HISTORY : November 2008, November 2009, April 2010
---------------------------------------------------------------------------
newPackage("OldToricVectorBundles",
    Headline => "vector bundles on toric varieties",
    Version => "1.1",
    Date => "August 21, 2014",
    Authors => {
         {Name => "René Birkner",
	  HomePage => "http://page.mi.fu-berlin.de/rbirkner/indexen.htm",
	  Email => "rbirkner@math.fu-berlin.de"},
         {Name => "Nathan Ilten",
	  HomePage => "http://people.cs.uchicago.edu/~nilten/",
	  Email => "nilten@cs.uchicago.edu"},
         {Name => "Lars Petersen",
	  Email => "petersen@math.fu-berlin.de"}},
    Keywords => {"Toric Geometry"},
    Certification => {
	 "journal name" => "The Journal of Software for Algebra and Geometry: Macaulay2",
	 "journal URI" => "http://j-sag.org/",
	 "article title" => "Computations with equivariant toric vector bundles",
	 "acceptance date" => "2010-06-15",
	 "published article URI" => "http://j-sag.org/Volume2/jsag-3-2010.pdf",
	 "published code URI" => "http://j-sag.org/Volume2/ToricVectorBundles.m2",
	 "repository code URI" => "https://github.com/Macaulay2/M2/blob/master/M2/Macaulay2/packages/ToricVectorBundles.m2",
	 "release at publication" => "314a1e7a1a5f612124f23e2161c58eabeb491f46",
	 "version at publication" => "1.0",
	 "volume number" => "2",
	 "volume URI" => "http://j-sag.org/Volume2/"
	 },
    DebuggingMode => false,
    PackageExports => {"OldPolyhedra"}
    )

-- Check version compatibility of Polyhedra
if (options OldPolyhedra)#Version < "1.1" then error("expected at least version 1.1 of OldPolyhedra to be installed.")

---------------------------------------------------------------------------
-- COPYRIGHT NOTICE:
--
-- Copyright 2010 René Birkner, Nathan Owen Ilten, and Lars Petersen
--
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
--
---------------------------------------------------------------------------

export {"ToricVectorBundle",
     "ToricVectorBundleKaneyama", 
     "ToricVectorBundleKlyachko",
     "toricVectorBundle", 
     "addBase", 
     "addBaseChange", 
     "addDegrees", 
     "addFiltration", 
     "areIsomorphic", 
     "base",
     "cartierIndex",
     "charts",
     "cocycleCheck", 
     "cotangentBundle",
     "deltaE",
     "details",  
     "eulerChi", 
     "existsDecomposition", 
     "filtration", 
     "findWeights", 
     "isGeneral", 
     "isomorphism", 
     "isVectorBundle", 
     "randomDeformation",
     "regCheck", 
     "tangentBundle", 
     "twist", 
     "weilToCartier", 
     "hirzebruchFan",
     "pp1ProductFan", 
     "projectiveSpaceFan"}


protect allRaysTable
protect isoMatrix
protect gradedRing
protect cech
protect isVB
protect cocyle
protect degreesList
protect cocycle
protect weights
protect isomorphic

---------------------------------------------------------------------------
-- DEFINING NEW TYPES
---------------------------------------------------------------------------


-- Defining the new type ToricVectorBundle, the parent type to the two types of TVB
ToricVectorBundle = new Type of HashTable

-- Defining the new type ToricVectorBundleKaneyama
ToricVectorBundleKaneyama = new Type of ToricVectorBundle
ToricVectorBundleKaneyama.synonym = "vector bundle on a toric variety (Kaneyama's description)"
globalAssignment ToricVectorBundleKaneyama

-- Defining the new type ToricVectorBundleKlyachko
ToricVectorBundleKlyachko = new Type of ToricVectorBundle
ToricVectorBundleKlyachko.synonym = "vector bundle on a toric variety (Klyachko's description)"
globalAssignment ToricVectorBundleKlyachko

-- Modifying the standard output for a ToricVectorBundleKaneyama to give an overview of its characteristica
net ToricVectorBundleKaneyama := tvb -> ( horizontalJoin flatten ( 
	  "{", 
	  -- prints the parts vertically
	  stack (horizontalJoin \ sort apply({"dimension of the variety",
			                      "rank of the vector bundle",
					      "number of affine charts"}, key -> (net key, " => ", net tvb#key))),
	  "}" ))

-- Modifying the standard output for a ToricVectorBundleKlyachko to give an overview of its characteristica
net ToricVectorBundleKlyachko := tvb -> ( horizontalJoin flatten ( 
	  "{", 
	  -- prints the parts vertically
	  stack (horizontalJoin \ sort apply({"dimension of the variety",
					      "rank of the vector bundle",
					      "number of affine charts",
					      "number of rays"}, key -> (net key, " => ", net tvb#key))),
	  "}" ))


---------------------------------------------------------------
-- Sorting rays
---------------------------------------------------------------

-- A ray is a matrix ZZ^n <-- ZZ^1, so rays can be sorted by assembling them
-- into a matrix and calling "sortColumns".  We sort the rays as in the package
-- OldPolyhedra, so that changes to the algorithm for computing the hash code of
-- matrices doesn't affect what we do.

raySort = value OldPolyhedra#"private dictionary"#"raySort"

---------------------------------------------------------------
-- FUNCTIONS TO CONSTRUCT VECTOR BUNDLES AND MODIFY THEM
---------------------------------------------------------------


-- PURPOSE : Building a Vector Bundle of rank 'k' on the Toric Variety given by the Fan 'F'
toricVectorBundle = method(Options => true)

--   INPUT : '(k,F)',  a strictly positive integer 'k' and a pure and full dimensional Fan 'F'
--  OUTPUT : A ToricVectorBundleKaneyama or ToricVectorBundleKlyachko
-- COMMENT : If no option is given the function will return a ToricVectorBundleKlyachko, if "Type" => "Kaneyama" is given it returns a ToricVectorBundleKaneyama
toricVectorBundle (ZZ,Fan) := {"Type"=>"Klyachko"} >> opts -> (k,F) -> (
     if opts#"Type" == "Kaneyama" then makeVBKaneyama(k,F) else if opts#"Type" == "Klyachko" then makeVBKlyachko(k,F) else error("Expected Type to be Klyachko or Kaneyama."))


--   INPUT : '(k,F,L1,L2)',  a strictly positive integer 'k',a pure and full dimensional Fan 'F', and two lists 'L1' and 'L2'
--  OUTPUT : A ToricVectorBundleKaneyama or ToricVectorBundleKlyachko
-- COMMENT : If no option is given the function will return a ToricVectorBundleKlyachko where the base matrices are given in the first list and the 
--     	     filtration matrices are given in the second list, 
--     	     if "Type" => "Kaneyama" is given it returns a ToricVectorBundleKaneyama where the degree matrices are given in the first list and the
--     	     transition matrices are given in the second list.
toricVectorBundle (ZZ,Fan,List,List) := {"Type"=>"Klyachko"} >> opts -> (k,F,L1,L2) -> (
     if opts#"Type" == "Kaneyama" then makeVBKaneyama(k,F,L1,L2) else if opts#"Type" == "Klyachko" then makeVBKlyachko(k,F,L1,L2) else error("Expected Type to be Klyachko or Kaneyama."))


-- PURPOSE : Changing the base matrices of a given ToricVectorBundleKlyachko to those given in the List 
--   INPUT : '(tvb,L)',  a ToricVectorBundle 'tvb' and a list 'L'of k by k matrices over a common ring/field, one for each
--     	    	      	   ray of the underlying fan
--  OUTPUT : The ToricVectorBundleKlyachko 'tvb' 
-- COMMENT : Note that the  matrices in 'L' will be assigned to the rays in the order they appear in rays tvb
addBase = method(TypicalValue => ToricVectorBundleKlyachko)
addBase (ToricVectorBundleKlyachko,List) := (tvb,L) -> (
     -- Extracting data out of tvb
     k := tvb#"rank of the vector bundle";
     n := tvb#"number of rays";
     R := raySort toList tvb#"ToricVariety"#"rays";
     -- Checking for input errors
     if n != #L then error("Expected number of matrices to match number of rays of the fan.");
     if any(L, l -> not instance(l,Matrix)) then error("Expected the bases to be given as matrices.");
     P := unique apply(L,ring);
     if #P != 1 then (
	  if P === {QQ,ZZ} or P === {ZZ,QQ} then (
	       L = apply(L, l -> promote(l,QQ));
	       P = {QQ})
	  else error("Expected all the bases to be over the same ring."));
     -- Creating the table of bases for the rays
     baseTable := hashTable apply(n, i -> ( 
	       M := L#i;
	       -- Checking for more input errors
	       if numColumns M != k or numRows M != k then error("Expected the base change matrices to be rank times rank matrices.");
	       if det M == 0 then error("Expected the bases to have full rank.");
	       -- Inserting the matrix at the i-th position
	       R#i => M));
     -- Writing the bases into the bundle
     new ToricVectorBundleKlyachko from {
	  "ring" => first P,
	  "rayTable" => tvb#"rayTable",
	  "baseTable" => baseTable,
	  "filtrationMatricesTable" => tvb#"filtrationMatricesTable",
	  "filtrationTable" => tvb#"filtrationTable",
	  "ToricVariety" => tvb#"ToricVariety",
	  "number of affine charts" => tvb#"number of affine charts",
	  "dimension of the variety" => tvb#"dimension of the variety",
	  "rank of the vector bundle" => tvb#"rank of the vector bundle",
	  "number of rays" => tvb#"number of rays",
	  symbol cache => new CacheTable})


-- PURPOSE : Changing the transition matrices of a given ToricVectorBundle to those given in the List 
--   INPUT : '(tvb,L)',  a ToricVectorBundle 'tvb' and a list 'L'of k by k matrices over QQ, one for each 
--     	    	      	   	  pair of top dimensional Cones intersecting in a common codim 1 face. 
--  OUTPUT : The ToricVectorBundle 'tvb' 
-- COMMENT : Note that the ToricVectorBundle already has a list of pairs (i,j) denoting the codim 1 intersections 
--     	     of two top dim cones, with i<j and they are ordered in lexicographic order. So the matrices in 'L'
--     	     will be assigned to the pairs (i,j) in that order, where the matrix A assigned to (i,j) denotes the 
--     	     transition
--     	    	 (e_i^1,...,e_i^k) = (e_j^1,...,e_j^k)* A
addBaseChange = method(TypicalValue => ToricVectorBundleKaneyama)
addBaseChange (ToricVectorBundleKaneyama,List) := (tvb,L) -> (
     -- Extracting data out of tvb
     pairlist := sort keys tvb#"baseChangeTable";
     k := tvb#"rank of the vector bundle";
     -- Checking for input errors
     if #pairlist != #L then error("Expected the number of matrices to match the number of codim 1 Cones.");
     baseChangeTable := hashTable apply(#pairlist, i -> ( 
	       M := L#i;
	       -- Checking for more input errors
	       if not instance(M,Matrix) then error("Expected the transition matrices to be given as rank times rank matrices.");
	       if numColumns M != k or numRows M != k then error("Expected the base change matrices to be k by k matrices.");
	       if det M == 0 then error("The base change matrices must be invertible.");
	       R := ring source M;
	       M = if R === ZZ or R === QQ then promote(M,QQ) else error("Expected base change over ZZ or QQ");
	       -- Inserting the matrix at the i-th position
	       pairlist#i => M));
     -- Writing the new transition matrices into the bundle
     new ToricVectorBundleKaneyama from {
	  "degreeTable" => tvb#"degreeTable",
	  "baseChangeTable" => baseChangeTable,
	  "ToricVariety" => tvb#"ToricVariety",
	  "number of affine charts" => tvb#"number of affine charts",
	  "dimension of the variety" => tvb#"dimension of the variety",
	  "rank of the vector bundle" => k,
	  "codim1Table" => tvb#"codim1Table",
	  "topConeTable" => tvb#"topConeTable",
	  symbol cache => new CacheTable})


-- PURPOSE : Changing the degrees of the local generators of a given ToricVectorBundleKaneyama to those given in the List 
--   INPUT : '(tvb,L)',  a ToricVectorBundleKaneyama 'tvb' and a list 'L'of n by k matrices over ZZ, one for each 
--     	    	      	 top dimensional Cone. 
--  OUTPUT : The ToricVectorBundleKaneyama 'tvb' 
-- COMMENT : Note that in the ToricVectorBundleKaneyama the top dimensional Cones are already numbered and that the degree
--     	     matrices will be assigned to the Cones in that order. 
addDegrees = method(TypicalValue => ToricVectorBundleKaneyama)
addDegrees (ToricVectorBundleKaneyama,List) := (tvb,L) -> (
     -- Extracting data out of tvb
     tCT := sort keys tvb#"degreeTable";
     k := tvb#"rank of the vector bundle";
     n := tvb#"dimension of the variety";
     -- Checking for input errors
     if #tCT != #L then error("Number of degree matrices must match the number of top dim cones.");
     degreeTable := hashTable apply(#tCT, i -> ( 
	       M := L#i;
	       -- Checking for more input errors
	       if not instance(M,Matrix) then error("The degrees must be given as dimension times rank matrices.");
	       if ring M =!= ZZ then error("Expected the degrees to be in the ZZ lattice.");
	       if numColumns M != k then error("The number of degrees must match the vector bundle rank.");
	       if numRows M != n then error("The degrees must have the dimension of the underlying toric variety.");
	       -- Inserting the degree matrix
	       tCT#i => M));
     -- Writing the new degree table into the bundle
     new ToricVectorBundleKaneyama from {
	  "degreeTable" => degreeTable,
	  "baseChangeTable" => tvb#"baseChangeTable",
	  "ToricVariety" => tvb#"ToricVariety",
	  "number of affine charts" => tvb#"number of affine charts",
	  "dimension of the variety" => n,
	  "rank of the vector bundle" => k,
	  "codim1Table" => tvb#"codim1Table",
	  "topConeTable" => tvb#"topConeTable",
	  symbol cache => new CacheTable})


--   INPUT : '(tvb,L)',  a ToricVectorBundleKlyachko 'tvb' and a list 'L'of 1 by k matrices over ZZ, one for each 
--     	    	      	   	  ray of the fan
--  OUTPUT : The ToricVectorBundleKlyachko 'tvb' 
-- COMMENT : Note that the  matrices in 'L' will be assigned to the rays in the order they appear in rays tvb
addFiltration = method(TypicalValue => ToricVectorBundleKlyachko)
addFiltration (ToricVectorBundleKlyachko,List) := (tvb,L) -> (
     -- Extracting data out of tvb
     n := tvb#"number of rays";
     k := tvb#"rank of the vector bundle";
     R := rays tvb;
     -- Checking for input errors
     if n != #L then error("The number of matrices has to match the number of rays of the fan.");
     if any(L, l -> not instance(l,Matrix)) then error("The filtrations have to be given as matrices.");
     if any(L, l -> ring l =!= ZZ) then error("The filtrations have to be given as matrices over ZZ.");
     if any(L, l -> numColumns l != k or numRows l != 1) then error("The filtrations have to be given as 1 times n matrices.");
     -- Writing the new filtration matrices  into the table
     filtrationMatricesTable := hashTable apply(n, i -> R#i => L#i);
     -- Computing the list of changes in the filtrations
     filtrationTable := hashTable apply(pairs filtrationMatricesTable, p -> (
	       L := flatten entries p#1;
	       L1 := sort unique L;
	       p#0 => hashTable ({(min L1 - 1) => {}} |  apply(L1, l -> l => positions(L,e -> e == l)))));
     -- Writing the new filtration maps and changes tables into the bundle
     new ToricVectorBundleKlyachko from {
	  "ring" => tvb#"ring",
	  "rayTable" => tvb#"rayTable",
	  "baseTable" => tvb#"baseTable",
	  "filtrationMatricesTable" => filtrationMatricesTable,
	  "filtrationTable" => filtrationTable,
	  "ToricVariety" => tvb#"ToricVariety",
	  "number of affine charts" => tvb#"number of affine charts",
	  "dimension of the variety" => tvb#"dimension of the variety",
	  "rank of the vector bundle" => tvb#"rank of the vector bundle",
	  "number of rays" => tvb#"number of rays",
	  symbol cache => new CacheTable})


-- PURPOSE : Giving the number of affine charts of a ToricVectorBundle
--   INPUT : 'tvb', a ToricVectorBundle
--  OUTPUT : 'ZZ',  the number of affine charts
charts = method(TypicalValue => ZZ)
charts ToricVectorBundle := tvb -> tvb#"number of affine charts"

	       
-- PURPOSE : Checking if the ToricVectorBundleKaneyama fulfills the cocycle condition
--   INPUT : 'tvb',  a ToricVectorBundleKaneyama 
--  OUTPUT : 'true' or 'false' 
cocycleCheck = method(TypicalValue => Boolean)
cocycleCheck ToricVectorBundleKaneyama := (cacheValue symbol cocycle)( tvb -> (
     	  -- Extracting data out of tvb
     	  n := tvb#"dimension of the variety";
     	  k := tvb#"rank of the vector bundle";
     	  bCT := tvb#"baseChangeTable";
     	  topCones := sort keys tvb#"topConeTable";
     	  L := hashTable {};
     	  -- For each codim 2 Cone computing the list of topCones which have this Cone as a face
     	  -- and save the list of indices of these topCones as an element in L
     	  for i from 0 to #topCones - 1  do L = merge(hashTable apply(faces(2,topCones#i), C -> C => {i}),L,(a,b) -> sort join(a,b));
     	  -- Finding the cyclic order of every list of topCones in L and write this cyclic order as a 
     	  -- list of consecutive pairs
     	  L = for l in values L list (
	       pairings := {};
	       start := l#0;
	       a := start;
	       l = drop(l,1);
	       i := position(l, e -> dim intersection(topCones#a,topCones#e) == n-1);
	       while i =!= null do (
		    pairings = pairings | {(a,l#i)};
		    a = l#i;
		    l = drop(l,{i,i});
		    i = position(l, e -> dim intersection(topCones#a,topCones#e) == n-1));
	       if dim intersection(topCones#a,topCones#start) == n-1 then pairings | {(a,start)} else continue);
     	  -- Check for every cyclic order of topCones if the product of the corresponding transition
     	  -- matrices is the identity
     	  all(L, l -> product apply(reverse l, e -> if e#0 > e#1 then inverse bCT#(e#1,e#0) else bCT#e) == map(QQ^k,QQ^k,1))))


-- PURPOSE : Presenting some details of the given ToricVectorBundle
--   INPUT : 'tvb',  a ToricVectorBundleKaneyama
--  OUTPUT : '(A,C)',	 where 'A' is a hashTable giving the enumeration of the maximal cones with their rays and degree matrix, 
--     	    	      	 and 'B' gives the transition matrices for the codim 1 pairs
-- COMMENT : This function gives the possibility to have a quick overview on the main properties of a ToricVectorBundleKaneyama
details = method()
details ToricVectorBundle := tvb -> (
     if instance(tvb,ToricVectorBundleKaneyama) then (hashTable apply(pairs(tvb#"topConeTable"), p -> ( p#1 => (rays p#0,tvb#"degreeTable"#(p#0)))),tvb#"baseChangeTable")
     else hashTable apply(rays tvb, r -> r => (tvb#"baseTable"#r,tvb#"filtrationMatricesTable"#r)))


-- PURPOSE : Checking if a ToricVectorBundleKaneyama satisfies the regularity conditions of the degrees
--   INPUT : 'tvb', a ToricVectorBundleKaneyama
--  OUTPUT : 'true' or 'false'
-- COMMENT : This function is for checking ToricVectorBundles whose degrees and matrices 
--     	     are inserted by hand. Those generated for example by tangentBundle fulfill the 
--     	     conditions automatically.
regCheck = method(TypicalValue => Boolean)
regCheck ToricVectorBundleKaneyama := (cacheValue symbol regCheck)( tvb -> (
     	  -- Extracting the necessary data
     	  tCT := sort keys tvb#"topConeTable";
     	  c1T := tvb#"codim1Table";
     	  bCT := tvb#"baseChangeTable";
     	  dT := tvb#"degreeTable";
     	  k := tvb#"rank of the vector bundle";
     	  all(keys bCT, p -> (
	       	    -- Taking a pair corresponding to a codim 1 cone, the corresponding transition matrix and its inverse
	       	    A := bCT#p;
	       	    B := inverse A;
	       	    -- Computing the dual of the codim 1 cone
	       	    C := dualCone c1T#p;
	       	    -- Check for all pairs of degree vectors of the two top Cones the reg condition
	       	    all(k, i -> (
			      ri := (dT#(tCT#(p#1)))_{i};
			      all(k, j -> (
				   	rj := (dT#(tCT#(p#0)))_{j};
				   	(if A^{i}_{j} != 0 then contains(C,rj-ri) else true) and (if A^{j}_{i} != 0 then contains(C,ri-rj) else true)))))))))



----------------------------------------------------------------------------
-- OPERATIONS ON TORIC VECTOR BUNDLES
----------------------------------------------------------------------------


-- PURPOSE : Returning the base representation of the bundle
--   INPUT : 'tvb',  a ToricVectorBundleKlyachko
--  OUTPUT : A HashTable which gives for each ray of the fan the matrix of the basis
base = method(TypicalValue => HashTable)
base ToricVectorBundleKlyachko := tvb -> tvb#"baseTable"


-- PURPOSE : Returning the filtration matrices of the bundle
--   INPUT : 'tvb',  a ToricVectorBundleKlyachko
--  OUTPUT : A HashTable which gives for each ray of the matrix of the filtration
filtration = method(TypicalValue => HashTable)
filtration ToricVectorBundleKlyachko := tvb -> tvb#"filtrationMatricesTable"


-- PURPOSE : Checking for the descriptions of two given vector bundles in Klyachko's description if they are isomorphic
--   INPUT : '(T1,T2)',  two ToricVectorBundleKlyachko
--  OUTPUT : 'true', if they are isomorphic, 'false' otherwise
-- COMMENT : If the check reveals that they are isomorphic, the isomorphism can be obtained with the function isomorphism
areIsomorphic = method(TypicalValue => Boolean)
areIsomorphic (ToricVectorBundleKlyachko,ToricVectorBundleKlyachko) := (T1,T2) -> (
     -- Creating the entries in the cacheTables of the two bundles if they are not yet present
     if not T1.cache.?isomorphic then (
	  T1.cache.isomorphic = new MutableHashTable;
	  if not T1.cache.?isoMatrix then T1.cache.isoMatrix = new MutableHashTable);
     if not T2.cache.?isomorphic then (
	  T2.cache.isomorphic = new MutableHashTable;
	  if not T2.cache.?isoMatrix then T2.cache.isoMatrix = new MutableHashTable);
     -- If this pairing has not been checked before, check it now
     if not T1.cache.isomorphic#?T2 then (
	  local isoMatrix;
	  T1.cache.isomorphic#T2 = (
	       -- To be isomorphic, the bundles must be over the same TV, over the same ring and must have the same rank
	       T1#"ToricVariety" == T2#"ToricVariety" and T1#"ring" === T2#"ring" and T1#"rank of the vector bundle" == T2#"rank of the vector bundle" and (
		    -- If this is the case, extract the filtrations
		    fMT1 := T1#"filtrationMatricesTable";
		    fMT2 := T2#"filtrationMatricesTable";
		    bT1 := T1#"baseTable";
		    bT2 := T2#"baseTable";
		    bundleRing := T1#"ring";
		    R := rays T1;
		    r0 := R#0;
		    R = drop(R,1);
		    -- Check for the first ray, if they have the same filtration numbers and dimensions of the filtration steps
		    sort fMT1#r0 == sort fMT2#r0 and (
			 -- if this is the case, resort both base matrices according to the filtration and compute the possible isomorphism
			 A := submatrix'(sort(promote(fMT1#r0,bundleRing) || bT1#r0),{0},);
			 B := submatrix'(sort(promote(fMT2#r0,bundleRing) || bT2#r0),{0},);
			 isoMatrix = B*(A^-1);
			 -- check for the remaining rays if the filtrations are identical
			 all(R, r -> (
				   f1 := flatten entries fMT1#r;
				   f2 := flatten entries fMT2#r;
				   sort f1 == sort f2 and all(unique f1, e -> (
					     E1 := (bT1#r)_(positions(f1, i -> i <= e));
					     E2 := (bT2#r)_(positions(f2, i -> i <= e));
					     image(isoMatrix*E1) == image E2)))))));
	  -- If they are isomorphic then write the isomorphism into the cache of both bundles
	  if T1.cache.isomorphic#T2 then (
	       T1.cache.isoMatrix#T2 = isoMatrix;
	       T2.cache.isomorphic#T1 = true;
	       T2.cache.isoMatrix#T1 = isoMatrix^-1));
     T1.cache.isomorphic#T2)


-- PURPOSE : Obtaining the isomorphism if two vector bundles are isomorphic
--   INPUT : '(T1,T2)',  two ToricVectorBundleKlyachko
--  OUTPUT : The isomorphism, if they are isomorphic, otherwise an error
isomorphism = method(TypicalValue => Matrix)
isomorphism (ToricVectorBundleKlyachko,ToricVectorBundleKlyachko) := (T1,T2) -> (
     if not areIsomorphic(T1,T2) then error("The bundles are not isomorphic");
     T1.cache.isoMatrix#T2)				


-- PURPOSE : Compute the Euler characteristic
eulerChi = method(TypicalValue => ZZ)

--   INPUT : '(T,u)',  where 'T' is a ToricVectorBundle and 'u' is a one column matrix over ZZ giving a degree vector
--  OUTPUT : The Euler characteristic of the Cech complex at degree 'u'
eulerChi (Matrix,ToricVectorBundle) := (u,T) -> (
     if not T.cache.?eulerChi then T.cache.eulerChi = new MutableHashTable;
     if not T.cache.eulerChi#?u then (
	  n := T#"dimension of the variety";
	  -- Compute the Cech complex and compute the alternating sum of the dimensions
	  if instance(T,ToricVectorBundleKlyachko) then T.cache.eulerChi#u = sum apply(n+1, i -> (-1)^i * sum values (cechComplex(i,T,u))#1)
	  else T.cache.eulerChi#u = sum apply(n+2, i -> (-1)^i * numColumns (cechComplex(i,T,u))#1));
     T.cache.eulerChi#u)

--   INPUT : 'T',  a ToricVectorBundle
--  OUTPUT : The Euler characteristic of the bundle
eulerChi ToricVectorBundle := T -> (
     -- Compute the set of degrees with possible cohomology
     L := latticePoints deltaE T;
     -- Sum up their characteristics
     sum apply(L, l -> eulerChi(l,T)))


-- PURPOSE : Returning the table of codimension 1 cones of the underlying fan
--   INPUT : 'T',  a ToricVectorBundleKaneyama
--  OUTPUT : a HashTable
codim1Table = method(TypicalValue => HashTable)
codim1Table ToricVectorBundleKaneyama := T -> T#"codim1Table"     


-- PURPOSE : Computing the cohomology group of a given ToricVectorBundle
--   INPUT : '(i,T,weight)',  'i' for the 'i'th cohomology group, 'T' a ToricVectorBundle, and 'weight' the degree
--  OUTPUT : 'ZZ',	     the graded module of the degree 'weight' part of the 'i'th cohomology group of 'T'
cohomology(ZZ,ToricVectorBundle,Matrix) := opts -> (i,T,weight) -> cohom(i,T,weight)


-- PURPOSE : Computing the cohomology group of a given ToricVectorBundle
--   INPUT : '(i,T,P)',  'i' for the 'i'th cohomology group, 'T' a ToricVectorBundle, and 'P' a list of degrees
--  OUTPUT : 'List',	     the list of the graded modules of the corresponding degree parts of the cohomology group which are non zero
cohomology(ZZ,ToricVectorBundle,List) := opts -> (i,T,P)-> (
     if opts.Degree == 1 then print ("Number of degrees to calculate: "|(toString(#P)));
     for j in P list (
	  if opts.Degree == 1 then << "." << flush;
	  j = cohomology(i,T,j);
	  if j != 0 then j else continue))

   
-- PURPOSE : Computing the cohomology group of a given ToricVectorBundle
--   INPUT : '(i,T)',  'i' for the 'i'th cohomology group, 'T' a ToricVectorBundle
--  OUTPUT : the group as a graded module where the generators have the corresponding degree of the weight vector
-- COMMENT : if the option "Degree" => 1 is given then it displays the number of degrees to calculate
cohomology(ZZ,ToricVectorBundle) := opts -> (i,T)-> (
     L := cohomology(i,T,latticePoints deltaE T,Degree => opts.Degree);
     if L == {} then (ring T)^0 else directSum L)


-- PURPOSE : Computing the rank of the cohomology group of a given ToricVectorBundle
--   INPUT : '(i,S)',  'i' for the 'i'th cohomology group, 'S' a Sequence of ToricVectorBundle and a weight vector
--  OUTPUT : 'ZZ',	     the rank of the degree 'weight' part of the 'i'th cohomology group of the bundle
hh(ZZ,Sequence) := (i,S) -> (
     -- Checking for input errors
     if #S != 2 then error("The Sequence has to contain a toric vector bundle and a weight vector.");
     if not instance(S#1,Matrix) then error("The second argument has to be a weight vector given by a matrix.");
     if not instance(S#0,ToricVectorBundleKaneyama) and not instance(S#0,ToricVectorBundleKlyachko) then error("The first argument has to be a toric vector bundle.");
     (T,u) := S;
     rank cohomology(i,T,u))


-- PURPOSE : Computing the rank of the cohomology group of a given ToricVectorBundle
--   INPUT : '(i,T)',  'i' for the 'i'th cohomology group, 'T' a ToricVectorBundle
--  OUTPUT : 'ZZ',  the rank of the 'i'th cohomology group
hh(ZZ,ToricVectorBundle) := ZZ => (i,T) -> rank cohomology(i,T)


-- PURPOSE : Computing the coker bundle of a toric vector bundle
--   INPUT : '(T,M)', where 'T' is a ToricVectorBundleKlyachko and 'M' a matrix with the bundle space as target
--  OUTPUT : The bundle given by the cokernels of the filtrations
coker (ToricVectorBundleKlyachko,Matrix) := (T,M) -> (
     k := T#"rank of the vector bundle";
     tRing := T#"ring";
     -- Checking for input errors
     if k != numRows M then error("The source of the matrix has to be the vector bundle.");
     if tRing =!= ring M then error("Matrix and bundle have to be over the same ring."); 
     -- Computing the map from the bundle to the kernel
     N := transpose mingens ker transpose M;
     -- Computing a basis of the cokernel
     coKerGens := mingens image N;
     newRank := numColumns coKerGens;
     bT := T#"baseTable";
     fT := T#"filtrationTable";
     -- Computing the new baseTable with filtrations
     bT = hashTable apply(keys bT, j -> (
	       fTj := drop(sort keys fT#j,1);
	       cols := {};
	       oldCoKer := map(tRing^newRank,tRing^0,0);
	       -- Going through the filtration steps and computing the cokernel for each step
	       j => apply(fTj, i -> (
			 cols = cols | fT#j#i;
			 -- Computing the cokernel
			 A := N * (bT#j)_cols;
			 -- Representing this in the basis chosen
			 gkMA := (gens ker (coKerGens | A))^{0..newRank-1};
			 -- Selecting the new basis elements that appear in this filtration step
			 gkMA = mingens (image(oldCoKer | gkMA) / image oldCoKer);
			 -- Appending these new vectors
			 oldCoKer = oldCoKer |gkMA;
			 -- appending the filtration step number
			 (gkMA,matrix {toList(numColumns gkMA:i)})))));
     -- Generating the new filtration matrices and tables
     fMT := hashTable apply(pairs bT, p -> p#0 => matrix {apply(p#1,last)});
     fT = hashTable apply(pairs fMT, p -> (
	       L := flatten entries p#1;
	       L1 := sort unique L;
	       p#0 => hashTable ({min L1 - 1 => {}} | apply(L1, l -> l => positions(L,e -> e == l)))));
     bT = hashTable apply(pairs bT, p -> p#0 => matrix {apply(p#1,first)});
     Tnew := new ToricVectorBundleKlyachko from {
	  "ring" => T#"ring",
	  "rayTable" => T#"rayTable",
	  "baseTable" => bT,
	  "filtrationMatricesTable" => fMT,
	  "filtrationTable" => fT,
	  "ToricVariety" => T#"ToricVariety",
	  "number of affine charts" => T#"number of affine charts",
	  "dimension of the variety" => T#"dimension of the variety",
	  "rank of the vector bundle" => newRank,
	  "number of rays" => T#"number of rays",
	  symbol cache => new CacheTable};
     if T.cache.?isVB and T.cache.isVB then Tnew.cache.isVB = T.cache.isVB;
     Tnew)     	       

	       
-- PURPOSE : Computing the cotangent bundle on a smooth, pure, and full dimensional Toric Variety 
cotangentBundle = method(Options => {"Type" => "Klyachko"})

--   INPUT : 'F',  a smooth, pure, and full dimensional Fan
--  OUTPUT : 'tvb',  a ToricVectorBundle
cotangentBundle Fan := opts -> F -> (
     if opts#"Type" == "Klyachko" then dual tangentBundleKlyachko F else if opts#"Type" == "Kaneyama" then cotangentBundleKaneyama F else error("Expected Type to be Klyachko or Kaneyama."))

-- PURPOSE : Computing the polytope deltaE in the degree space such that outside this polytope
--     	     every cohomology is 0 
deltaE = method()

--   INPUT : 'tvb',  a ToricVectorBundle
--  OUTPUT : a Polyhedron
deltaE ToricVectorBundle := (cacheValue symbol deltaE)( T -> (
	  if not isComplete T#"ToricVariety" then error("The toric variety needs to be complete.");
     	  n := T#"dimension of the variety";
	  if instance(T,ToricVectorBundleKaneyama) then (
	       dT := values T#"degreeTable";
	       dT = matrix {dT};
	       convexHull dT)
	  else (
	       W := findWeights T;
	       W = apply(W,first);
	       W = matrix {W};
	       convexHull W)))

--oldDeltaE = method()
--oldDeltaE ToricVectorBundle := (cacheValue symbol oldDeltaE)( tvb -> (
--     	  if not isComplete tvb#"ToricVariety" then error("The toric variety needs to be complete.");
--     	  n := tvb#"dimension of the variety";
--	  if instance(tvb,ToricVectorBundleKaneyama) then (
--	       -- Extracting necessary data
--     	       raylist := rays tvb;
--     	       rl := #raylist;
--     	       k := tvb#"rank of the vector bundle";
--     	       tCT := sort keys tvb#"topConeTable";
--     	       dT := tvb#"degreeTable";
--     	       -- Creating an index table, for each ray the first top cone containing it
--     	       raytCTindex := hashTable apply(#raylist, r -> r => position(tCT, C -> contains(C,raylist#r)));
--     	       raylist = transpose matrix {raylist};
--     	       -- Get the subsets of 'n' elements in 'rl'
--     	       sset := subsets(rl,n);
--     	       jList := {{}};
--     	       -- Get all different combinations of choices of variety dimension many degree vectors
--     	       for i from 0 to n-1 do jList = flatten apply(jList, l -> apply(k, j -> l|{j}));
--     	       M := map(QQ^1,QQ^n,0);
--     	       v := map(QQ^1,QQ^1,0);
--     	       -- For every 'n' in 'l' subset and any combination in jList get the intersection of the dual cones
--     	       -- of the corresponding rays. If this is a non-empty compact polytope then add the vertices to the
--     	       -- list L
--     	       L := unique flatten apply(sset, s -> (
--	       	    	 unique for j in jList list (
--		    	      N := matrix apply(n, i -> {raylist^{s#i},raylist^{s#i} * ((dT#(tCT#(raytCTindex#(s#i))))_{j#i})});
--		    	      w := N_{n};
--		    	      N = submatrix'(N,{n});
--		    	      P := intersection(M,v,N,w);
--		    	      if isCompact P and (not isEmpty P) then vertices P else continue)));
--     	       -- Make a matrix of all the vertices in L
--     	       M = matrix {L};
--     	       convexHull M)
--	  else (
--	       -- Extracting necessary data
--	       rayTable := tvb#"rayTable";
--	       l := #rayTable;
--	       fMT := hashTable apply(pairs tvb#"filtrationMatricesTable", (i,j) -> (j = flatten entries j; i => matrix{{-(min j),max j}}));
--	  		      sset1 := select(subsets(rays tvb,n), s -> rank matrix {s} == n);
--	  		      convexHull matrix {apply(sset1, s -> (
--			 		     M := transpose matrix {apply(s, r -> (-r | r) || (fMT#r))};
--			 		     vertices intersection(M_{0..n-1},M_{n})))})))


--   INPUT : '(tvb1,tvb2)',  two ToricVectorBundle over the same Fan
--  OUTPUT : 'tvb',  a ToricVectorBundle which is the direct sum
ToricVectorBundle.directSum = args -> (
     args = toList args;
     T := args#0;
     scan(drop(args,1), E -> T = T ++ E);
     T)

      
ToricVectorBundle ++ ToricVectorBundle := (tvb1,tvb2) -> (
	  -- Checking for input errors
	  if tvb1#"ToricVariety" != tvb2#"ToricVariety" then error("Expected the bundles to be over the same toric variety.");
	  -- Extracting data out of tvb1 and tvb2
	  k1 := tvb1#"rank of the vector bundle";
	  k2 := tvb2#"rank of the vector bundle";
	  if instance(tvb1,ToricVectorBundleKaneyama) and instance(tvb2,ToricVectorBundleKaneyama) then (
	       -- Generating the trivial bundle of dimension k1+k2
	       E := makeVBKaneyama(k1 + k2,tvb1#"ToricVariety");
	       -- Computing the new degree table and transition matrices and writing the degrees and transition matrices into the bundle
	       E = new ToricVectorBundleKaneyama from {
	       	    "degreeTable" => merge(tvb1#"degreeTable",tvb2#"degreeTable", (a,b) -> a|b),
	       	    "baseChangeTable" => merge(tvb1#"baseChangeTable",tvb2#"baseChangeTable", (a,b) -> a++b),
	       	    "ToricVariety" => E#"ToricVariety",
	       	    "number of affine charts" => E#"number of affine charts",
	       	    "dimension of the variety" => E#"dimension of the variety",
	       	    "rank of the vector bundle" => k1 + k2,
	       	    "codim1Table" => E#"codim1Table",
	       	    "topConeTable" => E#"topConeTable",
	       	    symbol cache => new CacheTable};
	       if (tvb1.cache.?regCheck and tvb2.cache.?regCheck and tvb1.cache.regCheck and tvb2.cache.regCheck and (
		    	 tvb1.cache.?cocycle and tvb2.cache.?cocycle and tvb1.cache.cocycle and tvb2.cache.cocycle)) then (
	       	    E.cache.regCheck = true;
	       	    E.cache.cocycle = true);
	       E)
	  else if instance(tvb1,ToricVectorBundleKlyachko) and instance(tvb2,ToricVectorBundleKlyachko) then (
	       k := k1 + k2;
     	       F := tvb1#"ToricVariety";
     	       R := tvb1#"ring";
     	       tvb := makeVBKlyachko(k,F);
     	       fT1 := tvb1#"filtrationMatricesTable";
     	       fT2 := tvb2#"filtrationMatricesTable";
     	       bT1 := tvb1#"baseTable";
     	       bT2 := tvb2#"baseTable";
     	       filtrationTable := apply(rays tvb, r -> fT1#r | fT2#r);
     	       baseTable := apply(rays tvb, r -> bT1#r ++ bT2#r);
     	       tvb = addFiltration(tvb,filtrationTable);
     	       tvb = addBase(tvb,baseTable);
     	       if tvb1.cache.?isVB and tvb2.cache.?isVB and tvb1.cache.isVB and tvb2.cache.isVB then tvb.cache.isVB = true;
     	       tvb)
	  else error("The two bundles have to be in the same description."))


-- ToricVectorBundleKlyachko ++ ToricVectorBundleKlyachko := (tvb1,tvb2) -> (
--     -- Extracting data out of tvb1 and tvb2
--     k1 := (tvb1#"rank of the vector bundle");
--     k2 := (tvb2#"rank of the vector bundle");
--     k := k1 + k2;
--     F := tvb1#"ToricVariety";
--     R := tvb1#"ring";
--     tvb := makeVBKlyachko(k,F);
--     fT1 := tvb1#"filtrationMatricesTable";
--     fT2 := tvb2#"filtrationMatricesTable";
--     bT1 := tvb1#"baseTable";
--     bT2 := tvb2#"baseTable";
--     filtrationTable := apply(rays tvb, r -> fT1#r | fT2#r);
--     baseTable := apply(rays tvb, r -> bT1#r ++ bT2#r);
--     tvb = addFiltration(tvb,filtrationTable);
--     tvb = addBase(tvb,baseTable);
--     if tvb1.cache.?isVB and tvb2.cache.?isVB and tvb1.cache.isVB and tvb2.cache.isVB then tvb.cache.isVB = true;
--     tvb)


-- PURPOSE : Computing the dual bundle to a given ToricVectorBundle
--   INPUT : 'tvb',  a ToricVectorBundle
--  OUTPUT : the dual ToricVectorBundle
dual ToricVectorBundle := {} >> opts -> tvb -> (
     if instance(tvb,ToricVectorBundleKaneyama) then (
     	  -- Inverting the degrees and the transition matrices
     	  degreeTable := hashTable apply(pairs tvb#"degreeTable", p -> p#0 => -(p#1));
     	  baseChangeTable := hashTable apply(pairs tvb#"baseChangeTable", p -> p#0 => transpose inverse p#1);
     	  -- Writing the inverted tables into the bundle
     	  E := new ToricVectorBundleKaneyama from {
	       "degreeTable" => degreeTable,
	       "baseChangeTable" => baseChangeTable,
	       "ToricVariety" => tvb#"ToricVariety",
	       "number of affine charts" => tvb#"number of affine charts",
	       "dimension of the variety" => tvb#"dimension of the variety",
	       "rank of the vector bundle" => tvb#"rank of the vector bundle",
	       "codim1Table" => tvb#"codim1Table",
	       "topConeTable" => tvb#"topConeTable",
	       symbol cache => new CacheTable};
     	  if tvb.cache.?regCheck and tvb.cache.regCheck and tvb.cache.?cocycle and tvb.cache.cocycle then (
	       E.cache.regCheck = true;
	       E.cache.cocycle = true);
     	  E)
     else (
	  -- Inverting the filtration. If the filtration has d steps then the new n-th boundary is -(d-n+1th boundary)-1 and the n-th step is the 
     	  -- d-n+2 th step
     	  fT := hashTable apply(pairs tvb#"filtrationTable", (r,e) -> r => (k:=sort keys e;e = apply(#k-1, i -> (k#i,e#(k#(i+1))))|{(last k,{})}; hashTable apply(e, entry -> -(entry#0)-1 => entry#1)));
     	  fMT := hashTable apply(pairs fT, q -> q#0 => (q1new:= hashTable flatten apply(pairs q#1, p -> apply(p#1, i -> i => p#0)); matrix {apply(#q1new, j -> q1new#j)}));
     	  -- The orthogonal complement is given by the transpose of the inverse matrix
     	  bT := hashTable apply(pairs tvb#"baseTable", p -> p#0 => transpose inverse p#1);
     	  T := new ToricVectorBundleKlyachko from {
	       "ring" => tvb#"ring",
	       "rayTable" => tvb#"rayTable",
	       "baseTable" => bT,
	       "filtrationMatricesTable" => fMT,
	       "filtrationTable" => fT,
	       "ToricVariety" => tvb#"ToricVariety",
	       "number of affine charts" => tvb#"number of affine charts",
	       "dimension of the variety" => tvb#"dimension of the variety",
	       "rank of the vector bundle" => tvb#"rank of the vector bundle",
	       "number of rays" => tvb#"number of rays",
	       symbol cache => new CacheTable};
     	  if tvb.cache.?isVB and tvb.cache.isVB then T.cache.isVB = true;
     	  T))
	  
	  
-- PURPOSE : Checking if a given List of possible degree vectors admits a Decomposition in torus eigenspaces that give the filtration
--   INPUT : '(T,L)',  where 'T' is a ToricVectorBundleKlyachko and 'L' is a List where the i-th entry is either a matrix or a List of 
--     	    	       matrices of possible degree vectors for the i-th cone in maxCones
--  OUTPUT : 'true' if a selection of degrees for each maximal cone admits a decomposition, 'false' otherwise
existsDecomposition = method()
existsDecomposition (ToricVectorBundleKlyachko,List) := (T,L) -> (
     -- Checking if the list contains only matrices and lists and converting the former into a list with this matrix
     L = apply(L, l -> if instance(l,List) then l else if instance(l,Matrix) then {l} else error("The elements of the list have to be either matrices or lists of them."));
     if not T.cache.?degreesList then T.cache.degreesList = {};
     mC := maxCones T;
     mC = apply(mC, C -> (C = C#"rays"; apply(numColumns C, i -> C_{i})));
     -- Checking for input errors
     if #mC != #L then error("There has to be a degree matrix or list of degree matrices for each maximal cone of the fan.");
     -- Check if any combination of matrices in L has already been checked and thus saved in the cache
     if any(T.cache.degreesList, dl -> all(toList(0..#dl-1), i -> (set L#i)#?(dl#i))) then true 
     -- otherwise for each maximal cone check the decomposition criterion
     else (
	  -- Add to each Cone the list of possible degrees
     	  mC = apply(#mC, i -> (mC#i,L#i));
     	  allRaysTable := tableForAllRays T;
     	  n := T#"dimension of the variety";
     	  k := rank T;
     	  R := T#"ring";
	  -- Recursive function that runs through all possible combinations of filtration steps for the rays of a cone
     	  recursiveCheck := (fList,Es,D) -> (
	       -- if there is still a list of filtration steps, call recursiveCheck again for each entry
	       if fList != {} then (
	       	    Lr := fList#0#1;
	       	    r := fList#0#0;
	       	    all(Lr, l -> recursiveCheck(drop(fList,1),intersectMatrices(Es,l#1),select(D, d -> (d * r)_(0,0) <= l#0))))
	       -- otherwise we have a choice of filtration steps and check the condition
	       else numColumns Es == #D);
	  -- The check for the criterion begins with the complete bundle
     	  E := map(R^k,R^k,1);
	  -- For each cone check if there is one of the degree matrices that admits a decomposition
     	  L = for C in mC list (
	       fList := apply(C#0, r -> (r,allRaysTable#r));
	       d := select(1,C#1, D -> (
		    	 D = promote(D,QQ);
		    	 D = apply(numColumns D, i -> transpose D_{i});
		    	 recursiveCheck(fList,E,D)));
	       -- If there is one that admits a decomposition return that, otherwise return the empty set for L
	       if d == {} then break {} else d#0);
	  -- If there is a combination then save it to the cache
     	  if L != {} then (
	       if not T.cache.?isVB then T.cache.isVB = true;
	       T.cache.degreesList = T.cache.degreesList|{L});
	  L != {}))


-- PURPOSE : Computing the 'l'-th exterior power of a ToricVectorBundle
--   INPUT : '(l,tvb)',  where 'l' is a strictly positive integer and 'tvb'is a TorcVectorBundle
--  OUTPUT : 'tvb',  a ToricVectorBundle which is the 'l'-th exterior power
exteriorPower (ZZ,ToricVectorBundle) := ToricVectorBundle => opts -> (l,tvb) -> (
     k := tvb#"rank of the vector bundle";
     -- Checking for input errors
     if l < 0 then error("The power has to be positive.");
     -- Generating the list of 'l'-tuples of 0..k-1 and the corresponding index table
     ind := subsets(k,l);
     indtable := hashTable apply(#ind, i -> ind#i => i);
     if instance(tvb,ToricVectorBundleKlyachko) then (
     	  if l == 0 then toricVectorBundle(1,tvb#"ToricVariety")
	  else if l > k then toricVectorBundle(0,tvb#"ToricVariety")
	  else (
	       -- Extracting data
     	       baseTable := tvb#"baseTable";
     	       filtrationTable := tvb#"filtrationMatricesTable";
     	       Rs := rays tvb;
     	       R := tvb#"ring";
     	       F := tvb#"ToricVariety";
     	       -- Computing the 'l'-th exterior powers of the base matrices
     	       baseTable = apply(Rs, r -> (
	       	    	 B := baseTable#r;
	       	    	 M := mutableMatrix(R,#ind,#ind);
	       	    	 for j in ind do for k in ind do M_(indtable#k,indtable#j) = det(B^k_j);
	       	    	 matrix M));
     	       -- Computing the 'l'-th exterior power of the filtration matrices
     	       filtrationTable = apply(Rs, r -> (
	       	    	 filt := filtrationTable#r;
	       	    	 matrix {apply(ind, j -> ( sum flatten entries filt_j))}));
     	       T := makeVBKlyachko(#ind,F,baseTable,filtrationTable);
     	       if tvb.cache.?isVB and tvb.cache.isVB then T.cache.isVB = true;
     	       T))
     else (
	  if l == 0 then toricVectorBundle(1,tvb#"ToricVariety","Type" => "Kaneyama")
	  else if l > k then toricVectorBundle(0,tvb#"ToricVariety","Type" => "Kaneyama")
	  else (
	       -- Computing the 'l'-th exterior powers of the transition matrices
     	       baseChangeTable := hashTable apply(pairs tvb#"baseChangeTable", p -> p#0 =>  matrix apply(ind, j -> apply(ind, k -> det (p#1)^j_k)));
     	       -- Computing the 'l'-th exterior power of the degrees
     	       degreeTable := hashTable apply(pairs tvb#"degreeTable", p -> p#0 => matrix {apply(ind, j -> (p#1)_j * matrix toList(l:{1}))});
     	       E := new ToricVectorBundleKaneyama from {
	       	    "degreeTable" => degreeTable,
	       	    "baseChangeTable" => baseChangeTable,
	       	    "ToricVariety" => tvb#"ToricVariety",
	       	    "number of affine charts" => tvb#"number of affine charts",
	       	    "dimension of the variety" => tvb#"dimension of the variety",
	       	    "rank of the vector bundle" => #ind,
	       	    "codim1Table" => tvb#"codim1Table",
	       	    "topConeTable" => tvb#"topConeTable",
	       	    symbol cache => new CacheTable};
     	       if tvb.cache.?regCheck and tvb.cache.regCheck and tvb.cache.?cocycle and tvb.cache.cocycle then (
	       	    E.cache.regCheck = true;
	       	    E.cache.cocycle = true);
     	       E)))


-- PURPOSE : Returning the underlying fan of a toric vector bundle
--   INPUT : 'T',  a ToricVectorBundleKaneyama
--  OUTPUT : a Fan
fan ToricVectorBundle := T -> T#"ToricVariety"


-- PURPOSE : Finding all possible sets of weight vectors for each maximal cone in the fan that admit the 
--           filtration steps on the rays
--   INPUT : 'T',  a ToricVectorBundleKlyachko
--  OUTPUT : a List,  where the i-th entry is the list of possible weight matrices for the i-th cone in maxCones T
findWeights = method(TypicalValue => List)
findWeights ToricVectorBundleKlyachko := (cacheValue symbol weights)( T -> (
     	  -- Get the maximal cones and save their rays
	  mC := maxCones T;
     	  mC = apply(mC, C -> (C = C#"rays"; apply(numColumns C, i -> C_{i})));
     	  n := T#"dimension of the variety";
     	  k := rank T;
	  -- Recursive function that goes through the rays and checks for the current ray which filtration steps are possible and for 
	  -- these calls itself again
	  -- E is the intersection of filtrations of the rays considered so far, L is the list of remaining rays with filtration steps not chosen so far, 
	  -- R is the list of filtration steps not chosen before for rays already handled, these are the possible steps for the next column and newColumn 
	  -- is the already created part of the new column
     	  recursiveColumnsConstructer := (E,L,R,newColumn) -> (
	       if L != {} then (
	       	    l := L#0;
	       	    L = drop(L,1);
	       	    flatten for e in unique l list (
		    	 -- Check if e admits an intersection of the filtrations
			 if ker(E|e#1) != 0 then (
			      -- if so call the function again for the next ray
			      i := position(l, le -> le == e);
			      recursiveColumnsConstructer(intersectMatrices(E,e#1),L,R|{drop(l,{i,i})},newColumn|{e#0}))
		    	 else continue))
	       else {(R,newColumn)});
	  -- Recursive function that generates the columns (filtration combinations for a weight vector) by calling the columns constructor and then, if
	  -- this has created columns, call it self again with the list of remaining filtration steps
     	  recursiveMatricesConstructer := (Elist,L,M) -> (
	       Lnew := recursiveColumnsConstructer(Elist#0#1,L,{},{Elist#0#0});
	       if #L#0 != 1 then flatten apply(Lnew, (f,s) -> recursiveMatricesConstructer(drop(Elist,1),f,M|{s}))
	       else apply(Lnew, (f,s) -> M|{s}));
     	  fMT := T#"filtrationMatricesTable";
     	  bT := T#"baseTable";
     	  bundleRing := T#"ring";
	  allRaysTable := tableForAllRays T;
     	  apply(mC, C -> (
		    -- For each maximal cone compute the possible weightvector matrices
	       	    L := apply(C, r -> allRaysTable#r);
	       	    E := L#0;
		    -- Compute the possible combinations of filtration steps
	       	    Flist := recursiveMatricesConstructer(E,drop(L,1),{});
	       	    Flist = apply(Flist, m -> promote(transpose matrix m,QQ));
	       	    R := promote(transpose matrix {C},QQ);
		    Rrank := rank R;
		    -- Check if this combination admits a weightvector matrix
		    if Rrank != n then (
			 M := R^{0..Rrank-1};
			 for F in Flist list (
			      D := systemSolver(M,F^{0..Rrank-1});
			      if liftable(D,ZZ) and R*D == F then lift(D,ZZ)
			      else continue))
		    else (
			 Rn := inverse R^{0..n-1};
			 for F in Flist list (
			      Dn := Rn * (F^{0..Rrank-1});
			      if liftable(Dn,ZZ) and R*Dn == F then lift(Dn,ZZ)
			      else continue))))))


-- PURPOSE : Generating the graded Ring for the cohomology groups
--   INPUT : 'T',  a ToricVectorBundle
--  OUTPUT : the ring of the bundle with degree space the lattice of the variety
ring ToricVectorBundle := (cacheValue symbol gradedRing)( T -> (
	  if instance(T,ToricVectorBundleKlyachko) then (T#"ring")[DegreeRank => T#"dimension of the variety"]
	  else QQ[DegreeRank => T#"dimension of the variety"]))


-- PURPOSE : Computing the image bundle of a toric vector bundle
--   INPUT : '(T,M)', where 'T' is a ToricVectorBundleKlyachko and 'M' a matrix with the bundle space as its source
--  OUTPUT : The bundle given by the images of the filtrations
image (ToricVectorBundleKlyachko,Matrix) := (T,M) -> (
     k := T#"rank of the vector bundle";
     tRing := T#"ring";
     -- Checking for input errors
     if k != numColumns M then error("The source of the matrix has to be the vector bundle.");
     if tRing =!= ring M then error("The matrix and the bundle have to be over the same ring."); 
     -- Compute a basis of the image
     Mgens := mingens image M;
     ranknew := numColumns Mgens;
     bT := T#"baseTable";
     fT := T#"filtrationTable";
     -- for each ray compute the image of the filtration
     bT = hashTable apply(keys bT, j -> (
	       fTj := drop(sort keys fT#j,1);
	       cols := {};
	       oldImage := map(tRing^ranknew,tRing^0,0);
	       -- for each filtration step compute the image
	       j => apply(fTj, i -> (
			 cols = cols | fT#j#i;
			 -- take the image of the i-th filtration
			 A := M * (bT#j)_cols;
			 -- Represent this in the basis chosen
			 gkMA := (gens ker (Mgens | A))^{0..ranknew-1};
			 -- Select the new basis vectors of the filtration
			 gkMA = mingens (image(oldImage | gkMA) / image oldImage);
			 -- and add them to the matrix
			 oldImage = oldImage |gkMA;
			 -- save the new matrix and filtration step
			 (gkMA,matrix {toList(numColumns gkMA:i)})))));
     -- Generate the new filtration matrices and tables
     fMT := hashTable apply(pairs bT, p -> p#0 => matrix {apply(p#1,last)});
     fT = hashTable apply(pairs fMT, p -> (
	       L := flatten entries p#1;
	       L1 := sort unique L;
	       p#0 => hashTable ({(min L1-1) => {}} | apply(L1, l -> l => positions(L,e -> e == l)))));
     bT = hashTable apply(pairs bT, p -> p#0 => matrix {apply(p#1,first)});
     Tnew := new ToricVectorBundleKlyachko from {
	  "ring" => T#"ring",
	  "rayTable" => T#"rayTable",
	  "baseTable" => bT,
	  "filtrationMatricesTable" => fMT,
	  "filtrationTable" => fT,
	  "ToricVariety" => T#"ToricVariety",
	  "number of affine charts" => T#"number of affine charts",
	  "dimension of the variety" => T#"dimension of the variety",
	  "rank of the vector bundle" => ranknew,
	  "number of rays" => T#"number of rays",
	  symbol cache => new CacheTable};
     if T.cache.?isVB and T.cache.isVB then Tnew.cache.isVB = true;
     Tnew)


-- PURPOSE : Check for a ToricVectorBundleKlyachko if it is general
--   INPUT : 'tvb',  a ToricVectorBundleKlyachko
--  OUTPUT : 'true' or 'false'
-- COMMENT : A toricVectorBundle is general if for every generating cone 'C' the following holds:
--     	     For every choice of filtration steps i_1,...,i_n for the rays r_1,..,r_n of C 
--     	     codim \bigcap E^r_j(i_j) = min {\sum codim E^r_j(i_j),rank E}
--     	     holds.
isGeneral = method()
isGeneral ToricVectorBundleKlyachko := (cacheValue symbol isGeneral)( tvb -> (
	  fT := tvb#"filtrationMatricesTable";
     	  fT = hashTable apply(pairs fT, p -> p#0 => flatten entries p#1);
     	  bT := tvb#"baseTable";
     	  L := hashTable apply(pairs fT, (j,q) -> j => apply(sort unique q, i -> (bT#j)_(positions(fT#j, e -> e <= i))));     
     	  -- recursive function to check every combination of filtration steps
     	  recursiveCheck := (L,Es) -> (
	       -- if there is still a list of filtration steps, call recursiveCheck again for each entry
	       if L != {} then all(L#0, l -> recursiveCheck(drop(L,1),Es|{l}))
	       -- otherwise we have a choice of filtration steps and check the condition
	       else (
	       	    n := numRows Es#0;
	       	    codimSum := sum apply(Es, A -> n - numColumns A);
	       	    codimSum = min(codimSum,n);	       
	       	    R := ring Es#0;
	       	    E := map(R^n,R^n,1);
	       	    Es = select(Es, e -> numColumns e != n);
	       	    scan(Es, A -> E = intersectMatrices(E,A));
	       	    n - numColumns E == codimSum));
     	  F := maxCones tvb#"ToricVariety";
     	  all(F, C -> (
	       	    C = C#"rays";
	       	    C = apply(numColumns C, i -> C_{i});
	       	    recursiveCheck(apply(C, r -> L#r),{})))))


-- PURPOSE : Checking if the data in T in fact defines a vectorbundle, i.e., satisfies the decomposition condition or
--     	     regularity and cocycle condition
--   INPUT : 'T',  a ToricVectorBundle
--  OUTPUT : 'true' if 'T' is fact a bundle, 'false' otherwise
isVectorBundle = method()
isVectorBundle ToricVectorBundle := (cacheValue symbol isVB)( T -> (
	  if instance(T,ToricVectorBundleKlyachko) then (
	       L := findWeights T;
	       all(L, l -> l != {}) and existsDecomposition(T,L))
	  else regCheck T and cocycleCheck T))


-- PURPOSE : Computing the kernel bundle of a toric vector bundle
--   INPUT : '(T,M)', where 'T' is a ToricVectorBundleKlyachko and 'M' a matrix with the bundle space as source
--  OUTPUT : The bundle given by the kernels of the filtrations
ker (ToricVectorBundleKlyachko,Matrix) := opts -> (T,M) -> (
     k := T#"rank of the vector bundle";
     tRing := T#"ring";
     -- Checking for input errors
     if k != numColumns M then error("The source of the matrix has to be the vector bundle.");
     if tRing =!= ring M then error("Matrix and bundle have to be over the same ring.");
     -- Compute a basis of the kernel
     M = mingens ker M;
     ranknew := numColumns M;
     bT := T#"baseTable";
     fT := T#"filtrationTable";
     -- Compute the new filtration for each ray
     bT = hashTable apply(keys bT, j -> (
	       fTj := drop(sort keys fT#j,1);
	       cols := {};
	       oldKer := map(tRing^ranknew,tRing^0,0);
	       -- compute each filtration step
	       j => apply(fTj, i -> (
			 cols = cols | fT#j#i;
			 A := (bT#j)_cols;
			 -- Represent the kernel intersected with the actual filtration step in the basis chosen
			 gkMA := (gens ker (M | A))^{0..ranknew-1};
			 -- Select the "new" vectors
			 gkMA = mingens (image(oldKer | gkMA) / image oldKer);
			 oldKer = oldKer |gkMA;
			 -- Save the new vectors and the filtration step
			 (gkMA,matrix {toList(numColumns gkMA:i)})))));
     -- Compute the filtration matrices and tables
     fMT := hashTable apply(pairs bT, p -> p#0 => matrix {apply(p#1,last)});
     fT = hashTable apply(pairs fMT, p -> (
	       L := flatten entries p#1;
	       L1 := sort unique L;
	       p#0 => hashTable ({min L1 - 1 => {}} | apply(L1, l -> l => positions(L,e -> e == l)))));
     bT = hashTable apply(pairs bT, p -> p#0 => matrix {apply(p#1,first)});
     Tnew := new ToricVectorBundleKlyachko from {
	  "ring" => T#"ring",
	  "rayTable" => T#"rayTable",
	  "baseTable" => bT,
	  "filtrationMatricesTable" => fMT,
	  "filtrationTable" => fT,
	  "ToricVariety" => T#"ToricVariety",
	  "number of affine charts" => T#"number of affine charts",
	  "dimension of the variety" => T#"dimension of the variety",
	  "rank of the vector bundle" => ranknew,
	  "number of rays" => T#"number of rays",
	  symbol cache => new CacheTable};
     if T.cache.?isVB and T.cache.isVB then Tnew.cache.isVB = true;
     Tnew)
     

-- PURPOSE : Returning the maximal cones of the underlying fan
--   INPUT : 'T',  a ToricVectorBundle
--  OUTPUT : a List of Cones
maxCones ToricVectorBundle := T -> sort maxCones T#"ToricVariety"


-- PURPOSE : Compute a random deformation of a ToricVectorBundleKlyachko
randomDeformation = method(TypicalValue => ToricVectorBundleKlyachko)

--   INPUT : '(tvb,l,h)',  where 'tvb' is a ToricVectorBundleKlyachko, 'l' and 'h' are integers
--  OUTPUT : a ToricVectorBundleKlyachko, a random deformation
-- COMMENT : Simply replaces the base matrices by random matrices of full rank with entries between 
--     	     'l' and 'h'
randomDeformation (ToricVectorBundleKlyachko,ZZ,ZZ) := (tvb,l,h) -> (
     -- Checking for input errors
     if l > h then error("Expected the first integer to be less or equal than the second integer.");
     k := tvb#"rank of the vector bundle";
     -- For each ray generate a new k by k matrix of full rank with entries between 'l' and  'h'
     bT := hashTable apply(pairs tvb#"baseTable", p -> (
	       A := 0 * p#1;
	       while det A == 0 do A = generateRandomMatrix(k,k,l,h);
	       p#0 => promote(A,tvb#"ring")));
     -- Keep the old filtration
     new ToricVectorBundleKlyachko from {
	  "ring" => tvb#"ring",
	  "rayTable" => tvb#"rayTable",
	  "baseTable" => bT,
	  "filtrationMatricesTable" => tvb#"filtrationMatricesTable",
	  "filtrationTable" => tvb#"filtrationTable",
	  "ToricVariety" => tvb#"ToricVariety",
	  "number of affine charts" => tvb#"number of affine charts",
	  "dimension of the variety" => tvb#"dimension of the variety",
	  "rank of the vector bundle" => tvb#"rank of the vector bundle",
	  "number of rays" => tvb#"number of rays",
	  symbol cache => new CacheTable})

--   INPUT : '(tvb,h)',  where 'tvb' is a ToricVectorBundleKlyachko and 'h' an integer
--  OUTPUT : a ToricVectorBundleKlyachko, a random deformation
-- COMMENT : Simply replaces the base matrices by random matrices of full rank with entries between 
--     	     0 and 'h'
randomDeformation (ToricVectorBundleKlyachko,ZZ) := (tvb,h) -> randomDeformation(tvb,0,h)


-- PURPOSE : Returning the rank of the vector bundle
--   INPUT : 'T',  a ToricVectorBundle
rank ToricVectorBundle := T -> T#"rank of the vector bundle"


-- PURPOSE : Giving the rays of the underlying Fan of a toric vector bundle
--   INPUT : 'tvb',  a TorcVectorBundle
--  OUTPUT : 'L',  a List containing the rays of the Fan underlying the bundle
rays ToricVectorBundle := tvb -> raySort toList tvb#"ToricVariety"#"rays"


-- PURPOSE : Computing the 'l'-th symmetric power of a Toric Vector Bundle
--   INPUT : '(l,tvb)',  where 'l' is a strictly positive integer and 'tvb' is a ToricVectorBundle
--  OUTPUT : 'tvb',  a ToricVectorBundle which is the 'l'-th symmetric power
symmetricPower(ZZ,ToricVectorBundle) := (l,tvb) -> (
     -- Checking for input errors
     if l < 0 then error("The power has to be strictly positive.");
     -- Extracting data
     k := tvb#"rank of the vector bundle";
     -- Generating the list of 'l'-tuples of 0..k-1 with duplicates and the corresponding index table
     ind := sort apply(subsets(k+l-1,l),s -> apply(#s, i -> s#i-i));
     allind := sort unique flatten apply(ind, permutations);
     indtable := hashTable apply(#ind, i -> ind#i => i);
     if instance(tvb,ToricVectorBundleKlyachko) then (
	  if l == 0 then toricVectorBundle(1,tvb#"ToricVariety")
	  else (
     	       baseTable := tvb#"baseTable";
     	       filtrationTable := tvb#"filtrationMatricesTable";
     	       Rs := rays tvb;
     	       R := tvb#"ring";
     	       F := tvb#"ToricVariety";
     	       -- Computing the 'l'-th symmetric product of the base matrices
     	       baseTable = apply(Rs, r -> (
	       	    	 B := baseTable#r;
	       	    	 M := mutableMatrix(R,#ind,#ind);
	       	    	 for i1 in ind do (
		    	      Bi := B_(i1);
		    	      for j in allind do M_(indtable#(sort j),indtable#i1) = M_(indtable#(sort j),indtable#i1) + product apply(#j, j1 -> Bi_(j#j1,j1)));
	       	    	 matrix M));
     	       -- Computing the 'l'-th symmetric products of the filtration matrices
     	       filtrationTable = apply(Rs, r -> (
	       	    	 filt := filtrationTable#r;
	       	    	 matrix {apply(ind, j -> sum flatten entries filt_j)}));
     	       T := makeVBKlyachko(#ind,F,baseTable,filtrationTable);
     	       if tvb.cache.?isVB and tvb.cache.isVB then T.cache.isVB=true;
     	       T))
     else (
	  if l == 0 then toricVectorBundle(1,tvb#"ToricVariety","Type" => "Kaneyama")
	  else (
	       -- Computing the 'l'-th symmetric powers of the transition matrices
     	       baseChangeTable := hashTable apply(pairs tvb#"baseChangeTable", p -> (
	       	    	 B := p#1;
	       	    	 M := mutableMatrix(QQ,#ind,#ind);
	       	    	 for i1 in ind do (
		    	      Bi := B_(i1);
		    	      for j in allind do M_(indtable#(sort j),indtable#i1) = M_(indtable#(sort j),indtable#i1) + product apply(#j, j1 -> Bi_(j#j1,j1)));
	       	    	 M = matrix M;
	       	    	 p#0 => M));
     	       -- Computing the 'l'-th symmetric powers of the degrees
     	       degreeTable := hashTable apply(pairs tvb#"degreeTable", p -> (
	       	    	 dM := p#1;
	       	    	 dM = transpose matrix apply(ind, j -> flatten entries(dM_j * matrix toList((#j):{1})));
	       	    	 p#0 => dM));
     	       E := new ToricVectorBundleKaneyama from {
	       	    "degreeTable" => degreeTable,
	       	    "baseChangeTable" => baseChangeTable,
	       	    "ToricVariety" => tvb#"ToricVariety",
	       	    "number of affine charts" => tvb#"number of affine charts",
	       	    "dimension of the variety" => tvb#"dimension of the variety",
	       	    "rank of the vector bundle" => #ind,
	       	    "codim1Table" => tvb#"codim1Table",
	       	    "topConeTable" => tvb#"topConeTable",
	       	    symbol cache => new CacheTable};
     	       if tvb.cache.?regCheck and tvb.cache.regCheck and tvb.cache.?cocycle and tvb.cache.cocycle then (
	       	    E.cache.regCheck = true;
	       	    E.cache.cocycle = true);
     	       E)))


-- PURPOSE : Computing the tangent bundle on a smooth, pure, and full dimensional Toric Variety 
--   INPUT : 'F',  a smooth, pure, and full dimensional Fan
--  OUTPUT : 'tvb',  a ToricVectorBundle
-- COMMENT : If no option is given the function will return a ToricVectorBundleKlyachko, if "Type" => "Kaneyama" is given it returns a ToricVectorBundleKaneyama
tangentBundle = method(Options => {"Type" => "Klyachko"})
tangentBundle Fan := opts -> F -> (
     if opts#"Type" == "Klyachko" then tangentBundleKlyachko F else if opts#"Type" == "Kaneyama" then dual cotangentBundleKaneyama F else error("Expected Type to be Klyachko or Kaneyama."))


-- PURPOSE : Checking if two toric vector bundles are equal
--   INPUT : '(tvb1,tvb2)',  two ToricVectorBundle
--  OUTPUT : 'true' or 'false' 
ToricVectorBundle == ToricVectorBundle := (tvb1,tvb2) -> tvb1 === tvb2


-- PURPOSE : Computing the tensor product of two toric vector bundles over the same Fan
--   INPUT : '(tvb1,tvb2)',  two ToricVectorBundle over the same Fan in the same description
--  OUTPUT : 'tvb',  a ToricVectorBundle which is the tensor product in the same description
tensor(ToricVectorBundle, ToricVectorBundle) := ToricVectorBundle => {} >> opts -> (tvb1, tvb2) -> (
     -- Checking for input errors
     if tvb1#"ToricVariety" != tvb2#"ToricVariety" then error("Expected bundles over the same toric variety.");
     k1 := tvb1#"rank of the vector bundle";
     k2 := tvb2#"rank of the vector bundle";
     if instance(tvb1,ToricVectorBundleKaneyama) and instance(tvb2,ToricVectorBundleKaneyama) then (
     	  -- Extracting data out of tvb1 and tvb2
     	  -- Generating the trivial bundle of dimension k1+k2
     	  E := makeVBKaneyama(k1 * k2,tvb1#"ToricVariety");
     	  -- Computing the new degree table and transition matrices and writing the degrees and transition matrices into the bundle
     	  E = new ToricVectorBundleKaneyama from {
	       "degreeTable" => merge(tvb1#"degreeTable",tvb2#"degreeTable", (a,b) -> matrix {flatten apply(k2, j -> apply(k1, i -> a_{i}+b_{j}))}),
	       "baseChangeTable" => merge(tvb1#"baseChangeTable",tvb2#"baseChangeTable", (a,b) -> (
		    	 matrix flatten apply(k2, j -> apply(k1, i -> flatten apply(k2, j' -> apply(k1, i' -> a_(i,i') * b_(j,j'))))))),
	       "ToricVariety" => E#"ToricVariety",
	       "number of affine charts" => E#"number of affine charts",
	       "dimension of the variety" => E#"dimension of the variety",
	       "rank of the vector bundle" => k1 + k2,
	       "codim1Table" => E#"codim1Table",
	       "topConeTable" => E#"topConeTable",
	       symbol cache => new CacheTable};
     	  if (tvb1.cache.?regCheck and tvb2.cache.?regCheck and tvb1.cache.regCheck and tvb2.cache.regCheck and (
	       	    tvb1.cache.?cocycle and tvb2.cache.?cocycle and tvb1.cache.cocycle and tvb2.cache.cocycle)) then (
	       E.cache.regCheck = true;
	       E.cache.cocycle = true);
     	  E)
     else if instance(tvb1,ToricVectorBundleKlyachko) and instance(tvb2,ToricVectorBundleKlyachko) then (
	  -- Extracting data out of tvb1 and tvb2
     	  F := tvb1#"ToricVariety";
     	  bT1 := tvb1#"baseTable";
     	  bT2 := tvb2#"baseTable";
     	  fmT1 := tvb1#"filtrationMatricesTable";
     	  fmT2 := tvb2#"filtrationMatricesTable";
     	  -- Computing the bases and filtration matrices
     	  k := k1 * k2;
     	  tvb := makeVBKlyachko(k,F);
     	  R := rays tvb;
     	  baseTable := apply(R, r -> bT1#r ** bT2#r);
     	  filtrationTable := apply(R, r -> matrix {flatten apply(flatten entries fmT1#r, e1 -> apply(flatten entries fmT2#r, e2 -> e1 + e2))});
     	  -- Writing the new Tables into the bundle
     	  tvb = addBase(tvb,baseTable);
     	  tvb = addFiltration(tvb,filtrationTable);
     	  if tvb1.cache.?isVB and tvb2.cache.?isVB and tvb1.cache.isVB and tvb2.cache.isVB then tvb.cache.isVB = true;
     	  tvb)
     else error("The two toric vector bundles have to be in the same description."))


ToricVectorBundle ** ToricVectorBundle := (tvb1,tvb2) -> tensor(tvb1,tvb2)
-- ToricVectorBundleKlyachko ** ToricVectorBundleKlyachko := tensor


-- PURPOSE : Computing the twist of a Toric Vector Bundle by a divisor line bundle
--   INPUT : '(T,d)',  where 'T' is a toricVectorBundleKlyachko and 'd' a list of integers one for each ray of the fan
--  OUTPUT : a ToricVectorBundleKlyachko
-- COMMENT : If d={d_1,..d_l} then this corresponds to the line bundle which is the d_i twist on the i-th ray
twist = method(TypicalValue => ToricVectorBundleKlyachko)
twist (ToricVectorBundleKlyachko,List) := (T,d) -> (
     k := T#"rank of the vector bundle";
     fT := T#"filtrationMatricesTable";
     -- Checking for input errors
     if #d != #fT then error("The number of twists has to match the number of rays of the fan.");
     R := rays T;
     fT = apply(#R, i -> fT#(R#i) + matrix{toList(k:-(d#i))});
     addFiltration(T,fT))


-- PURPOSE : Computing the Cartier index of a Weil divisor
--   INPUT : '(L,F)',  where 'F' is a Fan and 'L' is a list of integers defining a Weil divisor
--  OUTPUT : The smallest multiple of the divisor which is Cartier if the divisor is QQ-Cartier, if not 
--     	     an error is returned
cartierIndex = method(TypicalValue => ZZ)
cartierIndex (List,Fan) := (L,F) -> (
     rl := raySort toList F#"rays";
     -- Checking for input errors
     if #L != #rl then error("The number of weights has to equal the number of rays.");
     n := ambDim F;
     -- Checking for further errors and assigning the weights to the rays
     L = hashTable apply(#rl, i -> (if class L#i =!= ZZ then error("The weights have to be in ZZ."); rl#i => L#i));
     -- Keeping track of the lowest common multiple of denominators of the degrees,
     -- to check whether the divisor itself is Cartier or which multiple
     denom := 1;
     -- Computing the degree vector for every top dimensional cone
     scan(sort maxCones F, C -> (
	       rC := C#"rays";
	       -- Taking the first n x n submatrix
	       rC1 := rC_{0..n-1};
	       -- Setting up the solution vector by composing the corresponding weights
	       v := matrix apply(n, i -> (c := rC1_{i}; {-(L#c)}));
	       -- Computing the degree vector
	       w := vertices intersection(matrix {toList(n:0)},matrix {{0}},transpose rC1,v);
	       -- Checking if w also fulfils the equations given by the remaining rays
	       if numColumns rC != n then (
		    v = v || matrix apply(toList(n..(numColumns rC)-1), i -> {-(L#(rC_{i}))});
	            if (transpose rC)*w - v != 0 then error("The weights do not define a Cartier divisor."));
	       -- Check if w is QQ-Cartier
	       scan(flatten entries w, e -> denom = lcm(denominator e ,denom))));
     denom)


-- PURPOSE : Generating the Vector Bundle given by a divisor
weilToCartier = method(Options => {"Type" => "Klyachko"})

--   INPUT : '(L,F)',  a list 'L' of weight vectors, one for each ray of the Fan 'F'
--  OUTPUT : 'tvb',  a ToricVectorBundle
-- COMMENT : If no option is given the function will return a ToricVectorBundleKlyachko, if "Type" => "Kaneyama" is given it returns a ToricVectorBundleKaneyama
weilToCartier (List,Fan) := opts -> (L,F) -> (
     rl := raySort toList F#"rays";
     -- Checking for input errors
     if #L != #rl then error("The number of weights has to equal the number of rays.");
     n := ambDim F;
     if opts#"Type" == "Kaneyama" then (
	  if not isPure F or ambDim F != dim F then error("Expected the Fan to be pure of maximal dimension.");
     	  -- Creating 0 matrices to compute intersection of hyperplanes to compute the degrees
	  Mfull := matrix {toList(n:0)};
	  vfull := matrix {{0}};
	  -- Checking for further errors and assigning the weights to the rays
	  L = hashTable apply(#rl, i -> (if class L#i =!= ZZ then error("The weights have to be in ZZ."); rl#i => L#i));
	  -- Keeping track of the lowest common multiple of denominators of the degrees,
	  -- to check whether the divisor itself is Cartier or which multiple
	  denom := 1;
	  -- Computing the degree vector for every top dimensional cone
	  tvb := makeVBKaneyama(1,F);
	  gC := sort keys tvb#"degreeTable";
	  gC = apply(gC, C -> (
		    rC := C#"rays";
		    -- Taking the first n x n submatrix
		    rC1 := rC_{0..n-1};
		    -- Setting up the solution vector by composing the corresponding weights
		    v := matrix apply(n, i -> (c := rC1_{i}; {-(L#c)}));
		    -- Computing the degree vector
		    w := vertices intersection(Mfull,vfull,transpose rC1,v);
		    -- Checking if w also fulfils the equations given by the remaining rays
		    if numColumns rC != n then (
			 v = v || matrix apply(toList(n..(numColumns rC)-1), i -> {-(L#(rC_{i}))});
			 if (transpose rC)*w - v != 0 then error("The weights do not define a Cartier divisor."));
		    -- Check if w is QQ-Cartier
		    scan(flatten entries w, e -> denom = lcm(denominator e ,denom));
		    w));
	  -- If the divisor is only QQ Cartier, then its replaced by its first Cartier multiple
	  if denom != 1 then error("The divisor is only QQ-Cartier, but "|toString(denom)|" times the divisor is Cartier.");
	  gC = apply(gC, e -> substitute(denom*e,ZZ));
	  -- Construct the actual line bundle
	  addDegrees(tvb,gC))
     else if opts#"Type" == "Klyachko" then (
	  if any(L, l -> not instance(l,ZZ)) then error("The weights have to be in ZZ.");
	  ind := cartierIndex(L,F);
	  if ind != 1 then error("The divisor is only QQ-Cartier, but "|toString(ind)|" times the divisor is Cartier.");
	  T := makeVBKlyachko(1,F,apply(L, l -> matrix{{1_QQ}}),apply(L, l -> matrix{{-l}}));
     	  T.cache.isVB = true;
	  T)
     else error("Expected Type to be Klyachko or Kaneyama."))


-- PURPOSE : Constructing the fan of projective n-space
--   INPUT : 'n',  a strictly positive integer
--  OUTPUT : The fan of projective n-space
projectiveSpaceFan = method(TypicalValue => Fan)
projectiveSpaceFan ZZ := n -> (
     if n < 1 then error("The dimension has to be strictly positive.");
     normalFan convexHull (map(ZZ^n,ZZ^n,1)|map(ZZ^n,ZZ^1,0)))


-- PURPOSE : Constructing the fan of the product of n projective 1-spaces
--   INPUT : 'n',  a strictly positive integer
--  OUTPUT : The fan of the product of n projective 1-spaces
pp1ProductFan = method(TypicalValue => Fan)
pp1ProductFan ZZ := n -> (
     if n < 1 then error("The number of PP^1's has to be strictly positive.");
     normalFan hypercube n)


-- PURPOSE : Constructing the fan of the Hirzebruch n-surface
--   INPUT : 'n',  a positive integer
--  OUTPUT : The fan of the Hirzebruch n-surface
hirzebruchFan = method(TypicalValue => Fan)
hirzebruchFan ZZ := n -> hirzebruch n



---------------------------------------
-- AUXILIARY FUNCTIONS, not public
---------------------------------------


-- PURPOSE : Computing the Cech complex of a vector bundle
cechComplex = method()

--   INPUT : '(k,T,u)', where 'k' is an integer between -1 and the dimension of the bundle +1, 'T' a ToricVectorBundleKlyachko, and 'u' a
--     	    	        one column matrix giving a degree vector
--  OUTPUT : '(Fk,Fkcolumns,FktoFk+1)', where 'Fk' is a hashTable with the summands of the 'k'th chain, 'Fkcolumns' is a hashTable with the
--     	    	      	   	        dimensions of these summands, and 'FktoFk+1' is a hashTable with the components of the 'k'th 
--     	    	      	   	        boundary operator
cechComplex (ZZ,ToricVectorBundleKlyachko,Matrix) := (k,T,u) -> (
     -- Checking for input errors
     if numRows u != T#"dimension of the variety" or numColumns u != 1 then error("Expected a matrix with 1 column and ", toString T#"dimension of the variety", " rows.");
     if ring u =!= ZZ then error("The degree has to be an integer vector.");
     if k < -1 or T#"dimension of the variety"+1 < k then error("k has to be between 0 and the variety dimension for the k-th cohomology");
     -- For a given space F1 at chain k in the filtration together with the degree vector 'u' and the information of the bundle this auxiliary 
     -- function computes the boundary operator to the next chain (k+1) which is F1toF2, the dimensions of the summands of 'F1' in 'F1columns' 
     -- and the next chain 'F2'
     makeNewDiffAndTarget := (F1,u,fMT,rT,bT,tvbR,tvbrank,k,n) -> (
	  F2 := {};
	  F1toF2 := {};
	  counter := 0;
	  F1columns := {};
	  -- if k==n then the next chain is 0 as well as the boundary operator
	  if k == n then (
	       F2 = {(0,{},map(tvbR^tvbrank,tvbR^0,0))};
	       F1toF2 = {};
	       F1columns = {0 => tvbrank})
	  -- k==n-1 then the next chain is "complete bundle" and the boundary operator is the map of all summands of Fn-2
	  else if k == n-1 then (
	       F2 = {(0,{},map(tvbR^tvbrank,tvbR^tvbrank,1))};
	       F1toF2 = apply(pairs F1, (j,dat) -> (
			 F1columns = append(F1columns,j => numColumns(dat#1));
			 (j,0,dat#1))))
	  else (
	       -- for each cone in F1 compute the cones of one dimension less and their bundle
	       scan(pairs(F1), (num,dat) -> (
			 R := dat#0;
			 Er := dat#1;
			 -- go through the rays of the cone and remove each of them at a time
			 scan(#R, i -> (
				   Ri := drop(R,{i,i});
				   pos := position(F2, f -> f#1 === Ri);
				   -- Check if the resulting cone already exists in the new chain F2, if so just add Er to the boundary operator
				   if pos =!= null then F1toF2 = append(F1toF2,(num,pos,((-1)^i)*Er)) else (
					-- if not compute E for new cone and append it to F2
					Esum := apply(Ri, r -> (rT#r,((transpose u)*r)_(0,0),r));
					Esum = apply(Esum, e -> (e#0,positions(flatten entries(fMT#(e#2)), j -> (j <= e#1)),e#2));
					if any(Esum, e -> e#1 == {}) then F2 = append(F2,(counter,Ri,map(tvbR^tvbrank,tvbR^0,0))) else (
					     E := map(tvbR^tvbrank,tvbR^tvbrank,1);
					     Esum = select(Esum, e -> sort(e#1) != toList(0..tvbrank-1));
					     Esum = apply(Esum, e -> (bT#(e#2))_(e#1));
					     scan(Esum, A -> E = intersectMatrices(E,A));
					     F2 = append(F2,(counter,Ri,E)));
					F1toF2 = append(F1toF2,(num,counter,((-1)^i)*Er));
					counter = counter + 1)));
			 -- Save the dimension of Er into F1columns
			 F1columns = append(F1columns,num => numColumns Er))));
	  (hashTable apply(F1toF2, f -> (f#0,f#1) => f#2),hashTable F1columns,hashTable apply(F2, f -> f#0 => (f#1,f#2))));
     if not T.cache.?cech then T.cache.cech = new MutableHashTable;
     fMT := T#"filtrationMatricesTable";
     tvbR := T#"ring";
     tvbrank := T#"rank of the vector bundle";
     n := T#"dimension of the variety";
     -- if k==n+1 the chain is 0 and there is no map
     if k == n+1 then (hashTable {0 => ({},map(tvbR^tvbrank,tvbR^0,0))},hashTable {},hashTable {}) else (
	  rT := T#"rayTable";
	  bT := T#"baseTable";
	  if not T.cache.cech#?(k,u) then (
	       -- rT will be used to sort the rays
	       
	       -- if the previous chain has not been computed we have to compute the cones of the right dimension (n-k)
	       if not T.cache.cech#?(k-1,u) or k == 0 then (
		    -- if k==n then the chain is the "complete bundle" and the next chain is 0
		    if k == n then (
			 T.cache.cech#(k,u) = (hashTable {0 => ({},map(tvbR^tvbrank,tvbR^tvbrank,1))},hashTable {0 => tvbrank},hashTable {});
			 T.cache.cech#(k+1,u) = hashTable {0 => ({},map(tvbR^tvbrank,tvbR^0,0))})
		    -- if k==-1 the chain is 0
		    else if k == -1 then T.cache.cech#(k,u) = (hashTable { 0 => ({},map(tvbR^tvbrank,tvbR^0,0))},hashTable {0 => 0},hashTable {})
		    else (
			 F1 := cones(n-k,T#"ToricVariety");
			 -- for each n-k cone in the fan compute Er, the bundle over this cone for the degree u
			 F1 = hashTable apply(#F1, Cnum -> (
				   C := F1#Cnum;
				   R := C#"rays";
				   R = apply(numColumns R, i -> (R_{i}));
				   R = sort apply(R, r -> (rT#r,r));
				   Esum := apply(R, r -> (r#0,((transpose u)*(r#1))_(0,0),r#1));
				   R = apply(R, r -> (r#1));
				   Esum = apply(Esum, e -> (e#0,positions(flatten entries fMT#(e#2), j -> (j <= e#1)),e#2));
				   if any(Esum, e -> e#1 == {}) then Cnum => (R,map(tvbR^tvbrank,tvbR^0,0)) else (
					E := map(tvbR^tvbrank,tvbR^tvbrank,1);
					Esum = select(Esum, e -> sort(e#1) != toList(0..tvbrank-1));
					Esum = apply(Esum, e -> (bT#(e#2))_(e#1));
					scan(Esum, A -> E = intersectMatrices(E,A));
					Cnum => (R,E))));
			 -- Compute the boundary operator with the auxiliary function
			 (F1toF2,F1columns,F2) := makeNewDiffAndTarget(F1,u,fMT,rT,bT,tvbR,tvbrank,k,n);
			 T.cache.cech#(k,u) = (F1,F1columns,F1toF2);
			 -- Save the next chain to the cache
			 if not T.cache.cech#?(k+1,u) then T.cache.cech#(k+1,u) = F2))
	       else (
		    -- if the previous chain exists use this to compute the chain in question
		    F10 := T.cache.cech#(k-1,u);
		    (F10toF11,F10columns,F11) := makeNewDiffAndTarget(F10,u,fMT,rT,bT,tvbR,tvbrank,k-1,n);
		    (F11toF12,F11columns,F12) := makeNewDiffAndTarget(F11,u,fMT,rT,bT,tvbR,tvbrank,k,n);
		    T.cache.cech#(k-1,u) = (F10,F10columns,F10toF11);
		    T.cache.cech#(k,u) = (F11,F11columns,F11toF12);
		    -- save the next chain to the cache as well
		    if not T.cache.cech#?(k+1,u) then T.cache.cech#(k+1,u) = F12))
	  -- if the cache only consists of the chain but not of the boundary operator compute this
	  else if not instance(T.cache.cech#(k,u),Sequence) then (
	       F21 := T.cache.cech#(k,u);
	       (F21toF22,F21columns,F22) := makeNewDiffAndTarget(F21,u,fMT,rT,bT,tvbR,tvbrank,k,n);
	       T.cache.cech#(k,u) = (F21,F21columns,F21toF22);
	       if not T.cache.cech#?(k+1,u) then T.cache.cech#(k+1,u) = F22);
	  T.cache.cech#(k,u)))

--   INPUT : '(k,T,u)', where 'k' is an integer between -1 and the dimension of the bundle +1, 'T' a ToricVectorBundleKlyachko, and 'u' a
--     	    	        one column matrix giving a degree vector
--  OUTPUT : '(Fk,Fkcolumns,FktoFk+1)', where 'Fk' is a hashTable with the summands of the 'k'th chain, 'Fkcolumns' is a hashTable with the
--     	    	      	   	        dimensions of these summands, and 'FktoFk+1' is a hashTable with the components of the 'k'th 
--     	    	      	   	        boundary operator
cechComplex (ZZ,ToricVectorBundleKaneyama,Matrix) := (k,tvb,u) -> ( 
     -- Checking for input errors
     if numRows u != tvb#"dimension of the variety" or numColumns u != 1 then error("Expected a matrix with 1 column and ", toString tvb#"dimension of the variety", " rows.");
     if ring u =!= ZZ then error("The degree has to be an integer vector.");
     if k < 0 or tvb#"dimension of the variety"+1 < k then error("k has to be between 0 and the variety dimension for the k-th cohomology.");
     -- For a given space F1 at chain k in the filtration together with the degree vector 'u' and the information of the bundle this auxiliary 
     -- function computes the boundary operator to the next chain (k+1) which is F1toF2, the dimensions of the summands of 'F1' in 'F1columns' 
     -- and the next chain 'F2'
     makeNewDiffAndTarget := (M1,rk,l,tCT,bCT,dT) -> (
	  -- Recursive function that finds a path over codim 1 cones from one topdim cone ('i') to another ('j')
     	  -- using the steps in 'pl'
     	  findpath := (i,j,pl) -> (
	       -- Recursive function finds a path from the actual cone 'i' to the Cone 'j' using the steps in 'pl'
	       -- where 'cl' is the  sequence of steps taken so far from the original 'i' and 'minpath' is the 
	       -- shortest path found so far
	       findrecursive := (i,j,pl,cl,minpath) -> (
	       	    -- If the last step from 'i' to 'j' is part of 'pl' then add '(i,j)' to 'cl'
	       	    if member((i,j),pl) or member((j,i),pl) then (
		    	 cl = append(cl,(i,j));
		    	 -- Check if the new found path is shorter than shortest so far
		    	 if #cl < #minpath or minpath == {} then minpath = cl)
	       	    -- otherwise find a path with the remaining steps in 'pl'
	       	    else (
		    	 L1 := {};
		    	 L2 := {};
		    	 -- Sort the remaining possible steps into those containing 'i'in 'L1' and those who not in 'L2'
		    	 for e in pl do if member(i,e) then L1 = append(L1,e) else L2 = append(L2,e);
		    	 -- Call findrecursive for each step in 'L1', with new starting cone the other index in the pair and new 
		    	 -- remaining pairs list 'L2' and add the step to 'cl'
		    	 for e in L1 do ( 
			      if e#0 == i then minpath = findrecursive(e#1,j,L2,append(cl,e),minpath)
			      else minpath = findrecursive(e#0,j,L2,append(cl,(e#1,e#0)),minpath)));
	       	    minpath);
	       -- Start with an empty sequence of steps, no minimal path yet and all possible stepsd
	       cl := {};
	       minpath := {};
	       findrecursive(i,j,pl,cl,minpath));
	  M2 := {};
	  for p in pairs M1 do (
	       L := select(toList(0..rk-1), i -> not member(i,p#1#0));
	       for i from last(p#0)+1 to l-1 do (
		    cl := append(p#0,i);
		    C := intersection(p#1#1,tCT#i);
		    degs := dT#(tCT#(cl#0));
		    M2 = append(M2,cl => (sort unique join(p#1#0,select(L, i -> contains(dualCone C,u- degs_{i}))),C))));
	  M2 = hashTable M2;
	  -- Constructing the zero map over QQ
     	  d1 := map(QQ^0,QQ^0,0);
     	  -- Constructing the matrix of the sequence for the cohomology
	  scan(pairs M1, (a,b) -> (
		    b = b#0;
		    -- 'A' will be a column of the matrix d1 of the sequence
		    A := map(QQ^0,QQ^(#b),0);
		    -- One intersection in M1 is selected, by going through the intersections in M2 we get the first "column" of block matrices in A 
		    -- by looking at the images in all intersections in M2
		    scan(pairs M2, (c,d) -> (
			      -- Only if the intersection is made by intersecting with one more cone, the resulting matrix has to be computed, 
			      -- because otherwise it is automatically zero
			      if isSubset(a,c) then (
				   -- get the signum by looking at the position the new cone is inserted
				   signum := (-1)^(#c - position(c, e -> not member(e,a)) - 1);
				   i := a#0;
				   j := c#0;
				   -- if i == j then no base change between the two representations has to be made, so the submatrix of the 
				   -- identity inserting the positions of the degrees 'b' into the degrees 'd' is added in this column
				   if i == j then A = A || (signum * (map(QQ^rk,QQ^rk,1))_b)
				   -- Otherwise we have to find the transition matrix from cone 'i' to Cone 'j'
				   else (
					-- find the transition matrix
					mpath := findpath(i,j,keys bCT);
					-- If the path has one element then we take the 'b'-'d' part of that matrix, otherwise the multiplication 
					-- of the matrices corresponding to the steps in the path and add the path as a new step with corresponding matrix
					if #mpath == 1 then (
					     if i < j then A = A || (signum * (bCT#(i,j))_b)
					     else A = A || (signum * (inverse (bCT#(j,i)))_b))
					else (
					     A1 := map(QQ^rk,QQ^rk,1);
					     for p in mpath do (
						  if p#0 < p#1 then A1 = bCT#p * A1
						  else A1 = (inverse bCT#(p#1,p#0))*A1);
					     if i < j then bCT = hashTable join(apply(pairs bCT, ps -> ps#0 => ps#1), {(i,j) => A1})
					     else bCT = hashTable join(apply(pairs bCT, ps -> ps#0 => ps#1), {(j,i) => inverse A1});
					     A = A || (signum * A1_b))))
			      else (
				   A = A || map(QQ^rk,QQ^(#b),0))));
		    -- Adding the new column to d1
		    if d1 == map(QQ^0,QQ^0,0) then d1 = A
		    else d1 = d1 | A));
	  (d1,M2));
     if not tvb.cache.?cech then tvb.cache.cech = new MutableHashTable;
     rk := tvb#"rank of the vector bundle";
     l := tvb#"number of affine charts";
     tCT := sort keys tvb#"topConeTable";
     bCT := tvb#"baseChangeTable";
     dT := tvb#"degreeTable";
     if not tvb.cache.cech#?(k,u) then (
     	  if k == 0 then (
	       M20 := hashTable apply(subsets(l,k+1), cl -> (
		    	 C := intersection apply(cl, i -> tCT#i);
		    	 degs := dT#(tCT#(cl#0));
		    	 L := select(toList(0..rk-1), i -> contains(dualCone C,u - degs_{i}));
		    	 cl => (L,C)));
	       (d20,M30) := makeNewDiffAndTarget(M20,rk,l,tCT,bCT,dT);
	       tvb.cache.cech#(k,u) = (M20,d20);
	       tvb.cache.cech#(k+1,u) = M30)
	  else (
	       M1 := if not tvb.cache.cech#?(k-1,u) then (
	       	    hashTable apply(subsets(l,k), cl -> (
		    	      C := intersection apply(cl, i -> tCT#i);
		    	      degs := dT#(tCT#(cl#0));
		    	      L := select(toList(0..rk-1), i -> contains(dualCone C,u - degs_{i}));
		    	      cl => (L,C)))) else tvb.cache.cech#(k-1,u);
	       (d1,M2) := makeNewDiffAndTarget(M1,rk,l,tCT,bCT,dT);
	       (d2,M3) := makeNewDiffAndTarget(M2,rk,l,tCT,bCT,dT);
	       tvb.cache.cech#(k-1,u) = (M1,d1);
	       tvb.cache.cech#(k,u) = (M2,d2);
	       tvb.cache.cech#(k+1,u) = M3))
     else if not instance(tvb.cache.cech#(k,u),Sequence) then (
	  M21 := tvb.cache.cech#(k,u);
	  (d21,M31) := makeNewDiffAndTarget(M21,rk,l,tCT,bCT,dT);
	  tvb.cache.cech#(k,u) = (M21,d21);
	  tvb.cache.cech#(k+1,u) = M31);
     tvb.cache.cech#(k,u))


-- PURPOSE : Checking for a matrix if it is over ZZ or QQ and returning an error if not
--   INPUT : '(M,msg)',  where 'M' is a matrix and 'msg' is the name of the object 'M' describes
--  OUTPUT : The matrix promoted to QQ if it was over ZZ or QQ, otherwise an error
chkZZQQ = (M,msg) -> (
     R := ring M;
     if R =!= ZZ and R =!= QQ then error("expected matrix of ",msg," to be over ZZ or QQ");
     promote(M,QQ));


-- PURPOSE : Computing the cohomology of a given ToricVectorBundle
cohom = method()
--   INPUT : '(k,tvb,u)',  'k' for the 'k'th cohomology group, 'tvb' a ToricVectorBundleKaneyama, and 'u' the degree
--  OUTPUT : 'ZZ',	     the dimension of the degree 'u' part of the 'k'th cohomology group of 'tvb'
cohom (ZZ,ToricVectorBundleKaneyama,Matrix) := (k,T,u) -> (
     if not T.cache.?HH then T.cache.HH = new MutableHashTable;
     if not T.cache.HH#?(k,u) then (
	  -- Get the k-1 th and k th differential
	  d := if k == 0 then rank ker (cechComplex(k,T,u))#1 else (
	       -- Generate the two boundary operators
	       d1 := (cechComplex(k-1,T,u))#1;
	       d2 := (cechComplex(k,T,u))#1;
	       (rank ker d2) - (rank image d1));
	  T.cache.HH#(k,u) = (ring T)^(toList(d:flatten entries(-u))));
     T.cache.HH#(k,u))

--   INPUT : '(k,tvb,u)',  'k' for the 'k'th cohomology group, 'tvb' a ToricVectorBundleKlyachko, and 'u' the degree
--  OUTPUT : 'ZZ',	     the dimension of the degree 'u' part of the 'k'th cohomology group of 'tvb'
cohom (ZZ,ToricVectorBundleKlyachko,Matrix) := (k,T,u) -> (
     if not T.cache.?HH then T.cache.HH = new MutableHashTable;
     if not T.cache.HH#?(k,u) then (
	  -- Get the k-1 th, k th and k+1 th chain in the Cech complex
     	  (F1,F1columns,F1toF2) := cechComplex(k-1,T,u);
     	  (F2,F2columns,F2toF3) := cechComplex(k,T,u);
     	  F3 := (cechComplex(k+1,T,u))#0;
     	  tvbR := T#"ring";
     	  tvbrank := T#"rank of the vector bundle";
     	  -- Generate the two boundary operators
     	  MapF1toF2 := matrix apply(#F2, j -> apply(#F1, i -> if F1toF2#?(i,j) then F1toF2#(i,j) else map(tvbR^tvbrank,tvbR^(F1columns#i),0)));
     	  MapF2toF3 := matrix apply(#F3, j -> apply(#F2, i -> if F2toF3#?(i,j) then F2toF3#(i,j) else map(tvbR^tvbrank,tvbR^(F2columns#i),0)));
     	  -- Compute the cohomology
     	  d := (rank ker MapF2toF3)-(rank image MapF1toF2);
     	  T.cache.HH#(k,u) = (ring T)^(toList(d:flatten entries(-u))));
     T.cache.HH#(k,u))


-- PURPOSE : Computing the cotangent bundle on a smooth, pure, and full dimensional Toric Variety 
--   INPUT : 'F',  a smooth, pure, and full dimensional Fan
--  OUTPUT : 'tvb',  a ToricVectorBundleKaneyama 
cotangentBundleKaneyama = F -> (
     -- Checking for input errors
     if not isSmooth F then error("The Toric Variety has to be smooth.");
     if not isComplete F then error("The Toric Variety has to be complete.");
     if not isPointed F then error("The Fan has to be pointed.");
     -- Generating the trivial bundle of dimension n
     n := dim F;
     tvb := makeVBKaneyama(n,F);
     tCT := sort keys tvb#"topConeTable";
     pairlist := keys tvb#"baseChangeTable";
     -- Computing the degrees and transition matrices of the cotangent bundle
     degreeTable := hashTable apply(tCT, p -> p => substitute(rays dualCone p,ZZ));
     baseChangeTable := hashTable apply(pairlist, p -> ( p => substitute(inverse(degreeTable#(tCT#(p#1)))*(degreeTable#(tCT#(p#0))),QQ)));
     -- Writing the data into the bundle
     E := new ToricVectorBundleKaneyama from {
	  "degreeTable" => degreeTable,
	  "baseChangeTable" => baseChangeTable,
	  "ToricVariety" => tvb#"ToricVariety",
	  "number of affine charts" => tvb#"number of affine charts",
	  "dimension of the variety" => n,
	  "rank of the vector bundle" => n,
	  "codim1Table" => tvb#"codim1Table",
	  "topConeTable" => tvb#"topConeTable",
	  symbol cache => new CacheTable};
     E.cache.regCheck = true;
     E.cache.cocyle = true;
     E)


-- PURPOSE : Constructing the fan of projective n-space
generateRandomMatrix = method(TypicalValue => Matrix)

--   INPUT : '(m,n,h)',  where 'm' and 'n' are strictly positive integers and 'h' is an integer
--  OUTPUT : An 'm' by 'n' matrix with random entries between 0 and 'h'
generateRandomMatrix (ZZ,ZZ,ZZ) := (m,n,h) -> matrix apply(m, i -> apply(n, j -> random h+1))

--   INPUT : '(m,n,l,h)',  where 'm' and 'n' are strictly positive integers and 'l' 'h' are integers 
--     	    	      	   of which 'l' is the smaller one
--  OUTPUT : An 'm' by 'n' matrix with random entries between 0 and 'h'
generateRandomMatrix (ZZ,ZZ,ZZ,ZZ) := (m,n,l,h) -> matrix apply(m, i -> apply(n, j -> random(l,h)))


-- PURPOSE : Computing the intersection of the images of two matrices
--   INPUT : '(M,N)', two matrices with the same target
--  OUTPUT : a matrix with the minimal generators of the intersection
intersectMatrices = (M,N) -> (
     m := numColumns M;
     N = gens ker(M | N);
     N = N^{0..m-1};
     gens trim image(M*N));


-- PURPOSE : Building a Vector Bundle of rank 'k' on the Toric Variety given by the Fan 'F'
--           with 0 degrees and identity transition matrices
--   INPUT : '(k,F)',  a strictly positive integer 'k' and a pure and full dimensional
--                     Fan 'F' 
--  OUTPUT : The ToricVectorBundleKaneyama 'VB'
makeVBKaneyama = method(TypicalValue => ToricVectorBundleKaneyama)
makeVBKaneyama (ZZ,Fan) := (k,F) -> (
     -- Checking for input errors
     if k < 0 then error("The vector bundle must have a positive rank.");
     if not isComplete F then error("The fan has to be complete.");
     if not isPointed F then error("The fan has to be pointed.");
     -- Writing the table of Cones of maximal dimension
     n := dim F;
     topConeTable := sort toList F#"generatingCones";
     topConeTable = hashTable apply(#topConeTable, i -> topConeTable#i => i);
     -- Saving the index pairs of top dimensional Cones that intersect in a codim 1 Cone
     Ltable := hashTable {};
     scan(pairs topConeTable, (C,a) -> Ltable = merge(Ltable,hashTable apply(faces(1,C), e -> e => a),(b,c) -> if b < c then (b,c) else (c,b)));
     Ltable = hashTable flatten apply(pairs Ltable, p -> if instance(p#1,Sequence) then p#1 => p#0 else {});
     -- Removing Cones on the "border" of F, which have only 1 index
     pairlist := sort keys Ltable;
     -- Saving the identity into the Table of transition matrices
     baseChangeTable := hashTable apply(pairlist, p -> p => map(QQ^k,QQ^k,1));
     -- Saving 0 degrees into the degree table
     degreeTable := hashTable apply(keys topConeTable, C -> C => map(ZZ^n,ZZ^k,0));
     -- Making the vector bundle
     new ToricVectorBundleKaneyama from {
	  "degreeTable" => degreeTable,
	  "baseChangeTable" => baseChangeTable,
	  "codim1Table" => Ltable,
	  "ToricVariety" => F,
	  "number of affine charts" => #topConeTable,
	  "dimension of the variety" => n,
	  "rank of the vector bundle" => k,
	  "topConeTable" => topConeTable,
	  symbol cache => new CacheTable})

--   INPUT : '(k,F,degreeList,matrixList)',  a strictly positive integer 'k', a pure and full dimensional
--                     Fan 'F' of dimension n, a list 'degreeList' of k by n matrices over ZZ, one for each 
--     	    	       top dimensional Cone in 'F' where the columns give the degrees of the generators in the 
--     	    	       corresponding affine chart to this Cone, and a list 'matrixList' of  k by k matrices 
--     	    	       over QQ, one for each pair of top dimensional Cones intersecting in a common codim 1 face. 
--  OUTPUT : The ToricVectorBundleKaneyama 'tvb' 
-- COMMENT : Note that the top dimensional cones are numbered starting with 0 and the codim 1 intersections are 
--           labelled by pairs (i,j) denoting the two top dim cones involved, with i<j and they are ordered
--     	     in lexicographic order. So the matrices in 'matrixList' will be assigned to the pairs (i,j) in that 
--     	     order, where the matrix A assigned to (i,j) denotes the transition
--     	    	 (e_i^1,...,e_i^k) = (e_j^1,...,e_j^k)* A
--     	     The matrices in 'degreeList' will be assigned to the cones in the order in which they are numbered.
makeVBKaneyama (ZZ,Fan,List,List) := (k,F,degreelist,matrixlist) -> (
     -- Generating the trivial vector bundle of rank k
     tvb := makeVBKaneyama(k,F);
     -- Adding the given degrees and transition matrices
     tvb = addDegrees(tvb,degreelist);
     tvb = addBaseChange(tvb,matrixlist);
     tvb)


-- PURPOSE : Building a Vector Bundle in the Klyachko description of rank 'k' on the Toric Variety given by the Fan 'F'
--           with trivial Filtration for every ray
--   INPUT : '(k,F)',  a strictly positive integer 'k' and a pure and full dimensional Fan 'F' 
--  OUTPUT : The ToricVectorBundleKlyachko 'VB'
makeVBKlyachko = method(TypicalValue => ToricVectorBundleKlyachko)
makeVBKlyachko (ZZ,Fan) := (k,F) -> (
     -- Checking for input errors
     if k < 0 then error("The vector bundle must have a positive rank.");
     if not isPointed F then error("The Fan has to be pointed");
     -- Writing the table of rays
     rT := raySort toList F#"rays";
     rT = hashTable apply(#rT, i -> rT#i => i);
     -- Writing the table of identity matrices for the vector bundle bases
     bT := hashTable apply(keys rT, i -> i => map(QQ^k,QQ^k,1));
     -- Writing the table of matrices for the filtration maps
     fMT := hashTable apply(keys rT, i -> i =>  matrix {toList(k:0)});
     -- Computing the list of changes in the filtrations
     fT := hashTable apply(pairs fMT, p -> (
	       L := flatten entries p#1;
	       L1 := sort unique L;
	       p#0 => hashTable ({min L1 - 1 => {}} | apply(L1, l -> l => positions(L,e -> e == l)))));
     -- Generating the vector bundle
     tvb := new ToricVectorBundleKlyachko from {
	  "ring" => QQ,
	  "rayTable" => rT,
	  "baseTable" => bT,
	  "filtrationMatricesTable" => fMT,
	  "filtrationTable" => fT,
	  "ToricVariety" => F,
	  "number of affine charts" => #(F#"generatingCones"),
	  "dimension of the variety" => dim F,
	  "rank of the vector bundle" => k,
	  "number of rays" => #rT,
	  symbol cache => new CacheTable};
     tvb.cache.isVB = true;
     tvb)

--   INPUT : '(k,F,baseList,filtrationList)',  a strictly positive integer 'k', a pure and full dimensional
--                     Fan 'F' of dimension n, a list 'baseList' of k by k matrices over the same ring/field, one for each 
--     	    	       ray of 'F' where the columns give the basis of the vector bundle over the ray, and a list 
--     	    	       'filtrationList' of  1 by k matrices over ZZ, one for each ray such that the i-th column of 
--     	    	       the base matrix is at first in the part of the filtration indexed by the i-th entry in the filtration 
--     	    	       matrix.
--  OUTPUT : The ToricVectorBundleKlyachko 'tvb' 
-- COMMENT : Note that the bases and filtration matrices will be assigned to the rays in the order, they appear in rays F
makeVBKlyachko (ZZ,Fan,List,List) := (k,F,Bm,Fm) -> (
     tvb := makeVBKlyachko(k,F);
     tvb = addBase(tvb,Bm);
     addFiltration(tvb,Fm))


-- PURPOSE : Solving the system R*X=F
--   INPUT : '(R,F)',  two matrices over ZZ
--  OUTPUT : a matrix of QQ solutions
systemSolver = (R,F) -> (
     (R1,Lmatrix,Rmatrix) := smithNormalForm lift(R,ZZ);
     F1 := entries(Lmatrix * F);
     Rmatrix * (matrix apply(numRows R1, i -> F1#i / R1_(i,i)) || map(QQ^(numColumns R1 - numRows R1),QQ^(#F1#0),0)))


-- PURPOSE : Generating the table of all rays together with their filtration 
--   INPUT : 'T',  a ToricVectorBundleKlyachko
--  OUTPUT : a hashTable,  with keys the rays of the variety and for each ray a list of pairs (the filtration step, the filtration)
tableForAllRays = method(TypicalValue => HashTable)
tableForAllRays ToricVectorBundleKlyachko := (cacheValue symbol allRaysTable)( T -> (
	  fMT := T#"filtrationMatricesTable";
     	  bT := T#"baseTable";
	  hashTable apply(rays T, r -> (
		    fT := flatten entries fMT#r;
	       	    r => apply(fT, e -> (e,(bT#r)_(positions(fT, i -> i <= e))))))))


-- PURPOSE : Computing the tangent bundle (Klyachko) on a smooth, pure, and full dimensional Toric Variety 
--   INPUT : 'F',  a smooth, pure, and full dimensional Fan
--  OUTPUT : 'tvb',  a ToricVectorBundleKlyachko 
tangentBundleKlyachko = F -> (
     -- Checking for input errors
     if not isSmooth F then error("The Toric Variety has to be smooth.");
     -- Generating the trivial bundle of dimension n
     n := dim F;
     tvb := makeVBKlyachko(n,F);
     -- Extracting the rayTable
     rayTable := apply(rays tvb,r -> promote(r,QQ));
     -- Adding the filtration matrix |-1,0,0,...,0| for each ray
     filtrationTable := apply(rayTable, r -> matrix{flatten({-1,toList(n-1:0)})});
     -- Adding the base which has as first vector the ray itself to each ray
     baseTable := apply(rayTable, r -> r | complement r);
     -- Adding bases filtration matrices to the bundle
     tvb = addFiltration(tvb,filtrationTable);
     tvb = addBase(tvb,baseTable);
     tvb.cache.isVB = true;
     tvb)



---------------------------------------
-- DOCUMENTATION
---------------------------------------


beginDocumentation()

document {
     Key => OldToricVectorBundles,
     Headline => "cohomology computations of equivariant vector bundles on toric varieties",
     
     "Using the descriptions of Kaneyama and Klyachko this package implements the construction of
     equivariant vector bundles on toric varieties.",
     
     PARA{}, "Note that this package implements vector bundles in Kaneyama's description only over 
     pure and full dimensional fans.",
     
     PARA{}, TT "OldToricVectorBundles", " uses the ", TO OldPolyhedra, " package by ", 
     HREF("http://page.mi.fu-berlin.de/rbirkner/indexen.htm", "René Birkner"), ". At least version 1.1 
     of ",TO OldPolyhedra," must be installed via ",TO installPackage," to use ",TT "OldToricVectorBundles",".",
     
     PARA{}, "Each vector bundle is saved either in the description of Kaneyama or the one of Klyachko. The 
     first description gives the multidegrees (in the dual lattice of the fan) of the generators of the bundle 
     over each full dimensional cone, and for each codimension-one cone a transition matrix 
     (See ",TO ToricVectorBundleKaneyama,"). The description of an equivariant vector bundle given by Klyachko 
     consists of filtrations of a fixed vector space for each ray in the fan of the base variety. Furthermore,
     these filtrations have to satisfy a certain compatibility condition (See ",TO ToricVectorBundleKlyachko,").",
     
     PARA{}, "For the mathematical background see ",
     
     UL {
	  {"Tamafumi Kaneyama,",EM "On equivariant vector bundles on an almost homogeneous variety", ", Nagoya Math. J. 57, 1975."},
	  {"Alexander A. Klyachko,",EM "Equivariant bundles over toral varieties", ", Izv. Akad. Nauk SSSR Ser. Mat., 53, 1989."},
	  {"Markus Perling,",EM "Resolution and moduli for equivariant sheaves over toric varieties", ", PhD Thesis, 2003."}
	},
     
     SeeAlso => {"OldPolyhedra::OldPolyhedra"}
     
     }

document {
     Key => ToricVectorBundle,
     Headline => "the class of all toric vector bundles",
     
     "In ",TO OldToricVectorBundles," an equivariant vector bundle on some toric variety is given as an object of class ",TT "ToricVectorBundle"," 
     which can be given in two descriptions:",
     
     UL {
	  {"By a collection of vector spaces with filtration for each ray of the underlying fan, ",TO ToricVectorBundleKlyachko,"."},
	  {"By a set of degree vectors for each maximal cone and a transition matrix for each pair of maximal cones of the underlying 
	       fan, ",TO ToricVectorBundleKaneyama,"."}
	},
     
     PARA{}, "For more detailed descriptions see the corresponding pages of the two subtypes.",
     
     SeeAlso => {ToricVectorBundleKlyachko,
	  ToricVectorBundleKaneyama}
     
     }
   
document {     
     Key => ToricVectorBundleKaneyama,
     Headline => "the class of all toric vector bundles in Kaneyama's description",     
     
     TEX ///"Consider an equivariant vector bundle $E$ of rank $k$ on a toric variety $X$ corresponding to a fan $\Sigma$. Then $E$ is 
     trivial on any invariant open affine subvariety of $X$ and moreover homogeneously generated by $k$ elements. 
     Furthermore, the transition maps between these trivializations are homogeneous of degree zero. Thus, 
     after fixing local homogeneous generators, we get a list of degrees of generators for each cone 
     in $\Sigma$, along with a transition map for each pair of cones. Conversely, given a list of $k$ degrees for every 
     cone of $\Sigma$ along with transition maps satisfying compatibility and regularity conditions for every pair of cones, 
     one can construct an equivariant vector bundle of rank $k$ on $X$."///,
     
     PARA{}, TEX ///"This description of equivariant vector bundles, due to Kaneyama, is implemented for complete, pointed fans in the following way: 
     It is only necessary to consider charts corresponding to maximal dimensional cones of $\Sigma$. Furthermore, each codimension-one cone of 
     $\Sigma$ corresponds to a pair of maximal dimensional cones, and thus to a transition map. Due to the compatibility condition for transition maps, 
     one can reconstruct the transition map corresponding to an arbitrary pair from the maps of this sort. If the dimension of $\Sigma$ is $n$ then 
     for each maximal dimensional cone the degree list of the corresponding chart is saved as an $n$ times $k$ matrix over ",TO ZZ,", giving 
     $k$ degree vectors in the dual lattice of the fan, one for each local generator of the bundle. Additionally, 
     for every pair of maximal cones intersecting in a common codimension-one face, there is a matrix in 
     GL($k$,",TO QQ,"), representing the transition map between these two affine charts. Indeed, suppose that 
     cones $\sigma_1$ and $\sigma_1$ intersect in some codimension-one face, with corresponding affine 
     charts $U_1$ and $U_2$. Then on the intersection, the $i$-th generator for $U_1$ has a unique 
     representation as a linear combination in the generators for $U_2$ after being multiplied with characters to all 
     have the required degree. The coefficients in this representation form the $i$-th column of the desired matrix."///,
     
     PARA{}, TEX ///"We briefly consider the example of  $\mathbb{P}^2$, corresponding to the complete fan with rays 
     through $(0,1)$, $(1,0)$, and $(-1,-1)$. Denote by $x$ the character of weight $[1,0]$ and by $y$ the character 
     of weight $[0,1]$. Now the coordinate rings of the three standard affine charts of $\mathbb{P}^2$ are generated by 
     respectively $(x^{ -1},x^{ -1}y)$, $(x,y)$, and $(xy^{ -1},y^{ -1})$. This means that the modules of differentials 
     are generated by respectively $(d(x^{ -1}),d(x^{ -1}y))$, $(dx,dy)$, and $(d(xy^{ -1}),d(y^{ -1}))$. These modules give us 
     local trivializations of the cotangent bundle on $\mathbb{P}^2$. The degrees of the generators for the first chart 
     then are $[-1,0]$ and $[-1,1]$, for example. Now, since $d(x^{ -1})=-x^{ -2}dx$ and $d(x^{ -1}y) = -x^{ -2}ydx + x^{ -1}dy$, 
     we get that the transition map between the generators of the first and second chart is given by the matrix with 
     columns $(-1,0)$ and $(-1,1)$."///,
          
     PARA{},"An instance of class ToricVectorBundleKlyachko, when displayed or printed, gives an overview  of the 
     characteristics of the bundle:",
     
     EXAMPLE {
	  " E = cotangentBundle(projectiveSpaceFan 2,\"Type\" => \"Kaneyama\")"
	  },
     
     PARA{}, "To see all relevant details of a bundle use ",TO details,". The data described above is all stored in a single hash table. In the example from above, the first chart has the key 0, and transition map described above has key (0,1):",
     
     EXAMPLE {
	  " details E"
	  },
     
     Caveat=> {"This implementation only supports vector bundles where the corresponding transition maps have coefficients in ",TO QQ,"."},
     
     SeeAlso => {ToricVectorBundleKlyachko,
	  ToricVectorBundle}
     
          }
     	  
document {     
     Key => ToricVectorBundleKlyachko,
     Headline => "the class of all toric vector bundles in Klyachko's description",
     
     TEX ///"A toric vector bundle on a toric variety $X$ is a locally free sheaf $E$
     together with an action of the torus $T$ on the geometric vector bundle $V(E)$
     such that the projection to the base $X$ is equivariant, and the action of $T$ on the fibers is linear. 
     There also is an induced action of $T$ on the local sections $s \in{}  \Gamma(U,E)$ 
     given by $(t*s)(x) = t^{ -1}(s(t x))$ . This implies that a regular section $x^u \in{}  \Gamma(X,O_X)$ 
     for an element $u$ in the character lattice $M$ also has weight $u$. 
     Other choices for the induced action are possible. In fact, the upper one is different from Klyachko's in his original description 
     where $x^u \in{}  \Gamma(X,O_X)$ has weight $-u$. 
     We denote by $E_0$ the fiber over the unit $t_0 \in{} T$,
     and by $U_\sigma \subset X$ the open affine torus invariant subset associated with the cone $\sigma$. 
     The primitive generator of the ray $\rho$ in the fan $\Sigma$ is denoted by $v_\rho$.
     Evaluating local homogeneous sections $\Gamma(U_{\rho},E)_u$ of weight $u$ at $t_0$ 
     provides us with an embedding of these finite dimensional vector spaces into $E_0$. One can show that 
     the upper choice of the induced torus action implies that the image of $\Gamma(U_\rho,E)_{u_1}$ is contained 
     in the image of $\Gamma(U_\rho,E)_{u_2}$ if and only if  the pairing  $(u_1-u_2,v_\rho) \leq 0$. 
     Furthermore one observes that the image only depends on the class of the weight $u$ 
     in the quotient lattice $M_\rho := M/M^\rho$, where $M^\rho$ denotes the intersection of $M$ 
     with the vector space perpendicular to the ray $\rho$. Since $M_\rho \cong \mathbb{Z}$ we denote the 
     image of $\Gamma(U_\rho,E)_u$ in $E_0$ by $E^\rho(i)$ with $i = (u,v_\rho)$. 
     Each ray $\rho \in{} \Sigma$ thus gives rise to an increasing filtration $\{E^\rho(i)\}$ of $E_0$. 
     Since $E_0$ is finite dimensional there is only a finite set of integers 
     $i$ for which a jump occurs, i.e., $E^\rho(i)$ strictly contains 
     $E^\rho(i-1)$. At all other steps the filtration remains constant. 
     Apart from that, each open affine subset $U_\sigma$ for $\sigma \in{} \Sigma$ induces a direct sum 
     decomposition of $E_0 = \oplus_{u \in{} M_\sigma}E^\sigma_u$ such that $E^\rho(i) = \sum_{(u,v_\rho) \leq i} E^\sigma_u$ 
     for each $\rho \in{} \sigma$ and $i \in{} \mathbb{Z}$. Observe that the lattice $M_\sigma$ 
     is defined analogously to the lattice $M_\rho$, i.e., it is the quotient lattice $M/M^\sigma$ where
     $M^\sigma$ denotes the intersection of $M$ with the vector space perpendicular to the cone $\sigma$."///,
     
     
     PARA{},"With the notation and conventions introduced above it is now possible to state the fundamental theorem of Klyachko which completely
     describes toric vector bundles in linear algebraic terms:",
     
     
     PARA{},TT "The category of toric vector bundles on the toric variety ",TEX ///$X$///, TT " is equivalent to the category of finite 
     dimensional ",TEX ///$k$///, TT"-vector spaces ",TEX ///$E_0$///, TT" with collections of increasing filtrations 
     ",TEX ///$\{E^{\rho}(i)| i \in{} \mathbb{Z}\}$///, TT", indexed by the rays of ",TEX ///$\Sigma$///, TT", satisfying the following 
     compatibility condition: For each cone ",TEX ///$\sigma \in{} \Sigma$///, TT" there is a decomposition ",TEX ///$E_0 = \oplus_{u \in{} M_\sigma} E_u$///, TT" 
     such that ",TEX ///$E^{\rho}(i) = \sum_{(u,v_\rho) \leq i} E_u$///, TT" for every ray ",TEX ///$\rho \in{} \sigma$///, TT" and 
     every ",TEX ///$i \in{} \mathbb{Z}$///,".",
               
       
     PARA{}, TEX ///"In contrast to the implementation of Kaneyama's description this one 
     works for every toric variety $X$ i.e., there are no restrictions on the fan $\Sigma$. 
     For each ray $\rho$ of the fan $\Sigma$ 
     there are two matrices comprising the necessary filtration data. The first one is  an invertible matrix $A(\rho) \in{} $ 
     GL("///,TT "k",",",TO QQ,TEX ///") whose columns contain a basis of the vector space $E_0$ which is associated to the 
     filtration corresponding to the ray $\rho$. The second one is a ",TT "1 x k"," integer matrix, the so 
     called filtration matrix. It determines at which step an element of the basis given in the first matrix actually contributes to 
     a certain subspace in the filtration, i.e., if the j-th entry of the filtration matrix is i then the j-th basis vector appears at the 
     i-th step in the filtration. Hence $E^{\rho}(i)$ is generated by all basis vectors listed
     in $A(\rho)$ whose corresponding entry in the filtration matrix is less or equal to $E_0$."///, 
          
     
     PARA{}, TEX ///"To link up to the description of Kaneyama we will also discuss the example of the cotangent bundle $\mathbf{\Omega}_X$
     of $X = \mathbb{P}^2$. Recall that $X$ can be given by the complete 
     fan with rays $\rho_1 = (1,0)$, $\rho_2 = (0,1)$, and $\rho_3 = (-1,-1)$. There are three maximal 
     cones, namely $\sigma_1$ spanned by $\rho_1,\rho_2$,  $\sigma_2$ spanned by 
     $\rho_2,\rho_3$, and $\sigma_3$ spanned by $\rho_3,\rho_1$.
     Each of them corresponds to a torus invariant affine chart $U_{\sigma_i}$. It follows that the $k[\sigma_1^v \cap M]$-module 
     $\Gamma(U_{\sigma_1},\Omega_X)$ is generated by $dx := d(x^{[1,0]})$, and $dy := d(x^{[0,1]})$, 
     and analogously for the remaining charts. We now fix a basis of $\Omega_0$ by evaluating the sections $dx,dy$ 
     at the unit $t_0$. This gives rise to filtrations $\Omega^\rho(i)$. We only consider the example $\rho = \rho_3$.
     The filtrations for the two other rays can be found by analogous calculations. 
     Now, $k[U_{\rho_3}] = k[x^{-1},x^{-1}y,xy^{-1}]$. Then, $\Gamma(U_{\rho_3},\Omega_X)$ is generated as a 
     $k[U_{\rho_3}]$-module by $-x^{-2}dx, -x^{-2}ydx + x^{-1}dy$. Thus, 
     $\Gamma(U_{\rho_3},\Omega_X)_{[1,0]} = 0$, $\Gamma(U_{\rho_3},\Omega_X)_{[0,0]}$ is generated by 
     $xy^{-1}(-x^{-2}ydx + x^{-1}dy)$, and $\Gamma(U_{\rho_3},\Omega_X)_{[-1,0]}$ 
     is two-dimensional. Since $[1,0], [0,0]$, and $[-1,0]$ pair with $v_{\rho_3}=(-1,-1)$
     to respectively $-1, 0$, and $1$, the filtration $\Omega^{\rho_3}(i)$ jumps at 
     $1$ and $0$ with corresponding basis vectors $(0,-1)$ and $(-1,1)$. 
     Since $\Omega_X$ already is a vector bundle we do not have to check the compatibility conditions."///,
               
         
     PARA{},"An instance of class ToricVectorBundleKlyachko, when displayed or printed, gives an overview 
     of the characteristics of the bundle:",     
     
     EXAMPLE {
	  " E = cotangentBundle(projectiveSpaceFan 2) "
	  },
     
     PARA{}, "To see all relevant details of a bundle use ",TO details,". The data described above are stored in a single hash table. 
              In the example from above, the keys are the rays of the fan, and each of them comes with a base matrix and a filtration matrix:",
     
     EXAMPLE {
	  " details E"
	  },
     
     SeeAlso => {ToricVectorBundleKaneyama,
	  ToricVectorBundle}
     
     }

document {
     Key => {addBaseChange, (addBaseChange,ToricVectorBundleKaneyama,List)},
     Headline => "changing the transition matrices of a toric vector bundle",
     Usage => " F = addBaseChange(E,L)",
     Inputs => {
	  "E" => ToricVectorBundleKaneyama,
	  "L" => List  => {"with matrices over ",TO ZZ," or ",TO QQ}
	  },
     Outputs => {
	  "F" => ToricVectorBundleKaneyama
	  },
     
     PARA{}, TT "addBaseChange"," replaces the transition matrices in ",TT "E"," by the matrices in 
     the ",TO List," ",TT "L",". The matrices in ",TT "L"," must be in GL(",TEX///$k$///,",",TO ZZ,") or 
     GL(",TEX///$k$///,",",TO QQ,"), where ",TEX///$k$///," is the rank of the vector bundle ",TT "T",". 
     The list has to contain one matrix for each maximal dimensional cone of the underlying fan over 
     which ",TT "E"," is defined. The fan can be recovered with ",TO (fan,ToricVectorBundle),". 
     The vector bundle already has a list of pairs ",TEX///$(i,j)$///," denoting the codim 1 intersections 
     of two maximal cones with ",TEX///$i<j$///," and they are ordered in lexicographic order. The matrices 
     will be assigned to the pairs ",TEX///$(i,j)$///," in that order. To see which codimension 1 cone 
     corresponds to the pair ",TEX///$(i,j)$///," use ",TO (details,ToricVectorBundle),". The 
     matrix ",TEX///$A$///," assigned to ",TEX///$(i,j)$///," denotes the transition 
     ",TEX///$(e_i^1,...,e_i^k) = (e_j^1,...,e_j^k)*A$///,". The matrices need not satisfy the regularity 
     or the cocycle condition. These can be checked with ",TO regCheck," and ",TO cocycleCheck,".",
     
     EXAMPLE {
	  " E = toricVectorBundle(2,pp1ProductFan 2,\"Type\" => \"Kaneyama\")",
	  " details E",
	  " F = addBaseChange(E,{matrix{{1,2},{0,1}},matrix{{1,0},{3,1}},matrix{{1,-2},{0,1}},matrix{{1,0},{-3,1}}})",
	  " details F",
	  " cocycleCheck F"
	  },
     
     SeeAlso => {addDegrees,regCheck,cocycleCheck}
     
     }

document {
     Key => {addBase, (addBase,ToricVectorBundleKlyachko,List)},
     Headline => "changing the basis matrices of a toric vector bundle in Klyachko's description",
     Usage => "F = addBase(E,L)",
     Inputs => {
	  "E" => ToricVectorBundleKlyachko,
	  "L" => List => {"with matrices over ",TO ZZ," or ",TO QQ}
	  },
     Outputs => {
	  "F" => ToricVectorBundleKlyachko
	  },
     
     PARA{}, TT "addBase"," replaces the basis matrices in ",TT "E"," by the matrices in 
     the ",TO List," ",TT "L",". The matrices in ",TT "L"," must be in GL(",TEX///$k,R$///,"), 
     where ",TEX///$k$///," is the rank of the vector bundle ",TT "E"," and ",TEX///$R$///," 
     is ",TO ZZ," or ",TO QQ,". The list has to contain one matrix for each ray of the 
     underlying fan over which ",TT "E"," is defined. Note that in ",TT "E"," the rays are 
     already sorted and that the basis matrices in ",TT "L"," will be assigned to the 
     rays in that order. To see the order use ",TO (rays,ToricVectorBundle),".",
     
     PARA{}, "The matrices need not satisfy the compatibility condition. This can 
     be checked with ",TO isVectorBundle,".",
     
     EXAMPLE {
	  " E = toricVectorBundle(2,pp1ProductFan 2)",
	  " details E",
	  " F = addBase(E,{matrix{{1,2},{3,1}},matrix{{-1,0},{3,1}},matrix{{1,2},{-3,-1}},matrix{{-1,0},{-3,-1}}})",
	  " details F",
	  " isVectorBundle F"
	  },
     
     SeeAlso => {base,addFiltration,isVectorBundle}
     
     }

document {
     Key => {addDegrees, (addDegrees,ToricVectorBundleKaneyama,List)},
     Headline => "changing the degrees of a toric vector bundle",
     Usage => " F = addDegrees(E,L)",
     Inputs => {
	  "E" => ToricVectorBundleKaneyama,
	  "L" => List => {"with matrices over ",TO ZZ}
	  },
     Outputs => {
	  "F" => ToricVectorBundleKaneyama
	  },
     
     PARA{}, TT "addDegrees"," replaces the degree matrices in ",TT "E"," by the matrices in 
     the ",TO List," ",TT "L",". The matrices in ",TT "L"," must be ",TEX///$n$///," by ",TEX///$k$///," 
     matrices over ",TO ZZ,", where ",TEX///$k$///," is the rank of the vector bundle ",TT "E"," 
     and ",TEX///$n$///," is the dimension of the underlying toric variety. The list has to contain one 
     matrix for each maximal dimensional cone of the underlying fan over which ",TT "E"," is defined. 
     Note that in ",TT "E"," the top dimensional cones are already sorted and that the degree matrices 
     in ",TT "L"," will be assigned to the cones in that order. To find out the order use ",TO (maxCones,ToricVectorBundle),". 
     The matrices need not satisfy the regularity condition. This can be checked with ",TO regCheck,".",
     
     EXAMPLE {
	  " E = toricVectorBundle(2,pp1ProductFan 2,\"Type\" => \"Kaneyama\")",
	  " details E",
	  " F = addDegrees(E,{matrix{{1,2},{3,1}},matrix{{-1,0},{3,1}},matrix{{1,2},{-3,-1}},matrix{{-1,0},{-3,-1}}})",
	  " details F",
	  " regCheck F"
	  },
     
     SeeAlso => {addBaseChange,regCheck,cocycleCheck}
     
     }

document {
     Key => {addFiltration, (addFiltration,ToricVectorBundleKlyachko,List)},
     Headline => "changing the filtration matrices of a toric vector bundle in Klyachko's description",
     Usage => "F = addFiltration(E,L)",
     Inputs => {
	  "E" => ToricVectorBundleKlyachko,
	  "L" => List => {"with matrices over ",TO ZZ}
	  },
     Outputs => {
	  "F" => ToricVectorBundleKlyachko
	  },
     
     PARA{}, TT "addFiltration"," replaces the filtration matrices in ",TT "E"," by the matrices in 
     the ",TO List," ",TT "L",". The matrices in ",TT "L"," must be ",TEX///$1$///," by ",TEX///$k$///," 
     matrices over ",TO ZZ,", where ",TEX///$k$///," is the rank of the vector bundle ",TT "E",". The 
     list has to contain one matrix for each ray of the underlying fan over which ",TT "E"," is defined. 
     Note that in ",TT "E"," the rays are already sorted and that the filtration matrices in ",TT "L"," 
     will be assigned to the rays in that order. To see the order, use ",TO (rays,ToricVectorBundle),".",
     
     PARA{}, TEX ///"The filtration on the vector bundle over a ray is given by the filtration matrix for this 
     ray in the following way: The first index $j$, such that the $i$-th basis 
     vector in the basis over this ray appears in the $j$-th step of the filtration, is the 
     $i$-th entry of the filtration matrix. OR in other words, the $j$-th step 
     step in the filtration is given by all columns of the basis matrix for which the corresponding entry 
     in the filtration matrix is less or equal to $j$."///,
     
     PARA{}, "The matrices need not satisfy the compatibility condition. This can be checked 
     with ",TO isVectorBundle,".",
     
     EXAMPLE {
	  " E = toricVectorBundle(2,pp1ProductFan 2)",
	  " details E",
	  " F = addFiltration(E,{matrix{{1,3}},matrix{{-1,3}},matrix{{2,-3}},matrix{{0,-1}}})",
	  " details F",
	  " isVectorBundle F"
	  },
     
     PARA{}, "This means that for example over the first ray the first basis vector of the filtration of ",TT "F"," 
     appears at the filtration step 1 and the second at 3.",
     
     SeeAlso => {filtration,addBase,isVectorBundle}
     
     }

document {
     Key => {areIsomorphic, (areIsomorphic,ToricVectorBundleKlyachko,ToricVectorBundleKlyachko)},
     Headline => "checks if two vector bundles are isomorphic",
     Usage => " b = areIsomorphic(E,F)",
     Inputs => {
	  "E" => ToricVectorBundleKlyachko,
	  "F" => ToricVectorBundleKlyachko
	  },
     Outputs => {
	  "b" => Boolean => {"whether ", TT "E", " and ", TT "F", " are isomorphic"}
	  },     
     
     PARA{}, TT "E"," and ",TT "F"," must be vector bundles over the same fan. Two equivariant vector 
     bundles in Klyachko's description are isomorphic if there exists a simultaneous isomorphism for 
     the filtered vector spaces of all rays. The method then returns whether the bundles are 
     isomorphic.",     
     
     EXAMPLE {
	  " HF = hirzebruchFan 2",
	  " E = exteriorPower(2, cotangentBundle HF)",
	  " F = weilToCartier({-1,-1,-1,-1},HF)",
	  " areIsomorphic(E,F)"
	  },
     
     PARA{}, "To obtain the isomorphism, if two bundles are isomorphic use ",TO isomorphism,".",
     
     SeeAlso => {isomorphism,base,filtration,details}
     
     }

document {
     Key => {base, (base,ToricVectorBundleKlyachko)},
     Headline => " the basis matrices for the rays",
     Usage => " b = base E",
     Inputs => {
	  "E" => ToricVectorBundleKlyachko
	  },
     Outputs => {
	  "b" => HashTable
	  },
     
     PARA{}, "The basis of a toric vector bundle in Klyachko's description is given for each ray as a square 
     matrix of rank ",TEX///$k$///," of the bundle. The output is a ",TO HashTable," where the keys are the 
     rays of the fan given as one column matrices over ",TO ZZ,", and for each ray a ",TEX///$k$///," 
     by ",TEX///$k$///," matrix over ",TO QQ," and ",TEX///$k$///," is the rank of the bundle.",
     
     EXAMPLE {
	  " E = tangentBundle hirzebruchFan 3",
	  " base E"
	  },
     
     SeeAlso => {addBase,filtration,isVectorBundle}
     
     }

document {
     Key => {cartierIndex, (cartierIndex,List,Fan)},
     Headline => " the Cartier index of a Weil divisor",
     Usage => " N = cartierIndex(L,F)",
     Inputs => {
	  "L" => List,
	  "F" => Fan => {"a pure and full dimensional fan"}
	  },
     Outputs => {
	  "N" => ZZ
	  },
     
     PARA{}, TT "L"," must be a list of weights, 
     exactly one for each ray of the fan. Then the Cartier index is the smallest strictly positive 
     natural number ",TEX ///$N$///," such that ",TEX ///$N$///," times the Weil divisor is Cartier. 
     If the Weil divisor defined by these weights is not ",TO QQ,"-Cartier, then ",TEX ///$N$///," would 
     be infinity. In this case ",TT "cartierIndex"," returns an error. Otherwise it returns ",TEX ///$N$///,".",
     
     EXAMPLE {
	  " F = fan posHull matrix {{1,5},{5,1}}",
	  " L = {2,2}",
	  " cartierIndex(L,F)"
	  },
     
     PARA{}, "If we change the Weil divisor we get a different Cartier index:",
     
     EXAMPLE {
	  " L = {3,3}",
	  " cartierIndex(L,F)"
	  },
     
     SeeAlso => {weilToCartier}
     
     }

document {
     Key => {charts, (charts,ToricVectorBundle)},
     Headline => " the number of maximal affine charts",
     Usage => " n = charts E",
     Inputs => {
	  "E" => ToricVectorBundle
	  },
     Outputs => {
	  "n" => ZZ
	  },
     
     PARA{}, "The function ",TT "charts"," returns the number of maximal cones in the underlying 
     fan, i.e., the number of affine charts.",
     
     EXAMPLE {
	  " E = cotangentBundle pp1ProductFan 3",
	  " charts E"
	  },
     
     SeeAlso => {"OldPolyhedra::Fan",(fan,ToricVectorBundle)}
     
     }

document {
     Key => {cocycleCheck, (cocycleCheck,ToricVectorBundleKaneyama)},
     Headline => " checks if a toric vector bundle fulfills the cocycle condition",
     Usage => " b = cocycleCheck E",
     Inputs => {
	  "E" => ToricVectorBundleKaneyama 
	  },
     Outputs => {
	  "b" => Boolean => {"whether ", TT "E", " satisfies the cocyle condition"}
	  },
     
     PARA{}, "The transition matrices in ",TT "E"," define an equivariant toric vector bundle 
     if they satisfy the cocycle condition. I.e. in this implementation of complete fans this 
     means that for every codimension 2 cone of the fan the cycle of transition matrices of 
     codimension 1 cones containing the codimension 2 cone gives the identity when multiplied.",
     
     EXAMPLE {
	  " E = toricVectorBundle(2,pp1ProductFan 2,\"Type\" => \"Kaneyama\")",
	  " details E",
	  " A = matrix{{1,2},{0,1}};",
	  " B = matrix{{1,0},{3,1}};",
	  " C = matrix{{1,-2},{0,1}};",
	  " E1 = addBaseChange(E,{A,B,C,matrix{{1,0},{0,1}}})",
	  " cocycleCheck E1",
	  " D = inverse(B)*A*C",
	  " E1 = addBaseChange(E,{A,B,C,D})",
	  " cocycleCheck E1"
	  },
     
     SeeAlso => {addBaseChange,addDegrees,regCheck}
     
     }

document {
     Key => {(cohomology,ZZ,ToricVectorBundle)},
     Headline => " the i-th cohomology group of a toric vector bundle",
     Usage => " c = HH^i E ",
     Inputs => {
	  "i" => ZZ,
	  "T" => ToricVectorBundle
	  },
     Outputs => {
	  "c" => Module
	  },
     
     PARA{}, "Computes the ",TEX///$i$///,"-th cohomology group of the toric vector bundle ",TEX///$E$///,". The 
     output is the ",TEX///$i$///,"-th cohomology group as a multigraded module. For this, it computes the 
     set of all degrees that can give non-zero cohomology (see ",TO deltaE,"). This set is finite if the 
     underlying toric variety is complete. If the toric variety is not complete then an error is returned.",
     
     PARA{},"The computation of the cohomology groups for a toric vector bundle given in terms of Kaneyama is done by 
     the usual Cech cohomology complex, again separately for every degree ",TEX///$u \in{} M$///,".",
     
     PARA{}, "If the option ",TT "Degree => 1"," is used then it displays the number of degrees for which 
     it computes the cohomology. ",TEX///$i$///," must be between ",TEX///$0$///," and the dimension of 
     the underlying toric variety.",
     
     EXAMPLE {
	  " E = tangentBundle(hirzebruchFan 3,\"Type\" => \"Kaneyama\")",
	  " HH^0 E",
	  " HH^0 (E,Degree => 1)"
	  },
     
     PARA{}, TEX ///"In case the toric vector bundle $E$ is given in Klyachko's description, there is a 
     special exact sequence of finite dimensional vector spaces for every weight $u \in{} M$ 
     whose cohomology groups in degree $i$ are isomorphic to $H^i(X,E)$. This exact
     sequence can be found in the Klyachko's paper listed on the main page of the documentation."///,
     
     PARA{}, "If the option ",TT "Degree => 1"," is used then it displays the number of degrees for which 
     it computes the cohomology. ",TEX///$i$///," must be between ",TEX///$0$///," and the dimension of 
     the underlying toric variety.",
     
     EXAMPLE {
	  " E = tangentBundle hirzebruchFan 3",
	  " HH^0 E",
	  " HH^0 (E,Degree => 1)"
	  },
     
     SeeAlso => {(ring,ToricVectorBundle),
	  deltaE,
	  (cohomology,ZZ,ToricVectorBundle,Matrix),
	  (cohomology,ZZ,ToricVectorBundle,List),
	  (hh,ZZ,ToricVectorBundle),
	  eulerChi}
     
     }

document {
     Key => {(cohomology,ZZ,ToricVectorBundle,List)},
     Headline => " the i-th cohomology of a toric vector bundle for a given list of degrees",
     Usage => " c = HH_i^E L",
     Inputs => {
	  "i" => ZZ,
	  "E" => ToricVectorBundle,
	  "L" => List => {" containing weights of the form, one column matrix over ",TO ZZ}
	  },
     Outputs => {
	  "c" => List
	  },
     
     PARA{}, TEX ///"Computes the $i$-th cohomology of the toric vector bundle $E$ for a 
     given list of degrees. For this $i$ must be between $0$ and the rank of 
     the vector bundle. The entries of the list "///,TT "L"," must be one column matrices each defining a point 
     in the lattice of the fan over which ",TEX///$E$///," is defined",
     
     EXAMPLE {
	  " E = tangentBundle hirzebruchFan 3",
	  " HH_0^E {matrix{{1},{0}},matrix{{-1},{0}}}"
	  },
     
     SeeAlso => {(ring,ToricVectorBundle),
	  deltaE,
	  (cohomology,ZZ,ToricVectorBundle),
	  (cohomology,ZZ,ToricVectorBundle,Matrix),
	  (hh,ZZ,ToricVectorBundle),
	  eulerChi}
     
     }

document {
     Key => {(cohomology,ZZ,ToricVectorBundle,Matrix)},
     Headline => " the i-th cohomology of a toric vector bundle in a given degree",
     Usage => " c = HH_i^E u ",
     Inputs => {
	  "i" => ZZ,
	  "E" => ToricVectorBundle,
	  "u" => Matrix => {"over ",TO ZZ," with just one column, giving a weight in the lattice"}
	  },
     Outputs => {
	  "c" => Module
	  },
     
     PARA{}, TEX ///"Computes the $i$-th cohomology group of the toric vector bundle $E$ of 
     degree $u$ where $u$ must be a one-column matrix giving a point in the 
     lattice of the fan over which $E$ is defined and $i$ must be between $0$ 
     and the dimension of the underlying toric variety."///,
     
     EXAMPLE {
	  " E = tangentBundle hirzebruchFan 3",
	  " HH^0 (E,matrix{{1},{0}})"
	  },
     
     SeeAlso => {(ring,ToricVectorBundle),
	  deltaE,
	  (cohomology,ZZ,ToricVectorBundle),
	  (cohomology,ZZ,ToricVectorBundle,List),
	  (hh,ZZ,ToricVectorBundle),
	  eulerChi}
          
     }

document {
     Key => {(coker,ToricVectorBundleKlyachko,Matrix)},
     Headline => " the cokernel of a morphism to a vector bundle",
     Usage => " E1 = coker(E,M)",
     Inputs => {
	  "E" => ToricVectorBundleKlyachko,
	  "M" => Matrix => {"over ",TO ZZ," or ",TO QQ}
	  },
     Outputs => {
	  "E1" => ToricVectorBundleKlyachko
	  },
     
     PARA{}, TT "M"," must be a matrix over ",TO ZZ," or ",TO QQ," where the target space is the space 
     of the bundle, i.e., the matrix must have ",TEX///$k$///," rows if the bundle has rank 
     ",TEX///$k$///,". Then the new bundle is given on each ray ",TEX///$\rho$///," by the following 
     filtration of coker(E,M)",TEX///${}^\rho = ( E^{\rho} ) / $///,"im(M) :",
     
     PARA{}, "coker(E,M)",TEX///${}^\rho(i) := E^{\rho}(i) / ( E^{\rho}(i) \cap $///," im(M) ).",
     
     EXAMPLE {
	  " E = tangentBundle hirzebruchFan 2",
	  " E = E ** E",
	  " M = matrix {{1,0},{0,1},{1,0},{0,1/1}}",
	  " E1 = coker(E,M)",
	  " details E1"
	  },
     
     SeeAlso => {(image,ToricVectorBundleKlyachko,Matrix),
	  (ker,ToricVectorBundleKlyachko,Matrix)}
     
     }

document {
     Key => {cotangentBundle, (cotangentBundle,Fan)},
     Headline => " the cotangent bundle on a toric variety",
     Usage => " E = cotangentBundle F",
     Inputs => {
	  "F" => Fan
	  },
     Outputs => {
	  "E" => {ofClass ToricVectorBundleKaneyama," or ",ofClass ToricVectorBundleKlyachko}
	  },
     
     PARA{}, "If the fan ",TT "F"," is pure, of full dimension and smooth, then the function generates the 
     cotangent bundle of the toric variety given by ",TT "F",". If no further options are given then the 
     resulting bundle will be in Klyachko's description:",
     
     EXAMPLE {
	  " F = projectiveSpaceFan 2",
	  " E = tangentBundle F",
	  " details E"
	  },
     
     PARA{}, "If the option ",TT "\"Type\" => \"Kaneyama\""," is given then the resulting bundle will be in 
     Kaneyama's description:",
     
     EXAMPLE {
	  " F = projectiveSpaceFan 2",
	  " E = tangentBundle(F,\"Type\" => \"Kaneyama\")",
	  " details E"
	  },
     
     SeeAlso => {tangentBundle}
     
     }

document {
     Key => {deltaE, (deltaE,ToricVectorBundle)},
     Headline => " the polytope of possible degrees that give non zero cohomology",
     Usage => " P = deltaE E",
     Inputs => {
	  "E" => ToricVectorBundle
	  },
     Outputs => {
	  "P" => Polyhedron
	  },
     
     PARA{}, "For a toric vector bundle over a complete toric variety there is a finite set of 
     degrees ",TEX///$u$///," such that the degree ",TEX///$u$///," part of the cohomology of the 
     vector bundle is non-zero. This function computes a polytope ",TEX///$\Delta_E$///,", such 
     that these degrees are contained in this polytope. If the underlying toric variety is not 
     complete then an error is returned.",
     
     EXAMPLE {
	  " E = toricVectorBundle(2,pp1ProductFan 2, \"Type\" => \"Kaneyama\")",
	  " P = deltaE E",
	  " vertices P",
	  " E1 = tangentBundle projectiveSpaceFan 2",
	  " P1 = deltaE E1",
	  " vertices P1"
	  },
     
     SeeAlso => {eulerChi,
	  (cohomology,ZZ,ToricVectorBundle),
	  (hh,ZZ,ToricVectorBundle)}
     
     }

document {
     Key => {details, (details,ToricVectorBundle)},
     Headline => " the details of a toric vector bundle",
     Usage => " ht = details E",
     Inputs => {
	  "E" => ToricVectorBundle
	  },
     Outputs => {
	  "ht" => Sequence => {" or ",TO HashTable," if the bundle is in Klyachko's description"}
	  },
     
     PARA{}, "For a toric vector bundle in Kaneyama's description, the sequence ",TT "ht"," contains 
     a hash table that assigns to each maximal cone ",TEX///$\sigma$///," of the underlying fan 
     its matrix of rays and its matrix of degrees, and a hash table giving a transition matrix for 
     every pair of maximal cones that intersect in a codimension 1 face.",
     
     EXAMPLE {
	  " E = tangentBundle(pp1ProductFan 2,\"Type\" => \"Kaneyama\")",
	  "details E"
	  },
     
     PARA{}, "For a toric vector bundle in Klyachko's description, the hash table ",TT "ht"," contains 
     the rays of the underlying fan and for each ray the basis of the bundle over this ray and the 
     filtration matrix.",
     
     EXAMPLE {
	  " E = tangentBundle pp1ProductFan 2",
	  "details E"
	  }
     
     }

document {
     Key => (dual,ToricVectorBundle),
     Headline => " the dual bundle of a toric vector bundle",
     Usage => " Ed = dual E",
     Inputs => {
	  "E" => ToricVectorBundle
	  },
     Outputs => {
	  "Ed" => ToricVectorBundle
	  },
     
     PARA{}, TT "dual"," computes the dual vector bundle of a toric vector bundle.",
     
     EXAMPLE {
	  " E = tangentBundle(pp1ProductFan 2,\"Type\" => \"Kaneyama\")",
	  " Ed = dual E",
	  " details Ed",
	  " Ed == cotangentBundle(pp1ProductFan 2,\"Type\" => \"Kaneyama\")"
	  },
     
     EXAMPLE {
	  " E = tangentBundle projectiveSpaceFan 2",
	  " Ed = dual E",
	  " details Ed",
	  " Ed == cotangentBundle projectiveSpaceFan 2"
	  },
     
     SeeAlso => {tangentBundle,cotangentBundle}
     
     }

document {
     Key => {eulerChi, (eulerChi,ToricVectorBundle), (eulerChi,Matrix,ToricVectorBundle)},
     Headline => " the Euler characteristic of a toric vector bundle",
     Usage => " i = eulerChi E \neulerChi(u,E)",
     Inputs => {
	  "E" => ToricVectorBundle,
	  "u" => Matrix => {"with just one column over ",TO ZZ," representing a degree vector"}
	  },
     Outputs => {
	  "i" => ZZ
	  },
     
     PARA{}, "This function computes the Euler characteristic of a vector bundle if only the bundle is given 
     to the function. For this it first computes the set of all degrees that give non-zero cohomology 
     (see ",TO deltaE,") and then computes the Euler characteristic for each these degrees. If the underlying 
     variety is not complete then this set may not be finite. Thus, for a non-complete toric variety an error 
     is returned.",
     
     PARA{},  "If in addition a one-column matrix over ",TO ZZ,", representing a degree vector ",TT "u",", is given, it 
     computes the Euler characteristic of the degree ",TT "u","-part of the vector bundle ",TT "E",". For this the variety 
     need not be complete.",
     
     EXAMPLE {
	  " E = tangentBundle hirzebruchFan 3",
	  " u = matrix {{0},{0}}",
	  " eulerChi(u,E)",
	  " eulerChi E"
	  },
     
     EXAMPLE {
	  " E = tangentBundle(hirzebruchFan 3,\"Type\" => \"Kaneyama\")",
	  " u = matrix {{0},{0}}",
	  " eulerChi(u,E)",
	  " eulerChi E"
	  },
     
     SeeAlso => {deltaE,
	  (cohomology,ZZ,ToricVectorBundle),
	  (hh,ZZ,ToricVectorBundle)}
     
     }

document {
     Key => {existsDecomposition, (existsDecomposition,ToricVectorBundleKlyachko,List)},
     Headline => " checks if a list of matrices of weight vectors for each maximal cone admits a decomposition",
     Usage => " b = existsDecomposition(E,L)",
     Inputs => {
	  "E" => ToricVectorBundleKlyachko,
	  "L" => List
	  },
     Outputs => {
	  "b" => Boolean => {"whether there exists a decomposition"}
	  },
     
     PARA{}, "The list ",TT "L"," must have one entry for each maximal cone ",TEX///$\sigma$///," in the 
     underlying fan ",TEX///$\Sigma$///," of ",TT "E",". If the rank of the bundle is ",TEX///$k$///," and 
     the ambient dimension of the variety is ",TEX///$n$///," then each entry must either be 
     an ",TEX///$n$///," by ",TEX///$k$///," matrix over ",TO ZZ," or a list of these. Then it checks for 
     each maximal cone in the fan (given in the order of ",TO (maxCones,ToricVectorBundle),") if 
     for any of the matrices in the corresponding entry in ",TT "L"," these weight vectors admit a decomposition 
     of the bundle into torus eigenspaces. See ",
     HREF("http://math.stanford.edu/~sampayne/", "Sam Payne's"), " ", EM "Moduli of toric vector bundles", ", 
     Compositio Math. 144, 2008. Lemma 3.5.",
     
     PARA{}, "One can for example use the output of the function ",TO findWeights,".",
     
     EXAMPLE{
	  " E = tangentBundle projectiveSpaceFan 3",
	  " L = findWeights E",
	  " existsDecomposition(E,L)"
	  },
     
     PARA{}, "Note that the data given in the description of ",TT "E"," defines an equivariant vector bundle 
     on the toric variety exactly if there exists a set of weight vectors for each maximal cone that admits a 
     decomposition. The function ",TO isVectorBundle," uses this.",
     
     SeeAlso => {findWeights,isVectorBundle,(maxCones,ToricVectorBundle)}
     
     }

document {
     Key => {(exteriorPower,ZZ,ToricVectorBundle)},
     Headline => " the 'l'-th exterior power of a toric vector bundle",
     Usage => " Ee = exteriorPower(l,E)",
     Inputs => {
	  "l" => ZZ => {" strictly positive"},
	  "E" => ToricVectorBundle
	  },
     Outputs => {
	  "Ee" => ToricVectorBundle
	  },
     
     PARA{}, TT "exteriorPower"," computes the ",TT "l","-th exterior power of a toric vector bundle in each 
     description. The resulting bundle will be given in the same description as the original bundle. 
     ",TT "l"," must be strictly positive and at most equal the rank of the bundle.",
     
     EXAMPLE {
	  " E = tangentBundle hirzebruchFan 3",
	  " details E",
	  " Ee = exteriorPower(2,E)",
	  " details Ee"
	  },
     
     SeeAlso => {(symbol ++,ToricVectorBundle,ToricVectorBundle),
	  (tensor,ToricVectorBundle,ToricVectorBundle),
	  (symmetricPower,ZZ,ToricVectorBundle)}
     
     }

document {
     Key => {(fan,ToricVectorBundle)},
     Headline => " the underlying fan of a toric vector bundle",
     Usage => " F = fan E",
     Inputs => {
	  "E" => ToricVectorBundle
	  },
     Outputs => {
	  "F" => Fan
	  },
     
     PARA{}, "Returns the fan of the underlying toric variety. This is an object of the package OldPolyhedra. 
     See also ",TO "OldPolyhedra::Fan",".",
     
     EXAMPLE {
	  " E = tangentBundle hirzebruchFan 3",
	  " F = fan E",
	  " rays F"
	  },
     
     SeeAlso => {"OldPolyhedra::Fan",charts,(maxCones,ToricVectorBundle)}
     
     }

document {
     Key => {filtration, (filtration,ToricVectorBundleKlyachko)},
     Headline => " the filtration matrices of the vector bundle",
     Usage => " f = filtration E",
     Inputs => {
	  "E" => ToricVectorBundleKlyachko
	  },
     Outputs => {
	  "f" => HashTable
	  },
     
     PARA{}, "For each ray of the fan there is a filtration matrix. If the bundle has rank ",TEX///$k$///," 
     then this is a one row matrix over ",TO ZZ," with ",TEX///$k$///," entries. This defines the 
     filtration on the corresponding base matrix (see ",TO base,") such that the ",TEX///$j$///,"-th 
     filtration is generated by all columns of the base matrix for which the entry in the same column of the 
     filtration matrix is less or equal to ",TEX///$j$///,".",
     
     EXAMPLE {
	  " E = tangentBundle hirzebruchFan 2",
	  " filtration E"
	  },
     
     PARA{}, "So in this example for each ray the first column of the basis appears at -1 and the second at 0.",
     
     SeeAlso => {addFiltration,base,isVectorBundle}
     
     }

document {
     Key => {findWeights, (findWeights,ToricVectorBundleKlyachko)},
     Headline => " finds the possible weight vectors for the maximal cones",
     Usage => " L = findWeights E",
     Inputs => {
	  "E" => ToricVectorBundleKlyachko
	  },
     Outputs => {
	  "L" => List
	  },
     
     PARA{}, "The list ",TT "L"," contains a list for each maximal cone ",TEX///$\sigma$///," of the 
     underlying fan. For each maximal cone ",TEX///$\sigma$///," this list contains all matrices of 
     possible weight vectors, that induce the filtrations on the rays of this cone (modulo permutations, 
     but yet not all permutations). This means that for one of these matrices ",TEX///$M$///," multiplied 
     with the matrix ",TEX///$R$///," of rays of this cone (the rays are the rows) gives the matrix of 
     filtrations of these rays (where for each filtration the entries may be permuted).",
     
     EXAMPLE{
	  " E = tangentBundle projectiveSpaceFan 3",
	  " findWeights E"
	  },
     
     SeeAlso => {filtration,existsDecomposition,isVectorBundle}
     
     }

document {
     Key => {(ring,ToricVectorBundle)},
     Headline => " the graded ring of the bundle",
     Usage => " R = ring E",
     Inputs => {
	  "E" => ToricVectorBundle
	  },
     Outputs => {
	  "R" => Ring
	  },
     
     PARA{}, "For a vector bundle in Kaneyama's description the graded ring is ",TO QQ," with degree 
     space the lattice of the underlying fan.",
     
     EXAMPLE{
	  " E = tangentBundle(projectiveSpaceFan 3,\"Type\" => \"Kaneyama\")",
	  " ring E"
	  },
     
     PARA{}, "For a vector bundle in Klyachko's description the graded ring is ",TO QQ," with degree 
     space the lattice of the underlying fan.",
     
     EXAMPLE{
	  " E = toricVectorBundle(1,projectiveSpaceFan 2, toList(3:matrix{{1/2}}),toList(3:matrix{{-1}}))",
	  " ring E"
	  },
     
     SeeAlso => {(cohomology,ZZ,ToricVectorBundle),
	  (cohomology,ZZ,ToricVectorBundle,Matrix),
	  (cohomology,ZZ,ToricVectorBundle,List)}
     
     }

document {
     Key => {(hh,ZZ,ToricVectorBundle)},
     Headline => " the rank of the i-th cohomology group of a toric vector bundle",
     Usage => " d = hh^i E \nd = hh^i (E,u)",
     Inputs => {
	  "i" => ZZ,
	  "E" => {"and an optional ",TT "u",", ",ofClass Matrix," over ",TO ZZ,", giving a point in the lattice of the fan"}
	  },
     Outputs => {
	  "d" => ZZ
	  },
     
     PARA{}, TT "hh^i"," computes the rank of the ",TEX///$i$///,"-th cohomology group. If no 
     further argument is given then it returns the rank of the complete cohomology group. For this 
     it computes the set of all degrees that can give non-zero cohomology (see ",TO deltaE,"). This 
     set is finite if the underlying toric variety is complete. If the toric variety is not complete, 
     then an error is returned.",
     
     PARA{}, "If in addition a one column matrix ",TEX///$u$///," over ",TO ZZ," is given it returns the 
     rank of the degree ",TEX///$u$///," part of the cohomology group. For this the variety need not be 
     complete.",
     
     EXAMPLE {
	  " E = tangentBundle hirzebruchFan 2",
	  " u = matrix{{0},{0}}",
	  " hh^0 (E,u)",
	  " hh^0 E"
	  },
     
     SeeAlso => {(cohomology,ZZ,ToricVectorBundle),
	  (cohomology,ZZ,ToricVectorBundle,Matrix),
	  (cohomology,ZZ,ToricVectorBundle,List),
	  deltaE}
     
     }

document {
     Key => {hirzebruchFan,(hirzebruchFan,ZZ)},
     Headline => "the fan of the n-th Hirzebruch surface",
     Usage => " F = hirzebruchFan n",
     Inputs => {
	  "n" => ZZ => {"positive"}
	  },
     Outputs => {
	  "F" => Fan
	  },
     
     PARA{}, "Generates the fan of the ",TEX///$n$///,"-th Hirzebruch surface.",
     
     EXAMPLE {
	  " F = hirzebruchFan 3",
	  " rays F"
	  },
     
     SeeAlso => {"OldPolyhedra::Fan",
	  "OldPolyhedra::hirzebruch",
	  pp1ProductFan,
	  projectiveSpaceFan}
     
     }

document {
     Key => {(image,ToricVectorBundleKlyachko,Matrix)},
     Headline => " the image of a vector bundle under a morphism",
     Usage => " E1 = image(E,M)",
     Inputs => {
	  "E" => ToricVectorBundleKlyachko,
	  "M" => Matrix => {"over ",TO ZZ," or ",TO QQ}
	  },
     Outputs => {
	  "E1" => ToricVectorBundleKlyachko
	  },
     
     PARA{}, TT "M"," must be a matrix over ",TO ZZ," or ",TO QQ," where the source space is the space 
     of the bundle, i.e., the matrix must have ",TEX///$k$///," columns if the bundle has rank ",TEX///$k$///,". 
     Then the new bundle is given on each ray ",TEX///$\rho$///," by the following filtration of 
     image",TEX///$(E,M)^\rho := M(E^\rho)$///," :",
     
     PARA{}, "image",TEX///$(E,M)^\rho(i) := M(E^\rho(i))$///,".",
     
     EXAMPLE {
	  " E = tangentBundle hirzebruchFan 2",
	  " E = E ** E",
	  " M = matrix {{1,0,1,0},{0,1,0,1/1}}",
	  " E1 = image(E,M)",
	  " details E1"
	  },
     
     SeeAlso => {(coker,ToricVectorBundleKlyachko,Matrix),
	  (ker,ToricVectorBundleKlyachko,Matrix)}
     
     }

document {
     Key => {isGeneral, (isGeneral,ToricVectorBundleKlyachko)},
     Headline => " checks whether a toric vector bundle is general",
     Usage => " b = isGeneral E",
     Inputs => {
	  "E" => ToricVectorBundleKlyachko
	  },
     Outputs => {
	  "b" => Boolean => {"whether ", TT "E", " is general"}
	  },
     
     PARA{}, TEX ///"A toric vector bundle in Klyachko's description is general if for every maximal cone 
     $\Sigma$ in the fan the following condition holds: Let $\rho_1,...,\rho_l$ be 
     the rays of $\sigma$. Then for every choice of filtration steps $i_1,...,i_l$ 
     for each ray, i.e., choose an integer for each ray where the filtration enlarges, the equation"///,
     
     PARA{}, "codim ",TEX///$(\cap E^{\rho_j} ( i_j )) = min \{ \sum ($///,"codim ",TEX///$E^{\rho_j} ( i_j )),rank E \}$///,
     
     PARA{}, "holds.",
     
     EXAMPLE {
	  " E = cotangentBundle hirzebruchFan 2",
	  " isGeneral E"
	  },
     
     SeeAlso => {filtration,base,randomDeformation}
     
     }

document {
     Key => {isomorphism, (isomorphism,ToricVectorBundleKlyachko,ToricVectorBundleKlyachko)},
     Headline => " the isomorphism if the two bundles are isomorphic",
     Usage => " M = isomorphism(E,F)",
     Inputs => {
	  "E" => ToricVectorBundleKlyachko,
	  "F" => ToricVectorBundleKlyachko
	  },
     Outputs => {
	  "M" => Matrix => {"over the ring over which the two bundles are defined"}
	  },
     
     PARA{}, "Two equivariant vector bundles in Klyachko's description are isomorphic if there exists a 
     simultaneous isomorphism for the filtered vector spaces of all rays. If the two bundles are isomorphic 
     (see ",TO areIsomorphic,") this function returns the isomorphism. For this, the two bundles must be 
     defined over the same fan.",
     
     EXAMPLE{
	  " HF = hirzebruchFan 2",
	  " E = exteriorPower(2, cotangentBundle HF)",
	  " F = weilToCartier({-1,-1,-1,-1},HF)",
	  " M = isomorphism(E,F)"
	  },
     
     SeeAlso => {areIsomorphic,base,filtration,details}
     
     }

document {
     Key => {isVectorBundle, (isVectorBundle,ToricVectorBundle)},
     Headline => " checks if the data does in fact define an equivariant toric vector bundle",
     Usage => " b = isVectorBundle E",
     Inputs => {
	  "E" => ToricVectorBundle
	  },
     Outputs => {
	  "b" => Boolean => {"whether ",TT "E"," defines a toric vector bundle"}
	  },
     
     PARA{}, "If ",TT "E"," is in Klyachko's description then the data in ",TT "E"," defines an equivariant 
     toric vector on the toric variety if and only if for each maximal cone exists a decomposition into 
     torus eigenspaces of the bundle. See ",HREF("http://math.stanford.edu/~sampayne/", "Sam Payne's"), " ", 
     EM "Moduli of toric vector bundles", ", Compositio Math. 144, 2008. Section 2.3. This uses the two 
     functions ",TO findWeights," and ",TO existsDecomposition,".",
     
     EXAMPLE{
	  " E = toricVectorBundle(2,pp1ProductFan 2)",
	  " E = addBase(E,{matrix{{1,2},{3,1}},matrix{{-1,0},{3,1}},matrix{{1,2},{-3,-1}},matrix{{-1,0},{-3,-1}}})",
	  " isVectorBundle E",
	  " F = toricVectorBundle(1,normalFan crossPolytope 3)",
	  " F = addFiltration(F,apply({2,1,1,2,2,1,1,2}, i -> matrix {{i}}))",
	  " isVectorBundle F"
	  },
     
     PARA{}, "If ",TT "E"," is in Kaneyama's description then data in ",TT "E"," defines an equivariant 
     toric vector bundle on the toric variety if and only if it satisfies the regularity and the cocycle 
     condition (See ",TO cocycleCheck," and ",TO regCheck,").",
     
     EXAMPLE{
	  " E = toricVectorBundle(2,pp1ProductFan 2,\"Type\" => \"Kaneyama\")",
	  " isVectorBundle E",
	  " E = addBaseChange(E,{matrix{{1,2},{3,1}},matrix{{-1,0},{3,1}},matrix{{1,2},{-3,-1}},matrix{{-1,0},{-3,-1}}})",
	  " isVectorBundle E"
	  },
     
     SeeAlso => {findWeights,
	  existsDecomposition,
	  addBase,
	  addFiltration,
	  cocycleCheck,
	  regCheck,
	  addBaseChange,
	  addDegrees,
	  details} 
     
     }

document {
     Key => {(ker,ToricVectorBundleKlyachko,Matrix)},
     Headline => " the kernel of a morphism to a vector bundle",
     Usage => " E1 = ker(E,M)",
     Inputs => {
	  "E" => ToricVectorBundleKlyachko,
	  "M" => Matrix => {"over ",TO ZZ," or ",TO QQ}
	  },
     Outputs => {
	  "E1" => ToricVectorBundleKlyachko
	  },
     
     PARA{}, TT "M"," must be a matrix over ",TO ZZ," or ",TO QQ," where the source space is the space 
     of the bundle, i.e., the matrix must have ",TEX///$k$///," columns if the bundle has rank ",TEX///$k$///,". 
     Then the new bundle is given on each ray ",TEX///$\rho$///," by the following filtration of 
     ker",TEX///$(E,M)^\rho := $///," ker",TEX///$(M) \cap (E^\rho)$///," :",
     
     PARA{}, "ker",TEX///$(E,M)^\rho(i) := $///," ker",TEX///$(M) \cap E^\rho(i)$///,".",
     
     EXAMPLE {
	  " E = tangentBundle hirzebruchFan 2",
	  " E = E ** E",
	  " M = matrix {{1,0,1,0},{0,1,0,1/1}}",
	  " E1 = ker(E,M)",
	  " details E1"
	  },
     
     SeeAlso => {(coker,ToricVectorBundleKlyachko,Matrix),
	  (image,ToricVectorBundleKlyachko,Matrix)}
     
     }

document {
     Key => {(maxCones,ToricVectorBundle)},
     Headline => " the list of maximal cones of the underlying fan",
     Usage => " L = maxCones E",
     Inputs => {
	  "E" => ToricVectorBundle
	  },
     Outputs => {
	  "L" => List => {" of cones"}
	  },
     
     PARA{}, "Returns the list of maximal cones of the underlying fan. These are the cones that 
     generate the fan, i.e., are not a face of another. See ",TO "OldPolyhedra::Fan",", ",TO "OldPolyhedra::maxCones"," 
     and ",TO "OldPolyhedra::Cone",".",
     
     EXAMPLE {
	  " E = tangentBundle pp1ProductFan 2",
	  " L = maxCones E",
	  " apply(L,rays)"
	  },
     
     EXAMPLE {
	  " E = tangentBundle(pp1ProductFan 2,\"Type\" => \"Kaneyama\")",
	  " L = maxCones E",
	  " apply(L,rays)"
	  },
     
     SeeAlso => {"OldPolyhedra::Fan",
	  "OldPolyhedra::maxCones",
	  "OldPolyhedra::Cone",
	  charts,
	  (fan,ToricVectorBundle),
	  (rays,ToricVectorBundle)}
     
     }

document {
     Key => (net,ToricVectorBundleKaneyama),
     Headline => "displays characteristics of a toric vector bundle",
     Usage => " net E",
     Inputs => {
	  "E" => ToricVectorBundleKaneyama
	  },
     
     PARA{}, "Displays an overview of the properties of a toric vector bundle, 
     the dimension of the variety, the number of affine charts, and the rank of the 
     vector bundle.",
     
     EXAMPLE {
	  " E = tangentBundle(hirzebruchFan 3,\"Type\" => \"Kaneyama\");",
	  " net E"
	  },
     
     SeeAlso => {(net,ToricVectorBundleKlyachko),
	  details}
     
     }

document {
     Key => (net,ToricVectorBundleKlyachko),
     Headline => "displays characteristics of a toric vector bundle in Klyachko's description",
     Usage => " net E",
     Inputs => {
	  "E" => ToricVectorBundleKlyachko
	  },
     
     PARA{}, "Displays an overview of the properties of a toric vector bundle, 
     the dimension of the variety, the number of affine charts, the number of rays of the fan, 
     and the rank of the vector bundle.",
     
     EXAMPLE {
	  " E = tangentBundle hirzebruchFan 3;",
	  " net E"
	  },
     
     SeeAlso => {(net,ToricVectorBundleKaneyama),
	  details}
     
     }

document {
     Key => {pp1ProductFan,(pp1ProductFan,ZZ)},
     Headline => "the fan of n products of PP^1",
     Usage => " F = pp1ProductFan n",
     Inputs => {
	  "n" => ZZ => {"strictly positive"}
	  },
     Outputs => {
	  "F" => Fan
	  },
     
     PARA{}, "Generates the fan of the product of ",TEX///$n$///," projective one-spaces. This is 
     the same as the normal fan of the ",TEX///$n$///," dimensional hypercube.",
     
     EXAMPLE {
	  " F = pp1ProductFan 2",
	  " apply(maxCones F, rays)"
	  },
     
     SeeAlso => {"OldPolyhedra::Fan",
	  hirzebruchFan,
	  projectiveSpaceFan}
     
     }

document {
     Key => {projectiveSpaceFan,(projectiveSpaceFan,ZZ)},
     Headline => "the fan of projective n space",
     Usage => " F = projectiveSpaceFan n",
     Inputs => {
	  "n" => ZZ => {"strictly positive"}
	  },
     Outputs => {
	  "F" => Fan
	  },
     
     PARA{}, "Generates the fan of projective ",TEX///$n$///,"-space.",
     
     EXAMPLE {
	  " F = projectiveSpaceFan 2",
	  " apply(maxCones F, rays)"
	  },
     
     SeeAlso => {"OldPolyhedra::Fan",
	  hirzebruchFan,
	  pp1ProductFan}
     
     }

document {
     Key => {randomDeformation, (randomDeformation,ToricVectorBundleKlyachko,ZZ), (randomDeformation,ToricVectorBundleKlyachko,ZZ,ZZ)},
     Headline => " a random deformation of a given toric vector bundle",
     Usage => " E1 = randomDeformation(E,h) \nE1 = randomDeformation(E,l,h)",
     Inputs => {
	  "E" => ToricVectorBundleKlyachko,
	  "l" => ZZ => {"less than ",TT "h"},
	  "h" => ZZ
	  },
     Outputs => {
	  "E1" => ToricVectorBundleKlyachko
	  },
     
     PARA{}, TEX ///"For a bundle of rank $k$ the 
     function "///,TT "randomDeformation",TEX ///" replaces 
     each base matrix by a random $k$ by $k$ matrix with entries
     between $l$ and $h$. For this $h$ must be greater 
     than $l$. If $l$ is not given then the random entries are between $0$ 
     and $h$ and then $h$ must be strictly positive."///,
     
     EXAMPLE {
	  " E = tangentBundle pp1ProductFan 2",
	  " details E",
	  " E1 = randomDeformation(E,-2,6)",
	  " details E1"
	  },
     
     SeeAlso => {base,filtration,details,isGeneral}
     }

document {
     Key => {(rank,ToricVectorBundle)},
     Headline => " the rank of the vector bundle",
     Usage => " k = rank E",
     Inputs => {
	  "E" => ToricVectorBundle
	  },
     Outputs => {
	  "k" => ZZ
	  },
     
     PARA{}, "Returns the rank ",TEX///$k$///," of the toric vector bundle in Kaneyama's description.",
     
     EXAMPLE {
	  " E = tangentBundle projectiveSpaceFan 3",
	  " rank E"
	  },
     
     SeeAlso => {(rays,ToricVectorBundle),
	  (fan,ToricVectorBundle),
	  charts}
     
     }

document {
     Key => {(rays,ToricVectorBundle)},
     Headline => " the rays of the underlying fan",
     Usage => " L = rays E",
     Inputs => {
	  "E" => ToricVectorBundle
	  },
     Outputs => {
	  "L" => List
	  },
     
     PARA{}, "Returns the rays of the fan of the underlying toric variety as a list. Each ray is 
     given as a one column matrix.",
     
     EXAMPLE {
	  " E = cotangentBundle projectiveSpaceFan 2",
	  " rays E"
	  },
     
     SeeAlso => {(rank,ToricVectorBundle),
	  (fan,ToricVectorBundle),
	  charts}
     
     }

document {
     Key => {regCheck, (regCheck,ToricVectorBundleKaneyama)},
     Headline => " checking the regularity condition for a toric vector bundle",
     Usage => " b = regCheck E",
     Inputs => {
	  "E" => ToricVectorBundleKaneyama
	  },
     Outputs => {
	  "b" => Boolean => {"whether ", TT "E", " satisfies the regularity condition"}
	  },
     
     PARA{}, TEX ///"For a toric vector bundle in Kaneyama's description, the regularity condition means that 
     for every pair of maximal cones $\sigma_1,\sigma_2$intersecting in a common 
     codimension-one face, the two sets of degrees $d_1,d_2$ and the transition 
     matrix $A_{1,2}$ fulfil the regularity condition. I.e. for every 
     $i$ and $j$ we have that either the $(i,j)$ entry of the 
     matrix $A_{1,2}$ is $0$ or the difference of 
     the $i$-th degree vector of $d_1$ of $\sigma_1$ and 
     the $j$-th degree vector of $d_2$ of $\sigma_2$ is in the 
     dual cone of the intersection of $\sigma_1$ and $\sigma_2$."///,
     
     PARA{}, "Note that this is only necessary for toric vector bundles generated 'by hand' 
     using ",TO addBaseChange," and ",TO addDegrees,", since bundles generated for example by 
     ",TO tangentBundle," satisfy the condition automatically.",
     
     EXAMPLE {
	  " E = tangentBundle(pp1ProductFan 2,\"Type\" => \"Kaneyama\")",
	  " regCheck E"
	  },
     
     SeeAlso => {addBaseChange,addDegrees,cocycleCheck,isVectorBundle}
     
     }

document {
     Key => {(symbol **,ToricVectorBundle,ToricVectorBundle)},
     Headline => " the tensor product of two toric vector bundles",
     Usage => " E = E1 ** E2",
     Inputs => {
	  "E1" => ToricVectorBundle,
	  "E2" => ToricVectorBundle
	  },
     Outputs => {
	  "E" => ToricVectorBundle
	  },
     
     PARA{}, "If ",TEX///$E_1$///," and ",TEX///$E_2$///," are defined over the same fan and in the same description, 
     then ",TT "tensor"," computes the tensor product of the two vector bundles in this description",
     
     EXAMPLE {
	  " E1 = toricVectorBundle(2,hirzebruchFan 3)",
	  " E2 = tangentBundle hirzebruchFan 3",
	  " E = E1 ** E2",
	  " details E"
	  },
     
     EXAMPLE {
	  " E1 = toricVectorBundle(2,hirzebruchFan 3,\"Type\" => \"Kaneyama\")",
	  " E2 = tangentBundle(hirzebruchFan 3,\"Type\" => \"Kaneyama\")",
	  " E = E1 ** E2",
	  " details E"
	  },
     
     SeeAlso => {(tensor,ToricVectorBundle,ToricVectorBundle),
	  (symbol ++,ToricVectorBundle,ToricVectorBundle),
	  (exteriorPower,ZZ,ToricVectorBundle),
	  (symmetricPower,ZZ,ToricVectorBundle)}
     
     }

document {
     Key => {(symbol ++,ToricVectorBundle,ToricVectorBundle)},
     Headline => " the direct sum of two toric vector bundles",
     Usage => " E = E1 ++ E2",
     Inputs => {
	  "E1" => ToricVectorBundle,
	  "E2" => ToricVectorBundle
	  },
     Outputs => {
	  "E" => ToricVectorBundle
	  },
     
     PARA{}, "If ",TEX///$E_1$///," and ",TEX///$E_2$///," are defined over the same fan, then ",TT "directSum"," computes 
     the direct sum of the two vector bundles. The bundles must both be given in the same description 
     and the resulting bundle will be in this description.",
     
     EXAMPLE {
	  " E1 = toricVectorBundle(2,hirzebruchFan 3)",
	  " E2 = tangentBundle hirzebruchFan 3",
	  " E = E1 ++ E2",
	  " details E"
	  },
     
     EXAMPLE {
	  " E1 = toricVectorBundle(2,hirzebruchFan 3,\"Type\" => \"Kaneyama\")",
	  " E2 = tangentBundle(hirzebruchFan 3,\"Type\" => \"Kaneyama\")",
	  " E = E1 ++ E2",
	  " details E"
	  },
     
     SeeAlso => {(symbol **,ToricVectorBundle,ToricVectorBundle),
	  (tensor,ToricVectorBundle,ToricVectorBundle),
	  (exteriorPower,ZZ,ToricVectorBundle),
	  (symmetricPower,ZZ,ToricVectorBundle)}
          
     }

document {
     Key => {(symbol ==,ToricVectorBundle,ToricVectorBundle)},
     Headline => " checks for equality",
     Usage => " b = E1 == E2",
     Inputs => {
	  "E1" => ToricVectorBundle,
	  "E2" => ToricVectorBundle
	  },
     Outputs => {
	  "E" => Boolean => {" whether the two toric vector bundles are equal"}
	  },
     
     PARA{}, "Checks if two toric vector bundles are identical. This only works if they are given in the same 
     description.",
     
     EXAMPLE {
	  " E1 = toricVectorBundle(2,hirzebruchFan 3)",
	  " E2 = tangentBundle hirzebruchFan 3",
	  " E1 == E2"
	  },
     
     EXAMPLE {
	  " E1 = toricVectorBundle(2,hirzebruchFan 3,\"Type\" => \"Kaneyama\")",
	  " E2 = tangentBundle(hirzebruchFan 3,\"Type\" => \"Kaneyama\")",
	  " E1 == E2"
	  },
     
     SeeAlso => {areIsomorphic,
	  isomorphism}
     
     }

document {
     Key => {(symmetricPower,ZZ,ToricVectorBundle)},
     Headline => " the 'l'-th symmetric power of a toric vector bundle",
     Usage => " Es = symmetricPower(l,E)",
     Inputs => {
	  "l" => ZZ => {" strictly positive"},
	  "E" => ToricVectorBundle
	  },
     Outputs => {
	  "Es" => ToricVectorBundle
	  },
     
     PARA{}, TT "symmetricPower"," computes the ",TEX///$l$///,"-th symmetric power of a toric vector bundle 
     in each description. The resulting bundle will be given in the same description as the original 
     bundle. ",TEX///$l$///," must be strictly positive.",
     
     EXAMPLE {
	  " E = tangentBundle hirzebruchFan 3",
	  " details E",
	  " Es = symmetricPower(2,E)",
	  " details Es"
	  },
     
     SeeAlso => {(exteriorPower,ZZ,ToricVectorBundle),
	  (symbol ++,ToricVectorBundle,ToricVectorBundle),
	  (tensor,ToricVectorBundle,ToricVectorBundle)}
          
     }

document {
     Key => {tangentBundle, (tangentBundle,Fan)},
     Headline => " the tangent bundle on a toric variety",
     Usage => " E = tangentBundle F",
     Inputs => {
	  "F" => Fan
	  },
     Outputs => {
	  "E" => ToricVectorBundle
	  },
     
     PARA{}, "If the fan ",TT "F"," is pure, of full dimension and smooth, then the function 
     generates the tangent bundle of the toric variety given by ",TT "F",". If no further 
     options are given then the resulting bundle will be in Klyachko's description:",
     
     EXAMPLE {
	  " F = pp1ProductFan 2",
	  " E = tangentBundle F",
	  " details E"
	  },
     
     PARA{}, "If the option ",TT "\"Type\" => \"Kaneyama\""," is given then the resulting bundle will be in 
     Kaneyama's description:",
     
     EXAMPLE {
	  " F = pp1ProductFan 2",
	  " E = tangentBundle(F,\"Type\" => \"Kaneyama\")",
	  " details E"
	  },
     
     SeeAlso => {cotangentBundle}
     
     }

document {
     Key => {(tensor,ToricVectorBundle,ToricVectorBundle)},
     Headline => " the tensor product of two toric vector bundles",
     Usage => " E = tensor(E1,E2)",
     Inputs => {
	  "E1" => ToricVectorBundle,
	  "E2" => ToricVectorBundle
	  },
     Outputs => {
	  "E" => ToricVectorBundle
	  },
     
     PARA{}, "If ",TT "E1"," and ",TT "E2"," are defined over the same fan and are in the same description, 
     then ",TT "tensor"," computes the tensor product of the two vector bundles in this description.",
     
     EXAMPLE {
	  " E1 = toricVectorBundle(2,hirzebruchFan 3)",
	  " E2 = tangentBundle hirzebruchFan 3",
	  " E = tensor(E1,E2)",
	  " details E"
	  },
     
     SeeAlso => {(symbol **,ToricVectorBundle,ToricVectorBundle),
	  (symbol ++,ToricVectorBundle,ToricVectorBundle),
	  (exteriorPower,ZZ,ToricVectorBundle),
	  (symmetricPower,ZZ,ToricVectorBundle)}
          
     }

document {
     Key => {toricVectorBundle, (toricVectorBundle,ZZ,Fan)},
     Headline => " the trivial bundle of rank 'k' for a given fan",
     Usage => " E = toricVectorBundle(k,F)",
     Inputs => {
	  "k" => ZZ => {" strictly positive"},
	  "F" => {"an object of class Fan"}
	  },
     Outputs => {
	  "E" => ToricVectorBundle
	  },
     
     PARA{}, "For a given pure, full dimensional and pointed Fan ",TT "F"," the 
     function ",TT "toricVectorBundle"," generates the trivial toric vector bundle of rank ",TT "k",".",
     
     PARA{}, TEX ///"If no further options are given then the resulting bundle will be in Klyachko's description:
     The basis assigned to every ray is the standard basis of $\mathbb{Q}^k$ and the filtration 
     is given by $0$ for all $i<0$ and $\mathbb{Q}^k$ 
     for $i>=0$."///,
     
     EXAMPLE{
	  " E = toricVectorBundle(2,projectiveSpaceFan 2)",
	  " details E"
	  },
     
     PARA{}, "If the option ",TT "\"Type\" => \"Kaneyama\""," is given then the resulting bundle will be in 
     Kaneyama's description: The degree vectors of this bundle are all zero vectors and the transition matrices 
     are all the identity. Note that for Kaneyama's description only complete, pointed fans are implemented and 
     thus a non complete fan will produce an error.",
     
     EXAMPLE {
	  " E = toricVectorBundle(2,pp1ProductFan 2,\"Type\" => \"Kaneyama\")",
	  " details E"
	  },
     
     SeeAlso => {addBaseChange,
	  addDegrees,
	  addBase,
	  addFiltration,
	  details,
	  regCheck,
	  cocycleCheck,
	  isVectorBundle}
     
     } 

document {
     Key => (toricVectorBundle,ZZ,Fan,List,List),
     Headline => " a toric vector bundle of rank 'k' with given filtrations or degrees",
     Usage => " E = toricVectorBundle(k,F,L1,L2)",
     Inputs => {
	  "k" => ZZ => {" strictly positive"},
	  "F" => {"an object of class Fan"},
	  "L1" => List,
	  "L2" => List
	  },
     Outputs => {
	  "E" => ToricVectorBundle
	  },
     
     PARA{}, "For a given pure, full dimensional and pointed fan ",TT "F"," the 
     function ",TT "toricVectorBundle"," generates the toric vector bundle of rank ",TT "k"," given 
     by the data in the two lists ",TT "L1"," and ",TT "L2",".",
     
     PARA{}, "If no further options are given then the resulting bundle will be in Klyachko's description: 
     The first list ",TT "L1"," will give the basis matrices and the second list ",TT "L2"," will give 
     the filtration matrices. Then the resulting vector bundle will have these basis and filtration 
     matrices. The number of matrices in ",TT "L1"," must match the number of rays of the fan and they 
     must be in GL(",TT "k",",",TEX///$R$///,") for ",TEX///$R$///," being ",TO ZZ," or ",TO QQ,". They 
     will be assigned to the rays in the order they appear in ",TT "rays F",". The number of  matrices 
     in ",TT "L2"," must also match the number of rays, and they must be ",TEX///$1$///," times ",TT "k"," 
     matrices over ",TO ZZ,". The assignment order is the same as for the basis matrices.",
     
     PARA{}, "Note that the basis and filtration matrices that are given to the function need not 
     satisfy the compatibility condition. This can by checked by using ",TO regCheck,".",
     
     EXAMPLE {
	  " L1 = {matrix {{1,0},{0,1}},matrix{{0,1},{1,0}},matrix{{-1,0},{-1,1}}}",
	  " L2 = {matrix {{-1,0}},matrix{{-2,-1}},matrix{{0,1}}}",
	  " E = toricVectorBundle(2,projectiveSpaceFan 2,L1,L2)",
	  " details E"
	  },
     
     PARA{}, "If the option ",TT "\"Type\" => \"Kaneyama\""," is given then the resulting bundle will be 
     in Kaneyama's description; Note that this is only implemented for complete, pointed fans: The first 
     list ",TT "L1"," will give the degree matrices and the second list ",TT "L2"," will give the 
     transition matrices. The number of matrices in ",TT "L1"," must match the number of maximal cones of 
     the fan and they must be ",TEX///$n$///," times ",TT "k"," matrices over ",TO ZZ,". They will be 
     assigned to the cones in the order they appear in ",TT "maxCones F",". The number of matrices 
     in ",TT "L2"," must match the number of pairs of maximal cones that intersect in a common 
     codimension-one face and must all be in GL(",TT "k",",",TO QQ,"). They will be assigned to the 
     pairs ",TEX///$(i,j)$///," in lexicographic order.",
     
     PARA{}, "Note that the degrees and transition matrices that are given to the function need not 
     satisfy the regularity or the cocycle condition. These can be checked by 
     using ",TO regCheck," and ",TO cocycleCheck,".",
     
      EXAMPLE {
	  " L1 = {matrix {{1,0},{0,1}},matrix{{0,1},{1,0}},matrix{{-1,0},{-1,1}}}",
	  " L2 = {matrix {{-1,0},{0,-1}},matrix{{0,1},{1,0}},matrix{{0,-1},{-1,0}}}",
	  " E = toricVectorBundle(2,projectiveSpaceFan 2,L1,L2,\"Type\" => \"Kaneyama\")",
	  " details E"
	  },
     
     SeeAlso => {addBaseChange,
	  addDegrees,
	  addBase,
	  addFiltration,
	  details,
	  regCheck,
	  cocycleCheck,
	  isVectorBundle}
     
     }

document {
     Key => {twist, (twist,ToricVectorBundleKlyachko,List)},
     Headline => " twists a toric vector bundle with a line bundle",
     Usage => " E1 = twist(E,L)",
     Inputs => {
	  "E" => ToricVectorBundleKlyachko,
	  "L" => List
	  },
     Outputs => {
	  "E1" => ToricVectorBundleKlyachko
	  },
     
     PARA{}, TT "twist"," takes a toric vector bundle ",TEX///$E$///," in Klyachko's description and a list 
     of integers ",TT "L",". The list must contain one entry for each ray of the underlying fan. Then 
     it computes the twist of the vector bundle by the line bundle given by these integers 
     (see ",TO weilToCartier,").",
     
     EXAMPLE {
	  " E = tangentBundle hirzebruchFan 2",
	  " L = {1,-2,3,-4}",
	  " E1 = twist(E,L)",
	  " details E1"
	  },
     
     SeeAlso => {weilToCartier,cartierIndex,details}
     
     }

document {
     Key => {weilToCartier, (weilToCartier,List,Fan)},
     Headline => " the line bundle given by a Cartier divisor",
     Usage => " E = weilToCartier(L,F)",
     Inputs => {
	  "L" => List,
	  "F" => Fan => {"a pure and full dimensional fan"}
	  },
     Outputs => {
	  "E" => {ofClass ToricVectorBundleKaneyama ," or ", ofClass ToricVectorBundleKlyachko}
	  },
     
     PARA{}, TT "L"," must a list of weights, exactly one for each ray of the fan. Then the list of weights 
     for each ray describes a Weil divisor on the toric variety. If the Weil divisor defined by these weights 
     defines in fact a Cartier divisor, then ",TT "weilToCartier"," computes the toric vector bundle associated 
     to the Cartier divisor.",
     
     PARA{}, "If no further options are given then the resulting bundle will be in Klyachko's description:",
     
     EXAMPLE {
	  " F = hirzebruchFan 3",
	  " E =weilToCartier({1,-3,4,-2},F)",
	  " details E"
	  },
     
     PARA{}, "If the option ",TT "\"Type\" => \"Kaneyama\""," is given then the resulting bundle will be in 
     Kaneyama's description:",
     
     EXAMPLE {
	  " F = hirzebruchFan 3",
	  " E =weilToCartier({1,-3,4,-2},F,\"Type\" => \"Kaneyama\")",
	  " details E"
	  },
     
     SeeAlso => {cartierIndex}
     
     }



---------------------------------------
-- TESTS
---------------------------------------


-- Test 0
-- Checking toricVectorBundle for Kaneyama type
TEST ///
T = toricVectorBundle(2,pp1ProductFan 2,"Type" => "Kaneyama")
assert(T#"baseChangeTable" === hashTable {(0,1) => map(QQ^2,QQ^2,1),(0,2) => map(QQ^2,QQ^2,1),(1,3) => map(QQ^2,QQ^2,1),(2,3) => map(QQ^2,QQ^2,1)})
assert(T#"degreeTable" === hashTable apply(maxCones pp1ProductFan 2, C -> C => map(ZZ^2,ZZ^2,0)))
assert(rank T == 2)
assert(T#"dimension of the variety" == 2)
L1 = {matrix {{1,0},{0,1}},matrix{{0,1},{1,0}},matrix{{-1,0},{-1,1}}}
L2 = {matrix {{-1,0},{0,-1}},matrix{{0,1},{1,0}},matrix{{0,-1},{-1,0}}}
T = toricVectorBundle(2,projectiveSpaceFan 2,L1,L2,"Type" => "Kaneyama")
assert(T#"baseChangeTable" === hashTable {(0,1) => matrix {{-1/1,0},{0,-1}},(0,2) => matrix{{0/1,1},{1,0}},(1,2) => matrix{{0/1,-1},{-1,0}}})
assert(T#"degreeTable" === hashTable {posHull matrix {{1,-1},{0,-1}} => matrix{{-1,0},{-1,1}}, posHull matrix {{1,0},{0,1}} => matrix{{0,1},{1,0}},posHull matrix {{-1,0},{-1,1}} => matrix{{1,0},{0,1}}})
assert(rank T == 2)
assert(T#"dimension of the variety" == 2)
///

-- Test 1
-- Checking toricVectorBundle for Klyachko type
TEST ///
T = toricVectorBundle(2,pp1ProductFan 2);
assert(T#"ring" === QQ)
assert(T#"filtrationMatricesTable" === hashTable {matrix{{-1},{0}} => map(ZZ^1,ZZ^2,0),matrix{{0},{-1}} => map(ZZ^1,ZZ^2,0),matrix{{1},{0}} => map(ZZ^1,ZZ^2,0),matrix{{0},{1}} => map(ZZ^1,ZZ^2,0)})
assert(T#"baseTable" === hashTable{matrix{{-1},{0}} => map(QQ^2,QQ^2,1),matrix{{0},{-1}} => map(QQ^2,QQ^2,1),matrix{{1},{0}} => map(QQ^2,QQ^2,1),matrix{{0},{1}} => map(QQ^2,QQ^2,1)})
assert(rank T == 2)
assert(T#"dimension of the variety" == 2)
L1 = {matrix {{1,0},{0,1}},matrix{{0,1},{1,0}},matrix{{-1,0},{-1,1}}}
L2 = {matrix {{-1,0}},matrix{{-2,-1}},matrix{{0,1}}}
T = toricVectorBundle(2,projectiveSpaceFan 2,L1,L2)
assert(T#"ring" === ZZ)
assert(T#"filtrationMatricesTable" === hashTable {matrix{{-1},{-1}} => matrix{{-1,0}},matrix{{0},{1}} => matrix{{-2,-1}},matrix{{1},{0}} => matrix{{0,1}}})
assert(T#"baseTable" === hashTable {matrix{{-1},{-1}} => matrix {{1,0},{0,1}},matrix{{0},{1}} => matrix{{0,1},{1,0}},matrix{{1},{0}} => matrix{{-1,0},{-1,1}}})
assert(rank T == 2)
assert(T#"dimension of the variety" == 2)
///

-- Test 2
-- Checking addBaseChange and cocycleCheck
TEST ///
T = toricVectorBundle(2,pp1ProductFan 2,"Type" => "Kaneyama")
T1 = addBaseChange(T,{matrix{{1,2},{0,1}},matrix{{1,0},{3,1}},matrix{{1,-2},{0,1}},matrix{{1,0},{-3,1}}})
assert cocycleCheck T1
T1 = addBaseChange(T,{matrix{{1,2},{0,1}},matrix{{1,0},{3,1}},matrix{{1,-2},{0,1}},matrix{{1,0},{-2,1}}})
assert not cocycleCheck T1
///

-- Test 3
-- Checking regCheck
TEST ///
T = toricVectorBundle(2,pp1ProductFan 2,"Type" => "Kaneyama")
assert regCheck T
T1 = addDegrees(T,{matrix{{1,2},{3,1}},matrix{{-1,0},{3,1}},matrix{{1,2},{-3,-1}},matrix{{-1,0},{-3,-1}}})
assert not regCheck T1
T1 = addDegrees(T,{matrix{{-1,0},{-3,-1}},matrix{{-1,0},{3,1}},matrix{{1,2},{-3,-1}},matrix{{1,2},{3,1}}})
assert regCheck T1
///

-- Test 4
-- Checking tangentBundle for Kaneyama
TEST ///
T = tangentBundle(pp1ProductFan 2,"Type" => "Kaneyama")
assert(T#"baseChangeTable" === hashTable {(0,1) => map(QQ^2,QQ^2,{{1, 0}, {0, -1}}), (0,2) => map(QQ^2,QQ^2,{{-1, 0}, {0, 1}}), (1,3) => map(QQ^2,QQ^2,{{-1, 0}, {0, 1}}), (2,3) => map(QQ^2,QQ^2,{{1, 0}, {0, -1}})})
assert(T#"degreeTable" === hashTable {posHull matrix {{-1,0},{0,1}} => matrix{{1,0},{0,-1}},posHull matrix {{-1,0},{0,-1}} => matrix{{1,0},{0,1}},posHull matrix {{1,0},{0,1}} => matrix{{-1,0},{0,-1}}, posHull matrix{{1,0},{0,-1}} => matrix{{-1,0},{0,1}}})
assert(rank T == 2)
assert(T#"dimension of the variety" == 2)
T = tangentBundle(projectiveSpaceFan 3, "Type" => "Kaneyama")
assert(T#"baseChangeTable" === hashTable {(0,1) => map(QQ^3,QQ^3,{{1, -1, 0}, {0, -1, 0}, {0, -1, 1}}), (0,2) => map(QQ^3,QQ^3,{{-1, 0, 0}, {-1, 1, 0}, {-1, 0, 1}}), (1,2) => map(QQ^3,QQ^3,{{-1, 1, 0}, {-1, 0, 0}, {-1, 0, 1}}), (0,3) => map(QQ^3,QQ^3,{{1, 0, -1}, {0, 0, -1}, {0, 1, -1}}), (1,3) => map(QQ^3,QQ^3,{{1, 0, -1}, {0, 1, -1}, {0, 0, -1}}), (2,3) => map(QQ^3,QQ^3,{{0, 0, -1}, {1, 0, -1}, {0, 1, -1}})})
assert(T#"degreeTable" === hashTable {posHull matrix{{1,0,0},{0,1,0},{0,0,1}} => matrix{{-1,0,0},{0,-1,0},{0,0,-1}},posHull matrix {{1,0,-1},{0,1,-1},{0,0,-1}} => matrix{{0,-1,0},{0,0,-1},{1,1,1}},posHull matrix {{0,-1,0},{1,-1,0},{0,-1,1}} => matrix{{1,1,1},{0,-1,0},{0,0,-1}}, posHull matrix{{1,-1,0},{0,-1,0},{0,-1,1}} => matrix{{0,-1,0},{1,1,1},{0,0,-1}}})
assert(rank T == 3)
assert(T#"dimension of the variety" == 3)
///

-- Test 5
-- Checking tangentBundle for Klyachko
TEST ///
T = tangentBundle hirzebruchFan 3
assert(T#"ring" === QQ)
assert(T#"filtrationMatricesTable" === hashTable {matrix{{-1},{3}} => matrix{{-1,0}},matrix{{0},{-1}} => matrix{{-1,0}},matrix{{1},{0}} => matrix{{-1,0}},matrix{{0},{1}} => matrix{{-1,0}}})
assert(T#"baseTable" === hashTable {matrix{{-1},{3}} => matrix{{-1,1/3},{3,0}},matrix{{0},{-1}} => matrix{{0_QQ,1},{-1,0}},matrix{{1},{0}} => map(QQ^2,QQ^2,1),matrix{{0},{1}} => matrix{{0_QQ,1},{1,0}}})
assert(rank T == 2)
assert(T#"dimension of the variety" == 2)
T = tangentBundle pp1ProductFan 3
assert(T#"ring" === QQ)
assert(T#"filtrationMatricesTable" === hashTable {matrix{{0},{1},{0}} => matrix{{-1,0,0}}, matrix{{-1},{0},{0}} => matrix{{-1,0,0}},matrix{{1},{0},{0}} => matrix{{-1,0,0}}, matrix{{0},{0},{-1}} => matrix{{-1,0,0}}, matrix{{0},{0},{1}} => matrix{{-1,0,0}}, matrix{{0},{-1},{0}} => matrix{{-1,0,0}}})
assert(T#"baseTable" === hashTable {matrix{{0},{1},{0}} => matrix{{0_QQ,1,0},{1,0,0},{0,0,1}}, matrix{{-1},{0},{0}} => matrix{{-1_QQ,0,0},{0,1,0},{0,0,1}},matrix{{1},{0},{0}} => matrix{{1_QQ,0,0},{0,1,0},{0,0,1}}, matrix{{0},{0},{-1}} => matrix{{0_QQ,1,0},{0,0,1},{-1,0,0}}, matrix{{0},{0},{1}} => matrix{{0_QQ,1,0},{0,0,1},{1,0,0}}, matrix{{0},{-1},{0}} => matrix{{0_QQ,1,0},{-1,0,0},{0,0,1}}})
assert(rank T == 3)
///

-- Test 6
-- Checking cotangentBundle for Kaneyama
TEST ///
T = cotangentBundle(hirzebruchFan 3,"Type" => "Kaneyama")
assert(T#"baseChangeTable" === hashTable {(0,1) => map(QQ^2,QQ^2,{{1, 0}, {0, -1}}), (0,2) => map(QQ^2,QQ^2,{{-1, 3}, {0, 1}}), (1,3) => map(QQ^2,QQ^2,{{-1, -3}, {0, 1}}), (2,3) => map(QQ^2,QQ^2,{{1, 0}, {0, -1}})})
assert(T#"degreeTable" === hashTable {posHull matrix {{1,0},{0,-1}} => matrix{{1,0},{0,-1}},posHull matrix {{1,0},{0,1}} => matrix{{1,0},{0,1}},posHull matrix {{0,-1},{1,3}} => matrix{{-1,3},{0,1}}, posHull matrix{{0,-1},{-1,3}} => matrix{{-1,-3},{0,-1}}})
assert(rank T == 2)
assert(T#"dimension of the variety" == 2)
T = cotangentBundle(pp1ProductFan 3, "Type" => "Kaneyama")
assert(T#"baseChangeTable" === hashTable {(2,6) => matrix{{-1_QQ,0,0},{0,1,0},{0,0,1}}, (4,5) => matrix{{1_QQ,0,0},{0,1,0},{0,0,-1}}, (4,6) => matrix{{1_QQ,0,0},{0,-1,0},{0,0,1}}, (3,7) => matrix{{-1_QQ,0,0},{0,1,0},{0,0,1}}, (5,7) => matrix{{1_QQ,0,0},{0,-1,0},{0,0,1}}, (6,7) => matrix{{1_QQ,0,0},{0,1,0},{0,0,-1}}, (0,1) => matrix{{1_QQ,0,0},{0,1,0},{0,0,-1}}, (0,2) => matrix{{1_QQ,0,0},{0,-1,0},{0,0,1}}, (1,3) => matrix{{1_QQ,0,0},{0,-1,0},{0,0,1}}, (0,4) => matrix{{-1_QQ,0,0},{0,1,0},{0,0,1}}, (2,3) => matrix{{1_QQ,0,0},{0,1,0},{0,0,-1}}, (1,5) => matrix{{-1_QQ,0,0},{0,1,0},{0,0,1}}})
assert(T#"degreeTable" === hashTable {posHull matrix{{1,0,0},{0,1,0},{0,0,1}} => matrix{{1,0,0},{0,1,0},{0,0,1}},posHull matrix{{-1,0,0},{0,1,0},{0,0,1}} => matrix{{-1,0,0},{0,1,0},{0,0,1}},posHull matrix{{1,0,0},{0,-1,0},{0,0,1}} => matrix{{1,0,0},{0,-1,0},{0,0,1}},posHull matrix{{1,0,0},{0,1,0},{0,0,-1}} => matrix{{1,0,0},{0,1,0},{0,0,-1}},posHull matrix{{-1,0,0},{0,-1,0},{0,0,1}} => matrix{{-1,0,0},{0,-1,0},{0,0,1}},posHull matrix{{-1,0,0},{0,1,0},{0,0,-1}} => matrix{{-1,0,0},{0,1,0},{0,0,-1}},posHull matrix{{1,0,0},{0,-1,0},{0,0,-1}} => matrix{{1,0,0},{0,-1,0},{0,0,-1}},posHull matrix{{-1,0,0},{0,-1,0},{0,0,-1}} => matrix{{-1,0,0},{0,-1,0},{0,0,-1}}})
assert(rank T == 3)
assert(T#"dimension of the variety" == 3)
///

-- Test 7
-- Checking cotangentBundle for Klyachko
TEST ///
T = cotangentBundle hirzebruchFan 2
assert(T#"ring" === QQ)
assert(T#"filtrationMatricesTable" === hashTable {matrix{{-1},{2}} => matrix{{1,0}},matrix{{0},{-1}} => matrix{{1,0}},matrix{{1},{0}} => matrix{{1,0}},matrix{{0},{1}} => matrix{{1,0}}})
assert(T#"baseTable" === hashTable {matrix{{-1},{2}} => matrix{{0,2},{1/2,1}},matrix{{0},{-1}} => matrix{{0_QQ,1},{-1,0}},matrix{{1},{0}} => map(QQ^2,QQ^2,1),matrix{{0},{1}} => matrix{{0_QQ,1},{1,0}}})
assert(rank T == 2)
assert(T#"dimension of the variety" == 2)
T = cotangentBundle pp1ProductFan 3
assert(T#"ring" === QQ)
assert(T#"filtrationMatricesTable" === hashTable {matrix{{0},{1},{0}} => matrix{{1,0,0}}, matrix{{-1},{0},{0}} => matrix{{1,0,0}},matrix{{1},{0},{0}} => matrix{{1,0,0}}, matrix{{0},{0},{-1}} => matrix{{1,0,0}}, matrix{{0},{0},{1}} => matrix{{1,0,0}}, matrix{{0},{-1},{0}} => matrix{{1,0,0}}})
assert(T#"baseTable" === hashTable {matrix{{0},{1},{0}} => matrix{{0_QQ,1,0},{1,0,0},{0,0,1}}, matrix{{-1},{0},{0}} => matrix{{-1_QQ,0,0},{0,1,0},{0,0,1}},matrix{{1},{0},{0}} => matrix{{1_QQ,0,0},{0,1,0},{0,0,1}}, matrix{{0},{0},{-1}} => matrix{{0_QQ,1,0},{0,0,1},{-1,0,0}}, matrix{{0},{0},{1}} => matrix{{0_QQ,1,0},{0,0,1},{1,0,0}}, matrix{{0},{-1},{0}} => matrix{{0_QQ,1,0},{-1,0,0},{0,0,1}}})
assert(rank T == 3)
///

-- Test 8
-- Checking isVectorBundle
TEST ///
T = toricVectorBundle(2,pp1ProductFan 2)
T1 = addBase(T,{matrix{{1,2},{3,1}},matrix{{-1,0},{3,1}},matrix{{1,2},{-3,-1}},matrix{{-1,0},{-3,-1}}})
assert isVectorBundle T1
T = toricVectorBundle(1,normalFan crossPolytope 3)
L = apply({2,1,1,2,2,1,1,2}, i -> matrix {{i}});
T = addFiltration(T,L)
assert not isVectorBundle T
///

-- Test 9
-- Checking deltaE for Kaneyama
TEST ///
T = toricVectorBundle(3,projectiveSpaceFan 2,"Type" => "Kaneyama")
assert(deltaE T == convexHull matrix{{0},{0}})
T = tangentBundle(projectiveSpaceFan 2,"Type" => "Kaneyama")
assert(deltaE T == convexHull matrix {{-1,1,0,1,0,-1},{0,0,-1,-1,1,1}})
T = cotangentBundle(pp1ProductFan 3,"Type" => "Kaneyama")
assert(deltaE T == convexHull matrix {{-1,1,0,0,0,0},{0,0,-1,1,0,0},{0,0,0,0,-1,1}})
///

-- Test 10
-- Checking deltaE for Klyachko
TEST ///
T = toricVectorBundle(3,projectiveSpaceFan 2)
assert(deltaE T == convexHull matrix{{0},{0}})
T = tangentBundle projectiveSpaceFan 2
assert(deltaE T == convexHull matrix {{-1, 1, 0, 1, 0, -1}, {0, 0, -1, -1, 1, 1}})
T = cotangentBundle pp1ProductFan 3
assert(deltaE T == convexHull matrix {{-1,1,0,0,0,0},{0,0,-1,1,0,0},{0,0,0,0,-1,1}})
///

-- Test 11
-- Checking cohomology for Kaneyama
TEST ///
T = toricVectorBundle(2,pp1ProductFan 2,"Type" => "Kaneyama")
assert(cohomology(0,T,matrix{{0},{0}}) == (ring T)^{{0,0},{0,0}})
assert(cohomology(0,T) == (ring T)^{{0,0},{0,0}})
assert(cohomology(1,T) == (ring T)^0)
assert(cohomology(2,T) == (ring T)^0)
T1 = tangentBundle(pp1ProductFan 2,"Type" => "Kaneyama")
assert(cohomology(0,T1,matrix{{0},{0}}) == (ring T1)^{{0,0},{0,0}})
assert(cohomology(0,T1,matrix{{1},{1}}) == (ring T1)^0)
assert(cohomology(0,T1) == (ring T1)^{{1,0},{0,1},{0,0},{0,0},{0,-1},{-1,0}})
assert(cohomology(1,T1) == (ring T1)^0)
assert(cohomology(2,T1) == (ring T1)^0)
T = tangentBundle(hirzebruchFan 3 * projectiveSpaceFan 1,"Type" => "Kaneyama")
assert(cohomology(0,T,{matrix {{2},{1},{0}}, matrix{{3},{1},{0}}}) == {(ring T)^{{-2,-1,0}},(ring T)^{{-3,-1,0}}})
assert(cohomology(1,T,{matrix {{-2},{-1},{0}}, matrix{{-1},{-1},{0}}}) == {(ring T)^{{2, 1, 0}},(ring T)^{{1, 1, 0}}})
assert(cohomology(2,T,matrix{{0},{0},{0}}) == (ring T)^0)
assert(cohomology(3,T,matrix{{0},{0},{0}}) == (ring T)^0)
///

-- Test 12
-- Checking cohomology for Klyachko
TEST ///
T = toricVectorBundle(2,pp1ProductFan 2)
assert(cohomology(0,T,matrix{{0},{0}}) == (ring T)^{{0,0},{0,0}})
assert(cohomology(0,T) == (ring T)^{{0,0},{0,0}})
assert(cohomology(1,T) == (ring T)^0)
assert(cohomology(2,T) == (ring T)^0)
T1 = tangentBundle pp1ProductFan 2
assert(cohomology(0,T1,matrix{{0},{0}}) == (ring T1)^{{0,0},{0,0}})
assert(cohomology(0,T1,matrix{{1},{1}}) == (ring T1)^0)
assert(cohomology(0,T1) == (ring T1)^{{1,0},{0,1},{0,0},{0,0},{0,-1},{-1,0}})
assert(cohomology(1,T1) == (ring T1)^0)
assert(cohomology(2,T1) == (ring T1)^0)
T = tangentBundle(hirzebruchFan 3 * projectiveSpaceFan 1)
assert(cohomology(0,T) == (ring T)^{{0, 0, 1}, {1, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {-1, 0, 0}, {0, 0, -1}, {0, -1, 0}, {-1, -1, 0}, {-2, -1, 0}, {-3, -1, 0}})
assert(cohomology(1,T) == (ring T)^{{2, 1, 0}, {1, 1, 0}})
assert(cohomology(2,T) == (ring T)^0)
assert(cohomology(3,T) == (ring T)^0)
///

-- Test 13
-- Checking weilToCartier
TEST ///
T = weilToCartier({1,4,3,2},projectiveSpaceFan 3,"Type" => "Kaneyama")
assert(T#"baseChangeTable" === hashTable {(0,1) => map(QQ^1,QQ^1,1),(0,2) => map(QQ^1,QQ^1,1),(0,3) => map(QQ^1,QQ^1,1),(1,2) => map(QQ^1,QQ^1,1),(1,3) => map(QQ^1,QQ^1,1),(2,3) => map(QQ^1,QQ^1,1)})
assert(T#"degreeTable" === hashTable {posHull matrix {{1,0,-1},{0,1,-1},{0,0,-1}} => matrix{{-2},{-3},{6}},posHull matrix {{0,-1,0},{1,-1,0},{0,-1,1}} => matrix{{8},{-3},{-4}},posHull matrix {{1,-1,0},{0,-1,0},{0,-1,1}} => matrix{{-2},{7},{-4}},posHull map(ZZ^3,ZZ^3,1) => matrix{{-2},{-3},{-4}}})
assert(rank T == 1)
assert(T#"dimension of the variety" == 3)
T = weilToCartier({1,4,3,2},projectiveSpaceFan 3)
assert(T#"ring" === QQ)
assert(T#"filtrationMatricesTable" === hashTable {matrix{{-1},{-1},{-1}} => matrix{{-1}},matrix{{0},{0},{1}} => matrix{{-4}},matrix{{0},{1},{0}} => matrix{{-3}}, matrix{{1},{0},{0}} => matrix{{-2}}})
assert(T#"baseTable" === hashTable {matrix{{-1},{-1},{-1}} => matrix{{1_QQ}},matrix{{0},{0},{1}} => matrix{{1_QQ}},matrix{{0},{1},{0}} => matrix{{1_QQ}}, matrix{{1},{0},{0}} => matrix{{1_QQ}}})
assert(rank T == 1)
assert(T#"dimension of the variety" == 3)
///

-- Test 14
-- Checking directSum for Kaneyama
TEST ///
T1 = tangentBundle(projectiveSpaceFan 3,"Type" => "Kaneyama")
T2 = weilToCartier({1,7,5,3},projectiveSpaceFan 3,"Type" => "Kaneyama")
T = T1 ++ T2
assert(T#"baseChangeTable" === hashTable {(0,1) => matrix{{1_QQ,-1,0,0},{0,-1,0,0},{0,-1,1,0},{0,0,0,1}}, (0,2) => matrix{{-1_QQ,0,0,0},{-1,1,0,0},{-1,0,1,0},{0,0,0,1}}, (1,2) => matrix{{-1_QQ,1,0,0},{-1,0,0,0},{-1,0,1,0},{0,0,0,1}}, (0,3) => matrix{{1_QQ,0,-1,0},{0,0,-1,0},{0,1,-1,0},{0,0,0,1}}, (1,3) => matrix{{1_QQ,0,-1,0},{0,1,-1,0},{0,0,-1,0},{0,0,0,1}}, (2,3) => matrix{{0_QQ,0,-1,0},{1,0,-1,0},{0,1,-1,0},{0,0,0,1}}})
assert(T#"degreeTable" === hashTable {posHull matrix {{1,0,-1},{0,1,-1},{0,0,-1}} => matrix{{0,-1,0,-3},{0,0,-1,-5},{1,1,1,9}},posHull matrix {{0,-1,0},{1,-1,0},{0,-1,1}} => matrix{{1,1,1,13},{0,-1,0,-5},{0,0,-1,-7}},posHull matrix {{1,-1,0},{0,-1,0},{0,-1,1}} => matrix{{0,-1,0,-3},{1,1,1,11},{0,0,-1,-7}},posHull map(ZZ^3,ZZ^3,1) => matrix{{-1,0,0,-3},{0,-1,0,-5},{0,0,-1,-7}}})
assert(rank T == 4)
assert(T#"dimension of the variety" == 3)
assert(T == directSum {T1,T2})
T1 = cotangentBundle(hirzebruchFan 3,"Type" => "Kaneyama")
T2 = tangentBundle(hirzebruchFan 3,"Type" => "Kaneyama")
T = T1 ++ T2
assert(T#"baseChangeTable" === hashTable {(0,1) => matrix{{1_QQ,0,0,0},{0,-1,0,0},{0,0,1,0},{0,0,0,-1}}, (0,2) => matrix{{-1_QQ,3,0,0},{0,1,0,0},{0,0,-1,0},{0,0,3,1}}, (1,3) => matrix{{-1_QQ,-3,0,0},{0,1,0,0},{0,0,-1,0},{0,0,-3,1}}, (2,3) => matrix{{1_QQ,0,0,0},{0,-1,0,0},{0,0,1,0},{0,0,0,-1}}})
assert(T#"degreeTable" === hashTable {posHull matrix{{1,0},{0,-1}} => matrix{{1,0,-1,0},{0,-1,0,1}}, posHull matrix{{0,-1},{1,3}} => matrix{{-1,3,1,-3},{0,1,0,-1}}, posHull matrix{{1,0},{0,1}} => matrix{{1,0,-1,0},{0,1,0,-1}}, posHull matrix{{0,-1},{-1,3}} => matrix {{-1,-3,1,3},{0,-1,0,1}}})
assert(rank T == 4)
assert(T#"dimension of the variety" == 2)
///

--Test 15
-- Checking directSum for Klyachko
TEST ///
T1 = tangentBundle projectiveSpaceFan 3
T2 = weilToCartier({1,7,5,3},projectiveSpaceFan 3)
T = T1 ++ T2
assert(T#"ring" === QQ)
assert(T#"filtrationMatricesTable" === hashTable {matrix{{-1},{-1},{-1}} => matrix{{-1,0,0,-1}},matrix{{0},{0},{1}} => matrix{{-1,0,0,-7}},matrix{{0},{1},{0}} => matrix{{-1,0,0,-5}}, matrix{{1},{0},{0}} => matrix{{-1,0,0,-3}}})
assert(T#"baseTable" === hashTable {matrix{{-1},{-1},{-1}} => matrix{{-1_QQ,0,0,0},{-1,1,0,0},{-1,0,1,0},{0,0,0,1}},matrix{{0},{0},{1}} => matrix{{0_QQ,1,0,0},{0,0,1,0},{1,0,0,0},{0,0,0,1}},matrix{{0},{1},{0}} => matrix{{0_QQ,1,0,0},{1,0,0,0},{0,0,1,0},{0,0,0,1}}, matrix{{1},{0},{0}} => matrix{{1_QQ,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}}})
assert(rank T == 4)
assert(T#"dimension of the variety" == 3)
assert(T == directSum {T1,T2})
T1 = cotangentBundle hirzebruchFan 3
T2 = tangentBundle hirzebruchFan 3
T = T1 ++ T2
assert(T#"ring" === QQ)
assert(T#"filtrationMatricesTable" === hashTable {matrix{{-1},{3}} => matrix{{1,0,-1,0}},matrix{{0},{-1}} => matrix{{1,0,-1,0}},matrix{{0},{1}} => matrix{{1,0,-1,0}}, matrix{{1},{0}} => matrix{{1,0,-1,0}}})
assert(T#"baseTable" === hashTable {matrix{{-1},{3}} => matrix{{0,3,0,0},{1/3,1,0,0},{0,0,-1,1/3},{0,0,3,0}},matrix{{0},{-1}} => matrix{{0_QQ,1,0,0},{-1,0,0,0},{0,0,0,1},{0,0,-1,0}},matrix{{0},{1}} => matrix{{0,1_QQ,0,0},{1,0,0,0},{0,0,0,1},{0,0,1,0}}, matrix{{1},{0}} => map(QQ^4,QQ^4,1)})
assert(rank T == 4)
assert(T#"dimension of the variety" == 2)
///

-- Test 16
-- Checking dual for Kaneyama
TEST ///
T = dual weilToCartier({1,4,3,2},projectiveSpaceFan 3,"Type" => "Kaneyama")
assert(T#"baseChangeTable" === hashTable{(0,1) => matrix{{1_QQ}},(0,2) => matrix{{1_QQ}}, (0,3) => matrix{{1_QQ}}, (1,2) => matrix{{1_QQ}},(1,3) => matrix{{1_QQ}},(2,3) => matrix{{1_QQ}}})
assert(T#"degreeTable" === hashTable{posHull matrix {{1,0,-1},{0,1,-1},{0,0,-1}} => matrix{{2},{3},{-6}},posHull matrix {{0,-1,0},{1,-1,0},{0,-1,1}} => matrix{{-8},{3},{4}},posHull matrix {{1,-1,0},{0,-1,0},{0,-1,1}} => matrix{{2},{-7},{4}},posHull map(ZZ^3,ZZ^3,1) => matrix{{2},{3},{4}}})
assert(rank T == 1)
assert(T#"dimension of the variety" == 3)
T1 = tangentBundle(projectiveSpaceFan 3,"Type" => "Kaneyama")
T = dual(T1 ++ T)
assert(T#"baseChangeTable" === hashTable{(0,2) => matrix{{-1_QQ,-1,-1,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}},(0,1) => matrix{{1_QQ,0,0,0},{-1,-1,-1,0},{0,0,1,0},{0,0,0,1}}, (0,3) => matrix{{1_QQ,0,0,0},{-1,-1,-1,0},{0,1,0,0},{0,0,0,1}}, (1,2) => matrix{{0_QQ,1,0,0},{-1,-1,-1,0},{0,0,1,0},{0,0,0,1}},(1,3) => matrix{{1_QQ,0,0,0},{0,1,0,0},{-1,-1,-1,0},{0,0,0,1}},(2,3) => matrix{{-1_QQ,-1,-1,0},{1,0,0,0},{0,1,0,0},{0,0,0,1}}})
assert(T#"degreeTable" === hashTable{posHull matrix {{1,0,-1},{0,1,-1},{0,0,-1}} => matrix{{0,1,0,-2},{0,0,1,-3},{-1,-1,-1,6}},posHull matrix {{0,-1,0},{1,-1,0},{0,-1,1}} => matrix{{-1,-1,-1,8},{0,1,0,-3},{0,0,1,-4}},posHull matrix {{1,-1,0},{0,-1,0},{0,-1,1}} => matrix{{0,1,0,-2},{-1,-1,-1,7},{0,0,1,-4}},posHull map(ZZ^3,ZZ^3,1) => matrix{{1,0,0,-2},{0,1,0,-3},{0,0,1,-4}}})
assert(rank T == 4)
assert(T#"dimension of the variety" == 3)
///

-- Test 17
-- Checking dual for Klyachko
TEST ///
T = dual weilToCartier({1,4,3,2},projectiveSpaceFan 3)
assert(T#"ring" === QQ)
assert(T#"filtrationMatricesTable" === hashTable {matrix{{-1},{-1},{-1}} => matrix{{1}},matrix{{0},{0},{1}} => matrix{{4}},matrix{{0},{1},{0}} => matrix{{3}}, matrix{{1},{0},{0}} => matrix{{2}}})
assert(T#"baseTable" === hashTable {matrix{{-1},{-1},{-1}} => matrix{{1_QQ}},matrix{{0},{0},{1}} => matrix{{1_QQ}},matrix{{0},{1},{0}} => matrix{{1_QQ}}, matrix{{1},{0},{0}} => matrix{{1_QQ}}})
assert(rank T == 1)
assert(T#"dimension of the variety" == 3)
T1 = tangentBundle projectiveSpaceFan 3
T = dual(T1 ++ T)
assert(T#"ring" === QQ)
assert(T#"filtrationMatricesTable" === hashTable {matrix{{-1},{-1},{-1}} => matrix{{1,0,0,-1}},matrix{{0},{0},{1}} => matrix{{1,0,0,-1}},matrix{{0},{1},{0}} => matrix{{1,0,0,-1}}, matrix{{1},{0},{0}} => matrix{{1,0,0,-1}}})
assert(T#"baseTable" === hashTable {matrix{{-1},{-1},{-1}} => matrix{{-1_QQ,-1,-1,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}},matrix{{0},{0},{1}} => matrix{{0_QQ,1,0,0},{0,0,1,0},{1,0,0,0},{0,0,0,1}},matrix{{0},{1},{0}} => matrix{{0_QQ,1,0,0},{1,0,0,0},{0,0,1,0},{0,0,0,1}}, matrix{{1},{0},{0}} => matrix{{1_QQ,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}}})
assert(rank T == 4)
assert(T#"dimension of the variety" == 3)
///

-- Test 18
-- Checking tensor for Kaneyama
TEST ///
T1 = tangentBundle(pp1ProductFan 2,"Type" => "Kaneyama")
T2 = cotangentBundle(pp1ProductFan 2,"Type" => "Kaneyama")
T = T1 ** T2
assert(T#"baseChangeTable" === hashTable{(0,2) => matrix{{1_QQ,0,0,0},{0,-1,0,0},{0,0,-1,0},{0,0,0,1}},(0,1) => matrix{{1_QQ,0,0,0},{0,-1,0,0},{0,0,-1,0},{0,0,0,1}}, (1,3) => matrix{{1_QQ,0,0,0},{0,-1,0,0},{0,0,-1,0},{0,0,0,1}}, (2,3) => matrix{{1_QQ,0,0,0},{0,-1,0,0},{0,0,-1,0},{0,0,0,1}}})
assert(T#"degreeTable" === hashTable{posHull matrix {{-1,0},{0,1}} => matrix{{0,-1,1,0},{0,-1,1,0}},posHull matrix {{-1,0},{0,-1}} => matrix{{0,-1,1,0},{0,1,-1,0}},posHull matrix {{1,0},{0,-1}} => matrix{{0,1,-1,0},{0,1,-1,0}},posHull map(ZZ^2,ZZ^2,1) => matrix{{0,1,-1,0},{0,-1,1,0}}})
assert(rank T == 4)
assert(T#"dimension of the variety" == 2)
T1 = tangentBundle(hirzebruchFan 2,"Type" => "Kaneyama")
T2 = weilToCartier({5,1,7,3},hirzebruchFan 2,"Type" => "Kaneyama")
T2 = T2 ++ T2
T = T1 ** T2
assert(T#"baseChangeTable" === hashTable{(0,1) => matrix{{1_QQ,0,0,0},{0,-1,0,0},{0,0,1,0},{0,0,0,-1}},(0,2) => matrix{{-1_QQ,0,0,0},{2,1,0,0},{0,0,-1,0},{0,0,2,1}}, (1,3) => matrix{{-1_QQ,0,0,0},{-2,1,0,0},{0,0,-1,0},{0,0,-2,1}}, (2,3) => matrix{{1_QQ,0,0,0},{0,-1,0,0},{0,0,1,0},{0,0,0,-1}}})
assert(T#"degreeTable" === hashTable{posHull matrix {{1,0},{0,1}} => matrix{{-4,-3,-4,-3},{-1,-2,-1,-2}},posHull matrix {{1,0},{0,-1}} => matrix{{-4,-3,-4,-3},{5,6,5,6}},posHull matrix {{0,-1},{-1,2}} => matrix{{18,19,18,19},{5,6,5,6}},posHull matrix{{0,-1},{1,2}} => matrix{{6,3,6,3},{-1,-2,-1,-2}}})
assert(rank T == 4)
assert(T#"dimension of the variety" == 2)
///

-- Test 19
-- Checking tensor for Klyachko
TEST ///
T1 = tangentBundle pp1ProductFan 2
T2 = cotangentBundle pp1ProductFan 2
T = T1 ** T2
assert(T#"ring" === QQ)
assert(T#"filtrationMatricesTable" === hashTable {matrix{{-1},{0}} => matrix{{0,-1,1,0}},matrix{{0},{-1}} => matrix{{0,-1,1,0}},matrix{{0},{1}} => matrix{{0,-1,1,0}}, matrix{{1},{0}} => matrix{{0,-1,1,0}}})
assert(T#"baseTable" === hashTable {matrix{{-1},{0}} => matrix{{1_QQ,0,0,0},{0,-1,0,0},{0,0,-1,0},{0,0,0,1}},matrix {{0},{-1}} => matrix{{0_QQ,0,0,1},{0,0,-1,0},{0,-1,0,0},{1,0,0,0}},matrix {{0},{1}} => matrix{{0_QQ,0,0,1},{0,0,1,0},{0,1,0,0},{1,0,0,0}},matrix{{1},{0}} => matrix{{1_QQ,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}}})
assert(rank T == 4)
assert(T#"dimension of the variety" == 2)
T1 = tangentBundle hirzebruchFan 2
T2 = weilToCartier({5,1,7,3},hirzebruchFan 2)
T2 = T2 ++ T2
T = T1 ** T2
assert(T#"ring" === QQ)
assert(T#"filtrationMatricesTable" === hashTable {matrix{{-1},{2}} => matrix{{-8,-8,-7,-7}},matrix{{0},{-1}} => matrix{{-6,-6,-5,-5}},matrix{{0},{1}} => matrix{{-2,-2,-1,-1}}, matrix{{1},{0}} => matrix{{-4,-4,-3,-3}}})
assert(T#"baseTable" === hashTable {matrix{{-1},{2}} => matrix{{-1,0,1/2,0},{0,-1,0,1/2},{2,0,0,0},{0,2,0,0}},matrix {{0},{-1}} => matrix{{0_QQ,0,1,0},{0,0,0,1},{-1,0,0,0},{0,-1,0,0}},matrix {{0},{1}} => matrix{{0_QQ,0,1,0},{0,0,0,1},{1,0,0,0},{0,1,0,0}},matrix{{1},{0}} => matrix{{1_QQ,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}}})
assert(rank T == 4)
assert(T#"dimension of the variety" == 2)
///

-- Test 20
-- Checking symmetricPower for Kaneyama
TEST ///
T = tangentBundle(projectiveSpaceFan 3,"Type" => "Kaneyama")
T = symmetricPower(2,T)
assert(T#"baseChangeTable" === hashTable{(0,1) => matrix{{1_QQ,-1,0,1,0,0},{0,-1,0,2,0,0},{0,-1,1,2,-1,0},{0,0,0,1,0,0},{0,0,0,2,-1,0},{0,0,0,1,-1,1}},(0,2) => matrix{{1_QQ,0,0,0,0,0},{2,-1,0,0,0,0},{2,0,-1,0,0,0},{1,-1,0,1,0,0},{2,-1,-1,0,1,0},{1,0,-1,0,0,1}}, (0,3) => matrix{{1_QQ,0,-1,0,0,1},{0,0,-1,0,0,2},{0,1,-1,0,-1,2},{0,0,0,0,0,1},{0,0,0,0,-1,2},{0,0,0,1,-1,1}}, (1,2) => matrix{{1_QQ,-1,0,1,0,0},{2,-1,0,0,0,0},{2,-1,-1,0,1,0},{1,0,0,0,0,0},{2,0,-1,0,0,0},{1,0,-1,0,0,1}}, (1,3) => matrix{{1_QQ,0,-1,0,0,1},{0,1,-1,0,-1,2},{0,0,-1,0,0,2},{0,0,0,1,-1,1},{0,0,0,0,-1,2},{0,0,0,0,0,1}},(2,3) => matrix{{0_QQ,0,0,0,0,1},{0,0,-1,0,0,2},{0,0,0,0,-1,2},{1,0,-1,0,0,1},{0,1,-1,0,-1,2},{0,0,0,1,-1,1}}})
assert(T#"degreeTable" === hashTable{posHull matrix{{1,-1,0},{0,-1,0},{0,-1,1}} => matrix{{0,-1,0,-2,-1,0},{2,2,2,2,2,2},{0,0,-1,0,-1,-2}},posHull matrix{{1,0,0},{0,1,0},{0,0,1}} => matrix{{-2,-1,-1,0,0,0},{0,-1,0,-2,-1,0},{0,0,-1,0,-1,-2}},posHull matrix{{1,0,-1},{0,1,-1},{0,0,-1}} => matrix{{0,-1,0,-2,-1,0},{0,0,-1,0,-1,-2},{2,2,2,2,2,2}},posHull matrix{{0,-1,0},{1,-1,0},{0,-1,1}} => matrix{{2,2,2,2,2,2},{0,-1,0,-2,-1,0},{0,0,-1,0,-1,-2}}})
assert(rank T == 6)
assert(T#"dimension of the variety" == 3)
///

-- Test 21
-- Checking symmetricPower for Klyachko
TEST ///
T = tangentBundle projectiveSpaceFan 3
T = symmetricPower(2,T)
assert(T#"ring" === QQ)
assert(T#"filtrationMatricesTable" === hashTable {matrix{{0},{0},{1}} => matrix{{-2,-1,-1,0,0,0}}, matrix{{-1},{-1},{-1}} => matrix{{-2,-1,-1,0,0,0}}, matrix{{1},{0},{0}} => matrix{{-2,-1,-1,0,0,0}}, matrix{{0},{1},{0}} => matrix{{-2,-1,-1,0,0,0}}})
assert(T#"baseTable" === hashTable {matrix{{0},{0},{1}} => matrix{{0_QQ,0,0,1,0,0},{0,0,0,0,1,0},{0,1,0,0,0,0},{0,0,0,0,0,1},{0,0,1,0,0,0},{1,0,0,0,0,0}}, matrix{{-1},{-1},{-1}} => matrix{{1_QQ,0,0,0,0,0},{2,-1,0,0,0,0},{2,0,-1,0,0,0},{1,-1,0,1,0,0},{2,-1,-1,0,1,0},{1,0,-1,0,0,1}}, matrix{{1},{0},{0}} => matrix{{1_QQ,0,0,0,0,0},{0,1,0,0,0,0},{0,0,1,0,0,0},{0,0,0,1,0,0},{0,0,0,0,1,0},{0,0,0,0,0,1}}, matrix{{0},{1},{0}} => matrix{{0_QQ,0,0,1,0,0},{0,1,0,0,0,0},{0,0,0,0,1,0},{1,0,0,0,0,0},{0,0,1,0,0,0},{0,0,0,0,0,1}}})
assert(rank T == 6)
assert(T#"dimension of the variety" == 3)
///

-- Test 22
-- Checking exteriorPower for Kaneyama
TEST ///
T = cotangentBundle(hirzebruch 3,"Type" => "Kaneyama")
T = exteriorPower(2,T)
assert(T#"baseChangeTable" === hashTable{(0,1) => matrix{{-1_QQ}}, (0,2) => matrix{{-1_QQ}}, (1,3) => matrix{{-1_QQ}}, (2,3) => matrix{{-1_QQ}}})
assert(T#"degreeTable" === hashTable{posHull matrix{{1,0},{0,1}} => matrix{{1},{1}},posHull matrix{{1,0},{0,-1}} => matrix{{1},{-1}},posHull matrix{{0,-1},{1,3}} => matrix {{2},{1}},posHull matrix{{0,-1},{-1,3}} => matrix {{-4},{-1}}})
assert(rank T == 1)
assert(T#"dimension of the variety" == 2)
T = tangentBundle(projectiveSpaceFan 3,"Type" => "Kaneyama")
T = exteriorPower(2,T)
assert(T#"baseChangeTable" === hashTable{(0,1) => matrix{{-1_QQ,0,0},{-1,1,-1},{0,0,-1}}, (0,2) => matrix{{-1_QQ,0,0},{0,-1,0},{1,-1,1}}, (0,3) => matrix{{0_QQ,-1,0},{1,-1,1},{0,0,1}}, (1,2) => matrix{{1_QQ,0,0},{1,-1,1},{0,-1,0}}, (1,3) => matrix{{1_QQ,-1,1},{0,-1,0},{0,0,-1}}, (2,3) => matrix{{0_QQ,1,0},{0,0,1},{1,-1,1}}})
assert(T#"degreeTable" === hashTable{posHull matrix{{1,-1,0},{0,-1,0},{0,-1,1}} => matrix{{-1,0,-1},{2,2,2},{0,-1,-1}},posHull matrix{{1,0,0},{0,1,0},{0,0,1}} => matrix{{-1,-1,0},{-1,0,-1},{0,-1,-1}},posHull matrix{{1,0,-1},{0,1,-1},{0,0,-1}} => matrix{{-1,0,-1},{0,-1,-1},{2,2,2}},posHull matrix{{0,-1,0},{1,-1,0},{0,-1,1}} => matrix{{2,2,2},{-1,0,-1},{0,-1,-1}}})
assert(rank T == 3)
assert(T#"dimension of the variety" == 3)
///

-- Test 23
-- Checking exteriorPower for Klyachko
TEST ///
T = cotangentBundle hirzebruch 3
T = exteriorPower(2,T)
assert(T#"ring" === QQ)
assert(T#"filtrationMatricesTable" === hashTable {matrix{{-1},{3}} => matrix{{1}}, matrix{{0},{1}} => matrix{{1}}, matrix{{0},{-1}} => matrix{{1}}, matrix{{1},{0}} => matrix{{1}}})
assert(T#"baseTable" === hashTable {matrix{{-1},{3}} => matrix{{-1_QQ}}, matrix{{0},{1}} => matrix{{-1_QQ}}, matrix{{0},{-1}} => matrix{{1_QQ}}, matrix{{1},{0}} => matrix{{1_QQ}}})
assert(rank T == 1)
assert(T#"dimension of the variety" == 2)
T = tangentBundle projectiveSpaceFan 3
T = exteriorPower(2,T)
assert(T#"ring" === QQ)
assert(T#"filtrationMatricesTable" === hashTable {matrix{{0},{0},{1}} => matrix{{-1,-1,0}}, matrix{{-1},{-1},{-1}} => matrix{{-1,-1,0}}, matrix{{1},{0},{0}} => matrix{{-1,-1,0}}, matrix{{0},{1},{0}} => matrix{{-1,-1,0}}})
assert(T#"baseTable" === hashTable {matrix{{0},{0},{1}} => matrix{{0_QQ,0,1},{-1,0,0},{0,-1,0}}, matrix{{-1},{-1},{-1}} => matrix{{-1_QQ,0,0},{0,-1,0},{1,-1,1}}, matrix{{1},{0},{0}} => matrix{{1_QQ,0,0},{0,1,0},{0,0,1}}, matrix{{0},{1},{0}} => matrix{{-1_QQ,0,0},{0,0,1},{0,1,0}}})
assert(rank T == 3)
assert(T#"dimension of the variety" == 3)
///

-- Test 24
-- Checking eulerChi
TEST ///
T = tangentBundle hirzebruchFan 3
u = matrix {{0},{0}}
assert(eulerChi(u,T) == 2)
assert(eulerChi T == 6)
T = cotangentBundle projectiveSpaceFan 4
assert(eulerChi T == -1)
T = tangentBundle(hirzebruchFan 3,"Type" => "Kaneyama")
u = matrix {{0},{0}}
assert(eulerChi(u,T) == 2)
assert(eulerChi T == 6)
///

-- Test 25
-- Checking coker
TEST ///
T = tangentBundle hirzebruchFan 2
T = T ** T
M = matrix {{1,0},{0,1},{1,0},{0,1/1}}
T1 = coker(T,M)
assert(T1#"ring" === QQ)
assert(T1#"filtrationMatricesTable" === hashTable {matrix{{-1},{2}} => matrix{{-2,-1}}, matrix{{0},{-1}} => matrix{{-2,-1}}, matrix{{0},{1}} => matrix{{-2,-1}}, matrix{{1},{0}} => matrix{{-2,-1}}})
assert(T1#"baseTable" === new HashTable from {map(ZZ^2,ZZ^1,{{0}, {-1}}) => map(QQ^2,QQ^2,{{0, 1}, {1, 0}}), map(ZZ^2,ZZ^1,{{1}, {0}}) => map(QQ^2,QQ^2,{{1,
      0}, {0, 1}}), map(ZZ^2,ZZ^1,{{-1}, {2}}) => map(QQ^2,QQ^2,{{-1/2, 1/2}, {1, 0}}), map(ZZ^2,ZZ^1,{{0}, {1}}) => map(QQ^2,QQ^2,{{0,
      1}, {1, 0}})})
assert(rank T1 == 2)
assert(T1#"dimension of the variety" == 2)
///

-- Test 26
-- Checking image
TEST ///
T = tangentBundle hirzebruchFan 2
T = T ** T
M = matrix {{1,-1,1,-1},{0,-1,0,1/1}}
T1 = image(T,M)
assert(T1#"ring" === QQ)
assert(T1#"filtrationMatricesTable" === hashTable {matrix{{-1},{2}} => matrix{{-2,-1}}, matrix{{0},{-1}} => matrix{{-2,-1}}, matrix{{0},{1}} => matrix{{-2,-1}}, matrix{{1},{0}} => matrix{{-2,-1}}})
assert(T1#"baseTable" === new HashTable from {map(ZZ^2,ZZ^1,{{0}, {-1}}) => map(QQ^2,QQ^2,{{-1, 1}, {1, 0}}), map(ZZ^2,ZZ^1,{{1}, {0}}) => map(QQ^2,QQ^2,{{1,
     0}, {0, 1}}), map(ZZ^2,ZZ^1,{{-1}, {2}}) => map(QQ^2,QQ^2,{{-1/2, 1/2}, {1, 0}}), map(ZZ^2,ZZ^1,{{0}, {1}}) => map(QQ^2,QQ^2,{{-1,
     1}, {1, 0}})})
assert(rank T1 == 2)
assert(T1#"dimension of the variety" == 2)
///

-- Test 27
-- Checking ker
TEST ///
T = tangentBundle hirzebruchFan 2
T = T ** T
M = matrix {{1,0,1,0},{0,1,0,1/1}}
T1 = ker(T,M)
assert(T1#"ring" === QQ)
assert(T1#"filtrationMatricesTable" === hashTable {matrix{{-1},{2}} => matrix{{-1,0}}, matrix{{0},{-1}} => matrix{{-1,0}}, matrix{{0},{1}} => matrix{{-1,0}}, matrix{{1},{0}} => matrix{{-1,0}}})
assert(T1#"baseTable" === new HashTable from {map(ZZ^2,ZZ^1,{{0}, {-1}}) => map(QQ^2,QQ^2,{{0, 1}, {1, 0}}), map(ZZ^2,ZZ^1,{{1}, {0}}) => map(QQ^2,QQ^2,{{1,
      0}, {0, 1}}), map(ZZ^2,ZZ^1,{{-1}, {2}}) => map(QQ^2,QQ^2,{{-1/2, 1/2}, {1, 0}}), map(ZZ^2,ZZ^1,{{0}, {1}}) => map(QQ^2,QQ^2,{{0,
      1}, {1, 0}})})
assert(rank T1 == 2)
assert(T1#"dimension of the variety" == 2)
///

-- Test 28
-- Checking twist
TEST ///
T = tangentBundle projectiveSpaceFan 3
L = {1,-4,3,-2}
T = twist(T,L)
assert(T#"ring" === QQ)
assert(T#"baseTable" === hashTable {matrix{{0},{0},{1}} => matrix{{0_QQ,1,0},{0,0,1},{1,0,0}}, matrix{{-1},{-1},{-1}} => matrix{{-1_QQ,0,0},{-1,1,0},{-1,0,1}}, matrix{{1},{0},{0}} => matrix{{1_QQ,0,0},{0,1,0},{0,0,1}},matrix{{0},{1},{0}} => matrix{{0_QQ,1,0},{1,0,0},{0,0,1}}})
assert(T#"filtrationMatricesTable" === hashTable {matrix{{0},{0},{1}} => matrix{{3,4,4}}, matrix{{-1},{-1},{-1}} => matrix{{-2,-1,-1}}, matrix{{1},{0},{0}} => matrix{{1, 2, 2}}, matrix{{0},{1},{0}} => matrix{{-4,-3,-3}}})
assert(rank T == 3)
assert(T#"dimension of the variety" == 3)
///

-- Test 29
-- Checking isGeneral
TEST ///
T = tangentBundle pp1ProductFan 3
assert isGeneral T
L1 = {matrix {{1,0},{0,1}},matrix{{1,1},{0,1}},matrix{{-1,0},{0,1}},matrix{{-1,1},{0,-1}}}
L2 = {matrix {{-1,0}},matrix{{-1,0}},matrix{{-1,0}},matrix{{1,1}}}
T = toricVectorBundle(2,hirzebruchFan 3,L1,L2)
assert not isGeneral T
///

-- Test 30
-- Checking cartierIndex
TEST ///
C=posHull matrix {{1,2},{2,1}}
C1=posHull matrix {{1,-1},{2,-1}}
C2=posHull matrix {{2,-1},{1,-1}}
F=fan{C,C1,C2}
assert(cartierIndex({1,1,1},F) == 3)
assert(cartierIndex({3,3,3},F) == 1)
///


end


---------------------------------------
-- END OF FILE
---------------------------------------
uninstallPackage "ToricVectorBundles"
installPackage "ToricVectorBundles"
check "ToricVectorBundles"
restart

loadPackage "ToricVectorBundles";
P1 = convexHull matrix {{1,2,3,3,2,1,0,0},{0,0,1,2,3,3,2,1}};
F1 = normalFan P1;
T1 = tangentBundle F1
HH^1(T1)
HH^2(T1)
P2 = convexHull matrix {
     {1,0,0,-1,0,-1,0,1}, 
     {0,1,0,-1,0,0,-1,1}, 
     {0,0,1,0,-1,0,0,0}};
F2 = faceFan P2;
T2 = tangentBundle F2
HH^1(T2)
Omega = cotangentBundle F2
Omega == dual T2
Endo = T2 ** Omega
HH^1(Endo)
K = weilToCartier({-1,-1,-1,-1,-1,-1,-1,-1},F2)
areIsomorphic(K,exteriorPower(3,Omega))
restart