/
NumericalImplicitization.m2
2000 lines (1809 loc) · 87.7 KB
/
NumericalImplicitization.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
newPackage("NumericalImplicitization",
Headline => "a package for computing numerical invariants of images of varieties",
Version => "2.1.0",
Date => "May 18, 2019",
Authors => {
{Name => "Justin Chen",
Email => "jchen646@math.gatech.edu",
HomePage => "https://people.math.gatech.edu/~jchen646/"},
{Name => "Joe Kileel",
Email => "jkileel@math.princeton.edu",
HomePage => "https://web.math.princeton.edu/~jkileel/"}
},
PackageImports => {},
PackageExports => {"NumericalAlgebraicGeometry"},
Reload => true,
DebuggingMode => false
)
export {
"numericalSourceSample",
"numericalImageSample",
"numericalEval",
"numericalNullity",
"Precondition",
"SVDGap",
"numericalImageDim",
"numericalHilbertFunction",
"ConvertToCone",
"NumericalInterpolationTable",
"hilbertFunctionArgument",
"hilbertFunctionValue",
"UseSLP",
"imagePoints",
"interpolationBasis",
"interpolationSVD",
"interpolationMatrix",
"extractImageEquations",
"AttemptZZ",
"numericalImageDegree",
"pseudoWitnessSet",
"DoRefinements",
"DoTraceTest",
"MaxAttempts",
"MaxPoints",
"MaxThreads",
"Repeats",
"TraceThreshold",
-- "Endgame",
"PseudoWitnessSet",
"isCompletePseudoWitnessSet",
"sourceEquations",
"sourceSlice",
"generalCombinations",
"imageSlice",
"witnessPointPairs",
"isOnImage"
}
-- software options: default is M2engine throughout
NumericalInterpolationTable = new Type of HashTable
NumericalInterpolationTable.synonym = "numerical interpolation table"
globalAssignment NumericalInterpolationTable
net NumericalInterpolationTable := T -> (
(net ofClass class T | ", indicating") ||
("the space of degree " | (toString T.hilbertFunctionArgument) |
" forms in the ideal of the image has dimension " | (toString T.hilbertFunctionValue))
)
PseudoWitnessSet = new Type of HashTable
PseudoWitnessSet.synonym = "pseudo-witness set"
globalAssignment PseudoWitnessSet
net PseudoWitnessSet := W -> (
(net ofClass class W | ", indicating") ||
("the image has degree " | (toString W.degree))
)
checkRings = method(Options => {symbol ConvertToCone => false})
-- checks if the rings of F and I agree and have floating point arithmetic, and converts F, I, pts to the affine cone if ConvertToCone is false
checkRings (Matrix, Ideal, List) := Sequence => opts -> (F, I, pts) -> (
k := coefficientRing ring I;
if not numrows F == 1 then error "Expected map to be given by a 1-row matrix of polynomials";
if not ring F === ring I then error "Expected same rings for ideal and map";
if not instance(class(1_k), InexactFieldFamily) then error "Expected coefficient field with floating point arithmetic";
if opts.ConvertToCone then (
JJ := getSymbol "JJ";
S := k(monoid[append(gens ring I, JJ)]);
toS := map(S, ring I);
((last gens S)*(toS F | matrix{{1_S}}), toS(I), pts/(p -> point{append(p#Coordinates, 1_k)}))
) else (F, I, pts)
)
numericalSourceSample = method(Options => {Software => M2engine})
numericalSourceSample (Ideal, Thing, ZZ) := List => opts -> (I, W, sampleSize) -> (
R := ring I;
if I == 0 then ( k := coefficientRing R; return (entries random(k^(sampleSize), k^(#gens R)))/(p -> {p})/point; );
samplePoints := if instance(W, Point) and not I.cache.?WitnessSet then (
d := first numericalDimensions(vars R, I, W);
squaredUpSource := randomSlice(gens I, #gens R - d, {});
startSys := squaredUpSource | randomSlice(vars R, d, {W, "source"});
flatten apply(sampleSize, i -> track(startSys, squaredUpSource | randomSlice(vars R, d, {}), {W}, opts))
) else (
if not I.cache.?WitnessSet then I.cache.WitnessSet = if instance(W, WitnessSet) then W else first components(numericalIrreducibleDecomposition(I, opts));
apply(sampleSize, i -> sample I.cache.WitnessSet)
);
if precision R <= precision ring samplePoints#0#Coordinates#0 then samplePoints else refine(polySystem(I_*), samplePoints, Bits => precision R)
)
numericalSourceSample (Ideal, WitnessSet) := List => opts -> (I, W) -> numericalSourceSample(I, W, 1, opts)
numericalSourceSample (Ideal, Point) := List => opts -> (I, p) -> numericalSourceSample(I, p, 1, opts)
numericalSourceSample (Ideal, ZZ) := List => opts -> (I, sampleSize) -> numericalSourceSample(I, null, sampleSize)
numericalSourceSample Ideal := List => opts -> I -> numericalSourceSample(I, 1, opts)
numericalImageSample = method(Options => options numericalSourceSample)
numericalImageSample (Matrix, Ideal, List, ZZ) := List => opts -> (F, I, pts, sampleSize) -> (
samplePoints := if #pts > 0 then numericalSourceSample(I, pts#0, sampleSize-#pts, opts) else numericalSourceSample(I, sampleSize, opts);
numericalEval(F, samplePoints, false) /point
)
numericalImageSample (Matrix, Ideal, ZZ) := List => opts -> (F, I, sampleSize) -> numericalImageSample(F, I, {}, sampleSize, opts)
numericalImageSample (Matrix, Ideal) := List => opts -> (F, I) -> numericalImageSample(F, I, {}, 1, opts)
numericalImageSample (List, Ideal, List, ZZ) := List => opts -> (F, I, pts, sampleSize) -> numericalImageSample(matrix{F}, I, pts, sampleSize, opts)
numericalImageSample (List, Ideal, ZZ) := List => opts -> (F, I, sampleSize) -> numericalImageSample(matrix{F}, I, {}, sampleSize, opts)
numericalImageSample (List, Ideal) := List => opts -> (F, I) -> numericalImageSample(matrix{F}, I, {}, 1, opts)
numericalImageSample (RingMap, Ideal, List, ZZ) := List => opts -> (F, I, pts, sampleSize) -> numericalImageSample(F.matrix, I, pts, sampleSize, opts)
numericalImageSample (RingMap, Ideal, ZZ) := List => opts -> (F, I, sampleSize) -> numericalImageSample(F.matrix, I, {}, sampleSize, opts)
numericalImageSample (RingMap, Ideal) := List => opts -> (F, I) -> numericalImageSample(F.matrix, I, {}, 1, opts)
numericalEval = method()
numericalEval (Matrix, List, Boolean) := List => (F, upstairsPoints, includeUpstairs) -> ( -- returns a list of either matrices, or pairs of the form (Point, Matrix)
evalPts := upstairsPoints/(p -> (p, sub(F, matrix p)));
if includeUpstairs then evalPts else evalPts/last
)
numericalDimensions = method(Options => options numericalSourceSample)
numericalDimensions (Matrix, Ideal, Point) := List => opts -> (F, I, p) -> ( --outputs {dim(V(I)), dim(F(V(I))}
(F, I, p) = checkRings(F, I, {p});
p0 := 1/norm(2, matrix p#0)*(matrix p#0);
dF := sub(transpose jacobian F, p0);
if I == 0 then return {#gens ring I, #gens ring I - numericalNullity(dF, false)};
sourceJacobian := sub(transpose jacobian I, p0);
sourceDim := numericalNullity(sourceJacobian, false);
{sourceDim, sourceDim - numericalNullity(sourceJacobian || dF, false)}
)
numericalDimensions (Matrix, Ideal) := ZZ => opts -> (F, I) -> numericalDimensions(F, I, first numericalSourceSample(I, Software => opts.Software), opts)
numericalImageDim = method(Options => options numericalSourceSample)
numericalImageDim (Matrix, Ideal, Point) := ZZ => opts -> (F, I, p) -> last numericalDimensions(F, I, p, opts)
numericalImageDim (Matrix, Ideal) := ZZ => opts -> (F, I) -> last numericalDimensions(F, I, opts)
numericalImageDim (List, Ideal, Point) := ZZ => opts -> (F, I, p) -> last numericalDimensions(matrix{F}, I, p, opts)
numericalImageDim (List, Ideal) := ZZ => opts -> (F, I) -> last numericalDimensions(matrix{F}, I, opts)
numericalImageDim (RingMap, Ideal, Point) := ZZ => opts -> (F, I, p) -> last numericalDimensions(F.matrix, I, p, opts)
numericalImageDim (RingMap, Ideal) := ZZ => opts -> (F, I) -> last numericalDimensions(F.matrix, I, opts)
-- converts M to a list of 1-element lists of row matrices (to normalize rows easily)
-- listForm satisfies M == matrix listForm M (if numrows M, numcols M > 0), and this conversion is fast
listForm Matrix := A -> apply(entries A, r -> {matrix{r}})
rowScale := (L, s) -> matrix flatten apply(L, r -> if r#0 == 0 then {} else {(s/norm(2,r#0))*r}) -- deletes any zero rows
-- doubleScale := L -> transpose rowScale((entries transpose rowScale(L,1))/(r -> {matrix{r}}), sqrt(#L/(numcols(L#0#0))))
numericalNullity = method(Options => {symbol SVDGap => 1e5, Verbose => false, symbol Precondition => false})
numericalNullity (List, Boolean) := List => opts -> (M, keepSVD) -> (
if matrix M == 0 then return if keepSVD then {numcols M#0#0, 0} else numcols M#0#0;
if opts.Verbose then print "Performing normalization preconditioning ...";
T := timing A := if opts.Precondition then rowScale(M, 1) else matrix M;
if opts.Verbose then print(" -- used " | toString(T#0) | " seconds");
if opts.Verbose then print "Computing numerical kernel ...";
T = timing (S, U, Vt) := SVD A; -- do not use DivideConquer => true!
if opts.Verbose then print(" -- used " | toString(T#0) | " seconds");
largestGap := (#S, opts.SVDGap);
for i from 1 to #S-1 do (
if S#i == 0 then ( largestGap = (i, "infinity"); break; )
else if S#(i-1)/S#i > last largestGap then ( largestGap = (i, S#(i-1)/S#i); break; );
);
if keepSVD then {numcols A - first largestGap, (S, U, Vt)} else numcols A - first largestGap
)
numericalNullity (Matrix, Boolean) := ZZ => opts -> (M, keepSVD) -> if numrows M == 0 then numcols M else numericalNullity(listForm M, keepSVD, opts)
numericalNullity Matrix := ZZ => opts -> M -> numericalNullity(M, false, opts)
debug needsPackage "SLPexpressions"
monomialGate = method()
monomialGate (RingElement, List, List) := ProductGate => (m, varList, expList) -> (
productGate flatten apply(#gens ring m, i -> apply(expList#i, j -> varList#i))
)
monomialGate (RingElement, List) := ProductGate => (m, varList) -> monomialGate(m, varList, first exponents m)
makeInterpolationMatrix = method()
makeInterpolationMatrix (Matrix, List) := List => (mons, pts) -> (
X := apply(#gens ring mons, i -> inputGate ("x"|i));
Y := matrix{apply(flatten entries mons, m -> monomialGate(m, X))};
E := makeEvaluator(Y, matrix{X});
out := mutableMatrix(ring pts#0, numrows Y, numcols Y);
apply(pts/mutableMatrix, p -> (
evaluate(E, p, out);
{matrix out}
))
)
numericalHilbertFunction = method(Options => {
symbol ConvertToCone => false,
symbol Precondition => true,
Software => M2engine,
symbol SVDGap => 1e5,
symbol UseSLP => false,
Verbose => true})
numericalHilbertFunction (Matrix, Ideal, List, ZZ) := NumericalInterpolationTable => opts -> (F, I, sampleImagePoints, d) -> ( --outputs a degree d interpolation table for F(V(I))
(F, I, sampleImagePoints) = checkRings(F, I, sampleImagePoints, ConvertToCone => opts.ConvertToCone);
y := getSymbol "y";
allMonomials := basis(d, (coefficientRing ring I)(monoid[y_0..y_(numcols F-1)]));
N := numcols allMonomials;
if #sampleImagePoints < N then (
if opts.Verbose then print "Sampling image points ...";
T := timing sampleImagePoints = sampleImagePoints | numericalImageSample(F, I, sampleImagePoints, N, Software => opts.Software);
if opts.Verbose then print(" -- used " | toString(T#0) | " seconds");
);
sampleImagePoints = apply(sampleImagePoints/matrix, p -> 1/norm(2,p)*p);
if opts.Verbose then print "Creating interpolation matrix ...";
T = timing A := if opts.UseSLP then makeInterpolationMatrix(allMonomials, sampleImagePoints) else apply(sampleImagePoints, p -> {sub(allMonomials, p)});
if opts.Verbose then print(" -- used " | toString(T#0) | " seconds");
interpolationData := numericalNullity(A, true, Precondition => opts.Precondition, SVDGap => opts.SVDGap, Verbose => opts.Verbose);
new NumericalInterpolationTable from {
symbol hilbertFunctionArgument => d,
symbol hilbertFunctionValue => first interpolationData,
symbol imagePoints => VerticalList sampleImagePoints,
symbol interpolationBasis => allMonomials,
symbol interpolationSVD => last interpolationData,
symbol interpolationMatrix => matrix A,
symbol map => F
}
)
numericalHilbertFunction (Matrix, Ideal, ZZ) := NumericalInterpolationTable => opts -> (F, I, d) -> numericalHilbertFunction(F, I, {}, d, opts)
numericalHilbertFunction (List, Ideal, List, ZZ) := NumericalInterpolationTable => opts -> (F, I, sampleImagePoints, d) -> numericalHilbertFunction(matrix{F}, I, sampleImagePoints, d, opts)
numericalHilbertFunction (List, Ideal, ZZ) := NumericalInterpolationTable => opts -> (F, I, d) -> numericalHilbertFunction(matrix{F}, I, {}, d, opts)
numericalHilbertFunction (RingMap, Ideal, List, ZZ) := NumericalInterpolationTable => opts -> (F, I, sampleImagePoints, d) -> numericalHilbertFunction(F.matrix, I, sampleImagePoints, d, opts)
numericalHilbertFunction (RingMap, Ideal, ZZ) := NumericalInterpolationTable => opts -> (F, I, d) -> numericalHilbertFunction(F.matrix, I, {}, d, opts)
realPartMatrix := A -> matrix apply(entries A, r -> r/realPart)
imPartMatrix := A -> matrix apply(entries A, r -> r/imaginaryPart)
extractImageEquations = method(Options => {symbol Threshold => 5, symbol AttemptZZ => false})
extractImageEquations NumericalInterpolationTable := Matrix => opts -> T -> (
if not opts.AttemptZZ then (
(V, mons) := (last T.interpolationSVD, T.interpolationBasis);
clean(10.0^(-opts.Threshold), mons*sub(conjugate transpose V^{numrows V-T.hilbertFunctionValue..numrows V-1}, ring mons))
) else (
A := T.interpolationMatrix;
B := random(RR)*realPartMatrix A + random(RR)*imPartMatrix A;
C := matrix apply(entries B, r -> r/(e -> lift(round(10^(1+opts.Threshold)*round(opts.Threshold, e)), ZZ)));
D := submatrix(LLL(id_(ZZ^(numcols C)) || C), toList (0..<numcols T.interpolationBasis), toList(0..<T.hilbertFunctionValue));
E := T.interpolationBasis*sub(D, ring T.interpolationBasis);
val := sub(E, T.imagePoints#0);
if clean(10.0^(-opts.Threshold), val) != 0 then (
<< "Warning: some of the integer equations may be inexact. Their values at a sample image point are " << val << endl;
);
E
)
)
extractImageEquations (Matrix, Ideal, ZZ) := Matrix => opts -> (F, I, d) -> extractImageEquations(numericalHilbertFunction(F, I, d), opts)
extractImageEquations (List, Ideal, ZZ) := Matrix => opts -> (F, I, d) -> extractImageEquations(numericalHilbertFunction(matrix{F}, I, d), opts)
extractImageEquations (RingMap, Ideal, ZZ) := Matrix => opts -> (F, I, d) -> extractImageEquations(numericalHilbertFunction(F.matrix, I, d), opts)
round (ZZ, ZZ) := ZZ => (n, x) -> x
round (ZZ, CC) := CC => (n, x) -> round(n, realPart x) + ii*round(n, imaginaryPart x)
round (ZZ, BasicList) := BasicList => (n, L) -> L/round_n
round (ZZ, Matrix) := Matrix => (n, M) -> matrix(entries M/round_n)
round (ZZ, RingElement) := RingElement => (n, f) -> (
C := coefficients f;
((C#0)*round(n, lift(C#1, coefficientRing ring f)))_(0,0)
)
pseudoWitnessSet = method(Options => {
symbol DoRefinements => false,
symbol DoTraceTest => true,
symbol MaxAttempts => 5,
symbol MaxPoints => infinity,
symbol MaxThreads => 1,
Software => M2engine,
symbol Repeats => 3,
symbol TraceThreshold => 1e-5,
symbol Threshold => 5,
-- symbol Endgame => false,
Verbose => true})
pseudoWitnessSet (Matrix, Ideal, List, Thing) := PseudoWitnessSet => opts -> (F, I, pointPairs, sliceMatrix) -> ( --outputs a pseudo-witness set for F(V(I))
local imagePointString, local pairTable, local startSystem;
y := getSymbol "y";
k := coefficientRing ring I;
targetRing := k(monoid[y_1..y_(numcols F)]);
if #pointPairs == 0 then error "Expected source point";
sourcePoint := pointPairs#0#0;
dims := numericalDimensions(F, I, sourcePoint);
numAttempts := 0;
traceResult := opts.TraceThreshold + 1;
(fiberSlice, fiberdim) := ({}, first dims - last dims);
while not traceResult < opts.TraceThreshold and numAttempts < opts.MaxAttempts do (
if numAttempts > 0 then sourcePoint = first numericalSourceSample(I, sourcePoint, Software => opts.Software);
pullbackSlice := if sliceMatrix === null then randomSlice(F, last dims, {sourcePoint, "source"}) else (
if numAttempts == 0 and not all(pointPairs, pair -> clean((10.0)^(-opts.Threshold), sub(sliceMatrix, matrix pair#0)) == 0) then error "Expected input points to lie on input slice";
flatten entries sliceMatrix
);
squaredUpSource := if I == 0 then {} else randomSlice(gens I, #gens ring I - first dims, {});
if fiberdim > 0 then (
fiberSlice = randomSlice(vars ring I, fiberdim, {sourcePoint, "source"});
if numAttempts == 0 and #pointPairs > 1 then pointPairs = numericalEval(F, {sourcePoint} | flatten apply(toList(1..#pointPairs-1), i -> (
codimSlice := randomSlice(F - sub(matrix pointPairs#i#1, ring F), first dims - fiberdim, {});
localFiberSlice := codimSlice | squaredUpSource | randomSlice(vars ring I, fiberdim, {pointPairs#i#0, "source"});
globalFiberSlice := codimSlice | squaredUpSource | fiberSlice;
myTrack(localFiberSlice, globalFiberSlice, {pointPairs#i#0})
)), true);
);
newStartSystem := squaredUpSource | fiberSlice | pullbackSlice;
newPairs := if numAttempts > 0 then numericalEval(F, myTrack(startSystem, newStartSystem, (values pairTable)/first, opts), true) else pointPairs/(pair -> (pair#0, matrix pair#1));
if #newPairs == 0 then (
if opts.Verbose then print "Failed to track old points to new slice. Retrying...";
numAttempts = numAttempts + 1;
continue;
);
pairTable = new MutableHashTable;
for pair in newPairs do (
imagePointString = toString round(opts.Threshold, last pair);
if not pairTable#?imagePointString then pairTable#imagePointString = pair;
);
startSystem = newStartSystem;
pointPairs = monodromyLoop(F, last dims, startSystem, pairTable, opts);
if not opts.DoTraceTest then break;
if opts.DoRefinements then (
if opts.Verbose then print "Refining solutions...";
pointPairs = numericalEval(F, refine(startSystem, pointPairs/first, Bits => precision ring I), true);
);
if opts.Verbose then print("Running trace test ...");
traceResult = traceTest(F, last dims, pointPairs, startSystem, opts);
if not traceResult < opts.TraceThreshold and opts.Verbose then print("Failed trace test! Trace: " | toString traceResult);
numAttempts = numAttempts + 1;
);
if opts.Verbose then (
if traceResult > opts.TraceThreshold then (
print("Degree of image should be at least " | #pointPairs);
print("Consider changing parameters (Repeats, MaxAttempts, Threshold) or reparametrizing for a better result.");
-- Alternatively, consider increasing precision (e.g. changing ground field to CC_100).
);
);
new PseudoWitnessSet from {
symbol isCompletePseudoWitnessSet => traceResult < opts.TraceThreshold,
symbol degree => #pointPairs,
symbol map => F,
symbol sourceEquations => I,
symbol generalCombinations => matrix{squaredUpSource},
symbol sourceSlice => matrix{fiberSlice},
symbol imageSlice => matrix{pullbackSlice},
symbol witnessPointPairs => VerticalList apply(pointPairs, pair -> (pair#0, point pair#1)),
symbol trace => traceResult
}
)
pseudoWitnessSet(Matrix, Ideal, Point) := PseudoWitnessSet => opts -> (F, I, p) -> (
(F, I, p) = checkRings(F, I, {p});
pseudoWitnessSet(F, I, numericalEval(F, p, true), null, opts)
)
pseudoWitnessSet (Matrix, Ideal) := PseudoWitnessSet => opts -> (F, I) -> (
if opts.Verbose then print "Sampling point in source ...";
pseudoWitnessSet(F, I, first numericalSourceSample I, opts)
)
pseudoWitnessSet(List, Ideal, List, Thing) := PseudoWitnessSet => opts -> (F, I, pointPairs, L) -> pseudoWitnessSet(matrix{F}, I, pointPairs, L, opts)
pseudoWitnessSet(List, Ideal, Point) := PseudoWitnessSet => opts -> (F, I, p) -> pseudoWitnessSet(matrix{F}, I, p, opts)
pseudoWitnessSet (List, Ideal) := PseudoWitnessSet => opts -> (F, I) -> pseudoWitnessSet(matrix{F}, I, opts)
pseudoWitnessSet(RingMap, Ideal, List, Thing) := PseudoWitnessSet => opts -> (F, I, pointPairs, L) -> pseudoWitnessSet(F.matrix, I, pointPairs, L, opts)
pseudoWitnessSet(RingMap, Ideal, Point) := PseudoWitnessSet => opts -> (F, I, p) -> pseudoWitnessSet(F.matrix, I, p, opts)
pseudoWitnessSet (RingMap, Ideal) := PseudoWitnessSet => opts -> (F, I) -> pseudoWitnessSet(F.matrix, I, opts)
numericalImageDegree = method(Options => options pseudoWitnessSet)
numericalImageDegree PseudoWitnessSet := ZZ => opts -> W -> W.degree
numericalImageDegree (Matrix, Ideal) := ZZ => opts -> (F, I) -> (pseudoWitnessSet(F, I, opts)).degree
numericalImageDegree (List, Ideal) := ZZ => opts -> (F, I) -> (pseudoWitnessSet(matrix{F}, I, opts)).degree
numericalImageDegree (RingMap, Ideal) := ZZ => opts -> (F, I) -> (pseudoWitnessSet(F.matrix, I, opts)).degree
myTrack = method(Options => options pseudoWitnessSet)
myTrack (List, List, List) := List => opts -> (startSystem, targetSystem, startSolutions) -> (
k := coefficientRing ring startSystem#0;
randomGamma := random k;
if #startSolutions > max(20, 2*opts.MaxThreads) and opts.MaxThreads > 1 then ( -- prints many errors, but continues to run
--setIOExclusive(); -- buggy: causes isReady to indefinitely hang
startSolutionsList := pack(ceiling(#startSolutions/opts.MaxThreads), startSolutions);
threadList := {};
for paths in startSolutionsList do (
threadList = append(threadList, schedule(x -> timing track x, (startSystem, targetSystem, paths, gamma => randomGamma, Software => opts.Software)));
);
while not all(threadList, isReady) do sleep 1;
results := delete(null, threadList/taskResult);
targetSolutions := flatten(results/last);
if opts.Verbose then print("Finished tracking " | #targetSolutions | " paths in parallel, in " | toString sum(results/first) | " seconds");
) else ( -- if startSolutions is empty then error is thrown!
T := timing targetSolutions = track(startSystem, targetSystem, startSolutions, gamma => randomGamma, Software => opts.Software);
if opts.Verbose and T#0 > 1 then print (" -- used " | toString(T#0) | " seconds");
);
goodSols := select(targetSolutions, p -> p#?SolutionStatus and p#SolutionStatus == Regular);
if opts.Verbose and #goodSols < #startSolutions then print("Paths going to infinity: " | #startSolutions - #goodSols | " out of " | #startSolutions);
if opts.DoRefinements then goodSols = apply(refine(polySystem targetSystem, goodSols, Bits => precision k), p -> point sub(matrix p, k));
goodSols
)
randomSlice = method() -- returns a list of c random linear combinations of polys (row matrix) passing through (optional source or target) point, via translation
randomSlice (Matrix, ZZ, List) := List => (polys, c, pointData) -> (
R := ring polys;
coeffs := random(R^(numcols polys), R^c);
G := polys*coeffs;
flatten entries(G - if #pointData == 0 then 0 else sub(if pointData#1 == "source" then sub(G, matrix pointData#0) else (matrix pointData#0)*coeffs, R))
)
monodromyLoop = method(Options => options pseudoWitnessSet)
monodromyLoop (Matrix, ZZ, List, MutableHashTable) := List => opts -> (F, imageDim, startSystem, pairTable) -> (
numRepetitiveMonodromyLoops := 0;
numPts := {#values pairTable};
if opts.Verbose then print "Tracking monodromy loops ...";
while numRepetitiveMonodromyLoops < opts.Repeats do (
intermediateSystem1 := drop(startSystem, -imageDim) | randomSlice(F | matrix{{10_(ring F)}}, imageDim, {});
startSols := (values pairTable)/first;
-- increment := if opts.Endgame and #startSols > 100 and #numPts > 5 and all((firstDifference firstDifference numPts)_{-3..-1}, d -> d < 0) then (
-- startSols = startSols_(randomInts(#startSols, max(100, #startSols//10)));
-- 1/4
-- ) else 1;
intermediateSolutions1 := myTrack(startSystem, intermediateSystem1, startSols, opts);
if #intermediateSolutions1 > 0 then (
endSolutions := myTrack(intermediateSystem1, startSystem, intermediateSolutions1, opts);
if #endSolutions > 0 then (
candidatePairs := numericalEval(F, endSolutions, true);
for pair in candidatePairs do (
imagePointString := toString round(opts.Threshold, last pair);
if not pairTable#?imagePointString then pairTable#imagePointString = pair;
);
);
);
if numPts#-1 < #values pairTable then numRepetitiveMonodromyLoops = 0
else numRepetitiveMonodromyLoops = numRepetitiveMonodromyLoops + 1;
numPts = append(numPts, #values pairTable);
if opts.Verbose then print ("Points found: " | numPts#-1);
if numPts#-1 >= opts.MaxPoints then break;
);
values pairTable
)
traceTest = method(Options => options pseudoWitnessSet)
traceTest (Matrix, ZZ, List, List) := RR => opts -> (F, imageDim, intersectionPointPairs, startSystem) -> (
C := coefficientRing ring F;
startUpstairsPoints := intersectionPointPairs/first;
startDownstairsPoints := intersectionPointPairs/last;
for translationMagnitude in {0,1,3,2,-1,5,-2,6} do (
randomTranslation := 10^(translationMagnitude)*flatten entries(map(C^1, C^(#startSystem - imageDim), 0) | random(C^1, C^imageDim));
gammas := {random C, random C};
firstStepSystem := startSystem + (first gammas)*randomTranslation;
secondStepSystem := startSystem + (last gammas)*randomTranslation;
firstStepUpstairsPoints := myTrack(startSystem, firstStepSystem, startUpstairsPoints, opts);
if #firstStepUpstairsPoints == #startUpstairsPoints then (
secondStepUpstairsPoints := myTrack(startSystem, secondStepSystem, startUpstairsPoints, opts);
if #secondStepUpstairsPoints == #startUpstairsPoints then (
firstStepDownstairsPoints := numericalEval(F, firstStepUpstairsPoints, false);
secondStepDownstairsPoints := numericalEval(F, secondStepUpstairsPoints, false);
traceList := (1/first gammas)*(firstStepDownstairsPoints - startDownstairsPoints) - (1/last gammas)*(secondStepDownstairsPoints - startDownstairsPoints);
return norm(2,sum traceList);
);
);
);
infinity
)
isOnImage = method(Options => {
MaxThreads => 1,
Software => M2engine,
Threshold => 5,
Verbose => true})
isOnImage (PseudoWitnessSet, Point) := Boolean => opts -> (W, q) -> (
q = matrix q;
if not W.isCompletePseudoWitnessSet then print "Warning: not a complete pseudo-witness set! May return false negative.";
F := W.map;
I := W.sourceEquations;
if not ring q === coefficientRing ring I then error "Point must have coordinates in the coefficient ring of the ideal.";
fiberSlice := flatten entries W.sourceSlice;
pullbackSlice := flatten entries W.imageSlice;
squaredUpSource := flatten entries W.generalCombinations;
startUpstairsPoints := W.witnessPointPairs /first;
newPullbackSlice := randomSlice(F, #pullbackSlice, {q, "target"});
targetUpstairsPoints := myTrack(squaredUpSource | fiberSlice | pullbackSlice, squaredUpSource | fiberSlice | newPullbackSlice, startUpstairsPoints, opts);
imagePointTable := hashTable apply(numericalEval(F, targetUpstairsPoints, false), p -> round(opts.Threshold, p) => 0);
imagePointTable#?(round(opts.Threshold, q))
)
isOnImage (Matrix, Ideal, Point) := Boolean => opts -> (F, I, q) -> isOnImage(pseudoWitnessSet(F, I, opts), q, opts)
isOnImage (List, Ideal, Point) := Boolean => opts -> (F, I, q) -> isOnImage(matrix{F}, I, q, opts)
isOnImage (RingMap, Ideal, Point) := Boolean => opts -> (F, I, q) -> isOnImage(F.matrix, I, q, opts)
isWellDefined NumericalInterpolationTable := Boolean => T -> (
-- CHECK DATA STRUCTURE
-- CHECK KEYS
K := keys T;
expectedKeys := set {
symbol hilbertFunctionArgument,
symbol hilbertFunctionValue,
symbol imagePoints,
symbol interpolationBasis,
symbol interpolationSVD,
symbol interpolationMatrix,
symbol map
};
if set K =!= expectedKeys then (
if debugLevel > 0 then (
added := toList(K - expectedKeys);
missing := toList(expectedKeys - K);
if #added > 0 then << "-- unexpected key(s): " << toString added << endl;
if #missing > 0 then << "-- missing keys(s): " << toString missing << endl;
);
return false
);
-- CHECK TYPES
if not instance(T.hilbertFunctionArgument, ZZ) then (
if debugLevel > 0 then << "-- expected `hilbertFunctionArgument' to be an integer" << endl;
return false
);
if not instance(T.hilbertFunctionValue, ZZ) then (
if debugLevel > 0 then << "-- expected `hilbertFunctionValue' to be an integer" << endl;
return false
);
if not instance(T.map, Matrix) then (
if debugLevel > 0 then << "-- expected `map' to be a matrix" << endl;
return false
);
if not instance(T.interpolationBasis, Matrix) then (
if debugLevel > 0 then << "-- expected `interpolationBasis' to be a matrix" << endl;
return false
);
if not instance(T.interpolationMatrix, Matrix) then (
if debugLevel > 0 then << "-- expected `interpolationMatrix' to be a matrix" << endl;
return false
);
if not instance(T.interpolationSVD, Sequence) then (
if debugLevel > 0 then << "-- expected `interpolationSVD' to be a sequence" << endl;
return false
);
if not instance(first T.interpolationSVD, List) then (
if debugLevel > 0 then << "-- expected first element of `interpolationSVD' to be a list" << endl;
return false
);
if not all(first T.interpolationSVD, s -> instance(s, RR)) then (
if debugLevel > 0 then << "-- expected first element of `interpolationSVD' to be a list of singular values" << endl;
return false
);
if not all(drop(T.interpolationSVD, 1), M -> instance(M, Matrix)) then (
if debugLevel > 0 then << "-- expected second and third elements of `interpolationSVD' to be matrices" << endl;
return false
);
-- CHECK MATHEMATICAL STRUCTURE
if not unique flatten last degrees T.interpolationBasis === {T.hilbertFunctionArgument} then (
if debugLevel > 0 then << ("-- expected `interpolationBasis' to consist of monomials of degree " | T.hilbertFunctionArgument) << endl;
return false
);
if not all({coefficientRing ring T.interpolationBasis, ring(T.interpolationSVD#2)}/class, C -> C === ComplexField) then (
if debugLevel > 0 then << "-- expected ground field to be complex numbers" << endl;
return false
);
numMonomials := binomial(numcols T.map + T.hilbertFunctionArgument - 1, T.hilbertFunctionArgument);
if not #gens ring T.interpolationBasis === numcols T.map or not numcols T.interpolationBasis === numMonomials then (
if debugLevel > 0 then << ("-- expected `interpolationBasis' to have " | numMonomials | " monomials in " | #T.map | " variables") << endl;
return false
);
true
)
isWellDefined PseudoWitnessSet := Boolean => W -> (
-- CHECK DATA STRUCTURE
-- CHECK KEYS
K := keys W;
expectedKeys := set {
symbol isCompletePseudoWitnessSet,
symbol degree,
symbol map,
symbol sourceEquations,
symbol sourceSlice,
symbol generalCombinations,
symbol imageSlice,
symbol witnessPointPairs,
symbol trace
};
if set K =!= expectedKeys then (
if debugLevel > 0 then (
added := toList(K - expectedKeys);
missing := toList(expectedKeys - K);
if #added > 0 then << "-- unexpected key(s): " << toString added << endl;
if #missing > 0 then << "-- missing keys(s): " << toString missing << endl;
);
return false
);
-- CHECK TYPES
if not instance(W.isCompletePseudoWitnessSet, Boolean) then (
if debugLevel > 0 then << "-- expected `isCompletePseudoWitnessSet' to be a Boolean" << endl;
return false
);
if not instance(W.degree, ZZ) then (
if debugLevel > 0 then << "-- expected `degree' to be an integer" << endl;
return false
);
if not instance(W.map, Matrix) then (
if debugLevel > 0 then << "-- expected `map' to be a matrix" << endl;
return false
);
if not instance(W.sourceEquations, Ideal) then (
if debugLevel > 0 then << "-- expected `sourceEquations' to be an ideal" << endl;
return false
);
if not instance(W.sourceSlice, Matrix) then (
if debugLevel > 0 then << "-- expected `sourceSlice' to be a matrix" << endl;
return false
);
if not instance(W.generalCombinations, Matrix) then (
if debugLevel > 0 then << "-- expected `generalCombinations' to be a matrix" << endl;
return false
);
if not instance(W.imageSlice, Matrix) then (
if debugLevel > 0 then << "-- expected `imageSlice' to be a matrix" << endl;
return false
);
if not instance(W.witnessPointPairs, List) then (
if debugLevel > 0 then << "-- expected `witnessPointPairs' to be a list" << endl;
return false
);
if not all(W.witnessPointPairs, pair -> instance(pair, Sequence)) then (
if debugLevel > 0 then << "-- expected `witnessPointPairs' to be a list of sequences" << endl;
return false
);
if not all(W.witnessPointPairs, pair -> all(pair, p -> instance(p, Point))) then (
if debugLevel > 0 then << "-- expected `witnessPointPairs' to be a list of sequences of points" << endl;
return false
);
if not instance(W.trace, RR) then (
if debugLevel > 0 then << "-- expected `trace' to be a real number" << endl;
return false
);
-- CHECK MATHEMATICAL STRUCTURE
R := ring W.sourceEquations;
if not R === ring W.map then (
if debugLevel > 0 then << "-- expected `map' and `sourceEquations' to have the same ring" << endl;
return false
);
if not instance(class 1_(coefficientRing R), InexactFieldFamily) then (
if debugLevel > 0 then << "-- expected ground field to have floating point arithmetic" << endl;
return false
);
if not all(W.witnessPointPairs, pair -> #(pair#0#Coordinates) === #gens R and #(pair#1#Coordinates) === numcols W.map) then (
if debugLevel > 0 then << "-- number of coordinates in `witnessPointPairs' do not match" << endl;
return false
);
if not all(W.witnessPointPairs/first, p -> clean(1e-10, sub(gens W.sourceEquations, matrix p)) == 0) then (
if debugLevel > 0 then << " -- expected first components of `witnessPointPairs' to satisfy `sourceEquations'" << endl;
return false
);
if not all(W.witnessPointPairs, pair -> clean(1e-10, matrix last pair - sub(W.map, matrix first pair)) == 0) then (
if debugLevel > 0 then << " -- expected components `witnessPointPairs' to correspond under `map'" << endl;
return false
);
if not all(W.witnessPointPairs/first/matrix, p -> clean(1e-10, sub(W.imageSlice, p)) == 0) then (
if debugLevel > 0 then << " -- expected second components of `witnessPointPairs' to lie on `imageSlice'" << endl;
return false
);
true
)
-- firstDifference = method()
-- firstDifference List := List => L -> drop(L, 1) - drop(L, -1)
-- randomInts = method()
-- randomInts (ZZ, ZZ) := List => (n, s) -> (
-- L := toList(0..<n);
-- apply(s, i -> ( a := L#(random(#L)); L = L - set{a}; a ))
-- )
beginDocumentation()
--Documention--
--<<docTemplate
doc ///
Key
NumericalImplicitization
Headline
implicitization using numerical algebraic geometry
Description
Text
This package supports user-friendly calculation of basic invariants of the image
of a polynomial map. The computational techniques (interpolation, homotopy
continuation and monodromy) come from numerical algebraic geometry.
Many varieties of interest in algebraic geometry and its applications are usefully
described as images of polynomial maps, via a parametrization. Implicitization is the
process of converting a parametric description of a variety into an intrinsic, or implicit,
description. Classically, implicitization refers to the procedure of computing the defining
equations of a parametrized variety, and in theory this is accomplished by finding the
kernel of a ring homomorphism, via Gröbner bases. In practice however,
symbolic Gröbner basis computations are often time consuming, even for
medium scale problems, and do not scale well with respect to the size of the input.
Despite this, one would often like to know basic information about a parametrized
variety, even when symbolic methods are prohibitively expensive. Examples of
such information are discrete invariants such as the
@TO2{numericalImageDim, "dimension"}@, the
@TO2{pseudoWitnessSet, "degree"}@, or
@TO2{numericalHilbertFunction, "Hilbert function"}@
values. Other examples include Boolean tests, for example whether a particular point
@TO2{isOnImage, "lies on"}@ a parametrized variety. The goal of this package is to
provide such information; in other words to numerically implicitize a parametrized variety.
{\em NumericalImplicitization} builds on existing numerical algebraic geometry software:
@TO2{NumericalAlgebraicGeometry,"NAG4M2"}@, @TO Bertini@ and
@TO PHCpack@. The user may specify any of these to use for path tracking and
point sampling; by default, the native software NAG4M2 is used. Currently, all methods
are implemented for reduced and irreducible varieties.
{\bf Reference:}
[1] A.J. Sommese and C.W. Wampler,
The numerical solution of systems of polynomials.
{\it World Scientific Publishing} (2005).
///
doc ///
Key
numericalSourceSample
(numericalSourceSample, Ideal, Thing, ZZ)
(numericalSourceSample, Ideal, WitnessSet)
(numericalSourceSample, Ideal, Point)
(numericalSourceSample, Ideal, ZZ)
(numericalSourceSample, Ideal)
Headline
samples a general point on a variety
Usage
numericalSourceSample(I, W, s)
numericalSourceSample(I, p, s)
numericalSourceSample(I, W)
numericalSourceSample(I, p)
numericalSourceSample(I, s)
numericalSourceSample(I)
Inputs
I:Ideal
which is prime, specifying a variety $V(I)$
W:WitnessSet
a witness set for $V(I)$
p:Point
a point on the source $V(I)$
s:ZZ
the number of points to sample on the source $V(I)$
Outputs
:List
of sample points on the source $V(I)$
Consequences
Item
If $I$ is not the zero ideal, and an initlal point $p$ is not specified, then a numerical
irreducible decomposition of $I$ is performed, and cached under {\tt I.cache.WitnessSet}.
Description
Text
This method computes a list of sample points on a variety numerically. If $I$ is the
zero ideal in a polynomial ring of dimension $n$, then an $n$-tuple of random
elements in the ground field is returned. Otherwise, a
@TO2{numericalIrreducibleDecomposition, "numerical irreducible decomposition"}@
of $I$ is computed, which is then used to sample points.
If the number of points $s$ is unspecified, then it is assumed that $s = 1$.
One can provide a witness set for $V(I)$ if a witness set is already known.
Alternatively, one can provide an initial point $p$ on the source $V(I)$, which is then used to
generate additional points on the source $V(I)$. This can be much quicker than performing
a numerical irreducible decomposition.
In the example below, we sample a point from $A^3$ and then $3$ points from
$V(x^2 + y^2 + z^2 - 1)$ in $A^3$.
Example
R = CC[x,y,z];
samp = numericalSourceSample(ideal 0_R)
samp#0
I = ideal(x^2 + y^2 + z^2 - 1);
numericalSourceSample(I, 3)
Text
In the following example, we sample a point from $SO(5)$, by starting with the
identity matrix as an initial point:
Example
n = 5
R = RR[a_(1,1)..a_(n,n)]
A = genericMatrix(R,n,n);
I = ideal(A*transpose A - id_(R^n));
p = point id_(RR^n)
time q = first numericalSourceSample(I, p)
O = matrix pack(n, q#Coordinates/realPart)
clean(1e-10, O*transpose O - id_(RR^n)) == 0
Caveat
Since numerical irreducible decompositions are done over @TO CC@, if $I$ is not the zero
ideal, then the output will be a point in complex space
(regardless of the ground field of the ring of $I$).
SeeAlso
numericalImageSample
///
doc ///
Key
numericalImageSample
(numericalImageSample, Matrix, Ideal, List, ZZ)
(numericalImageSample, Matrix, Ideal, ZZ)
(numericalImageSample, Matrix, Ideal)
(numericalImageSample, List, Ideal, List, ZZ)
(numericalImageSample, List, Ideal, ZZ)
(numericalImageSample, List, Ideal)
(numericalImageSample, RingMap, Ideal, List, ZZ)
(numericalImageSample, RingMap, Ideal, ZZ)
(numericalImageSample, RingMap, Ideal)
Headline
samples general points on the image of a variety
Usage
numericalImageSample(F, I, P, s)
numericalImageSample(F, I, s)
numericalImageSample(F, I)
Inputs
F:
a @TO2{Matrix, "matrix"}@, or @TO2{List, "list"}@, or
@TO2{RingMap, "ring map"}@, specifying a map
I:Ideal
which is prime, specifying a source variety $V(I)$
P:List
of points on $F(V(I))$
s:ZZ
the number of points to sample in $F(V(I))$
Outputs
:List
of sample points on $F(V(I)))$
Description
Text
This method computes a list of sample points on the image of a variety
numerically, by calling @TO numericalSourceSample@.
If the number of points $s$ is unspecified, then it is assumed that $s = 1$.
One can optionally provide an initial list of points $P$ on $F(V(I))$, which
will then be completed to a list of $s$ points on $F(V(I))$.
The following example samples a point from the twisted cubic. We then
independently verify that this point does lie on the twisted cubic.
Example
R = CC[s,t];
F = {s^3,s^2*t,s*t^2,t^3};
p = first numericalImageSample(F, ideal 0_R)
A = matrix{p#Coordinates_{0,1,2}, p#Coordinates_{1,2,3}};
numericalNullity A == 2
Text
Here is how to sample a point from the Grassmannian $Gr(3,5)$ of
$P^2$'s in $P^4$, under its Plücker embedding in $P^9$.
We take maximal minors of a $3 x 5$ matrix, whose row span
gives a $P^2$ in $P^4$.
Example
R = CC[x_(1,1)..x_(3,5)];
F = (minors(3, genericMatrix(R, 3, 5)))_*;
numericalImageSample(F, ideal 0_R)
SeeAlso
numericalSourceSample
///
doc ///
Key
numericalImageDim
(numericalImageDim, Matrix, Ideal, Point)
(numericalImageDim, Matrix, Ideal)
(numericalImageDim, List, Ideal, Point)
(numericalImageDim, List, Ideal)
(numericalImageDim, RingMap, Ideal, Point)
(numericalImageDim, RingMap, Ideal)
Headline
computes the dimension of the image of a variety
Usage
numericalImageDim(F, I, p)
numericalImageDim(F, I)
Inputs
F:
a @TO2{Matrix, "matrix"}@, or @TO2{List, "list"}@, or
@TO2{RingMap, "ring map"}@, specifying a map
I:Ideal
which is prime, specifying a source variety $V(I)$
p:Point
a sample point on the source $V(I)$
Outputs
:ZZ
the dimension of $F(V(I)))$
Description
Text
The method computes the dimension of the image of a variety numerically.
Even if the source variety and map are projective, the affine (Krull)
dimension is returned. This ensures consistency with @TO dim@.
The following example computes the affine dimension of the Grassmannian
$Gr(3,5)$ of $P^2$'s in $P^4$, under its Plücker embedding in $P^9$.
Example
R = CC[x_(1,1)..x_(3,5)];
F = (minors(3, genericMatrix(R, 3, 5)))_*;
numericalImageDim(F, ideal 0_R)
Text
For comparison, here is how to do the same computation symbolically.
Example
R = QQ[x_(1,1)..x_(3,5)];
F = (minors(3, genericMatrix(R, 3, 5)))_*;
dim ker map(R,QQ[y_0..y_(#F-1)],F)
Text
Next is an example where direct symbolic computation fails to terminate quickly.
Part of the Alexander-Hirschowitz theorem states that the $14$th secant
variety of the $4$th Veronese of $P^4$ has affine dimension $69$, rather than
the expected $14*4 + 13 + 1 = 70$. See J. Alexander, A. Hirschowitz, $Polynomial
interpolation in several variables$, J. Alg. Geom. 4(2) (1995), 201-222. We
numerically verify this below.
Example
R = CC[a_(1,1)..a_(14,5)];
F = sum(1..14, i -> basis(4, R, Variables=>toList(a_(i,1)..a_(i,5))));
time numericalImageDim(F, ideal 0_R)
///
doc ///
Key
numericalNullity
(numericalNullity, Matrix)
(numericalNullity, Matrix, Boolean)
(numericalNullity, List, Boolean)
Precondition
[numericalHilbertFunction, Precondition]
[numericalNullity, Precondition]
SVDGap
[numericalHilbertFunction, SVDGap]
[numericalNullity, SVDGap]
Headline
computes numerical kernel dimension of a matrix
Usage
numericalNullity M
Inputs
M:Matrix
with real or complex entries
Outputs
:ZZ
dimension of the kernel of M
Description
Text
This method computes the dimension of the kernel of a matrix
with real or complex entries numerically, via singular value
decomposition (see @TO SVD@).
If $\sigma_1 \ge \ldots \ge \sigma_n$ are the singular values of
$M$, then to establish the nullity numerically we look for the
largest "significant" gap between two consecutive singular values, where
the gap between $\sigma_i$ and $\sigma_{i+1}$ is "significant" if the ratio
$\sigma_i / \sigma_{i+1}$ exceeds the value of {\tt SVDGap}.
If a gap is found which is greater than this threshold, then all singular values
after this gap are considered as numerically zero; if all gaps are
less than this threshold, then the matrix is considered numerically full rank.
The default value of {\tt SVDGap} is $1e5$.
The option {\tt Precondition} specifies whether the rows of
M will be normalized to have norm $1$ before computing the SVD.
This helps reveal nullity if the matrix is dense (e.g. for a generic
interpolation matrix), but not if the matrix is sparse (e.g. diagonal).
The default value is @TO false@.
Example
numericalNullity(matrix{{2, 1}, {0, 1e-5}}, Precondition => false)
numericalNullity(map(CC^2,CC^2,0))
Caveat
The option {\tt SVDGap} may require tuning by the user.
SeeAlso
SVD
numericalRank
///