Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jack4818
GitHub Repository: jack4818/Castryck-Decru-SageMath
Path: blob/main/speedup.sage
323 views
1
# Don't pollute the global namespace
2
def _do_speedup():
3
# And because why not
4
proof.all(False)
5
6
# Lorenz Panny has fixed both of the below monkey patches with the tickets:
7
# - https://trac.sagemath.org/ticket/34281 (Caching of the finite fields)
8
# - https://trac.sagemath.org/ticket/34284 (Dimension of hyperelliptic curve)
9
#
10
# We should check the version of sage and if >= 9.7 skip the below patches
11
from sage.misc.banner import require_version
12
if not require_version(9,7):
13
# Since this type gets created before we could ever hope to monkey patch the
14
# `sage.categories.fields.Fields.ParentMethods`
15
# method, we'll patch it on the relevant type instead.
16
# We'll patch a few different types to make sure we get the relevant things (large and small prime, extension and no extension)
17
p = 2^127 - 1 # Arbitrary large prime
18
to_patch = [GF(3), GF(3^2), GF(p), GF(p^2)]
19
for x in to_patch:
20
type(x).vector_space = sage.misc.cachefunc.cached_method(type(x).vector_space)
21
22
# An alternative would be to replace the bytecode in
23
# `sage.categories.fields.Fields.ParentMethods.vector_space`
24
# as all types share the same method, by identity
25
# Something to be explored later, perhaps :)
26
27
# No use calculating the dimension of HyperElliptic every single time
28
from sage.schemes.projective.projective_subscheme import AlgebraicScheme_subscheme_projective
29
AlgebraicScheme_subscheme_projective.dimension = lambda self: 1
30
31
32
_do_speedup()
33
34