From 5c96067059f135c4752738c7754b904ea465c1f1 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 29 Dec 2024 20:26:26 -0800 Subject: [PATCH 01/45] Replace imports from sage.all --- .../rational_linear_algebra.py | 6 +++++- .../rational_linear_algebra_wrapped.py | 5 ++++- .../complex_cusp_cross_section.py | 8 ++++++-- python/math_basics.py | 3 ++- python/snap/character_varieties.py | 3 ++- python/snap/find_field.py | 18 +++++++++++++++--- python/snap/fundamental_polyhedron.py | 2 +- python/snap/nsagetools.py | 17 ++++++++++++++--- python/snap/peripheral/dual_cellulation.py | 6 +++++- python/snap/peripheral/peripheral.py | 4 +++- python/snap/peripheral/surface.py | 10 ++++++++-- python/snap/polished_reps.py | 11 +++++++++-- python/snap/slice_obs_HKL.py | 16 ++++++++++++---- python/snap/t3mlite/spun.py | 6 +++--- python/snap/utilities.py | 3 ++- python/verify/complex_volume/adjust_torsion.py | 2 +- python/verify/complex_volume/closed.py | 3 ++- python/verify/complex_volume/extended_bloch.py | 8 +++++--- python/verify/hyperbolicity.py | 2 +- python/verify/interval_tree.py | 8 +++++--- python/verify/krawczyk_shapes_engine.py | 2 +- .../cusp_tiling_engine.py | 2 +- .../cusp_translate_engine.py | 3 ++- python/verify/short_slopes.py | 2 +- .../verify/upper_halfspace/extended_matrix.py | 2 +- python/verify/upper_halfspace/finite_point.py | 3 ++- python/verify/upper_halfspace/ideal_point.py | 9 ++++++--- 27 files changed, 119 insertions(+), 45 deletions(-) diff --git a/python/exterior_to_link/rational_linear_algebra.py b/python/exterior_to_link/rational_linear_algebra.py index add928d74..bc60c4750 100644 --- a/python/exterior_to_link/rational_linear_algebra.py +++ b/python/exterior_to_link/rational_linear_algebra.py @@ -17,7 +17,11 @@ from .. import sage_helper if sage_helper._within_sage and not use_pari_even_inside_sage: - from sage.all import QQ, RR, vector, matrix, VectorSpace + from sage.rings.rational_field import Q as QQ + from sage.rings.real_mpfr import RR + from sage.modules.free_module_element import free_module_element as vector + from sage.matrix.constructor import Matrix as matrix + from sage.modules.free_module import VectorSpace def rational_sqrt(x): """ diff --git a/python/exterior_to_link/rational_linear_algebra_wrapped.py b/python/exterior_to_link/rational_linear_algebra_wrapped.py index 7f304bfd6..d9583ea14 100644 --- a/python/exterior_to_link/rational_linear_algebra_wrapped.py +++ b/python/exterior_to_link/rational_linear_algebra_wrapped.py @@ -16,7 +16,10 @@ This file is not currently used by SnapPy, but is kept for possible future reference. """ -from sage.all import QQ, vector, matrix, VectorSpace +from sage.rings.rational_field import Q as QQ +from sage.modules.free_module_element import free_module_element as vector +from sage.matrix.constructor import Matrix as matrix +from sage.modules.free_module import VectorSpace class Vector: diff --git a/python/geometric_structure/cusp_neighborhood/complex_cusp_cross_section.py b/python/geometric_structure/cusp_neighborhood/complex_cusp_cross_section.py index f6d4db364..99066d83a 100644 --- a/python/geometric_structure/cusp_neighborhood/complex_cusp_cross_section.py +++ b/python/geometric_structure/cusp_neighborhood/complex_cusp_cross_section.py @@ -384,7 +384,9 @@ def _add_one_cusp_vertex_positions(self, cusp : t3m.Vertex): visited.add((tet1.Index, vert1)) def _debug_show_horotriangles(self, cusp : int =0): - from sage.all import line, real, imag + from sage.plot.line import line + from sage.functions.other import real + from sage.functions.other import imag self.add_vertex_positions_to_horotriangles() @@ -398,7 +400,9 @@ def _debug_show_horotriangles(self, cusp : int =0): if tet.Class[V].Index == cusp ]) def _debug_show_lifted_horotriangles(self, cusp : int =0): - from sage.all import line, real, imag + from sage.plot.line import line + from sage.functions.other import real + from sage.functions.other import imag self.add_vertex_positions_to_horotriangles() diff --git a/python/math_basics.py b/python/math_basics.py index 5796ee368..fdc047548 100644 --- a/python/math_basics.py +++ b/python/math_basics.py @@ -21,7 +21,8 @@ def is_Interval(x): return is_RealIntervalFieldElement(x) or is_ComplexIntervalFieldElement(x) if _within_sage: - from sage.all import prod, xgcd + from sage.misc.misc_c import prod + from sage.arith.misc import XGCD as xgcd from sage.rings.real_mpfi import RealIntervalFieldElement from sage.rings.complex_interval import ComplexIntervalFieldElement diff --git a/python/snap/character_varieties.py b/python/snap/character_varieties.py index 35f6c7ab8..1b9ede657 100644 --- a/python/snap/character_varieties.py +++ b/python/snap/character_varieties.py @@ -359,7 +359,8 @@ def character_variety_ideal(gens, rels=None): 2 """ presentation = character_variety(gens, rels) - from sage.all import PolynomialRing, QQ + from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing + from sage.rings.rational_field import Q as QQ R = PolynomialRing(QQ, [repr(v) for v in presentation.gens]) return R.ideal([R(p) for p in presentation.rels]) diff --git a/python/snap/find_field.py b/python/snap/find_field.py index 8421ac3e3..ce47ece26 100644 --- a/python/snap/find_field.py +++ b/python/snap/find_field.py @@ -1,6 +1,18 @@ -from sage.all import (cached_method, real_part, imag_part, round, ceil, floor, log, - ZZ, QQ, CDF, ComplexField, NumberField, PolynomialRing, - matrix, identity_matrix) +from sage.misc.cachefunc import cached_method +from sage.functions.other import real as real_part +from sage.functions.other import imag as imag_part +from sage.misc.functional import round +from sage.functions.other import ceil +from sage.functions.other import floor +from sage.misc.functional import log +from sage.rings.integer_ring import Z as ZZ +from sage.rings.rational_field import Q as QQ +from sage.rings.complex_double import CDF +from sage.rings.complex_mpfr import ComplexField +from sage.rings.number_field.number_field import NumberField +from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing +from sage.matrix.constructor import Matrix as matrix +from sage.matrix.special import identity_matrix import itertools diff --git a/python/snap/fundamental_polyhedron.py b/python/snap/fundamental_polyhedron.py index 3f1655bf8..19db3391e 100644 --- a/python/snap/fundamental_polyhedron.py +++ b/python/snap/fundamental_polyhedron.py @@ -11,7 +11,7 @@ from ..sage_helper import _within_sage if _within_sage: - from sage.all import matrix + from sage.matrix.constructor import Matrix as matrix else: from .utilities import Matrix2x2 as matrix diff --git a/python/snap/nsagetools.py b/python/snap/nsagetools.py index ea490b0cc..1c1edf354 100644 --- a/python/snap/nsagetools.py +++ b/python/snap/nsagetools.py @@ -6,9 +6,20 @@ if _within_sage: import sage - from sage.all import (ZZ, vector, matrix, block_matrix, identity_matrix, - gcd, prod, det, MatrixSpace, AbelianGroup, GroupAlgebra, - SageObject, PolynomialRing, LaurentPolynomialRing) + from sage.rings.integer_ring import Z as ZZ + from sage.modules.free_module_element import free_module_element as vector + from sage.matrix.constructor import Matrix as matrix + from sage.matrix.special import block_matrix + from sage.matrix.special import identity_matrix + from sage.arith.misc import GCD as gcd + from sage.misc.misc_c import prod + from sage.misc.functional import det + from sage.matrix.matrix_space import MatrixSpace + from sage.groups.abelian_gps.abelian_group import AbelianGroup + from sage.algebras.group_algebra import GroupAlgebra + from sage.structure.sage_object import SageObject + from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing + from sage.rings.polynomial.laurent_polynomial_ring import LaurentPolynomialRing from .polished_reps import polished_holonomy, MatrixRepresentation Id2 = MatrixSpace(ZZ, 2)(1) diff --git a/python/snap/peripheral/dual_cellulation.py b/python/snap/peripheral/dual_cellulation.py index 0bcee8762..44f0be63d 100644 --- a/python/snap/peripheral/dual_cellulation.py +++ b/python/snap/peripheral/dual_cellulation.py @@ -6,7 +6,11 @@ from .. import t3mlite as t3m if sage_helper._within_sage: - from sage.all import (ZZ, matrix, vector, ChainComplex, Graph) + from sage.rings.integer_ring import Z as ZZ + from sage.matrix.constructor import Matrix as matrix + from sage.modules.free_module_element import free_module_element as vector + from sage.homology.chain_complex import ChainComplex + from sage.graphs.graph import Graph class DualCell(): diff --git a/python/snap/peripheral/peripheral.py b/python/snap/peripheral/peripheral.py index 0bc162f7d..90ce76754 100644 --- a/python/snap/peripheral/peripheral.py +++ b/python/snap/peripheral/peripheral.py @@ -3,7 +3,9 @@ from . import link, dual_cellulation if sage_helper._within_sage: - from sage.all import matrix, vector, ZZ + from sage.matrix.constructor import Matrix as matrix + from sage.modules.free_module_element import free_module_element as vector + from sage.rings.integer_ring import Z as ZZ def peripheral_curve_from_snappy(dual_cell, snappy_data): diff --git a/python/snap/peripheral/surface.py b/python/snap/peripheral/surface.py index 5a5f078fc..5262c33c4 100644 --- a/python/snap/peripheral/surface.py +++ b/python/snap/peripheral/surface.py @@ -2,8 +2,14 @@ from ... import sage_helper if sage_helper._within_sage: - from sage.all import (ZZ, matrix, vector, ChainComplex, - cached_method, line, arrow, text) + from sage.rings.integer_ring import Z as ZZ + from sage.matrix.constructor import Matrix as matrix + from sage.modules.free_module_element import free_module_element as vector + from sage.homology.chain_complex import ChainComplex + from sage.misc.cachefunc import cached_method + from sage.plot.line import line + from sage.plot.arrow import arrow + from sage.plot.text import text else: def cached_method(func): return func diff --git a/python/snap/polished_reps.py b/python/snap/polished_reps.py index 4d720939f..753f55347 100644 --- a/python/snap/polished_reps.py +++ b/python/snap/polished_reps.py @@ -11,8 +11,15 @@ if _within_sage: import sage - from sage.all import RealField, ComplexField, gcd, prod, powerset - from sage.all import MatrixSpace, matrix, vector, ZZ + from sage.rings.real_mpfr import RealField + from sage.rings.complex_mpfr import ComplexField + from sage.arith.misc import GCD as gcd + from sage.misc.misc_c import prod + from sage.combinat.subset import powerset + from sage.matrix.matrix_space import MatrixSpace + from sage.matrix.constructor import Matrix as matrix + from sage.modules.free_module_element import free_module_element as vector + from sage.rings.integer_ring import Z as ZZ Object = sage.structure.sage_object.SageObject identity = lambda A: MatrixSpace(A.base_ring(), A.nrows())(1) abelian_group_elt = lambda v: vector(ZZ, v) diff --git a/python/snap/slice_obs_HKL.py b/python/snap/slice_obs_HKL.py index ad0aeb505..a549d6e41 100644 --- a/python/snap/slice_obs_HKL.py +++ b/python/snap/slice_obs_HKL.py @@ -45,10 +45,18 @@ from ..sage_helper import _within_sage, sage_method if _within_sage: - from sage.all import (ZZ, PolynomialRing, LaurentPolynomialRing, - GF, CyclotomicField, vector, matrix, - identity_matrix, block_matrix, - MatrixSpace, ChainComplex, prime_range) + from sage.rings.integer_ring import Z as ZZ + from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing + from sage.rings.polynomial.laurent_polynomial_ring import LaurentPolynomialRing + from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF + from sage.rings.number_field.number_field import CyclotomicField + from sage.modules.free_module_element import free_module_element as vector + from sage.matrix.constructor import Matrix as matrix + from sage.matrix.special import identity_matrix + from sage.matrix.special import block_matrix + from sage.matrix.matrix_space import MatrixSpace + from sage.homology.chain_complex import ChainComplex + from sage.rings.fast_arith import prime_range from .nsagetools import (MapToFreeAbelianization, compute_torsion, fox_derivative_with_involution, diff --git a/python/snap/t3mlite/spun.py b/python/snap/t3mlite/spun.py index bad74f2ec..fb020574c 100644 --- a/python/snap/t3mlite/spun.py +++ b/python/snap/t3mlite/spun.py @@ -10,9 +10,9 @@ from ...sage_helper import _within_sage if _within_sage: - from sage.all import gcd - from sage.all import vector as Vector - from sage.all import matrix as Matrix + from sage.arith.misc import GCD as gcd + from sage.modules.free_module_element import free_module_element as Vector + from sage.matrix.constructor import Matrix as Matrix else: from snappy.snap.t3mlite.linalg import Vector, Matrix, gcd diff --git a/python/snap/utilities.py b/python/snap/utilities.py index b6ca2b72d..2728621df 100644 --- a/python/snap/utilities.py +++ b/python/snap/utilities.py @@ -12,7 +12,8 @@ from ..pari import pari, PariError from .fundamental_polyhedron import Infinity if _within_sage: - from sage.all import matrix as sage_matrix, vector as sage_vector + from sage.matrix.constructor import Matrix as sage_matrix + from sage.modules.free_module_element import free_module_element as sage_vector from sage.rings.real_mpfr import RealField_class from ..sage_helper import ComplexField_class diff --git a/python/verify/complex_volume/adjust_torsion.py b/python/verify/complex_volume/adjust_torsion.py index a73f763c9..7b8c19ca3 100644 --- a/python/verify/complex_volume/adjust_torsion.py +++ b/python/verify/complex_volume/adjust_torsion.py @@ -1,6 +1,6 @@ from ...sage_helper import _within_sage, sage_method if _within_sage: - from sage.all import pi + from sage.symbolic.constants import pi import sage.all from .extended_bloch import * diff --git a/python/verify/complex_volume/closed.py b/python/verify/complex_volume/closed.py index 336657b29..fd96e8d21 100644 --- a/python/verify/complex_volume/closed.py +++ b/python/verify/complex_volume/closed.py @@ -6,7 +6,8 @@ from ...snap.t3mlite import simplex if _within_sage: - from sage.all import pi, xgcd + from sage.symbolic.constants import pi + from sage.arith.misc import XGCD as xgcd import sage.all from .. import hyperbolicity diff --git a/python/verify/complex_volume/extended_bloch.py b/python/verify/complex_volume/extended_bloch.py index 8a2bdf1ee..03bd45d8f 100644 --- a/python/verify/complex_volume/extended_bloch.py +++ b/python/verify/complex_volume/extended_bloch.py @@ -1,9 +1,11 @@ from ...sage_helper import _within_sage, sage_method if _within_sage: - from sage.all import (ComplexBallField, - RealField, - Integer, exp, pi) + from sage.rings.complex_arb import ComplexBallField + from sage.rings.real_mpfr import RealField + from sage.rings.integer import Integer + from sage.functions.log import exp + from sage.symbolic.constants import pi import sage.all diff --git a/python/verify/hyperbolicity.py b/python/verify/hyperbolicity.py index a549220b3..2b149da8e 100644 --- a/python/verify/hyperbolicity.py +++ b/python/verify/hyperbolicity.py @@ -7,7 +7,7 @@ 'verify_hyperbolicity' ] if _within_sage: - from sage.all import pi + from sage.symbolic.constants import pi import sage.all diff --git a/python/verify/interval_tree.py b/python/verify/interval_tree.py index 95ebd7df2..4b636e07f 100644 --- a/python/verify/interval_tree.py +++ b/python/verify/interval_tree.py @@ -300,7 +300,7 @@ def check_find_result(self, interval): self.brute_force_find(interval))) def check_consistency(self): - from sage.all import Infinity + from sage.rings.infinity import Infinity if self._root.isRed: raise Exception("Red root") _IntervalTreeTester._recursively_check_consistency( @@ -308,7 +308,7 @@ def check_consistency(self): @staticmethod def _recursively_check_consistency(node, l, r): - from sage.all import Infinity + from sage.rings.infinity import Infinity if not node: return -Infinity, 0 @@ -370,7 +370,9 @@ def print_tree_recursively(node, depth): @staticmethod def run_test(): - from sage.all import RIF, sin, Infinity + from sage.rings.real_mpfi import RIF + from sage.functions.trig import sin + from sage.rings.infinity import Infinity intervals = [ RIF(sin(1.2 * i), sin(1.2 * i) + sin(1.43 * i) ** 2) diff --git a/python/verify/krawczyk_shapes_engine.py b/python/verify/krawczyk_shapes_engine.py index 5e16821b3..84f256554 100644 --- a/python/verify/krawczyk_shapes_engine.py +++ b/python/verify/krawczyk_shapes_engine.py @@ -6,7 +6,7 @@ if _within_sage: from sage.rings.complex_interval_field import ComplexIntervalField from sage.rings.real_mpfi import RealIntervalField - from sage.all import ComplexDoubleField + from sage.rings.complex_double import ComplexDoubleField from snappy.pari import prec_dec_to_bits __all__ = ['KrawczykShapesEngine'] diff --git a/python/verify/maximal_cusp_area_matrix/cusp_tiling_engine.py b/python/verify/maximal_cusp_area_matrix/cusp_tiling_engine.py index 397cf994f..a8435f3fd 100644 --- a/python/verify/maximal_cusp_area_matrix/cusp_tiling_engine.py +++ b/python/verify/maximal_cusp_area_matrix/cusp_tiling_engine.py @@ -15,7 +15,7 @@ from .cusp_translate_engine import * if _within_sage: - from sage.all import matrix + from sage.matrix.constructor import Matrix as matrix import sage.all import heapq diff --git a/python/verify/maximal_cusp_area_matrix/cusp_translate_engine.py b/python/verify/maximal_cusp_area_matrix/cusp_translate_engine.py index cafcdc326..6a9503193 100644 --- a/python/verify/maximal_cusp_area_matrix/cusp_translate_engine.py +++ b/python/verify/maximal_cusp_area_matrix/cusp_translate_engine.py @@ -3,7 +3,8 @@ from ..upper_halfspace.finite_point import * if _within_sage: - from sage.all import vector, matrix + from sage.modules.free_module_element import free_module_element as vector + from sage.matrix.constructor import Matrix as matrix __all__ = ['CuspTranslateEngine'] diff --git a/python/verify/short_slopes.py b/python/verify/short_slopes.py index 4ff6456d7..eea753986 100644 --- a/python/verify/short_slopes.py +++ b/python/verify/short_slopes.py @@ -5,7 +5,7 @@ import math if _within_sage: - from sage.all import gcd + from sage.arith.misc import GCD as gcd else: # Python 3 has gcd in math from math import gcd diff --git a/python/verify/upper_halfspace/extended_matrix.py b/python/verify/upper_halfspace/extended_matrix.py index be53cc96e..c08f7941e 100644 --- a/python/verify/upper_halfspace/extended_matrix.py +++ b/python/verify/upper_halfspace/extended_matrix.py @@ -1,7 +1,7 @@ from ...sage_helper import _within_sage if _within_sage: - from sage.all import sqrt + from sage.misc.functional import sqrt __all__ = ['ExtendedMatrix'] diff --git a/python/verify/upper_halfspace/finite_point.py b/python/verify/upper_halfspace/finite_point.py index ffc26e26b..460261240 100644 --- a/python/verify/upper_halfspace/finite_point.py +++ b/python/verify/upper_halfspace/finite_point.py @@ -2,7 +2,8 @@ if _within_sage: import sage.all - from sage.all import matrix, sqrt + from sage.matrix.constructor import Matrix as matrix + from sage.misc.functional import sqrt from sage.rings.real_mpfi import is_RealIntervalFieldElement from .extended_matrix import ExtendedMatrix diff --git a/python/verify/upper_halfspace/ideal_point.py b/python/verify/upper_halfspace/ideal_point.py index a76c414eb..ea03607fe 100644 --- a/python/verify/upper_halfspace/ideal_point.py +++ b/python/verify/upper_halfspace/ideal_point.py @@ -18,7 +18,7 @@ if _within_sage: import sage.all - from sage.all import matrix + from sage.matrix.constructor import Matrix as matrix from .finite_point import * from .extended_matrix import * @@ -398,7 +398,9 @@ class _IdealPointTester(): """ def matrices(self): - from sage.all import RIF, CIF, matrix + from sage.rings.real_mpfi import RIF + from sage.rings.cif import CIF + from sage.matrix.constructor import Matrix as matrix return [ matrix.identity(CIF, 2), @@ -410,7 +412,8 @@ def matrices(self): [CIF(RIF(-0.3), RIF(1.1)), CIF(1)]]) ] def run_tests(self): - from sage.all import RIF, CIF + from sage.rings.real_mpfi import RIF + from sage.rings.cif import CIF bias = RIF(1.5) From b14f59dfcb5b199be7bb59abb26fe554d03e56f3 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 16:29:24 -0700 Subject: [PATCH 02/45] python/snap/polished_reps.py: Use try..except for imports from Sage --- python/snap/polished_reps.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/python/snap/polished_reps.py b/python/snap/polished_reps.py index 753f55347..51e8b7232 100644 --- a/python/snap/polished_reps.py +++ b/python/snap/polished_reps.py @@ -11,15 +11,21 @@ if _within_sage: import sage - from sage.rings.real_mpfr import RealField - from sage.rings.complex_mpfr import ComplexField - from sage.arith.misc import GCD as gcd - from sage.misc.misc_c import prod - from sage.combinat.subset import powerset - from sage.matrix.matrix_space import MatrixSpace - from sage.matrix.constructor import Matrix as matrix - from sage.modules.free_module_element import free_module_element as vector - from sage.rings.integer_ring import Z as ZZ + try: + # Monolithic Sage library + from sage.all import RealField, ComplexField, gcd, prod, powerset + from sage.all import MatrixSpace, matrix, vector, ZZ + except ImportError: + # Modularized Sage library + from sage.rings.real_mpfr import RealField + from sage.rings.complex_mpfr import ComplexField + from sage.arith.misc import GCD as gcd + from sage.misc.misc_c import prod + from sage.combinat.subset import powerset + from sage.matrix.matrix_space import MatrixSpace + from sage.matrix.constructor import Matrix as matrix + from sage.modules.free_module_element import free_module_element as vector + from sage.rings.integer_ring import Z as ZZ Object = sage.structure.sage_object.SageObject identity = lambda A: MatrixSpace(A.base_ring(), A.nrows())(1) abelian_group_elt = lambda v: vector(ZZ, v) From 801783d03ee6b6c3aec8afb7dfdb909049781b4c Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 17:40:39 -0700 Subject: [PATCH 03/45] src/snappy/verify/upper_halfspace/finite_point.py: Use try..except for imports from Sage --- python/verify/upper_halfspace/finite_point.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/python/verify/upper_halfspace/finite_point.py b/python/verify/upper_halfspace/finite_point.py index 460261240..53e24c447 100644 --- a/python/verify/upper_halfspace/finite_point.py +++ b/python/verify/upper_halfspace/finite_point.py @@ -1,10 +1,15 @@ from ...sage_helper import _within_sage if _within_sage: - import sage.all - from sage.matrix.constructor import Matrix as matrix - from sage.misc.functional import sqrt - from sage.rings.real_mpfi import is_RealIntervalFieldElement + import sage + try: + # Monolithic Sage library + from sage.all import matrix, sqrt + except ImportError: + # Modularized Sage library + from sage.matrix.constructor import Matrix as matrix + from sage.misc.functional import sqrt + from sage.rings.real_mpfi import is_RealIntervalFieldElement from .extended_matrix import ExtendedMatrix From 664ea76478bd08184c202c0ebe040890e5faefe9 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 19:12:14 -0700 Subject: [PATCH 04/45] python/snap/polished_reps.py: Move try..except for imports to sage_helper --- python/sage_helper.py | 20 +++++++++++++++++++- python/snap/polished_reps.py | 21 ++++----------------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/python/sage_helper.py b/python/sage_helper.py index 28517b672..48666928d 100644 --- a/python/sage_helper.py +++ b/python/sage_helper.py @@ -9,7 +9,7 @@ """ try: - import sage.all + import sage.structure.sage_object _within_sage = True except ImportError: _within_sage = False @@ -30,6 +30,24 @@ def sage_method(function): from sage.rings.complex_field import ComplexField, ComplexField_class from sage.rings.complex_number import create_ComplexNumber + try: + # Monolithic Sage library + from sage.all import RealField, ComplexField, gcd, prod, powerset + from sage.all import MatrixSpace, matrix, vector, ZZ + except ImportError: + # Modularized Sage library + from sage.rings.real_mpfr import RealField + from sage.rings.complex_mpfr import ComplexField + from sage.arith.misc import gcd + from sage.misc.misc_c import prod + from sage.combinat.subset import powerset + from sage.matrix.matrix_space import MatrixSpace + from sage.matrix.constructor import Matrix as matrix + from sage.modules.free_module_element import free_module_element as vector + from sage.rings.integer_ring import ZZ + + from sage.structure.sage_object import SageObject + else: import decorator diff --git a/python/snap/polished_reps.py b/python/snap/polished_reps.py index 51e8b7232..3e8560582 100644 --- a/python/snap/polished_reps.py +++ b/python/snap/polished_reps.py @@ -10,23 +10,10 @@ from .fundamental_polyhedron import * if _within_sage: - import sage - try: - # Monolithic Sage library - from sage.all import RealField, ComplexField, gcd, prod, powerset - from sage.all import MatrixSpace, matrix, vector, ZZ - except ImportError: - # Modularized Sage library - from sage.rings.real_mpfr import RealField - from sage.rings.complex_mpfr import ComplexField - from sage.arith.misc import GCD as gcd - from sage.misc.misc_c import prod - from sage.combinat.subset import powerset - from sage.matrix.matrix_space import MatrixSpace - from sage.matrix.constructor import Matrix as matrix - from sage.modules.free_module_element import free_module_element as vector - from sage.rings.integer_ring import Z as ZZ - Object = sage.structure.sage_object.SageObject + from ..sage_helper import RealField, ComplexField, gcd, prod, powerset + from ..sage_helper import MatrixSpace, matrix, vector, ZZ + from ..sage_helper import SageObject as Object + identity = lambda A: MatrixSpace(A.base_ring(), A.nrows())(1) abelian_group_elt = lambda v: vector(ZZ, v) else: From 27eed35bb0112144d2a87e3ba8813d75d5f23589 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 19:29:16 -0700 Subject: [PATCH 05/45] python/number.py: Go through .sage_helper instead of sage.all --- python/number.py | 2 +- python/sage_helper.py | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/python/number.py b/python/number.py index 235cd0342..2acedf41a 100644 --- a/python/number.py +++ b/python/number.py @@ -11,7 +11,7 @@ precision_of_exact_GEN = pari(0).precision() if _within_sage: - from sage.all import RealField, Integer, Rational, ZZ, QQ, RR, CC, SR + from .sage_helper import RealField, Integer, Rational, ZZ, QQ, RR, CC, SR from sage.structure.parent import Parent from sage.structure.unique_representation import UniqueRepresentation from sage.categories.homset import Hom diff --git a/python/sage_helper.py b/python/sage_helper.py index 48666928d..cf6d125fa 100644 --- a/python/sage_helper.py +++ b/python/sage_helper.py @@ -34,17 +34,23 @@ def sage_method(function): # Monolithic Sage library from sage.all import RealField, ComplexField, gcd, prod, powerset from sage.all import MatrixSpace, matrix, vector, ZZ + from sage.all import Integer, Rational, QQ, RR, CC, SR except ImportError: # Modularized Sage library - from sage.rings.real_mpfr import RealField - from sage.rings.complex_mpfr import ComplexField from sage.arith.misc import gcd - from sage.misc.misc_c import prod from sage.combinat.subset import powerset - from sage.matrix.matrix_space import MatrixSpace from sage.matrix.constructor import Matrix as matrix + from sage.matrix.matrix_space import MatrixSpace + from sage.misc.misc_c import prod from sage.modules.free_module_element import free_module_element as vector + from sage.rings.cc import CC + from sage.rings.complex_mpfr import ComplexField + from sage.rings.integer import Integer from sage.rings.integer_ring import ZZ + from sage.rings.rational import Rational + from sage.rings.rational_field import QQ + from sage.rings.real_mpfr import RealField, RR + from sage.symbolic.ring import SR from sage.structure.sage_object import SageObject From 3125594e3eb96903c6dbaf0d1d5293431dfba8ec Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 19:32:31 -0700 Subject: [PATCH 06/45] python/verify/upper_halfspace/finite_point.py: Go through sage_helper instead of using try..except for imports --- python/sage_helper.py | 3 +++ python/verify/upper_halfspace/finite_point.py | 9 +-------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/python/sage_helper.py b/python/sage_helper.py index cf6d125fa..9bc6861b2 100644 --- a/python/sage_helper.py +++ b/python/sage_helper.py @@ -35,12 +35,14 @@ def sage_method(function): from sage.all import RealField, ComplexField, gcd, prod, powerset from sage.all import MatrixSpace, matrix, vector, ZZ from sage.all import Integer, Rational, QQ, RR, CC, SR + from sage.all import is_RealIntervalFieldElement, sqrt except ImportError: # Modularized Sage library from sage.arith.misc import gcd from sage.combinat.subset import powerset from sage.matrix.constructor import Matrix as matrix from sage.matrix.matrix_space import MatrixSpace + from sage.misc.functional import sqrt from sage.misc.misc_c import prod from sage.modules.free_module_element import free_module_element as vector from sage.rings.cc import CC @@ -49,6 +51,7 @@ def sage_method(function): from sage.rings.integer_ring import ZZ from sage.rings.rational import Rational from sage.rings.rational_field import QQ + from sage.rings.real_mpfi import is_RealIntervalFieldElement from sage.rings.real_mpfr import RealField, RR from sage.symbolic.ring import SR diff --git a/python/verify/upper_halfspace/finite_point.py b/python/verify/upper_halfspace/finite_point.py index 53e24c447..5a8f52287 100644 --- a/python/verify/upper_halfspace/finite_point.py +++ b/python/verify/upper_halfspace/finite_point.py @@ -2,14 +2,7 @@ if _within_sage: import sage - try: - # Monolithic Sage library - from sage.all import matrix, sqrt - except ImportError: - # Modularized Sage library - from sage.matrix.constructor import Matrix as matrix - from sage.misc.functional import sqrt - from sage.rings.real_mpfi import is_RealIntervalFieldElement + from ...sage_helper import matrix, sqrt, is_RealIntervalFieldElement from .extended_matrix import ExtendedMatrix From 5a43792076dcf9ac71017ee91fb02af4876fd022 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 19:42:01 -0700 Subject: [PATCH 07/45] python/sage_helper.py: Fix for is_RealIntervalFieldElement --- python/sage_helper.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/sage_helper.py b/python/sage_helper.py index 9bc6861b2..3a0e82fd9 100644 --- a/python/sage_helper.py +++ b/python/sage_helper.py @@ -35,7 +35,7 @@ def sage_method(function): from sage.all import RealField, ComplexField, gcd, prod, powerset from sage.all import MatrixSpace, matrix, vector, ZZ from sage.all import Integer, Rational, QQ, RR, CC, SR - from sage.all import is_RealIntervalFieldElement, sqrt + from sage.all import sqrt except ImportError: # Modularized Sage library from sage.arith.misc import gcd @@ -51,10 +51,10 @@ def sage_method(function): from sage.rings.integer_ring import ZZ from sage.rings.rational import Rational from sage.rings.rational_field import QQ - from sage.rings.real_mpfi import is_RealIntervalFieldElement from sage.rings.real_mpfr import RealField, RR from sage.symbolic.ring import SR + from sage.rings.real_mpfi import is_RealIntervalFieldElement from sage.structure.sage_object import SageObject else: From ca7c6d38e66385ee3460fb03e5b8f8e5cb3df773 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 19:51:42 -0700 Subject: [PATCH 08/45] python/verify/upper_halfspace/ideal_point.py: Go through sage_helper --- python/sage_helper.py | 3 +++ python/verify/upper_halfspace/ideal_point.py | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/python/sage_helper.py b/python/sage_helper.py index 3a0e82fd9..db25b41cc 100644 --- a/python/sage_helper.py +++ b/python/sage_helper.py @@ -36,6 +36,7 @@ def sage_method(function): from sage.all import MatrixSpace, matrix, vector, ZZ from sage.all import Integer, Rational, QQ, RR, CC, SR from sage.all import sqrt + from sage.all import I, Infinity except ImportError: # Modularized Sage library from sage.arith.misc import gcd @@ -47,6 +48,8 @@ def sage_method(function): from sage.modules.free_module_element import free_module_element as vector from sage.rings.cc import CC from sage.rings.complex_mpfr import ComplexField + from sage.rings.imaginary_unit import I + from sage.rings.infinity import Infinity from sage.rings.integer import Integer from sage.rings.integer_ring import ZZ from sage.rings.rational import Rational diff --git a/python/verify/upper_halfspace/ideal_point.py b/python/verify/upper_halfspace/ideal_point.py index ea03607fe..f70fb940d 100644 --- a/python/verify/upper_halfspace/ideal_point.py +++ b/python/verify/upper_halfspace/ideal_point.py @@ -17,8 +17,8 @@ from ...sage_helper import _within_sage if _within_sage: - import sage.all - from sage.matrix.constructor import Matrix as matrix + from ...sage_helper import I, matrix + from ...sage_helper import Infinity as sage_Infinity from .finite_point import * from .extended_matrix import * @@ -211,7 +211,7 @@ def Euclidean_height_of_hyperbolic_triangle(idealPoints): for idealPoint in idealPoints: if idealPoint != Infinity: RIF = idealPoint.real().parent() - return RIF(sage.all.Infinity) + return RIF(sage_Infinity) raise Exception("What?") @@ -266,7 +266,7 @@ def _transform_points_to_make_first_one_infinity_and_inv_sl_matrix(idealPoints): z = idealPoints[0] CIF = z.parent() gl_matrix = matrix(CIF, [[ 0, 1], [ 1, -z]]) - sl_matrix = CIF(sage.all.I) * gl_matrix + sl_matrix = CIF(I) * gl_matrix inv_sl_matrix = _adjoint2(sl_matrix) # Apply it From ccacbcc17cd0c5539352cfcdcb0b18035b1aa5fa Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 19:54:10 -0700 Subject: [PATCH 09/45] python/number.py: If SR cannot be imported, just do not register a coercion --- python/number.py | 9 +++++++-- python/sage_helper.py | 3 +-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/python/number.py b/python/number.py index 2acedf41a..4341f85a6 100644 --- a/python/number.py +++ b/python/number.py @@ -66,8 +66,13 @@ def __init__(self, precision): self._precision = precision self.register_coercion(MorphismToSPN(ZZ, self, self._precision)) self.register_coercion(MorphismToSPN(QQ, self, self._precision)) - to_SR = Hom(self, SR, Sets())(lambda x: SR(x.sage())) - SR.register_coercion(to_SR) + try: + from sage.symbolic.ring import SR + except ImportError: + pass + else: + to_SR = Hom(self, SR, Sets())(lambda x: SR(x.sage())) + SR.register_coercion(to_SR) def _repr_(self): return "SnapPy Numbers with %s bits precision" % self._precision diff --git a/python/sage_helper.py b/python/sage_helper.py index db25b41cc..613f2bd4a 100644 --- a/python/sage_helper.py +++ b/python/sage_helper.py @@ -34,7 +34,7 @@ def sage_method(function): # Monolithic Sage library from sage.all import RealField, ComplexField, gcd, prod, powerset from sage.all import MatrixSpace, matrix, vector, ZZ - from sage.all import Integer, Rational, QQ, RR, CC, SR + from sage.all import Integer, Rational, QQ, RR, CC from sage.all import sqrt from sage.all import I, Infinity except ImportError: @@ -55,7 +55,6 @@ def sage_method(function): from sage.rings.rational import Rational from sage.rings.rational_field import QQ from sage.rings.real_mpfr import RealField, RR - from sage.symbolic.ring import SR from sage.rings.real_mpfi import is_RealIntervalFieldElement from sage.structure.sage_object import SageObject From 54fbfd09efcd9e91a7f0681e961eef75678380cc Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 19:58:32 -0700 Subject: [PATCH 10/45] python/verify/hyperbolicity.py: Go through sage_helper --- python/verify/hyperbolicity.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/verify/hyperbolicity.py b/python/verify/hyperbolicity.py index 2b149da8e..910bef659 100644 --- a/python/verify/hyperbolicity.py +++ b/python/verify/hyperbolicity.py @@ -8,7 +8,7 @@ if _within_sage: from sage.symbolic.constants import pi - import sage.all + from ..sage_helper import I class FalseTuple(tuple): @@ -103,7 +103,7 @@ def check_logarithmic_gluing_equations_and_positively_oriented_tets( CIF = shape_intervals[0].parent() RIF = CIF.real_field() # 2 pi i in that field - two_pi_i = CIF(2 * pi * sage.all.I) + two_pi_i = CIF(2 * pi * I) # Index of the next gluing equation to check LHS_index = 0 From 84898c9a648832988433e74db489a3db5fcdeac7 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 20:05:21 -0700 Subject: [PATCH 11/45] python/cusps/maximal_cusp_area_matrix.py: Go through sage_helper --- python/cusps/maximal_cusp_area_matrix.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/cusps/maximal_cusp_area_matrix.py b/python/cusps/maximal_cusp_area_matrix.py index ccef94763..e3b616ea7 100644 --- a/python/cusps/maximal_cusp_area_matrix.py +++ b/python/cusps/maximal_cusp_area_matrix.py @@ -9,7 +9,7 @@ from ..hyperboloid.distances import distance_r13_horoballs if _within_sage: - import sage.all + from ..sage_helper import Infinity def maximal_cusp_area_matrix(manifold, bits_prec, verified): """ @@ -63,7 +63,7 @@ def _diagonal_scale(mcomplex, i): return e ** 2 if mcomplex.verified: - d = mcomplex.RF(sage.all.Infinity) + d = mcomplex.RF(Infinity) else: d = mcomplex.RF(1e20) @@ -93,7 +93,7 @@ def _non_diagonal_scale(mcomplex, i, j): return e ** 2 if mcomplex.verified: - d = mcomplex.RF(sage.all.Infinity) + d = mcomplex.RF(Infinity) else: d = mcomplex.RF(1e20) From dc738d2dcb0d0d48d128ca0cb34a6398fe4db137 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 20:07:35 -0700 Subject: [PATCH 12/45] python/hyperboloid/distances.py: Go through sage_helper --- python/hyperboloid/distances.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/python/hyperboloid/distances.py b/python/hyperboloid/distances.py index ebbc467c3..56f313e74 100644 --- a/python/hyperboloid/distances.py +++ b/python/hyperboloid/distances.py @@ -8,7 +8,7 @@ from ..sage_helper import _within_sage # type: ignore if _within_sage: - import sage.all # type: ignore + from ..sage_helper import Infinity __all__ = ['distance_r13_lines', 'lower_bound_distance_r13_line_triangle'] @@ -183,7 +183,7 @@ def _safe_sqrt(p): if is_RealIntervalFieldElement(p): RIF = p.parent() - p = p.intersection(RIF(0, sage.all.Infinity)) + p = p.intersection(RIF(0, Infinity)) else: if p < 0: RF = p.parent() @@ -193,7 +193,7 @@ def _safe_sqrt(p): def _safe_log(p): if is_RealIntervalFieldElement(p): RIF = p.parent() - p = p.intersection(RIF(0, sage.all.Infinity)) + p = p.intersection(RIF(0, Infinity)) else: if p <= 0: RF = p.parent() @@ -207,7 +207,7 @@ def _safe_log_non_neg(p): if p == 0: if is_RealIntervalFieldElement(p): RIF = p.parent() - return RIF(-sage.all.Infinity) + return RIF(-Infinity) else: RF = p.parent() return RF(-1e20) @@ -217,7 +217,7 @@ def _safe_log_non_neg(p): def _safe_arccosh(p): if is_RealIntervalFieldElement(p): RIF = p.parent() - p = p.intersection(RIF(1, sage.all.Infinity)) + p = p.intersection(RIF(1, Infinity)) else: if p < 1: RF = p.parent() @@ -233,9 +233,9 @@ def _safe_div(a, b): if is_RealIntervalFieldElement(b): RIF = b.parent() if b == 0: - return RIF(sage.all.Infinity) + return RIF(Infinity) else: - return a / b.intersection(RIF(0, sage.all.Infinity)) + return a / b.intersection(RIF(0, Infinity)) else: if b <= 0: RIF = b.parent() From ac081ab682c98547267cd1135cdb1bf724606ca0 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 20:09:56 -0700 Subject: [PATCH 13/45] python/tiling/tile.py: Go through sage_helper --- python/tiling/tile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/tiling/tile.py b/python/tiling/tile.py index e3861f1ef..a5c70ad9b 100644 --- a/python/tiling/tile.py +++ b/python/tiling/tile.py @@ -10,7 +10,7 @@ from ..sage_helper import _within_sage # type: ignore if _within_sage: - import sage.all # type: ignore + from ..sage_helper import Infinity import heapq @@ -71,7 +71,7 @@ def compute_tiles(*, # Everything is a keyword argument RF = visited_lifted_tetrahedra._base_point[0].parent() if verified: - minus_infinity = RF(-sage.all.Infinity) + minus_infinity = RF(-Infinity) else: minus_infinity = RF(-1e20) From 8274cb5b8cbb3484a10cb7e119a4c33ffceff3ff Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 20:12:04 -0700 Subject: [PATCH 14/45] python/verify/complex_volume/adjust_torsion.py: Go through sage_helper --- python/verify/complex_volume/adjust_torsion.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/python/verify/complex_volume/adjust_torsion.py b/python/verify/complex_volume/adjust_torsion.py index 7b8c19ca3..fc5634b97 100644 --- a/python/verify/complex_volume/adjust_torsion.py +++ b/python/verify/complex_volume/adjust_torsion.py @@ -1,7 +1,6 @@ from ...sage_helper import _within_sage, sage_method if _within_sage: - from sage.symbolic.constants import pi - import sage.all + from ...sage_helper import pi from .extended_bloch import * from ...snap import t3mlite as t3m From 4e3189310bac12f894d35ae2e1481e06673ab5ab Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 20:13:02 -0700 Subject: [PATCH 15/45] python/verify/maximal_cusp_area_matrix/cusp_tiling_engine.py: Go through sage_helper --- python/verify/maximal_cusp_area_matrix/cusp_tiling_engine.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/python/verify/maximal_cusp_area_matrix/cusp_tiling_engine.py b/python/verify/maximal_cusp_area_matrix/cusp_tiling_engine.py index a8435f3fd..11312914d 100644 --- a/python/verify/maximal_cusp_area_matrix/cusp_tiling_engine.py +++ b/python/verify/maximal_cusp_area_matrix/cusp_tiling_engine.py @@ -15,8 +15,7 @@ from .cusp_translate_engine import * if _within_sage: - from sage.matrix.constructor import Matrix as matrix - import sage.all + from ...sage_helper import matrix import heapq From 9a01d66dbe6cddbe9c076087f9ccd0f4e9ebd111 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 20:14:49 -0700 Subject: [PATCH 16/45] python/verify/upper_halfspace/finite_point.py: Go through sage_helper --- python/verify/upper_halfspace/finite_point.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/verify/upper_halfspace/finite_point.py b/python/verify/upper_halfspace/finite_point.py index 5a8f52287..0920b4c5f 100644 --- a/python/verify/upper_halfspace/finite_point.py +++ b/python/verify/upper_halfspace/finite_point.py @@ -2,7 +2,7 @@ if _within_sage: import sage - from ...sage_helper import matrix, sqrt, is_RealIntervalFieldElement + from ...sage_helper import matrix, sqrt, is_RealIntervalFieldElement, Infinity from .extended_matrix import ExtendedMatrix @@ -168,7 +168,7 @@ def cosh_dist(self, other): RIF = r.parent() if _within_sage: if is_RealIntervalFieldElement(r): - return r.intersection(RIF(1,sage.all.Infinity)) + return r.intersection(RIF(1, Infinity)) if r < 1.0: return RIF(1.0) return r From 1f63268af38a2fa81785317d69c714ff376304da Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 20:17:36 -0700 Subject: [PATCH 17/45] python/pari.py: Use try..except for import of PariError --- python/pari.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/python/pari.py b/python/pari.py index 5a4236818..14fb071d9 100644 --- a/python/pari.py +++ b/python/pari.py @@ -18,7 +18,11 @@ prec_words_to_bits, prec_bits_to_dec, prec_dec_to_bits) - from sage.all import PariError + try: + from sage.all import PariError + except ImportError: + from sage.libs.pari.all import PariError + shut_up = lambda: None speak_up = lambda: None From 64477f6d611265398d5b3f365a177705aa50c16b Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 20:23:36 -0700 Subject: [PATCH 18/45] python/number.py: If SR cannot be imported, just do not register a coercion (fixup) --- python/number.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/number.py b/python/number.py index 4341f85a6..ca7d80c62 100644 --- a/python/number.py +++ b/python/number.py @@ -11,7 +11,7 @@ precision_of_exact_GEN = pari(0).precision() if _within_sage: - from .sage_helper import RealField, Integer, Rational, ZZ, QQ, RR, CC, SR + from .sage_helper import RealField, Integer, Rational, ZZ, QQ, RR, CC from sage.structure.parent import Parent from sage.structure.unique_representation import UniqueRepresentation from sage.categories.homset import Hom From c9ccfb0259bbab4fc76338e1206ba6999be1a538 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 20:26:06 -0700 Subject: [PATCH 19/45] python/verify/complex_volume/extended_bloch.py: Go through sage_helper --- python/verify/complex_volume/extended_bloch.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/python/verify/complex_volume/extended_bloch.py b/python/verify/complex_volume/extended_bloch.py index 03bd45d8f..8d5eee2bf 100644 --- a/python/verify/complex_volume/extended_bloch.py +++ b/python/verify/complex_volume/extended_bloch.py @@ -6,8 +6,7 @@ from sage.rings.integer import Integer from sage.functions.log import exp from sage.symbolic.constants import pi - - import sage.all + from ...sage_helper import I @sage_method @@ -108,8 +107,8 @@ def compute_Neumanns_Rogers_dilog_from_flattening_w0_w1(w0, w1): # Note that the values computed for log(z) and log(1-z) # are not verified to have the imaginary part between -pi and pi. - logZ = w0 - my_pi * p * sage.all.I - logOneMinusZ = - (w1 - my_pi * q * sage.all.I) + logZ = w0 - my_pi * p * I + logOneMinusZ = - (w1 - my_pi * q * I) # Neumann's formula for the complex volume is # @@ -145,7 +144,7 @@ def compute_Neumanns_Rogers_dilog_from_flattening_w0_w1(w0, w1): # Similar considerations apply to (2) used when Re(z) > 1/2. term1 = logZ * logOneMinusZ - term2 = my_pi * sage.all.I * (p * logOneMinusZ + q * logZ) + term2 = my_pi * I * (p * logOneMinusZ + q * logZ) if z.real().center() < 0.5: # Check that we can apply equation (1) From bbcd6c8b0a66cab044a1680223989425d442467d Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 20:27:19 -0700 Subject: [PATCH 20/45] python/verify/complex_volume/cusped.py: Go through sage_helper --- python/verify/complex_volume/cusped.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/verify/complex_volume/cusped.py b/python/verify/complex_volume/cusped.py index 3fc68d0d1..ac497bf15 100644 --- a/python/verify/complex_volume/cusped.py +++ b/python/verify/complex_volume/cusped.py @@ -1,7 +1,7 @@ from ...sage_helper import _within_sage, sage_method if _within_sage: - import sage.all + from ...sage_helper import I from .. import hyperbolicity from ...geometric_structure.cusp_neighborhood.complex_cusp_cross_section import ComplexCuspCrossSection @@ -53,4 +53,4 @@ def verified_complex_volume_cusped_torsion(manifold, bits_prec=None): # I. # Also add multiples of pi^2/2 to try to get the Chern-Simons part # between -pi^2/4 and pi^2/4. - return normalize_by_pi_square_over_two(complex_volume) / sage.all.I + return normalize_by_pi_square_over_two(complex_volume) / I From 5ce0eb034a1547f4a50697b6586b99fefb4bcdfe Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 20:30:59 -0700 Subject: [PATCH 21/45] python/upper_halfspace/__init__.py: Go through sage_helper for arccosh --- python/sage_helper.py | 2 ++ python/upper_halfspace/__init__.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/python/sage_helper.py b/python/sage_helper.py index 613f2bd4a..0fddd4d17 100644 --- a/python/sage_helper.py +++ b/python/sage_helper.py @@ -37,10 +37,12 @@ def sage_method(function): from sage.all import Integer, Rational, QQ, RR, CC from sage.all import sqrt from sage.all import I, Infinity + from sage.all import arccosh except ImportError: # Modularized Sage library from sage.arith.misc import gcd from sage.combinat.subset import powerset + from sage.functions.hyperbolic import arccosh from sage.matrix.constructor import Matrix as matrix from sage.matrix.matrix_space import MatrixSpace from sage.misc.functional import sqrt diff --git a/python/upper_halfspace/__init__.py b/python/upper_halfspace/__init__.py index f01d7cde2..d5a23277f 100644 --- a/python/upper_halfspace/__init__.py +++ b/python/upper_halfspace/__init__.py @@ -140,7 +140,7 @@ def _o13_matrix_column(A, m, Aadj): fAmj[0][1].imag() ] if _within_sage: - from sage.all import arccosh as _arccosh + from ..sage_helper import arccosh as _arccosh else: def _arccosh(z): return z.arccosh() From 80d3d61c93a4283e586e4c673f774c8837dc17c5 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 20:34:25 -0700 Subject: [PATCH 22/45] python/database.py: Go through sage_helper --- python/database.py | 10 +++++----- python/sage_helper.py | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/python/database.py b/python/database.py index 1082bc2ae..7d36993b5 100644 --- a/python/database.py +++ b/python/database.py @@ -22,17 +22,17 @@ import collections if _within_sage: - import sage.all + from .sage_helper import Integer, RealDoubleElement, RealNumber def is_int(slice): - return isinstance(slice, (sage.all.Integer, int)) + return isinstance(slice, (Integer, int)) def is_int_or_none(slice): - return isinstance(slice, (sage.all.Integer, int, type(None))) + return isinstance(slice, (Integer, int, type(None))) def is_float_or_none(slice): - return isinstance(slice, (float, sage.all.RealDoubleElement, - sage.rings.real_mpfr.RealNumber, type(None))) + return isinstance(slice, (float, RealDoubleElement, + RealNumber, type(None))) else: def is_int(slice): return isinstance(slice, int) diff --git a/python/sage_helper.py b/python/sage_helper.py index 0fddd4d17..827d48cb2 100644 --- a/python/sage_helper.py +++ b/python/sage_helper.py @@ -32,7 +32,7 @@ def sage_method(function): try: # Monolithic Sage library - from sage.all import RealField, ComplexField, gcd, prod, powerset + from sage.all import RealField, RealNumber, RealDoubleElement, ComplexField, gcd, prod, powerset from sage.all import MatrixSpace, matrix, vector, ZZ from sage.all import Integer, Rational, QQ, RR, CC from sage.all import sqrt @@ -56,7 +56,8 @@ def sage_method(function): from sage.rings.integer_ring import ZZ from sage.rings.rational import Rational from sage.rings.rational_field import QQ - from sage.rings.real_mpfr import RealField, RR + from sage.rings.real_double import RealDoubleElement + from sage.rings.real_mpfr import RealField, RealNumber, RR from sage.rings.real_mpfi import is_RealIntervalFieldElement from sage.structure.sage_object import SageObject From c3209238528ad18b2cd4b6168a7ae54776cdc6d3 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 20:50:15 -0700 Subject: [PATCH 23/45] Use 'from sage.symbolic.constants import pi' --- dev/drilling/smoke_test.py | 2 +- dev/drilling/smoke_test2.py | 2 +- python/verify/complex_volume/adjust_torsion.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dev/drilling/smoke_test.py b/dev/drilling/smoke_test.py index a8271ad23..e669aa2f9 100644 --- a/dev/drilling/smoke_test.py +++ b/dev/drilling/smoke_test.py @@ -5,7 +5,7 @@ from snappy.drilling import exceptions from snappy.drilling import perturb -from sage.all import pi +from sage.symbolic.constants import pi # perturb._tube_developing_radius = 1 diff --git a/dev/drilling/smoke_test2.py b/dev/drilling/smoke_test2.py index 45da51eef..f448f5d41 100644 --- a/dev/drilling/smoke_test2.py +++ b/dev/drilling/smoke_test2.py @@ -5,7 +5,7 @@ from snappy.drilling import exceptions from snappy.drilling import perturb -from sage.all import pi +from sage.symbolic.constants import pi # perturb._tube_developing_radius = 1 diff --git a/python/verify/complex_volume/adjust_torsion.py b/python/verify/complex_volume/adjust_torsion.py index fc5634b97..a2aaf625a 100644 --- a/python/verify/complex_volume/adjust_torsion.py +++ b/python/verify/complex_volume/adjust_torsion.py @@ -1,6 +1,6 @@ from ...sage_helper import _within_sage, sage_method if _within_sage: - from ...sage_helper import pi + from sage.symbolic.constants import pi from .extended_bloch import * from ...snap import t3mlite as t3m From 7a7036328e8146dabcc769cd45edff35e53a4479 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 21:20:53 -0700 Subject: [PATCH 24/45] python/verify/complex_volume/closed.py: Go through sage_helper --- python/verify/complex_volume/closed.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python/verify/complex_volume/closed.py b/python/verify/complex_volume/closed.py index fd96e8d21..98d1ec2ad 100644 --- a/python/verify/complex_volume/closed.py +++ b/python/verify/complex_volume/closed.py @@ -8,7 +8,7 @@ if _within_sage: from sage.symbolic.constants import pi from sage.arith.misc import XGCD as xgcd - import sage.all + from ...sage_helper import I from .. import hyperbolicity @@ -69,8 +69,8 @@ def zero_lifted_holonomy(manifold, m, l, f): # Compute by what multiple of 2 pi i to adjust g, a, b = xgcd(m_fill, l_fill) - m -= p * a * multiple_of_pi * sage.all.I - l -= p * b * multiple_of_pi * sage.all.I + m -= p * a * multiple_of_pi * I + l -= p * b * multiple_of_pi * I # For sanity, double check that we compute it right. p_interval = (m_fill * m + l_fill * l).imag() / multiple_of_pi @@ -166,4 +166,4 @@ def verified_complex_volume_closed_torsion(manifold, bits_prec=None): # I. # Also add multiples of pi^2/2 to try to get the Chern-Simons part # between -pi^2/4 and pi^2/4. - return normalize_by_pi_square_over_two(complex_volume) / sage.all.I + return normalize_by_pi_square_over_two(complex_volume) / I From 00c5b988c8cfd085cf32a50c8db0c8f443586ed8 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 21:58:51 -0700 Subject: [PATCH 25/45] cython/core/fundamental_group.pyx: Use import --- cython/core/fundamental_group.pyx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cython/core/fundamental_group.pyx b/cython/core/fundamental_group.pyx index 750f190f1..50a7b69ae 100644 --- a/cython/core/fundamental_group.pyx +++ b/cython/core/fundamental_group.pyx @@ -477,7 +477,8 @@ class FundamentalGroup(CFundamentalGroup): if _within_sage: - FundamentalGroup.__bases__ += (sage.structure.sage_object.SageObject,) + from sage.structure.sage_object import SageObject + FundamentalGroup.__bases__ += (SageObject,) # Holonomy Groups @@ -594,4 +595,5 @@ class HolonomyGroup(CHolonomyGroup): if _within_sage: - HolonomyGroup.__bases__ += (sage.structure.sage_object.SageObject,) + from sage.structure.sage_object import SageObject + HolonomyGroup.__bases__ += (SageObject,) From 4e1689afdd01a76a0a531ce23dc7dd010962d7ec Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 22:31:40 -0700 Subject: [PATCH 26/45] python/testing.py: Use import --- python/testing.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/python/testing.py b/python/testing.py index 2aeaaf7d0..fb3559319 100644 --- a/python/testing.py +++ b/python/testing.py @@ -78,8 +78,12 @@ def parse(self, string, name=''): return doctest.DocTestParser.parse(self, string, name) if _within_sage: - import sage.all - globs = {'PSL': sage.all.PSL, 'BraidGroup': sage.all.BraidGroup} + try: + from sage.all import PSL, BraidGroup + except ImportError: + from sage.groups.perm_gps.permgroup_named import PSL + from sage.groups.braid import BraidGroup + globs = {'PSL': PSL, 'BraidGroup': BraidGroup} else: globs = {} From 0e0df34007eb73e41530c55198236b0f17568b25 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 22:50:27 -0700 Subject: [PATCH 27/45] cython/core/abelian_group.pyx: Use import --- cython/core/abelian_group.pyx | 3 ++- python/testing.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/cython/core/abelian_group.pyx b/cython/core/abelian_group.pyx index d3a19acd0..0aaeb5b89 100644 --- a/cython/core/abelian_group.pyx +++ b/cython/core/abelian_group.pyx @@ -49,7 +49,8 @@ cdef class AbelianGroup(): 'as a sequence.') int_types = [int] if _within_sage: - int_types += [sage.rings.integer.Integer] + from sage.rings.integer import Integer + int_types += [Integer] for c in self.divisors: assert type(c) in int_types and c >= 0,\ 'Elementary divisors must be non-negative integers.\n' diff --git a/python/testing.py b/python/testing.py index fb3559319..902a7cbe9 100644 --- a/python/testing.py +++ b/python/testing.py @@ -81,6 +81,7 @@ def parse(self, string, name=''): try: from sage.all import PSL, BraidGroup except ImportError: + import sage.groups.perm_gps.permgroup_element from sage.groups.perm_gps.permgroup_named import PSL from sage.groups.braid import BraidGroup globs = {'PSL': PSL, 'BraidGroup': BraidGroup} From c6440f364f308ff6a36ea5cea05c736263a8a5bb Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 23:10:25 -0700 Subject: [PATCH 28/45] cython/core/basic.pyx: Remove .all import --- cython/core/basic.pyx | 1 - 1 file changed, 1 deletion(-) diff --git a/cython/core/basic.pyx b/cython/core/basic.pyx index 5e9c6531f..f866e66f3 100644 --- a/cython/core/basic.pyx +++ b/cython/core/basic.pyx @@ -19,7 +19,6 @@ python_major_version = sys.version_info.major from .sage_helper import _within_sage, SageNotAvailable from .pari import pari as pari try: - import sage.all import sage.structure.sage_object from sage.groups.perm_gps.permgroup_element import is_PermutationGroupElement from sage.groups.perm_gps.permgroup import PermutationGroup From 5b332d876454d0d49527c2d6e0cac3cb5c58c9d2 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 30 Dec 2024 21:17:46 -0800 Subject: [PATCH 29/45] python/sage_helper.py: Fix import of RealNumber --- python/sage_helper.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/sage_helper.py b/python/sage_helper.py index 827d48cb2..187299709 100644 --- a/python/sage_helper.py +++ b/python/sage_helper.py @@ -32,7 +32,7 @@ def sage_method(function): try: # Monolithic Sage library - from sage.all import RealField, RealNumber, RealDoubleElement, ComplexField, gcd, prod, powerset + from sage.all import RealField, RealDoubleElement, ComplexField, gcd, prod, powerset from sage.all import MatrixSpace, matrix, vector, ZZ from sage.all import Integer, Rational, QQ, RR, CC from sage.all import sqrt @@ -60,6 +60,7 @@ def sage_method(function): from sage.rings.real_mpfr import RealField, RealNumber, RR from sage.rings.real_mpfi import is_RealIntervalFieldElement + from sage.rings.real_mpfr import RealNumber from sage.structure.sage_object import SageObject else: From 8d02aee68547e04e2ff6bd3f549b647990d40538 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 30 Dec 2024 21:28:01 -0800 Subject: [PATCH 30/45] python/sage_helper.py: Import Complex* later --- python/sage_helper.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/python/sage_helper.py b/python/sage_helper.py index 187299709..cbd362e46 100644 --- a/python/sage_helper.py +++ b/python/sage_helper.py @@ -22,17 +22,9 @@ def sage_method(function): function._sage_method = True return function - try: # Sage >= 9.3, see https://trac.sagemath.org/ticket/24483 - from sage.rings.complex_mpfr import (ComplexField, - ComplexField_class, - create_ComplexNumber) - except ModuleNotFoundError: - from sage.rings.complex_field import ComplexField, ComplexField_class - from sage.rings.complex_number import create_ComplexNumber - try: # Monolithic Sage library - from sage.all import RealField, RealDoubleElement, ComplexField, gcd, prod, powerset + from sage.all import RealField, RealDoubleElement, gcd, prod, powerset from sage.all import MatrixSpace, matrix, vector, ZZ from sage.all import Integer, Rational, QQ, RR, CC from sage.all import sqrt @@ -63,6 +55,14 @@ def sage_method(function): from sage.rings.real_mpfr import RealNumber from sage.structure.sage_object import SageObject + try: # Sage >= 9.3, see https://trac.sagemath.org/ticket/24483 + from sage.rings.complex_mpfr import (ComplexField, + ComplexField_class, + create_ComplexNumber) + except ImportError: + from sage.rings.complex_field import ComplexField, ComplexField_class + from sage.rings.complex_number import create_ComplexNumber + else: import decorator From 7d883d154c4323d3402a7dedd49b9d29b79b6c81 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 30 Dec 2024 21:57:42 -0800 Subject: [PATCH 31/45] python/verify/upper_halfspace/extended_matrix.py: Use try..except for import --- python/verify/upper_halfspace/extended_matrix.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python/verify/upper_halfspace/extended_matrix.py b/python/verify/upper_halfspace/extended_matrix.py index c08f7941e..e790162c2 100644 --- a/python/verify/upper_halfspace/extended_matrix.py +++ b/python/verify/upper_halfspace/extended_matrix.py @@ -1,7 +1,10 @@ from ...sage_helper import _within_sage if _within_sage: - from sage.misc.functional import sqrt + try: + from sage.misc.functional import sqrt + except ImportError: + from sage.all import sqrt __all__ = ['ExtendedMatrix'] From 2ac51c373b7482146ff89082cafe617b4bb9df13 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 30 Dec 2024 22:05:37 -0800 Subject: [PATCH 32/45] python/verify/upper_halfspace/ideal_point.py: Use try...except for import --- python/verify/upper_halfspace/ideal_point.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/python/verify/upper_halfspace/ideal_point.py b/python/verify/upper_halfspace/ideal_point.py index f70fb940d..6de867259 100644 --- a/python/verify/upper_halfspace/ideal_point.py +++ b/python/verify/upper_halfspace/ideal_point.py @@ -398,8 +398,11 @@ class _IdealPointTester(): """ def matrices(self): - from sage.rings.real_mpfi import RIF - from sage.rings.cif import CIF + try: + from sage.rings.real_mpfi import RIF + from sage.rings.cif import CIF + except ImportError: + from sage.all import RIF, CIF from sage.matrix.constructor import Matrix as matrix return [ @@ -412,8 +415,11 @@ def matrices(self): [CIF(RIF(-0.3), RIF(1.1)), CIF(1)]]) ] def run_tests(self): - from sage.rings.real_mpfi import RIF - from sage.rings.cif import CIF + try: + from sage.rings.real_mpfi import RIF + from sage.rings.cif import CIF + except ImportError: + from sage.all import RIF, CIF bias = RIF(1.5) From f94a43bca16f704044f9c68cf0c293b748d99ff7 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 31 Dec 2024 19:42:18 -0800 Subject: [PATCH 33/45] python/sage_helper.py: Import CIF, RIF --- python/sage_helper.py | 3 +++ python/verify/upper_halfspace/ideal_point.py | 15 +-------------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/python/sage_helper.py b/python/sage_helper.py index cbd362e46..d21807fde 100644 --- a/python/sage_helper.py +++ b/python/sage_helper.py @@ -30,6 +30,7 @@ def sage_method(function): from sage.all import sqrt from sage.all import I, Infinity from sage.all import arccosh + from sage.all import RIF, CIF except ImportError: # Modularized Sage library from sage.arith.misc import gcd @@ -41,6 +42,7 @@ def sage_method(function): from sage.misc.misc_c import prod from sage.modules.free_module_element import free_module_element as vector from sage.rings.cc import CC + from sage.rings.cif import CIF from sage.rings.complex_mpfr import ComplexField from sage.rings.imaginary_unit import I from sage.rings.infinity import Infinity @@ -49,6 +51,7 @@ def sage_method(function): from sage.rings.rational import Rational from sage.rings.rational_field import QQ from sage.rings.real_double import RealDoubleElement + from sage.rings.real_mpfi import RIF from sage.rings.real_mpfr import RealField, RealNumber, RR from sage.rings.real_mpfi import is_RealIntervalFieldElement diff --git a/python/verify/upper_halfspace/ideal_point.py b/python/verify/upper_halfspace/ideal_point.py index 6de867259..d04924c8b 100644 --- a/python/verify/upper_halfspace/ideal_point.py +++ b/python/verify/upper_halfspace/ideal_point.py @@ -17,7 +17,7 @@ from ...sage_helper import _within_sage if _within_sage: - from ...sage_helper import I, matrix + from ...sage_helper import I, matrix, RIF, CIF from ...sage_helper import Infinity as sage_Infinity from .finite_point import * @@ -398,13 +398,6 @@ class _IdealPointTester(): """ def matrices(self): - try: - from sage.rings.real_mpfi import RIF - from sage.rings.cif import CIF - except ImportError: - from sage.all import RIF, CIF - from sage.matrix.constructor import Matrix as matrix - return [ matrix.identity(CIF, 2), matrix( @@ -415,12 +408,6 @@ def matrices(self): [CIF(RIF(-0.3), RIF(1.1)), CIF(1)]]) ] def run_tests(self): - try: - from sage.rings.real_mpfi import RIF - from sage.rings.cif import CIF - except ImportError: - from sage.all import RIF, CIF - bias = RIF(1.5) triangle = [ CIF(0), Infinity, CIF(1) ] From 1afb2d4c3f7a51d0d8507d863a461e6e53469e25 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 31 Dec 2024 19:46:54 -0800 Subject: [PATCH 34/45] python/verify/upper_halfspace/extended_matrix.py: Import from sage_helper --- python/verify/upper_halfspace/extended_matrix.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/python/verify/upper_halfspace/extended_matrix.py b/python/verify/upper_halfspace/extended_matrix.py index e790162c2..2997069e9 100644 --- a/python/verify/upper_halfspace/extended_matrix.py +++ b/python/verify/upper_halfspace/extended_matrix.py @@ -1,10 +1,7 @@ from ...sage_helper import _within_sage if _within_sage: - try: - from sage.misc.functional import sqrt - except ImportError: - from sage.all import sqrt + from ...sage_helper import sqrt __all__ = ['ExtendedMatrix'] From 9a434d91705358ecab60d30f8c666e53843dc612 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 31 Dec 2024 19:57:10 -0800 Subject: [PATCH 35/45] python/sage_helper.py: Add imports from python/snap/find_field.py --- python/sage_helper.py | 13 ++++++++++++- python/snap/find_field.py | 19 ++++--------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/python/sage_helper.py b/python/sage_helper.py index d21807fde..0ea737914 100644 --- a/python/sage_helper.py +++ b/python/sage_helper.py @@ -31,23 +31,34 @@ def sage_method(function): from sage.all import I, Infinity from sage.all import arccosh from sage.all import RIF, CIF + from sage.all import (cached_method, real_part, imag_part, round, ceil, floor, log, + CDF, ComplexField, NumberField, PolynomialRing, identity_matrix) except ImportError: # Modularized Sage library from sage.arith.misc import gcd from sage.combinat.subset import powerset from sage.functions.hyperbolic import arccosh + from sage.functions.other import (real as real_part, + imag as imag_part, + ceil, + floor) from sage.matrix.constructor import Matrix as matrix from sage.matrix.matrix_space import MatrixSpace - from sage.misc.functional import sqrt + from sage.matrix.special import identity_matrix + from sage.misc.cachefunc import cached_method + from sage.misc.functional import log, round, sqrt from sage.misc.misc_c import prod from sage.modules.free_module_element import free_module_element as vector from sage.rings.cc import CC from sage.rings.cif import CIF + from sage.rings.complex_double import CDF from sage.rings.complex_mpfr import ComplexField from sage.rings.imaginary_unit import I from sage.rings.infinity import Infinity from sage.rings.integer import Integer from sage.rings.integer_ring import ZZ + from sage.rings.number_field.number_field import NumberField + from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.rings.rational import Rational from sage.rings.rational_field import QQ from sage.rings.real_double import RealDoubleElement diff --git a/python/snap/find_field.py b/python/snap/find_field.py index ce47ece26..db754cc3f 100644 --- a/python/snap/find_field.py +++ b/python/snap/find_field.py @@ -1,20 +1,9 @@ -from sage.misc.cachefunc import cached_method -from sage.functions.other import real as real_part -from sage.functions.other import imag as imag_part -from sage.misc.functional import round -from sage.functions.other import ceil -from sage.functions.other import floor -from sage.misc.functional import log -from sage.rings.integer_ring import Z as ZZ -from sage.rings.rational_field import Q as QQ -from sage.rings.complex_double import CDF -from sage.rings.complex_mpfr import ComplexField -from sage.rings.number_field.number_field import NumberField -from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing -from sage.matrix.constructor import Matrix as matrix -from sage.matrix.special import identity_matrix import itertools +from ..sage_helper import (cached_method, real_part, imag_part, round, ceil, floor, log, + ZZ, QQ, CDF, ComplexField, NumberField, PolynomialRing, + matrix, identity_matrix) + def error(poly, z, a=ZZ(0)): """ From b74ed934d4b8f4a4bdd252ad74388223f219c386 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 31 Dec 2024 20:06:15 -0800 Subject: [PATCH 36/45] python/sage_helper.py: Add imports from python/exterior_to_link/rational_linear_algebra*.py --- python/exterior_to_link/rational_linear_algebra.py | 6 +----- python/exterior_to_link/rational_linear_algebra_wrapped.py | 5 +---- python/sage_helper.py | 2 ++ 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/python/exterior_to_link/rational_linear_algebra.py b/python/exterior_to_link/rational_linear_algebra.py index bc60c4750..c63825f29 100644 --- a/python/exterior_to_link/rational_linear_algebra.py +++ b/python/exterior_to_link/rational_linear_algebra.py @@ -17,11 +17,7 @@ from .. import sage_helper if sage_helper._within_sage and not use_pari_even_inside_sage: - from sage.rings.rational_field import Q as QQ - from sage.rings.real_mpfr import RR - from sage.modules.free_module_element import free_module_element as vector - from sage.matrix.constructor import Matrix as matrix - from sage.modules.free_module import VectorSpace + from ..sage_helper import QQ, RR, vector, matrix, VectorSpace def rational_sqrt(x): """ diff --git a/python/exterior_to_link/rational_linear_algebra_wrapped.py b/python/exterior_to_link/rational_linear_algebra_wrapped.py index d9583ea14..a58b4940b 100644 --- a/python/exterior_to_link/rational_linear_algebra_wrapped.py +++ b/python/exterior_to_link/rational_linear_algebra_wrapped.py @@ -16,10 +16,7 @@ This file is not currently used by SnapPy, but is kept for possible future reference. """ -from sage.rings.rational_field import Q as QQ -from sage.modules.free_module_element import free_module_element as vector -from sage.matrix.constructor import Matrix as matrix -from sage.modules.free_module import VectorSpace +from ..sage_helper import QQ, vector, matrix, VectorSpace class Vector: diff --git a/python/sage_helper.py b/python/sage_helper.py index 0ea737914..26b13a8e4 100644 --- a/python/sage_helper.py +++ b/python/sage_helper.py @@ -33,6 +33,7 @@ def sage_method(function): from sage.all import RIF, CIF from sage.all import (cached_method, real_part, imag_part, round, ceil, floor, log, CDF, ComplexField, NumberField, PolynomialRing, identity_matrix) + from sage.all import VectorSpace except ImportError: # Modularized Sage library from sage.arith.misc import gcd @@ -48,6 +49,7 @@ def sage_method(function): from sage.misc.cachefunc import cached_method from sage.misc.functional import log, round, sqrt from sage.misc.misc_c import prod + from sage.modules.free_module import VectorSpace from sage.modules.free_module_element import free_module_element as vector from sage.rings.cc import CC from sage.rings.cif import CIF From dc0347fa1e977dc039813eaf2063b8fbe61156b0 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 31 Dec 2024 20:29:24 -0800 Subject: [PATCH 37/45] python/sage_helper.py: Import RealField_class --- python/sage_helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/sage_helper.py b/python/sage_helper.py index 26b13a8e4..457981ec8 100644 --- a/python/sage_helper.py +++ b/python/sage_helper.py @@ -68,7 +68,7 @@ def sage_method(function): from sage.rings.real_mpfr import RealField, RealNumber, RR from sage.rings.real_mpfi import is_RealIntervalFieldElement - from sage.rings.real_mpfr import RealNumber + from sage.rings.real_mpfr import RealNumber, RealField_class from sage.structure.sage_object import SageObject try: # Sage >= 9.3, see https://trac.sagemath.org/ticket/24483 From 7a6b0b01fe37c84faa30f1ef67966c287fbe9b73 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 31 Dec 2024 20:29:47 -0800 Subject: [PATCH 38/45] More imports via sage_helper --- .../cusp_neighborhood/complex_cusp_cross_section.py | 6 ++---- python/snap/peripheral/peripheral.py | 4 +--- python/snap/peripheral/surface.py | 9 ++------- python/snap/t3mlite/spun.py | 4 +--- python/snap/utilities.py | 6 ++---- 5 files changed, 8 insertions(+), 21 deletions(-) diff --git a/python/geometric_structure/cusp_neighborhood/complex_cusp_cross_section.py b/python/geometric_structure/cusp_neighborhood/complex_cusp_cross_section.py index 99066d83a..40bdf5a89 100644 --- a/python/geometric_structure/cusp_neighborhood/complex_cusp_cross_section.py +++ b/python/geometric_structure/cusp_neighborhood/complex_cusp_cross_section.py @@ -385,8 +385,7 @@ def _add_one_cusp_vertex_positions(self, cusp : t3m.Vertex): def _debug_show_horotriangles(self, cusp : int =0): from sage.plot.line import line - from sage.functions.other import real - from sage.functions.other import imag + from sage.functions.other import real, imag self.add_vertex_positions_to_horotriangles() @@ -401,8 +400,7 @@ def _debug_show_horotriangles(self, cusp : int =0): def _debug_show_lifted_horotriangles(self, cusp : int =0): from sage.plot.line import line - from sage.functions.other import real - from sage.functions.other import imag + from sage.functions.other import real, imag self.add_vertex_positions_to_horotriangles() diff --git a/python/snap/peripheral/peripheral.py b/python/snap/peripheral/peripheral.py index 90ce76754..1be7f24bb 100644 --- a/python/snap/peripheral/peripheral.py +++ b/python/snap/peripheral/peripheral.py @@ -3,9 +3,7 @@ from . import link, dual_cellulation if sage_helper._within_sage: - from sage.matrix.constructor import Matrix as matrix - from sage.modules.free_module_element import free_module_element as vector - from sage.rings.integer_ring import Z as ZZ + from ...sage_helper import matrix, vector, ZZ def peripheral_curve_from_snappy(dual_cell, snappy_data): diff --git a/python/snap/peripheral/surface.py b/python/snap/peripheral/surface.py index 5262c33c4..df9bcebf6 100644 --- a/python/snap/peripheral/surface.py +++ b/python/snap/peripheral/surface.py @@ -2,14 +2,9 @@ from ... import sage_helper if sage_helper._within_sage: - from sage.rings.integer_ring import Z as ZZ - from sage.matrix.constructor import Matrix as matrix - from sage.modules.free_module_element import free_module_element as vector + from ...sage_helper import ZZ, matrix, vector, cached_method from sage.homology.chain_complex import ChainComplex - from sage.misc.cachefunc import cached_method - from sage.plot.line import line - from sage.plot.arrow import arrow - from sage.plot.text import text + from sage.plot.all import line, arrow, text else: def cached_method(func): return func diff --git a/python/snap/t3mlite/spun.py b/python/snap/t3mlite/spun.py index fb020574c..c5ee33b51 100644 --- a/python/snap/t3mlite/spun.py +++ b/python/snap/t3mlite/spun.py @@ -10,9 +10,7 @@ from ...sage_helper import _within_sage if _within_sage: - from sage.arith.misc import GCD as gcd - from sage.modules.free_module_element import free_module_element as Vector - from sage.matrix.constructor import Matrix as Matrix + from ...sage_helper import vector as Vector, matrix as Matrix, gcd else: from snappy.snap.t3mlite.linalg import Vector, Matrix, gcd diff --git a/python/snap/utilities.py b/python/snap/utilities.py index 2728621df..a6bbdfc7e 100644 --- a/python/snap/utilities.py +++ b/python/snap/utilities.py @@ -12,10 +12,8 @@ from ..pari import pari, PariError from .fundamental_polyhedron import Infinity if _within_sage: - from sage.matrix.constructor import Matrix as sage_matrix - from sage.modules.free_module_element import free_module_element as sage_vector - from sage.rings.real_mpfr import RealField_class - from ..sage_helper import ComplexField_class + from ..sage_helper import matrix as sage_matrix, vector as sage_vector + from ..sage_helper import RealField_class, ComplexField_class def is_field(R): return isinstance(R, (SnapPyNumbers, RealField_class, From 1b40d508a112bed2e4a5b9eace478ba2e94cdb08 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 31 Dec 2024 20:35:36 -0800 Subject: [PATCH 39/45] python/sage_helper.py: Import xgcd --- python/sage_helper.py | 4 ++-- python/verify/complex_volume/closed.py | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/python/sage_helper.py b/python/sage_helper.py index 457981ec8..0436def83 100644 --- a/python/sage_helper.py +++ b/python/sage_helper.py @@ -24,7 +24,7 @@ def sage_method(function): try: # Monolithic Sage library - from sage.all import RealField, RealDoubleElement, gcd, prod, powerset + from sage.all import RealField, RealDoubleElement, gcd, xgcd, prod, powerset from sage.all import MatrixSpace, matrix, vector, ZZ from sage.all import Integer, Rational, QQ, RR, CC from sage.all import sqrt @@ -36,7 +36,7 @@ def sage_method(function): from sage.all import VectorSpace except ImportError: # Modularized Sage library - from sage.arith.misc import gcd + from sage.arith.misc import gcd, xgcd from sage.combinat.subset import powerset from sage.functions.hyperbolic import arccosh from sage.functions.other import (real as real_part, diff --git a/python/verify/complex_volume/closed.py b/python/verify/complex_volume/closed.py index 98d1ec2ad..958cd177b 100644 --- a/python/verify/complex_volume/closed.py +++ b/python/verify/complex_volume/closed.py @@ -7,8 +7,7 @@ if _within_sage: from sage.symbolic.constants import pi - from sage.arith.misc import XGCD as xgcd - from ...sage_helper import I + from ...sage_helper import I, xgcd from .. import hyperbolicity From 30bb154cf8a18d15db0cb628650688faa9ee2322 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 31 Dec 2024 20:42:10 -0800 Subject: [PATCH 40/45] More imports via sage_helper --- python/verify/complex_volume/extended_bloch.py | 4 +--- .../verify/maximal_cusp_area_matrix/cusp_translate_engine.py | 3 +-- python/verify/short_slopes.py | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/python/verify/complex_volume/extended_bloch.py b/python/verify/complex_volume/extended_bloch.py index 8d5eee2bf..b495723fd 100644 --- a/python/verify/complex_volume/extended_bloch.py +++ b/python/verify/complex_volume/extended_bloch.py @@ -2,11 +2,9 @@ if _within_sage: from sage.rings.complex_arb import ComplexBallField - from sage.rings.real_mpfr import RealField - from sage.rings.integer import Integer from sage.functions.log import exp from sage.symbolic.constants import pi - from ...sage_helper import I + from ...sage_helper import I, Integer, RealField @sage_method diff --git a/python/verify/maximal_cusp_area_matrix/cusp_translate_engine.py b/python/verify/maximal_cusp_area_matrix/cusp_translate_engine.py index 6a9503193..15a390c06 100644 --- a/python/verify/maximal_cusp_area_matrix/cusp_translate_engine.py +++ b/python/verify/maximal_cusp_area_matrix/cusp_translate_engine.py @@ -3,8 +3,7 @@ from ..upper_halfspace.finite_point import * if _within_sage: - from sage.modules.free_module_element import free_module_element as vector - from sage.matrix.constructor import Matrix as matrix + from ...sage_helper import vector, matrix __all__ = ['CuspTranslateEngine'] diff --git a/python/verify/short_slopes.py b/python/verify/short_slopes.py index eea753986..3ecfd31d9 100644 --- a/python/verify/short_slopes.py +++ b/python/verify/short_slopes.py @@ -5,7 +5,7 @@ import math if _within_sage: - from sage.arith.misc import GCD as gcd + from ..sage_helper import gcd else: # Python 3 has gcd in math from math import gcd From b6c24c64a61367733eec1b1204b7445610894607 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 31 Dec 2024 21:01:29 -0800 Subject: [PATCH 41/45] Even more imports via sage_helper --- python/snap/slice_obs_HKL.py | 7 +------ python/verify/interval_tree.py | 7 +++---- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/python/snap/slice_obs_HKL.py b/python/snap/slice_obs_HKL.py index a549d6e41..7ad18c5c5 100644 --- a/python/snap/slice_obs_HKL.py +++ b/python/snap/slice_obs_HKL.py @@ -45,16 +45,11 @@ from ..sage_helper import _within_sage, sage_method if _within_sage: - from sage.rings.integer_ring import Z as ZZ - from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing + from ..sage_helper import ZZ, PolynomialRing, vector, matrix, identity_matrix, MatrixSpace from sage.rings.polynomial.laurent_polynomial_ring import LaurentPolynomialRing from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF from sage.rings.number_field.number_field import CyclotomicField - from sage.modules.free_module_element import free_module_element as vector - from sage.matrix.constructor import Matrix as matrix - from sage.matrix.special import identity_matrix from sage.matrix.special import block_matrix - from sage.matrix.matrix_space import MatrixSpace from sage.homology.chain_complex import ChainComplex from sage.rings.fast_arith import prime_range diff --git a/python/verify/interval_tree.py b/python/verify/interval_tree.py index 4b636e07f..ba35c9147 100644 --- a/python/verify/interval_tree.py +++ b/python/verify/interval_tree.py @@ -300,7 +300,7 @@ def check_find_result(self, interval): self.brute_force_find(interval))) def check_consistency(self): - from sage.rings.infinity import Infinity + from ..sage_helper import Infinity if self._root.isRed: raise Exception("Red root") _IntervalTreeTester._recursively_check_consistency( @@ -308,7 +308,7 @@ def check_consistency(self): @staticmethod def _recursively_check_consistency(node, l, r): - from sage.rings.infinity import Infinity + from ..sage_helper import Infinity if not node: return -Infinity, 0 @@ -370,9 +370,8 @@ def print_tree_recursively(node, depth): @staticmethod def run_test(): - from sage.rings.real_mpfi import RIF + from ..sage_helper import RIF, Infinity from sage.functions.trig import sin - from sage.rings.infinity import Infinity intervals = [ RIF(sin(1.2 * i), sin(1.2 * i) + sin(1.43 * i) ** 2) From 2ded24e13736a6a79202e67425f47b43e027a1f0 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 31 Dec 2024 21:49:22 -0800 Subject: [PATCH 42/45] python/sage_helper.py: Import ComplexBallField, exp, sin, block_matrix, prime_range --- python/math_basics.py | 4 ++-- python/sage_helper.py | 7 ++++++- python/snap/character_varieties.py | 3 +-- python/snap/fundamental_polyhedron.py | 2 +- python/snap/peripheral/dual_cellulation.py | 4 +--- python/snap/slice_obs_HKL.py | 4 +--- python/verify/complex_volume/extended_bloch.py | 4 +--- 7 files changed, 13 insertions(+), 15 deletions(-) diff --git a/python/math_basics.py b/python/math_basics.py index fdc047548..bdcdf72f0 100644 --- a/python/math_basics.py +++ b/python/math_basics.py @@ -21,8 +21,8 @@ def is_Interval(x): return is_RealIntervalFieldElement(x) or is_ComplexIntervalFieldElement(x) if _within_sage: - from sage.misc.misc_c import prod - from sage.arith.misc import XGCD as xgcd + from .sage_helper import prod, xgcd + from sage.rings.real_mpfi import RealIntervalFieldElement from sage.rings.complex_interval import ComplexIntervalFieldElement diff --git a/python/sage_helper.py b/python/sage_helper.py index 0436def83..1d5a8e8ab 100644 --- a/python/sage_helper.py +++ b/python/sage_helper.py @@ -34,18 +34,21 @@ def sage_method(function): from sage.all import (cached_method, real_part, imag_part, round, ceil, floor, log, CDF, ComplexField, NumberField, PolynomialRing, identity_matrix) from sage.all import VectorSpace + from sage.all import ComplexBallField, exp, sin, block_matrix, prime_range except ImportError: # Modularized Sage library from sage.arith.misc import gcd, xgcd from sage.combinat.subset import powerset from sage.functions.hyperbolic import arccosh + from sage.functions.log import exp from sage.functions.other import (real as real_part, imag as imag_part, ceil, floor) + from sage.functions.trig import sin from sage.matrix.constructor import Matrix as matrix from sage.matrix.matrix_space import MatrixSpace - from sage.matrix.special import identity_matrix + from sage.matrix.special import block_matrix, identity_matrix from sage.misc.cachefunc import cached_method from sage.misc.functional import log, round, sqrt from sage.misc.misc_c import prod @@ -53,8 +56,10 @@ def sage_method(function): from sage.modules.free_module_element import free_module_element as vector from sage.rings.cc import CC from sage.rings.cif import CIF + from sage.rings.complex_arb import ComplexBallField from sage.rings.complex_double import CDF from sage.rings.complex_mpfr import ComplexField + from sage.rings.fast_arith import prime_range from sage.rings.imaginary_unit import I from sage.rings.infinity import Infinity from sage.rings.integer import Integer diff --git a/python/snap/character_varieties.py b/python/snap/character_varieties.py index 1b9ede657..e5b2cf47d 100644 --- a/python/snap/character_varieties.py +++ b/python/snap/character_varieties.py @@ -359,8 +359,7 @@ def character_variety_ideal(gens, rels=None): 2 """ presentation = character_variety(gens, rels) - from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing - from sage.rings.rational_field import Q as QQ + from ..sage_helper import PolynomialRing, QQ R = PolynomialRing(QQ, [repr(v) for v in presentation.gens]) return R.ideal([R(p) for p in presentation.rels]) diff --git a/python/snap/fundamental_polyhedron.py b/python/snap/fundamental_polyhedron.py index 19db3391e..3a71f6d1c 100644 --- a/python/snap/fundamental_polyhedron.py +++ b/python/snap/fundamental_polyhedron.py @@ -11,7 +11,7 @@ from ..sage_helper import _within_sage if _within_sage: - from sage.matrix.constructor import Matrix as matrix + from ..sage_helper import matrix else: from .utilities import Matrix2x2 as matrix diff --git a/python/snap/peripheral/dual_cellulation.py b/python/snap/peripheral/dual_cellulation.py index 44f0be63d..74b2e2ffb 100644 --- a/python/snap/peripheral/dual_cellulation.py +++ b/python/snap/peripheral/dual_cellulation.py @@ -6,9 +6,7 @@ from .. import t3mlite as t3m if sage_helper._within_sage: - from sage.rings.integer_ring import Z as ZZ - from sage.matrix.constructor import Matrix as matrix - from sage.modules.free_module_element import free_module_element as vector + from ...sage_helper import ZZ, matrix, vector from sage.homology.chain_complex import ChainComplex from sage.graphs.graph import Graph diff --git a/python/snap/slice_obs_HKL.py b/python/snap/slice_obs_HKL.py index 7ad18c5c5..590f424f6 100644 --- a/python/snap/slice_obs_HKL.py +++ b/python/snap/slice_obs_HKL.py @@ -45,13 +45,11 @@ from ..sage_helper import _within_sage, sage_method if _within_sage: - from ..sage_helper import ZZ, PolynomialRing, vector, matrix, identity_matrix, MatrixSpace + from ..sage_helper import ZZ, PolynomialRing, vector, matrix, identity_matrix, MatrixSpace, block_matrix, prime_range from sage.rings.polynomial.laurent_polynomial_ring import LaurentPolynomialRing from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF from sage.rings.number_field.number_field import CyclotomicField - from sage.matrix.special import block_matrix from sage.homology.chain_complex import ChainComplex - from sage.rings.fast_arith import prime_range from .nsagetools import (MapToFreeAbelianization, compute_torsion, fox_derivative_with_involution, diff --git a/python/verify/complex_volume/extended_bloch.py b/python/verify/complex_volume/extended_bloch.py index b495723fd..379a2c643 100644 --- a/python/verify/complex_volume/extended_bloch.py +++ b/python/verify/complex_volume/extended_bloch.py @@ -1,10 +1,8 @@ from ...sage_helper import _within_sage, sage_method if _within_sage: - from sage.rings.complex_arb import ComplexBallField - from sage.functions.log import exp from sage.symbolic.constants import pi - from ...sage_helper import I, Integer, RealField + from ...sage_helper import I, Integer, RealField, ComplexBallField, exp @sage_method From 3bb486ecd837dc2cffc18ab148be735e07517966 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 1 Jan 2025 14:34:33 -0800 Subject: [PATCH 43/45] python/sage_helper.py: Move imports from nsagetools here --- python/sage_helper.py | 8 ++++++-- python/snap/nsagetools.py | 19 +++---------------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/python/sage_helper.py b/python/sage_helper.py index 1d5a8e8ab..f790378cf 100644 --- a/python/sage_helper.py +++ b/python/sage_helper.py @@ -34,9 +34,11 @@ def sage_method(function): from sage.all import (cached_method, real_part, imag_part, round, ceil, floor, log, CDF, ComplexField, NumberField, PolynomialRing, identity_matrix) from sage.all import VectorSpace - from sage.all import ComplexBallField, exp, sin, block_matrix, prime_range + from sage.all import ComplexBallField, exp, sin, block_matrix, prime_range, det + from sage.all import LaurentPolynomialRing, AbelianGroup, GroupAlgebra except ImportError: # Modularized Sage library + from sage.algebras.group_algebra import GroupAlgebra from sage.arith.misc import gcd, xgcd from sage.combinat.subset import powerset from sage.functions.hyperbolic import arccosh @@ -46,11 +48,12 @@ def sage_method(function): ceil, floor) from sage.functions.trig import sin + from sage.groups.abelian_gps.abelian_group import AbelianGroup from sage.matrix.constructor import Matrix as matrix from sage.matrix.matrix_space import MatrixSpace from sage.matrix.special import block_matrix, identity_matrix from sage.misc.cachefunc import cached_method - from sage.misc.functional import log, round, sqrt + from sage.misc.functional import det, log, round, sqrt from sage.misc.misc_c import prod from sage.modules.free_module import VectorSpace from sage.modules.free_module_element import free_module_element as vector @@ -64,6 +67,7 @@ def sage_method(function): from sage.rings.infinity import Infinity from sage.rings.integer import Integer from sage.rings.integer_ring import ZZ + from sage.rings.polynomial.laurent_polynomial_ring import LaurentPolynomialRing from sage.rings.number_field.number_field import NumberField from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.rings.rational import Rational diff --git a/python/snap/nsagetools.py b/python/snap/nsagetools.py index 1c1edf354..282ec449e 100644 --- a/python/snap/nsagetools.py +++ b/python/snap/nsagetools.py @@ -5,22 +5,9 @@ from ..sage_helper import _within_sage, sage_method if _within_sage: - import sage - from sage.rings.integer_ring import Z as ZZ - from sage.modules.free_module_element import free_module_element as vector - from sage.matrix.constructor import Matrix as matrix - from sage.matrix.special import block_matrix - from sage.matrix.special import identity_matrix - from sage.arith.misc import GCD as gcd - from sage.misc.misc_c import prod - from sage.misc.functional import det - from sage.matrix.matrix_space import MatrixSpace - from sage.groups.abelian_gps.abelian_group import AbelianGroup - from sage.algebras.group_algebra import GroupAlgebra - from sage.structure.sage_object import SageObject - from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing - from sage.rings.polynomial.laurent_polynomial_ring import LaurentPolynomialRing - + from ..sage_helper import ZZ, vector, matrix, block_matrix, identity_matrix, gcd, prod, det + from ..sage_helper import MatrixSpace, PolynomialRing, LaurentPolynomialRing + from ..sage_helper import SageObject, AbelianGroup, GroupAlgebra from .polished_reps import polished_holonomy, MatrixRepresentation Id2 = MatrixSpace(ZZ, 2)(1) else: From 6739b660c96e31cf58f9596112236b684efb7c71 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 1 Jan 2025 14:51:39 -0800 Subject: [PATCH 44/45] python/sage_helper.py: Move remaining imports from slice_obs_HKL here --- python/sage_helper.py | 14 +++++++++----- python/snap/slice_obs_HKL.py | 5 +---- python/verify/interval_tree.py | 3 +-- python/verify/krawczyk_shapes_engine.py | 4 +--- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/python/sage_helper.py b/python/sage_helper.py index f790378cf..4881c67bb 100644 --- a/python/sage_helper.py +++ b/python/sage_helper.py @@ -32,8 +32,9 @@ def sage_method(function): from sage.all import arccosh from sage.all import RIF, CIF from sage.all import (cached_method, real_part, imag_part, round, ceil, floor, log, - CDF, ComplexField, NumberField, PolynomialRing, identity_matrix) - from sage.all import VectorSpace + CDF, ComplexDoubleField, ComplexField, CyclotomicField, NumberField, PolynomialRing, identity_matrix) + from sage.all import FiniteField as GF + from sage.all import VectorSpace, ChainComplex from sage.all import ComplexBallField, exp, sin, block_matrix, prime_range, det from sage.all import LaurentPolynomialRing, AbelianGroup, GroupAlgebra except ImportError: @@ -49,6 +50,7 @@ def sage_method(function): floor) from sage.functions.trig import sin from sage.groups.abelian_gps.abelian_group import AbelianGroup + from sage.homology.chain_complex import ChainComplex from sage.matrix.constructor import Matrix as matrix from sage.matrix.matrix_space import MatrixSpace from sage.matrix.special import block_matrix, identity_matrix @@ -60,15 +62,16 @@ def sage_method(function): from sage.rings.cc import CC from sage.rings.cif import CIF from sage.rings.complex_arb import ComplexBallField - from sage.rings.complex_double import CDF + from sage.rings.complex_double import CDF, ComplexDoubleField from sage.rings.complex_mpfr import ComplexField from sage.rings.fast_arith import prime_range + from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF from sage.rings.imaginary_unit import I from sage.rings.infinity import Infinity from sage.rings.integer import Integer from sage.rings.integer_ring import ZZ from sage.rings.polynomial.laurent_polynomial_ring import LaurentPolynomialRing - from sage.rings.number_field.number_field import NumberField + from sage.rings.number_field.number_field import CyclotomicField, NumberField from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.rings.rational import Rational from sage.rings.rational_field import QQ @@ -76,7 +79,8 @@ def sage_method(function): from sage.rings.real_mpfi import RIF from sage.rings.real_mpfr import RealField, RealNumber, RR - from sage.rings.real_mpfi import is_RealIntervalFieldElement + from sage.rings.complex_interval_field import ComplexIntervalField + from sage.rings.real_mpfi import is_RealIntervalFieldElement, RealIntervalField from sage.rings.real_mpfr import RealNumber, RealField_class from sage.structure.sage_object import SageObject diff --git a/python/snap/slice_obs_HKL.py b/python/snap/slice_obs_HKL.py index 590f424f6..9ebdb7303 100644 --- a/python/snap/slice_obs_HKL.py +++ b/python/snap/slice_obs_HKL.py @@ -46,10 +46,7 @@ from ..sage_helper import _within_sage, sage_method if _within_sage: from ..sage_helper import ZZ, PolynomialRing, vector, matrix, identity_matrix, MatrixSpace, block_matrix, prime_range - from sage.rings.polynomial.laurent_polynomial_ring import LaurentPolynomialRing - from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF - from sage.rings.number_field.number_field import CyclotomicField - from sage.homology.chain_complex import ChainComplex + from ..sage_helper import LaurentPolynomialRing, GF, CyclotomicField, ChainComplex from .nsagetools import (MapToFreeAbelianization, compute_torsion, fox_derivative_with_involution, diff --git a/python/verify/interval_tree.py b/python/verify/interval_tree.py index ba35c9147..08ae51dd9 100644 --- a/python/verify/interval_tree.py +++ b/python/verify/interval_tree.py @@ -370,8 +370,7 @@ def print_tree_recursively(node, depth): @staticmethod def run_test(): - from ..sage_helper import RIF, Infinity - from sage.functions.trig import sin + from ..sage_helper import RIF, Infinity, sin intervals = [ RIF(sin(1.2 * i), sin(1.2 * i) + sin(1.43 * i) ** 2) diff --git a/python/verify/krawczyk_shapes_engine.py b/python/verify/krawczyk_shapes_engine.py index 84f256554..1313a3db6 100644 --- a/python/verify/krawczyk_shapes_engine.py +++ b/python/verify/krawczyk_shapes_engine.py @@ -4,9 +4,7 @@ from ..sage_helper import _within_sage, sage_method if _within_sage: - from sage.rings.complex_interval_field import ComplexIntervalField - from sage.rings.real_mpfi import RealIntervalField - from sage.rings.complex_double import ComplexDoubleField + from ..sage_helper import ComplexDoubleField, ComplexIntervalField, RealIntervalField from snappy.pari import prec_dec_to_bits __all__ = ['KrawczykShapesEngine'] From 033bff7d59972eeb2e10fd2d83c589bc514addcf Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 1 Jan 2025 14:58:16 -0800 Subject: [PATCH 45/45] python/snap/peripheral: Import ChainComplex via sage_helper --- python/snap/peripheral/dual_cellulation.py | 3 +-- python/snap/peripheral/surface.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/python/snap/peripheral/dual_cellulation.py b/python/snap/peripheral/dual_cellulation.py index 74b2e2ffb..c43e7a069 100644 --- a/python/snap/peripheral/dual_cellulation.py +++ b/python/snap/peripheral/dual_cellulation.py @@ -6,8 +6,7 @@ from .. import t3mlite as t3m if sage_helper._within_sage: - from ...sage_helper import ZZ, matrix, vector - from sage.homology.chain_complex import ChainComplex + from ...sage_helper import ZZ, matrix, vector, ChainComplex from sage.graphs.graph import Graph diff --git a/python/snap/peripheral/surface.py b/python/snap/peripheral/surface.py index df9bcebf6..7e00a4ca2 100644 --- a/python/snap/peripheral/surface.py +++ b/python/snap/peripheral/surface.py @@ -2,8 +2,7 @@ from ... import sage_helper if sage_helper._within_sage: - from ...sage_helper import ZZ, matrix, vector, cached_method - from sage.homology.chain_complex import ChainComplex + from ...sage_helper import ZZ, matrix, vector, cached_method, ChainComplex from sage.plot.all import line, arrow, text else: def cached_method(func):