# Don't pollute the global namespace1def _do_speedup():2# And because why not3proof.all(False)45# Lorenz Panny has fixed both of the below monkey patches with the tickets:6# - https://trac.sagemath.org/ticket/34281 (Caching of the finite fields)7# - https://trac.sagemath.org/ticket/34284 (Dimension of hyperelliptic curve)8#9# We should check the version of sage and if >= 9.7 skip the below patches10from sage.misc.banner import require_version11if not require_version(9,7):12# Since this type gets created before we could ever hope to monkey patch the13# `sage.categories.fields.Fields.ParentMethods`14# method, we'll patch it on the relevant type instead.15# We'll patch a few different types to make sure we get the relevant things (large and small prime, extension and no extension)16p = 2^127 - 1 # Arbitrary large prime17to_patch = [GF(3), GF(3^2), GF(p), GF(p^2)]18for x in to_patch:19type(x).vector_space = sage.misc.cachefunc.cached_method(type(x).vector_space)2021# An alternative would be to replace the bytecode in22# `sage.categories.fields.Fields.ParentMethods.vector_space`23# as all types share the same method, by identity24# Something to be explored later, perhaps :)2526# No use calculating the dimension of HyperElliptic every single time27from sage.schemes.projective.projective_subscheme import AlgebraicScheme_subscheme_projective28AlgebraicScheme_subscheme_projective.dimension = lambda self: 1293031_do_speedup()323334