/
CharacteristicClasses.m2
2561 lines (2359 loc) · 108 KB
/
CharacteristicClasses.m2
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
-- -*- coding: utf-8 -*-
newPackage(
"CharacteristicClasses",
Version =>"2.0",
Date => "October 24, 2015",
Authors => {{Name => "Martin Helmer",
Email => "martin.helmer@berkeley.edu",
HomePage => "https://math.berkeley.edu/~mhelmer/"},
{Name => "Christine Jost",
Email => "christine.e.jost@gmail.com"}},
Headline => "CSM classes, Segre classes and the Euler characteristic for some subschemes of smooth complete toric varieties",
Keywords => {"Intersection Theory"},
DebuggingMode => false,
PackageImports => { "Elimination", "PrimaryDecomposition", "NormalToricVarieties"},
Configuration => { "pathToBertini" => ""},
Certification => {
"journal name" => "The Journal of Software for Algebra and Geometry",
"journal URI" => "http://j-sag.org/",
"article title" => "Computing characteristic classes and the topological Euler characteristic of complex projective schemes",
"acceptance date" => "5 June 2015",
"published article URI" => "http://msp.org/jsag/2015/7-1/p04.xhtml",
"published code URI" => "http://msp.org/jsag/2015/7-1/jsag-v7-n1-x04-CharacteristicClasses.m2",
"repository code URI" => "http://github.com/Macaulay2/M2/blob/master/M2/Macaulay2/packages/CharacteristicClasses.m2",
"release at publication" => "82375d8c668f3acf1d825b8ba991081769fba742", -- git commit number in hex
"version at publication" => "1.1",
"volume number" => "7",
"volume URI" => "http://msp.org/jsag/2015/7-1/"
}
);
-- Check the ~/.Macaulay2/init-CharacteristicClasses.m2 file for the absolute path.
bertini'path = (options CharacteristicClasses).Configuration#"pathToBertini";
if not instance(bertini'path,String) then error "expected configuration option pathToBertini to be a string."
--Exported functions/variables
export{"Segre",
"CSM",
"Euler",
"Chern",
"ChowRing",
"ClassInChowRing",
"ClassInToricChowRing",
"ToricChowRing",
"isMultiHomogeneous",
"MultiProjCoordRing",
"CheckToricVarietyValid",
"Output",
"HashForm",
"HashFormXL",
"ChowRingElement",
"Method",
"InclusionExclusion",
"DirectCompleteInt",
"InputIsSmooth",
"IndsOfSmooth",
"CheckSmooth",
"CompMethod",
"ProjectiveDegree",
"PnResidual",
"bertini",
"bertiniCheck"
}
MultiProjCoordRing=method(TypicalValue=>Ring);
MultiProjCoordRing (Symbol,List):=(x,l)->(
kk:=ZZ/32749;
return MultiProjCoordRing(kk,x,l);
);
MultiProjCoordRing (Ring,List):=(kk,l)->(
x:=symbol x;
return MultiProjCoordRing(kk,x,l);
);
MultiProjCoordRing (List):=(l)->(
x:=symbol x;
kk:=ZZ/32749;
return MultiProjCoordRing(kk,x,l);
);
MultiProjCoordRing (Ring, Symbol,List):=(kk,x,l)->(
if not isField(kk) then(
<<"The coefficient ring must be a field, using the default field kk=ZZ/32749"<<endl;
kk=ZZ/32749;
);
totalDim:=sum(l);
m:=length(l);
numVars:=totalDim+m;
degs:={};
ind:=0;
for n in l do (
for i from 0 to n do(
degs=append(degs,OneAti(m,ind));
);
ind=ind+1;
);
return kk[x_0..x_(numVars-1),Degrees=>degs];
);
ClassInChowRing=method(TypicalValue=>RingElement);
ClassInChowRing (QuotientRing,RingElement) :=(A,f)->(
d:=degree f;
m:=numgens(A);
if not isMultiHomogeneous(f) then error "Requires Homogeneous Input"<<endl;
if length(d)!=m then(
error "The degree length of the input polynomial does not match the input ring"<<endl;
return 0;
);
return sum(m,i->d_i*A_i);
);
ClassInToricChowRing=method(TypicalValue=>RingElement);
ClassInToricChowRing (QuotientRing,RingElement) :=(A,f)->(
return substitute(f,A);
);
---------------------------------------------------------
--This function computes the Chern or Chern Fulton class
--
--Input: An Ideal I, of if the ambient spaces is a Toric variety
--an ideal and a NormalToricVariety. Optionally the
--associated Chow ring, or toric Chow ring may be input so
--that the output is returned in this ring
--
--Output: If V=V(I) (in a applicable toric variety X) is smooth
--the Chern class c(V)=c(TV)*[V] is output,
--if the input is not smooth the Chern-Fulton class (CF) is returned
--
--Computed as CF(V)=c(TX)*s(V,X).
-- (s(V,X) denoting the Segre class of the subscheme V)
--
--Optionally the output may be returned in the form of a MutableHashTable
--using the option: Output=>HashForm
--with the following keys:
--"Segre"=s(V,X)
--::"SegreList"-List for of "Segre"
--"CF"="Chern"=Chern-Fulton class (Chern class if V smooth)
--"G" the class of the 'Projective Degrees', see [7] (or [5])
--::"Glist"-List form of G
--
---------------------------------------------------------
Chern=method(TypicalValue=>RingElement,Options => {CompMethod=>ProjectiveDegree,Output=>ChowRingElement});
Chern (Ideal,Symbol) :=opts->(I,h)->(
if opts.CompMethod==PnResidual or opts.CompMethod==bertini then(
if degreeLength(ring(I))==1 then(
(chernList, ambientDim):= internalChernClassList(I, CompMethod => opts.CompMethod);
return output (chernList, ambientDim, h);
)
else(
<<"The input computational method is not valid for rings with degree length greater than 1"<<endl;
<<"The standard method will be used instead"<<endl;
);
);
return Chern(ChowRing(ring(I),h),I);
);
Chern (Ideal) :=opts->(I)->(
if (opts.CompMethod==PnResidual or opts.CompMethod==bertini) then(
H:=symbol H;
return Chern(I,H,CompMethod=>opts.CompMethod,Output=>opts.Output);
);
return Chern(ChowRing(ring(I)),I,Output=>opts.Output);
);
Chern (QuotientRing, Ideal) :=opts->(ChRing, I)->(
if not isMultiHomogeneous(I) then error "Requires Homogeneous Input, try saturating by the irrelevant ideal"<<endl;
B:=flatten entries sort basis ChRing;
ns:=degree last B;
n:=sum(ns);
m:=length ns;
R:=ring I;
ChernTR:=product(m,i->(1+(basis(OneAti(m,i),ChRing))_0_0)^(ns_i+1));
csm:=0;
if opts.Output==HashForm then(
csm=Segre(ChRing,I,Output=>opts.Output);
csm#"CF"=ChernTR*csm#"Segre";
csm#"Chern"=csm#"CF";
)
else(
csm=ChernTR*Segre(ChRing,I);
);
return csm;
);
Chern (NormalToricVariety,Ideal) :=opts-> (TorVar,I)->(
return Chern(ToricChowRing(TorVar),TorVar,I);
);
Chern (QuotientRing, NormalToricVariety,Ideal) :=opts-> (ChRing, TorVar,I)->(
if not isMultiHomogeneous(I) then error "Requires Homogeneous Input, try saturating by the irrelevant ideal"<<endl;
R:=ring I;
ChernTR:=substitute(product(numgens(R),i->(1+R_i)),ChRing);
csm:=0;
if opts.Output==HashForm then(
csm=Segre(ChRing,TorVar,I,Output=>opts.Output);
csm#"CF"=ChernTR*csm#"Segre";
csm#"Chern"=csm#"CF";
)
else(
csm=ChernTR*Segre(ChRing,TorVar,I);
);
return csm;
);
---------------------------------------------------------
--This function checks if the input is a toric variety for
--which the methods described in
--
--Input: A NormalToricVariety
--
--Output: true/false, true if the input if the methods of
-- are applicable, false otherwise.
--
---------------------------------------------------------
CheckToricVarietyValid=method(TypicalValue=>Boolean);
CheckToricVarietyValid NormalToricVariety:=X->(
-- needsPackage "NormalToricVarieties";
Value:=true;
for i from 0 to #(rays(X))-1 do (
if not isNef(X_i) then(
return false;
);
);
if length(primaryDecomposition ideal X)!=(#(rays(X))-dim(X)) then(
Value=false;
);
return Value;
);
---------------------------------------------------------
--This function checks if the input is Homogeneous with
--respect to the grading
--
--Input: An ideal or a polynomial in a polynomial ring R
--
--Output: true/false, true if the input is homogeneous with
--respect to the grading on R
--
---------------------------------------------------------
isMultiHomogeneous=method(TypicalValue=>Boolean);
isMultiHomogeneous Ideal:=I->(
Igens:=flatten entries gens(I);
d:=0;
fmons:=0;
for f in Igens do(
fmons=flatten entries monomials(f);
if length(fmons)>1 then(
d=degree(first(fmons));
for mon in fmons do(
if degree(mon)!=d then(
<<"Input term below is not homogeneous with respect to the grading"<<endl;
<<f<<endl;
return false;
);
);
);
);
return true;
);
isMultiHomogeneous RingElement:=f->(
return isMultiHomogeneous(ideal(f));
);
ToricChowRing=method(TypicalValue=>QuotientRing);
ToricChowRing NormalToricVariety:=TorVar->(
needsPackage "NormalToricVarieties";
assert isSimplicial TorVar;
--First build Chow ring, need Stanley-Reisner Ideal (SR) and the ideal
-- generated by the linear relations of the rays (J)
--See Cox, Little, Schenck Th. 12.5.3 and comments after proof
R:=ring(TorVar);
A:=0;
--For simplical toric var. Lemma 3.5 of Euler characteristic of coherent sheaves on simplicial torics via the Stanley-Reisner ring
-- (and probably other sources) tell us that the SR ideal is the Alexander
--dual of the toric irrelevant ideal
--SR:=dual monomialIdeal TorVar;
P:=primaryDecomposition ideal TorVar;
SR:=ideal for p in P list product flatten entries gens p;
F:=fan TorVar;
Fd:=dim(F);
--Build ideal generated by linear relations of the rays
Jl:={};
for j from 0 to dim(F)-1 do(
Jl=append (Jl,sum(length rays(TorVar), i->(((rays TorVar)_i)_j)*R_i ));
);
J:=ideal(Jl);
--Chow ring
if isSmooth(TorVar) then(
--if smooth our Chow ring should be over ZZ
--C:=QQ[gens R, Degrees=>degrees R, Heft=>heft R];
C:=ZZ[gens R];
A=C/substitute(SR+J,C);
)
else (error "Calculations for subschemes of singular toric varieties are not implemented yet";return 0;);
--Generators (as a ring) of the quotient ring representation of the Chow ring correspond to
--the divisors associated to the rays in the fan Theorem 12.5.3. Cox, Little, Schenck and
--comments above
return A;
);
---------------------------------------------------------
--This function builds the Chow ring of a product of
--projective spaces.
--
--Input: A graded polynomial ring which is the coordinate ring
--of a product of projective spaces
--
--Output: A quotient ring which represents the Chow ring of the
--product of projective spaces P=P^{n_1} x ....xP^{n_m} as
--A=ZZ[h_1,...,h_m]/(h_1^{n_1+a},...,h_m^{n_m+1})
-- with h_j denoting the (pushforward of) the rational equivalence
--class of a hyperplane in the projective space P^{n_j}.
--
--optionally one may choose a different symbol to represent
--the hyperplane classes
---------------------------------------------------------
ChowRing=method(TypicalValue=>QuotientRing);
ChowRing (Ring):=(R)->(
h:=symbol h;
return ChowRing(R,h);
);
ChowRing (Ring,Symbol):=(R,h)->(
Rgens:=gens R;
Rdegs:=degrees R;
degd:=0;
eqs:=0;
ChDegs:=unique Rdegs;
m:=length ChDegs;
C:=ZZ[h_1..h_m,Degrees=>ChDegs];
K:={};
inds:={};
rg:=0;
ns:={};
temp:=0;
for d in ChDegs do(
temp=0;
for a in Rdegs do(
if d==a then temp=temp+1;
);
ns=append(ns,temp);
);
for i from 0 to length(ChDegs)-1 do(
K=append(K,C_(i)^(ns_i));
);
K=substitute(ideal K,C);
A:=C/K;
return A;
);
Euler = method(TypicalValue => RingElement,Options => {Method=>InclusionExclusion,CompMethod=>ProjectiveDegree,InputIsSmooth=>false,Output=>ChowRingElement,IndsOfSmooth=>{}});
Euler Ideal:=opts->I->(
if opts.CompMethod==PnResidual or opts.CompMethod==bertini then(
if degreeLength(ring(I))==1 then(
return internalEuler(I, CompMethod => opts.CompMethod);
)
else(
<<"The input computational method is not valid for rings with degree length greater than 1"<<endl;
<<"The standard method will be used instead"<<endl;
);
);
A:=ChowRing(ring I);
B:=last flatten entries sort basis A;
csm:=0;
EC:=0;
if opts.InputIsSmooth==true then(
if opts.Output==HashForm then(
EC=Chern(A,I,CompMethod=>opts.CompMethod,Output=>opts.Output);
EC#"Euler"=EC#"CSM"_(B)
)
else(
csm=Chern(A,I,CompMethod=>opts.CompMethod);
EC=csm_(B);
);
)
else (
if opts.Output==HashForm then(
EC=CSM(A,I,Method=>opts.Method,Output=>opts.Output);
EC#"Euler"=EC#"CSM"_(B)
)
else(
csm=CSM(A,I,Method=>opts.Method,IndsOfSmooth=>opts.IndsOfSmooth);
EC=csm_(B);
);
);
return EC;
);
Euler (NormalToricVariety,Ideal):=opts->(TorVar,I)->(
A:=ToricChowRing TorVar;
B:=last flatten entries sort basis A;
csm:=0;
EC:=0;
if opts.InputIsSmooth==true then(
if opts.Output==HashForm then(
EC=Chern(A,TorVar,I,CompMethod=>opts.CompMethod,Output=>opts.Output);
EC#"Euler"=EC#"CSM"_(B)
)
else(
csm=Chern(A,I,CompMethod=>opts.CompMethod);
EC=csm_(B);
);
)
else (
if opts.Output==HashForm then(
EC=CSM(A,TorVar,I,Method=>opts.Method,Output=>opts.Output,IndsOfSmooth=>opts.IndsOfSmooth);
EC#"Euler"=EC#"CSM"_(B)
)
else(
csm=CSM(A,TorVar,I,Method=>opts.Method,IndsOfSmooth=>opts.IndsOfSmooth);
EC=csm_(B);
);
);
return EC;
);
Euler RingElement:=opts->csm->(
A:=ring csm;
B:=last flatten entries sort basis A;
EC:=csm_(B);
return EC;
);
CSM = method(TypicalValue => RingElement,Options => {CompMethod=>ProjectiveDegree,Method=>InclusionExclusion,CheckSmooth=>true,Output=>ChowRingElement,IndsOfSmooth=>{},InputIsSmooth=>false});
CSM NormalToricVariety :=opts->TorVar->(
A:=ToricChowRing(TorVar);
return CSM(A,TorVar,CheckSmooth=>opts.CheckSmooth);
);
CSM (QuotientRing, NormalToricVariety) :=opts->(A,TorVar)->(
--Generators (as a ring) of the quotient ring representation of the Chow ring correspond to
--the divisors associated to the rays in the fan Theorem 12.5.3. Cox, Little, Schenck and
--comments above
L:=gens(A);
Trays:=rays TorVar;
csm:=1_A;
Rmat:=0;
prodj:=0;
--The following implements the method described
--in Barthel, Brasselet, and Fieseler.
--Lemma 12.5.2 of Cox, Little, Schenck is used to find the Chow ring class of the
--orbit closure from divisors
--if the toric variety is smooth the multiplicity is 1.
Ssets:=0;
indsubsets:=0;
TorVarIsSmooth:=false;
if opts.CheckSmooth==true then TorVarIsSmooth=isSmooth(TorVar);
if TorVarIsSmooth then(
for i from 1 to dim(TorVar) do(
indsubsets=subsets((0..numgens(A)-1),i);
Ssets=for l in indsubsets list L_l;
csm=csm+sum(0..(length(Ssets)-1),j-> product(Ssets_j));
);
)
else(
for i from 1 to dim(TorVar) do(
indsubsets=subsets((0..numgens(A)-1),i);
Ssets=for l in indsubsets list L_l;
--csm=csm+sum(0..(length(Ssets)-1),j-> mult(transpose matrix Trays_(indsubsets_j))*product(Ssets_j));
for j from 0 to length(Ssets)-1 do(
Rmat=transpose matrix Trays_(indsubsets_j);
prodj=product(Ssets_j);
if prodj!=0 then(
csm=csm+ mult(Rmat)*prodj;
);
);
);
);
return csm;
)
CSM (NormalToricVariety, Ideal):= opts->(TorVar,I)->(
needsPackage "NormalToricVarieties";
return CSM(ToricChowRing(TorVar),TorVar,I,Method=>opts.Method,Output=>opts.Output,IndsOfSmooth=>opts.IndsOfSmooth,InputIsSmooth=>opts.InputIsSmooth);
);
CSM (QuotientRing,NormalToricVariety, Ideal):= opts->(ChRing,TorVar,I)->(
needsPackage "NormalToricVarieties";
KnownCSM:= new MutableHashTable;
return CSM(ChRing,TorVar,I,KnownCSM,Method=>opts.Method,Output=>opts.Output,IndsOfSmooth=>opts.IndsOfSmooth,InputIsSmooth=>opts.InputIsSmooth);
);
CSM (Ideal, Symbol) := opts -> (I,hyperplaneClass) -> (
if opts.CompMethod==PnResidual or opts.CompMethod==bertini then(
if degreeLength(ring(I))==1 then(
(csmList, ambientDim):= internalCSMClassList(I, CompMethod => opts.CompMethod);
return output (csmList, ambientDim,hyperplaneClass);
)
else(
<<"The input computational method is not valid for rings with degree length greater than 1"<<endl;
<<"The standard method will be used instead"<<endl;
);
);
if not isMultiHomogeneous(I) then error "Requires Homogeneous Input, try saturating by the irrelevant ideal"<<endl;
KnownCSM:=new MutableHashTable;
return CSM(ChowRing(ring(I),hyperplaneClass),I,KnownCSM,Method=>opts.Method,Output=>opts.Output,IndsOfSmooth=>opts.IndsOfSmooth,InputIsSmooth=>opts.InputIsSmooth);
)
CSM Ideal:=opts->I->(
if opts.CompMethod==PnResidual or opts.CompMethod==bertini then(
H:=symbol H;
return CSM(I,H,CompMethod=>opts.CompMethod)
);
if not isMultiHomogeneous(I) then error "Requires Homogeneous Input, try saturating by the irrelevant ideal"<<endl;
KnownCSM:=new MutableHashTable;
return CSM(ChowRing(ring I),I,KnownCSM,Method=>opts.Method,Output=>opts.Output,IndsOfSmooth=>opts.IndsOfSmooth,InputIsSmooth=>opts.InputIsSmooth);
);
CSM (QuotientRing,Ideal):=opts->(Chring,I)->(
KnownCSM:=new MutableHashTable;
return CSM(Chring,I,KnownCSM,Method=>opts.Method,Output=>opts.Output,IndsOfSmooth=>opts.IndsOfSmooth,InputIsSmooth=>opts.InputIsSmooth);
);
CSM (QuotientRing,Ideal,MutableHashTable):=opts->(ChRing,I,KnownCSMVals)->(
if not isMultiHomogeneous(I) then error "Requires Homogeneous Input, try saturating by the irrelevant ideal"<<endl;
R:=ring I;
if opts.InputIsSmooth==true then(
return Chern(ChRing,I,Output=>opts.Output);
);
B:=flatten entries sort basis ChRing;
ns:=degree last B;
n:=sum(ns);
m:=length ns;
KnownCSMVals#"m"=m;
--R:=ring I;
degs:=unique degrees R;
tempId:={};
PDl:={};
for d in degs do(
tempId={};
for y in gens(R) do(
if degree(y)==d then(
tempId=append(tempId,y);
);
);
PDl=append(PDl,ideal(tempId));
);
ChernTR:=product(m,i->(1+(basis(OneAti(m,i),ChRing))_0_0)^(ns_i+1));
return CSMMain(ChRing,I,{PDl,n,ChernTR},KnownCSMVals,opts.Method,opts.Output,opts.IndsOfSmooth);
);
CSM (QuotientRing,NormalToricVariety,Ideal,MutableHashTable):=opts->(ChRing,TorVar,I,KnownCSMVals)->(
needsPackage "NormalToricVarieties";
if not isMultiHomogeneous(I) then error "Requires Homogeneous Input, try saturating by the irrelevant ideal"<<endl;
R:=ring I;
ChernTR:=substitute(product(numgens(R),i->(1+R_i)),ChRing);
irel:=ideal TorVar;
PDl:=primaryDecomposition irel;
n:=dim(TorVar);
KnownCSMVals#"TorVar"=TorVar;
return CSMMain(ChRing,I,{PDl,n,ChernTR},KnownCSMVals,opts.Method,opts.Output,opts.IndsOfSmooth);
);
---------------------------------------------------------
--This function computes the Segre class
--
--Input: An Ideal I, or if the ambient spaces is a Toric variety
--an ideal and a NormalToricVariety. Optionally the
--associated Chow ring, or toric Chow ring may be input so
--that the output is returned in this ring
--
--Output: If V=V(I) (in a applicable toric variety X) is smooth
--the Segre class s(V,X) of the subscheme V is output,
--
-- For most situations computations are performed in the internal method
-- SegreMain, this employs the theoretical method described in [5,7].
-- Optionally CompMthod=>PnResidual or CompMthod=>bertini can be specified
-- in such a case the method described in [1] is used and the computation
-- is performed in the method internalSegre.
--
--Optionally the output may be returned in the form of a MutableHashTable
--using the option: Output=>HashForm
--with the following keys:
--"Segre"=s(V,X)
--::"SegreList"-List for of "Segre"
--"G" the class of the 'Projective Degrees', see [7] (or [5])
--::"Glist"-List form of G
--
---------------------------------------------------------
Segre = method(TypicalValue => RingElement,Options => {Output=>ChowRingElement,CompMethod=>ProjectiveDegree});
Segre (NormalToricVariety, Ideal):= opts->(TorVar,I)->(
return Segre(ToricChowRing(TorVar),TorVar,I,Output=>opts.Output);
);
Segre (QuotientRing,NormalToricVariety, Ideal):= opts->(ChRing,TorVar,I)->(
if not isMultiHomogeneous(I) then error"Requires Homogeneous Input, try saturating by the irrelevant ideal"<<endl;
A:=ChRing;
R:=ring I;
irel:=ideal TorVar;
PDl:=primaryDecomposition irel;
n:=dim(TorVar);
degI:= degrees I;
transDegI:= transpose degI;
len:= length transDegI;
maxDegs:= for i from 0 to len-1 list max transDegI_i;
maxexs:=flatten exponents first flatten entries monomials random(maxDegs,R);
alpha:=sum(numgens(R),i->maxexs_i*substitute(R_i,A));
return SegreMainToric(ChRing,TorVar,I,PDl,{alpha,n},opts.Output);
);
Segre (QuotientRing,Ideal):=opts->(ChRing,I) ->(
R:=ring I;
degs:=unique degrees R;
tempId:={};
PDl:={};
for d in degs do(
tempId={};
for y in gens(R) do(
if degree(y)==d then(
tempId=append(tempId,y);
);
);
PDl=append(PDl,ideal(tempId));
);
Output:=opts.Output;
return(SegreMainProjective(ChRing,I,PDl,Output));
);
Segre (Ideal, Symbol) := opts -> (I,hyperplaneClass) -> (
if opts.CompMethod==PnResidual or opts.CompMethod==bertini then(
if degreeLength(ring(I))==1 then(
(segreList, ambientDim):= internalSegreClassList(I, CompMethod=> opts.CompMethod));
return output (segreList, ambientDim,hyperplaneClass);
)
else(
<<"The input computational method is not valid for rings with degree length greater than 1"<<endl;
<<"The standard method will be used instead"<<endl;
);
return(Segre(ChowRing(ring(I),hyperplaneClass),I,Output=>opts.Output));
);
Segre Ideal:=opts->I ->(
if opts.CompMethod==PnResidual or opts.CompMethod==bertini then(
H:=symbol H;
return Segre(I,H,CompMethod=>opts.CompMethod)
);
return(Segre(ChowRing(ring(I)),I,Output=>opts.Output));
);
-- There is no test for the above functions using CompMethod=>Bertini as Bertini does not need to
-- be installed on every system that runs Macaulay2. However, the function bertiniCheck()
-- checks whether the commands Segre, Chern, CSM and Euler work when using Bertini
-- instead of symbolic computations.
bertiniCheck = () -> (
setRandomSeed 24;
x := symbol x; y := symbol y; z := symbol z; w := symbol w;
-- smooth example for Segre and ChernClass
R := QQ[x,y,z,w];
I := minors(2,matrix{{x,y,z},{y,z,w}});
totalSegre := Segre(I, CompMethod=>bertini);
assert( totalSegre == 3*( (ring(totalSegre))_0 )^2 - 10*( (ring(totalSegre))_0 )^3 );
totalChern := Chern(I, CompMethod=>bertini);
assert( totalChern == 3*( (ring(totalChern))_0 )^2 + 2 * ((ring(totalChern))_0)^3 );
-- singular example for CSM Class and Euler
S := QQ[x,y,z];
J := ideal(x^3 + x^2*z - y^2*z);
totalCSM := CSM(J, CompMethod=>bertini);
assert( totalCSM == 3*( (ring(totalCSM))_0 ) + 1*( (ring(totalCSM))_0 )^2 );
eulerCharacteristic := Euler(J, CompMethod=>bertini);
assert( eulerCharacteristic == 1 );
print "Test passed for the option CompMethod=>bertini for the commands Chern, Segre, CSM and Euler.";
)
---------------------------
--Internal functions
---------------------------
mult=RayMatrix->(
r:=rank RayMatrix;
return multr(RayMatrix,r);
)
--Find the multiplicity (or index) of a simplicial cone defined by the
-- rays given by the columns of the input RayMatrix pg. 300
-- Cox, Little, Schenck.
--pg 66-68, and others....
--Find the multiplicity (or index) of a simplicial cone defined by the
-- rays given by the columns of the input RayMatrix pg. 300
-- Cox, Little, Schenck.
multr=(RayMatrix,r)->(
m:=RayMatrix;
if m==0 then return 0;
if (numRows(m)==1 or numColumns(m)==1) then( return 1);
--r:=rank m;
if r<numRows(m) then(
m=transpose groebnerBasis(transpose(m), Strategy=>"MGB");
);
if r<numColumns(m) then(
--this shouldn't be reached when using mult in csm/euler calc
m= groebnerBasis(m, Strategy=>"MGB");
);
if numRows(m)==numColumns(m) then(
mymult:=abs(determinant(m,Strategy =>Cofactor));
return mymult;
)
else (
error "multiplicity computation error";
return 0;
);
)
SegreMainToric = (ChRing,TorVar,I,PDl,AlphNList,Output)->(
if not isMultiHomogeneous(I) then error"Requires Homogeneous Input, try saturating by the irrelevant ideal"<<endl;
alpha:=AlphNList_0;
n:=AlphNList_1;
return SegreMain(ChRing,I,PDl,{alpha,n,Output});
);
SegreMainToric2 = (ChRing,TorVar,I,PDl,Output)->(
if not isMultiHomogeneous(I) then error"Requires Homogeneous Input, try saturating by the irrelevant ideal"<<endl;
irel:=ideal TorVar;
n:=dim(TorVar);
A:=ChRing;
R:=ring I;
degI:= degrees I;
transDegI:= transpose degI;
len:= length transDegI;
maxDegs:= for i from 0 to len-1 list max transDegI_i;
maxexs:=flatten exponents first flatten entries monomials random(maxDegs,R);
alpha:=sum(numgens(R),i->maxexs_i*substitute(R_i,A));
return SegreMain(ChRing,I,PDl,{alpha,n,Output});
);
SegreMainProjective=(ChRing,I,PDl,Output)->(
if not isMultiHomogeneous(I) then error "Requires Homogeneous Input, try saturating by the irrelevant ideal"<<endl;
R:=ring I;
A:=ChRing;
B:=flatten entries sort basis A;
degs:=unique degrees R;
n:=numgens(R)-length(degs);
degI:= degrees I;
transDegI:= transpose degI;
len:= length transDegI;
maxDegs:= for i from 0 to len-1 list max transDegI_i;
deg1B:={};
for w in B do if sum(degree(w))==1 then deg1B=append(deg1B,w);
m:=length degs;
alpha:=sum(length deg1B,i->(basis(OneAti(m,i),A))_0_0*maxDegs_i);
return SegreMain(A,I,PDl,{alpha,n,Output});
);
SegreMain = (ChRing,I,PDl,alphaANDn)->(
-- take care of the special cases I = (0) and I = (1)
alpha:=alphaANDn_0;
n:=alphaANDn_1;
Output:=alphaANDn_2;
R:=ring I;
kk:=coefficientRing R;
A:=ChRing;
zdim:=0;
B:=flatten entries sort basis A;
for b in B do(
if sum(flatten(exponents(b)))==n then zdim=b;
);
seg:=0;
gbI:=groebnerBasis(I, Strategy=>"MGB");
codimI:= codim ideal leadTerm gbI;
if ideal(gbI)==ideal(0_R) then return 1_A;
t1:=symbol t1;
S:=kk[gens R, t1];
dimI:=n-codimI;
gensI:= delete(0_R,flatten sort entries gens I);
exmon:=0;
degI:= degrees I;
m:=length unique degrees R;
transDegI:= transpose degI;
len:= length transDegI;
maxDegs:= for i from 0 to len-1 list max transDegI_i;
J:= for i from 1 to n list sum(gensI,g -> g*random(kk)*random(maxDegs-degree(g),R));
RdList:={};
GList:={};
Jd:=0;
JT:=0;
c:={};
v:=0;
ve:=0;
K:=0;
Ls:=0;
LA:=0;
gbWt2:=0;
tall2:=0;
Yiota:=0;
ValuesTable:=new MutableHashTable;
n2:=n;--min(n,numgens(I));
if codimI<=n then(
GList=for iota from 0 to (codimI-1) list alpha^(iota);
for iota from codimI to n2 do(
Jd=substitute(ideal take(J,iota),S);
JT=ideal (1-t1*substitute(sum(gensI,g -> g*random(kk)),S));
c={};
for w in B do if sum(flatten(exponents(w)))==iota then c=append(c,w);
Yiota=0;
for w in c do(
Ls=0;
LA=0;
K=0;
v=zdim//w;
ve=flatten exponents(v);
--In this case we are working with the toric representation
--and may use exponents directly
if length(ve)==numgens(R) then(
for i from 0 to length(ve)-1 do(
if ve_i!=0 then (
Ls=Ls+sum(ve_i,j->ideal(random(degree(R_i),R)));
);
);
)
else(
--Projective representation, exponents associated with degrees ring
for i from 0 to length(ve)-1 do(
if ve_i!=0 then (
Ls=Ls+sum(ve_i,j->ideal(random(OneAti(m,i),R)));
);
);
);
for p in PDl do (
LA=LA+ideal(1-sum(numgens(p),i->random(kk)*p_i));
);
K=Jd+JT+substitute(Ls,S)+substitute(LA,S);
gbWt2 = groebnerBasis(K, Strategy=>"F4");
tall2 = numColumns basis(cokernel leadTerm gbWt2);
Yiota=Yiota+tall2*w;
);
GList=append(GList,Yiota);
);
for l from n2 to n-1 do(
GList=append(GList,0);
);
--the following performs the Aluffi tensor notation comp
--GxOMD:=sum(0..n,i->GList_i//((1+cOMaxDegs)^i));
temp3:=1;
GxOMD:=0;
ValuesTable#"Glist"=GList;
ValuesTable#"G"=sum(GList);
tayAlph:=1;
temp4:=1;
ind:=1;
while temp4!=0 do(
temp4=alpha*temp4;
tayAlph=tayAlph+(-1)^ind*temp4;
ind=ind+1;
);
for i from 0 to n do(
GxOMD=GxOMD+GList_i*(temp3);
temp3=temp3*tayAlph;
);
seg=1-(GxOMD*tayAlph);
ValuesTable#"Segre"=seg;
tseg:=terms(seg);
tot:=0;
use R;
if Output==HashForm then(
segList:={};
for i from 0 to n do(
tot=0_A;
for f in tseg do(
if sum(flatten(exponents(f)))==i then(
tot=tot+f
);
);
segList=append(segList,tot);
);
use R;
ValuesTable#"SegreList"=segList;
return ValuesTable;
)
else (
use R;
return seg
)
)
else(
segList=for i from 0 to n list 0_A;
seg=0_A;
if Output==HashForm then(
use R;
ValuesTable#"SegreList"=segList;
ValuesTable#"Segre"=seg;
ValuesTable#"Glist"=segList;
ValuesTable#"G"=seg;
return ValuesTable;
)
else (
use R;
return seg;
);
);
);
CSMInEx = (ChRing,I,RingInfoList,KnownCSMVals,Output)->(
R:=ring I;
A:=ChRing;
PDl:=RingInfoList_0;
n:=RingInfoList_1;
ChernTR:=RingInfoList_2;
gensI:=flatten entries gens I;
gbI:=groebnerBasis(I, Strategy=>"MGB");
if ideal(gbI)==ideal 1_R then return 0_A;
if ideal(gbI)==ideal 0_R then return ChernTR;
--B:=flatten entries sort basis A;
m:=0;
if KnownCSMVals#?"m" then m=KnownCSMVals#"m";
SegY:=0;
SegV:=0;
SegYH:=0;
V:=0;
K:=0;
J:=0;
csmInput:=false;
csmValsComputed:=new MutableHashTable;
vf:=0;
csm:=0;
f:=0;
csm2:=0;
Isubsets:=delete({},subsets(numgens(I)));
for ind in Isubsets do(
csmInput=false;
if KnownCSMVals#?ind then(
if instance(KnownCSMVals#ind,A) then(
csmInput=true;
);
);
f=gensI_ind;
if csmInput then(
csm=csm+(-1)^(length(f)+1)*KnownCSMVals#ind;
)
else(
K=radical ideal product(f);
J=ideal(delete(0_R,flatten entries jacobian K));
if KnownCSMVals#?"TorVar" then(
vf=flatten exponents first flatten entries monomials K_0;
V=sum(numgens(R),i->vf_i*substitute(R_i,A));
SegYH=SegreMainToric2(A,KnownCSMVals#"TorVar",J,PDl,HashForm);
SegY=SegYH#"SegreList";
if Output==HashFormXL then(
csmValsComputed#("G(Jacobian)"|toString(ind))=SegYH#"G";
csmValsComputed#("Segre(Jacobian)"|toString(ind))=SegYH#"Segre";
);
)
else (
vf=degree K_0;
V=sum(length vf, i-> vf_i*(basis(OneAti(m,i),A))_0_0);
SegYH=SegreMainProjective(A,J,PDl,HashForm);
SegY=SegYH#"SegreList";
if Output==HashFormXL then(
csmValsComputed#("G(Jacobian)"|toString(ind))=SegYH#"G";
csmValsComputed#("Segre(Jacobian)"|toString(ind))=SegYH#"Segre";
);
);
SegV=V//(1+V);
csm2=(-1)^(length(f)+1)*(ChernTR*(SegV+sum(n+1,i->sum(n+1-i,j->binomial(n-i,j)*(-V)^j*(-1)^(n-j-i)*SegY_(n-i-j)))) );
csm=csm+csm2;
csmValsComputed#ind=csm2*(-1)^(length(f)+1);
);
);
csmValsComputed#"CSM"=csm;
use R;
if Output==HashForm or Output==HashFormXL then return csmValsComputed else return csm;
);
CSMCompleteInt= (ChRing,I,RingInfoList,KnownCSMVals,Output,SmoothInds)->(
R:=ring I;
irelId:=irrell(R);
PDl:=RingInfoList_0;
n:=RingInfoList_1;
ChernTR:=RingInfoList_2;
A:=ChRing;
gbI:=groebnerBasis(I, Strategy=>"MGB");
if ideal(gbI)==ideal 1_R then return 0_A;
if ideal(gbI)==ideal 0_R then return ChernTR;
codimI:= codim ideal leadTerm gbI;
J2:=0;
Z:=0;
J:=0;
W:=0;
hyper:=0;
cont2:=false;
Sing:=0;
cont:=true;
SingInds:={};
SegY:=0;
Ssets:={};
gensI:=flatten entries gens I;
r:=length(gensI);
codimJ2:=0;
m:=0;
if KnownCSMVals#?"m" then m=KnownCSMVals#"m";
csm:=0;
if codimI!=length(gensI) then(
<<"The input ideal does not define a complete intersection, the option 'DirectComleteInt' may not be used."<<endl;
<<"Using Inclusion/Exclusion instead."<<endl;
return CSM(ChRing,I);
)
else(
if KnownCSMVals#?"SmoothPart" or KnownCSMVals#?"SingularPart" or (SmoothInds!={}) then(