M2
M2 copied to clipboard
Hom trims unnecessarily
The key line in Hom(M, N) runs:
H := trim kernel (transpose presentation M ** N);
I suspect trim is there to remove generators that give zero homomorphisms, for example. However, this trim can be very slow without even changing the result. Here is an example:
R = quotient Grassmannian(1,3, CoefficientRing => ZZ/3);
X = Proj R;
-- blackbox what N is, but it has 97 generators and 32 relations
N = module frobeniusPushforward(1, OO_X); -- rank 81
M = R^{0,-1, 43:-1, 52:-2}; -- rank 97
Now compare:
i13 : elapsedTime H = kernel (transpose presentation M ** N);
-- 0.0469308 seconds elapsed
i14 : elapsedTime H' = trim H;
-- 167.708 seconds elapsed
i15 : betti H', betti H
0 1 0 1
o15 = (total: 9409 3104, total: 9409 3104)
-2: 52 . -2: 52 .
-1: 2332 . -1: 2332 .
0: 4641 1664 0: 4641 1664
1: 2332 1408 1: 2332 1408
2: 52 32 2: 52 32
Which means that there was nothing to trim, but nearly 3 minutes (almost 100% of the computation) was a time waste.
I can think of two solutions:
- add an optional argument
MinimalGeneratorsforHom, perhaps set to false by default, which determines whether to trim the result; - never trim the result and leave it to the user to do that.
As an aside, we should do this anyway:
- fix
pruneandtrimto keep cachedhomomorphism,formation,components, etc. if present (what other cached results are important to keep?)