-
Notifications
You must be signed in to change notification settings - Fork 0
/
EDdegrees.m2
560 lines (501 loc) · 14.3 KB
/
EDdegrees.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
newPackage(
"EDdegrees",
Version => "0.2.2",
Headline => "A test package for EDdegree computations",
PackageExports => {"FMPIntersectionTheory"}
)
needsPackage "FMPIntersectionTheory"
export {
"isoQ",
"gEDdeg",
"EDdegSmooth",
"EDdegChiMa",
-- "tEDdegChi",
-- "timedEDdegChi",
"EDdeg",
"EDdegHypersurface",
"EDdegCurve",
-- "EDdegCurve2",
-- "conormalVariety",
-- "eddContributionAtQ",
-- "ratNormCurve",
-- "eddFermat",
-- "fermatHypersurface",
"Smooth",
"FieldExt"
-- "Verbose"
}
gEDdeg = method(TypicalValue => ZZ)
gEDdeg Ideal := X -> (
{*
Returns the "generic" ED degree of X, that is, the ED degree of a general translate
sumPolarRanks is a function from the package FMPIntersectionTheory
*}
return sumPolarRanks(X)
)
EDdeg = method(TypicalValue => ZZ,
Options => {Smooth=>false,
FieldExt=>false,
Verbose=>false})
EDdeg(Ideal) := opts -> (X) -> (return EDdeg(X,isoQ X))
EDdeg(Ideal,List) := opts -> (X,L) -> (return EDdeg(X,ideal(matrix{L} * transpose(matrix{terms (isoQ(X))_0}))))
EDdeg(Ideal,Ideal) := opts -> (X,Q) -> (
{*
computes ED degree of X using the algebraic formulation via Lagrange multipliers
*}
R := ring X;
C := first(R#baseRings);
-- can't just set c:=codim X because codim is buggy over field extensions
c := dim ring X - dim quotient X;
-- JQ := sum flatten entries jacobian Q;
M := matrix {for i from 1 to numgens R list
random(13,191)}|| transpose(jacobian(Q)) ||transpose(jacobian(X));
J := ideal ();
if opts.Smooth then (
J = saturate(X+minors(c + 2, M), Q);
) else (
sing := saturate trim minors(c, jacobian X);
J = saturate(X+minors(c + 2, M), sing*Q);
);
-- if (codim(J) != numgens(R)) then error "Something went wrong.. got infinitely many critical points";
if opts.FieldExt then (
if opts.Verbose then << "computing degree over field extension..." << endl;
return degreeOverFieldExt(J,Verbose=>opts.Verbose)
) else (
if opts.Verbose then << "computing degree normally..." << endl;
return degree J
)
)
EDdegSmooth = method(TypicalValue => ZZ,
Options => {Verbose => false})
EDdegSmooth(Ideal) := opts -> (X) -> (return EDdegSmooth(X,isoQ(X),opts))
EDdegSmooth(Ideal,RingElement) := opts -> (X,q) -> (return EDdegSmooth(X,ideal q,opts))
EDdegSmooth(Ideal,Ideal) := opts -> (X,Q) -> (
{*
Formula following Theorem 5.1
(1+2h) c(T*X x O(2h))
EDdeg(X) = gEDdeg(X) - \int --------------------- s(J(X \cap Q), X)
1+h
*}
if dim ideal singularLocus X > 0 then error "Expected a smooth variety";
c := cotangentTensorLineBundle(X,2);
h := (gens ring c)#1; -- hyperplane class in PPn
numer := (1+2*h)*c;
denom := sum (for i from 0 to length(gens ring h) list (-h)^i);
if opts.Verbose then << "Computing contribution (Segre class) now..." << endl;
contrib := integral (numer*denom*sub(segreQ(X,Q),ring c));
if opts.Verbose then << "Computing generic ED degree now..." << endl;
g := gEDdeg(X);
if opts.Verbose then << g - contrib << " = " << g << " - " << contrib << endl;
return g - contrib
-- return (numer,denom,sub(segreQ(X),ring c))
)
EDdegChiMa = method(TypicalValue => ZZ,
Options => {Verbose => false})
EDdegChiMa Ideal := opts -> X -> (
{*
Formula following Proposition 3.1
EDdeg(X) = chiMa(X) - chiMa(X \cap Q) - chiMa(X \cap H) + chiMa(X \cap H \cap Q)
*}
R := ring X;
H := ideal sum ((gens R) / (i-> random(13,223)*i));
Q := isoQ(X);
chiMaX := if dim X > 0 then integral chernMather(X) else return 0;
chiMaXH := if dim (X+H) > 0 then integral chernMather(X+H) else 0;
chiMaXQ := if dim (X+Q) > 0 then integral chernMather(X+Q) else 0;
chiMaXHQ := if dim (X+H+Q) > 0 then integral chernMather(X+H+Q) else 0;
if opts.Verbose then << "EDdeg(X) = (-1)^" << dim variety X << " ( " << chiMaX << " - " << chiMaXH << " - " << chiMaXQ << " + " << chiMaXHQ << " )" << endl;
return (-1)^(dim variety X)*(chiMaX - chiMaXH - chiMaXQ + chiMaXHQ)
-- return (X,H,Q)
)
EDdegHypersurface = method(TypicalValue => ZZ,
Options => {Verbose => false})
EDdegHypersurface Ideal := opts -> X -> (
{*
returns EDdegree of smooth hypersurface X
*}
s := sumPolarRanks(X);
c := eddContributionAtQ(X);
EDdeg := s - c;
<< EDdeg << " = " << s << " - " << c << endl;
return EDdeg
)
EDdegCurve = method(TypicalValue => ZZ,
Options => {Verbose => false})
EDdegCurve Ideal := opts -> C -> (
{*
In the plane, the main formula can be made quite simple
EDdeg(C) = deg(C)*(deg(C)-2) + #(C \cap Q)
and the last term can be computed as the number of (distinct) factors of a bivariate polynomial
*}
R := ring C;
F := coefficientRing R;
S' := F(monoid[getSymbol "i"]);
S := (S'/(S'_0^2+1))(monoid[getSymbol "s",getSymbol "t"]);
i := sub(S'_0,S);
s := S_0;
t := S_1;
f := [s^2-1,2*s,i*(s^2+1)];
m := for j to (numgens R - 1) list (R_j => f#j);
d := degree C;
p := if isSubset(C,ideal(R_0^2+R_2^2,R_1)) then (
1 + degreeOverFieldExt(radical sub(C,m))
) else (
degreeOverFieldExt(radical sub(C,m))
);
if opts.Verbose then << d << "(" << d << "-2) + " << p << endl;
return d*(d-2) + p
)
--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--
-----------------------------------------------------------
-- -- Utility functions
-----------------------------------------------------------
--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--
degreeOverFieldExt = method(TypicalValue => ZZ,
Options => {Verbose => false})
degreeOverFieldExt Ideal := opts -> p -> (
HS := numerator reduceHilbert hilbertSeries p;
if opts.Verbose then << HS << endl;
degs := gens ring HS;
return sub(HS,{first degs => 1} | (drop(degs,1) / (i -> i => 0)))
)
-- ith chern class, given the total chern class c
ci = (c,i) -> (someTerms(c,-i-1,1))
cotangentTensorLineBundle = (X,d) -> (
n := dim X;
XX := projectiveScheme X;
H := XX#Hyperplane;
cTX := if codim X == #(XX#Equations) then (
H^(codim X) * product(XX#Equations / (e -> 1 - (first degree e)*H))
) else (
chernMather X
);
cX := sub(cycleClass projectiveScheme X, ring cTX);
cTX = cTX // cX;
-- << cTX << endl;
h := (gens ring cTX)#1;
cT'X := sub(cTX,{h=>-h});
firstCoeff := sub(first flatten entries (coefficients someTerms(cT'X,-1,1))#1,ZZ);
cT'X = if firstCoeff > 0 then cT'X else -1*cT'X;
cL := 1 + d*h;
sum (for i from 0 to n list ( ci(cT'X,i) * cL^(n-1-i) ))
)
segreQ = (X,Q)-> (
return segreClass(ideal singularLocus(X+Q), X)
)
isoQ = X -> (
return ideal sum ((i -> i^2) \ gens ring X)
)
conormalVariety = X -> (
R := ring X;
C := coefficientRing R;
n := numgens R;
RxRdual := C(monoid[toSequence(gens R)| ((i -> (getSymbol "a")_i) \ (0..n-1)) ]);
I := saturate(sub(X,RxRdual),take(flatten entries gens RxRdual,numgens R));
J := saturate(sub(jacobian X,RxRdual),take(flatten entries gens RxRdual,numgens R));
y := (i->{RxRdual_i}) \ drop(vars RxRdual, numgens R);
return saturate(I + minors(2,matrix{(i->{RxRdual_i}) \(n..2*n-1)}| J),minors(1,J))
)
eddContributionAtQ = X -> (
{*
EDdeg(X) = gEDdeg(X) - \int (1+h)^n s(J(X \cap Q), X)
*}
R := ring X;
n := dim R - 1;
Q := isoQ(X);
s := segreClass(ideal singularLocus(X+Q), X);
C := ring s;
h := (gens ring s)#1;
return integral ((1+h)^n * s)
)
--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--
-----------------------------------------------------------
-- -- Utility functions for experiments
-----------------------------------------------------------
--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--
-------------------------
-- Rational normal curves
-------------------------
ratNormCurve = d -> (
-- x := getSymbol "x";
-- vrs := vars(0..d);
-- R := QQ(monoid[vrs]);
-- R := QQ(monoid[x_0..x_d]);
R := QQ(monoid[(0..d) / (i -> (getSymbol "x")_i)]);
-- M := matrix{{vrs_0..vrs_(d-1)},{vrs_1..vrs_d}};
-- M := matrix{{x_0..x_(d-1)},{x_1..x_d}};
-- M := matrix{{R_0,R_1},{R_1,R_2}};
M := matrix{take(gens R,{0,d-1}),take(gens R,{1,d})};
V := minors(2,M);
<< M << endl;
<< timing EDdeg(V,Smooth=>true) << endl;
<< timing EDdegChiMa(V) << endl;
<< timing EDdegSmooth(V) << endl;
)
-------------------------
-- Fermat Hypersurfaces
-------------------------
fermatHypersurface = (n,d) -> (
R := QQ(monoid[(i -> (getSymbol "x")_i) \ (0..n)]);
X := ideal sum ( (gens R) / (i -> i^d) );
return X
)
eddFermat = (n,d) -> (
R := QQ(monoid[(i -> (getSymbol "x")_i) \ (0..n)]);
gbd := sum apply(n,i->d*(d-1)^i);
F := sum apply(n+1,i->(gens R)_i^2);
M := matrix{apply(n+1,i->((gens R)_i)^(d-1))}||matrix{gens R};
I := ideal(F)+minors(2,M);
eddeg := gbd-(degree I)*(dim I);
<< eddeg << " = " << gbd << " - " << degree I << " * " << dim I << endl;
return eddeg
)
beginDocumentation()
doc ///
Key
EDdegrees
Headline
A package for computing Euclidean distance degrees
Description
Text
This package implements formulas found in [AH17] as well as the general formula from [DHO+17]
Caveat
SeeAlso
///
doc ///
Key
EDdeg
(EDdeg,Ideal)
Headline
Computes ED degree of any projective variety
Usage
EDdeg X
Inputs
X:Ideal
FieldExt=>Boolean
Determines whether to modify the way points are counted
Smooth=>Boolean
If X is smooth, we can skip computing the jacobian ideal, which saves time
Verbose=>Boolean
Outputs
:ZZ
Description
Example
PP3 = QQ[w,x,y,z];
X = minors(2,matrix{{w,x,y},{x,y,z}})
EDdeg X
///
doc ///
Key
EDdegCurve
(EDdegCurve,Ideal)
Headline
Computes the ED degree of a smooth plane curve
Usage
EDdegCurve X
Inputs
X:Ideal
Verbose=>Boolean
Outputs
:ZZ
Description
Text
In the plane, the main formula can be made quite simple:
EDdeg(C) = deg(C)*(deg(C)-2) - #(C \cap Q)
and the last term can be computed as the number of (distinct) factors of a bivariate polynomial
Example
PP2 = QQ[x,y,z];
C = ideal "x5+y5+z5";
EDdegCurve C
///
doc ///
Key
EDdegHypersurface
Headline
Computes the ED degree of a smooth hypersurface
Usage
EDdegHypersurface X
Inputs
X:Ideal
Verbose=>Boolean
Outputs
:ZZ
///
doc ///
Key
EDdegChiMa
Headline
Computes the ED degree of a general translate of a smooth variety
Usage
EDdegChiMa X
Inputs
X:Ideal
Outputs
:ZZ
///
doc ///
Key
EDdegSmooth
Headline
Computes the ED degree of any smooth variety
Usage
EDdegSmooth X
Verbose=>Boolean
Inputs
X:Ideal
Outputs
:ZZ
///
doc ///
Key
isoQ
Headline
Ideal of isotropic quadric in same ambient as X
Usage
isoQ X
Inputs
X:Ideal
Outputs
:Ideal
///
doc ///
Key
gEDdeg
Headline
ED degree of a general translate of X
Usage
gEDdeg X
Inputs
X:Ideal
Outputs
:ZZ
///
doc ///
Key
FieldExt
Headline
Option to indicate X is defined in a field extension
///
doc ///
Key
Smooth
Headline
Option to indicate X is known to be smooth
///
TEST ///
d = eddFermat(2,5)
F = fermatHypersurface(2,5)
assert(d == EDdeg(F))
assert(d == EDdeg(F,Smooth=>true))
-- EDdegChi(fermatHypersurface(2,5))
assert(d == EDdegSmooth(F))
d = eddFermat(2,6)
F = fermatHypersurface(2,6)
assert(d == EDdeg(F,Smooth=>true))
-- EDdegChi(fermatHypersurface(2,5))
assert(d == EDdegSmooth(F))
assert(d == EDdegHypersurface(F))
d = eddFermat(2,7)
F = fermatHypersurface(2,7)
assert(d == EDdeg(F,Smooth=>true))
-- EDdegChi(fermatHypersurface(2,5))
assert(d == EDdegSmooth(F))
assert(d == EDdegHypersurface(F))
///
TEST ///
for i from 3 to 20 do (
assert(eddFermat(2,i) == EDdegCurve fermatHypersurface(2,i))
)
///
TEST ///
PP3 = QQ[x_0..x_3]
C = minors(2,matrix{{x_0..x_2},{x_1..x_3}})
assert(7 == EDdeg(C,Smooth=>true))
assert(7 == EDdegChiMa(C))
assert(7 == EDdegSmooth(C))
PP4 = QQ[y_0..y_4]
C = minors(2, matrix{{y_0..y_3},{y_1..y_4}})
assert(10 == EDdeg(C,Smooth=>true))
assert(10 == EDdegChiMa(C))
assert(10 == EDdegSmooth(C))
PP5 = QQ[x_0..x_5]
C = minors(2, matrix{{x_0..x_4},{x_1..x_5}})
assert(13 == EDdegChiMa(C))
assert(13 == EDdegSmooth(C))
///
TEST ///
R = QQ[x,y,z]
q = x^2 + y^2 + z^2
C = ideal(q - 2*z^2)
assert(2 == EDdeg(C,Smooth=>true))
assert(2 == EDdegHypersurface(C))
assert(2 == EDdegSmooth(C))
C = ideal(x*q+y^3)
assert(5 == EDdeg(C,Smooth=>true))
assert(5 == EDdegHypersurface(C))
assert(5 == EDdegSmooth(C))
C = ideal(x*y*q+z^4)
assert(10 == EDdeg(C,Smooth=>true))
assert(10 == EDdegHypersurface(C))
assert(10 == EDdegSmooth(C))
C = ideal(x*y*(x+y)*q+z^5)
assert(17 == EDdeg(C,Smooth=>true))
assert(17 == EDdegHypersurface(C))
assert(17 == EDdegSmooth(C))
///
TEST ///
R = QQ[x,y,z,w]
q = x^2 + y^2 + z^2 + w^2
I = ideal(q+y^2)
assert(2 == EDdeg(I,Smooth=>true))
assert(2 == EDdegHypersurface(I))
assert(2 == EDdegSmooth(I))
I = ideal(q+x*y)
assert(4 == EDdeg(I,Smooth=>true))
assert(4 == EDdegHypersurface(I))
assert(4 == EDdegSmooth(I))
I = ideal(w*q+x*y*z)
assert(15 == EDdeg(I,Smooth=>true))
assert(15 == EDdegHypersurface(I))
assert(15 == EDdegSmooth(I))
///
TEST ///
R = QQ[a,b,c,d,e]
q = sum(gens R / (i -> i^2))
-- nonsingular
I = ideal(q + a^2)
assert(2 == EDdeg(I,Smooth=>true))
assert(2 == EDdegHypersurface(I))
assert(2 == EDdegSmooth(I))
I = ideal(q + a*b)
assert(4 == EDdeg(I,Smooth=>true))
assert(4 == EDdegHypersurface(I))
assert(4 == EDdegSmooth(I))
I = ideal(q + a*b + a*c + a*d + a*e + b*c + b*d + b*e + c*d + c*e + d*e)
assert(2 == EDdeg(I,Smooth=>true))
assert(2 == EDdegHypersurface(I))
assert(2 == EDdegSmooth(I))
I = ideal(e*q + a^3+b^3+c^3+d^3)
assert(45 == EDdeg(I,Smooth=>true))
assert(45 == EDdegHypersurface(I))
assert(45 == EDdegSmooth(I))
///
TEST ///
PP5 = QQ[x_0..x_5]
m = matrix{
{x_0,x_1,x_2},
{x_1,x_3,x_4},
{x_2,x_4,x_5}}
S = minors(2,m)
assert(13 == EDdeg(S,Smooth=>true))
assert(13 == EDdegChiMa(S))
assert(13 == EDdegSmooth(S))
///
TEST ///
sleep 5
///
end
restart
uninstallPackage("EDdegrees")
load("EDdegrees.m2")
installPackage("EDdegrees",RemakeAllDocumentation=>true,RerunExamples=>true)