From 2462dfbff27fbbb1855de78babdb57c835d8e701 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 29 Oct 2024 16:09:04 -0700 Subject: [PATCH 01/28] 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 012ca7ae5..9d2661c17 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 is_RealIntervalFieldElement from sage.rings.complex_interval import is_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 e6078820a..df617691f 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 46f492659..dc05d3e8f 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 ada49ea5097b7f9d1cef80b0ddb9d72aeec52255 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 16:29:24 -0700 Subject: [PATCH 02/28] 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 df617691f..e35500e30 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 368b2125edfa1b27cd3be671780ec51bf4a0cd60 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 17:40:39 -0700 Subject: [PATCH 03/28] 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 2431bbabd3821cce00ea7ddf4ed0c7aad95ff5c1 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 19:12:14 -0700 Subject: [PATCH 04/28] 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 e35500e30..4cf286d37 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 d1c72287cba03c0a7f38927bff5b8b3c8994b8db Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 19:29:16 -0700 Subject: [PATCH 05/28] 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 bc10c9a420c0bb03195dcf028a62cdd6feb81df5 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 19:32:31 -0700 Subject: [PATCH 06/28] 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 ddd860b526eb9c64bd260db1e79aee7c98f59627 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 19:42:01 -0700 Subject: [PATCH 07/28] 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 10febc57e1f9a8002869ee7a72f74a5286e57e97 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 19:51:42 -0700 Subject: [PATCH 08/28] 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 ad9167c9c1cf7c7b2372c4397d436fa52e256fe6 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 19:54:10 -0700 Subject: [PATCH 09/28] 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 fb2c9f59e17e7901a99abadf8fc8b397efdd199d Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 19:58:32 -0700 Subject: [PATCH 10/28] 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 cb146b3bceeb42ec61c7691bddd4ab756054a47a Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 20:05:21 -0700 Subject: [PATCH 11/28] 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 58b2f0df815bec58e05b0943a0fc850e368cc9fd Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 20:07:35 -0700 Subject: [PATCH 12/28] 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 f34f505ab3f21ddcbbfd090de6e0e6002cc4884c Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 20:09:56 -0700 Subject: [PATCH 13/28] 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 373e7b4d789319814295f8060d4c7ba87d4b3ae0 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 20:12:04 -0700 Subject: [PATCH 14/28] 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 d8f056e83f6a03e23c191612a36c296145d2f661 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 20:13:02 -0700 Subject: [PATCH 15/28] 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 f90932179dab1f0d06d16b78fe515ed9f88aea60 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 20:14:49 -0700 Subject: [PATCH 16/28] 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 191e29dc02f1e9314ecda79bb1f2bd024711f460 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 20:17:36 -0700 Subject: [PATCH 17/28] 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 dd399f3bea766bf6e8765eebe2b386b9650bcb86 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 20:23:36 -0700 Subject: [PATCH 18/28] 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 4168cb80747c6ec1b02c056f2f3af43913815945 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 20:26:06 -0700 Subject: [PATCH 19/28] 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 976c0e25d434a4fe0f4c301cd5db1feca3402bce Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 20:27:19 -0700 Subject: [PATCH 20/28] 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 ae3d43e005936b472ff4c6ad292a23eb53f3f0d5 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 20:30:59 -0700 Subject: [PATCH 21/28] 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 1e0e1c21d9b56d1912f05266ddc4e0e7529c6ad4 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 20:34:25 -0700 Subject: [PATCH 22/28] 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 3b0c383cf..ae6b53f2e 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 d2790399850be8fb78ac77d64f5ac117cb010ad6 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 20:50:15 -0700 Subject: [PATCH 23/28] 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 06ff706430da42109be65438f89b775218f6602c Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 21:20:53 -0700 Subject: [PATCH 24/28] 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 492f0a7e5e348e27bc98c65650d725dad618ebe6 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 21:58:51 -0700 Subject: [PATCH 25/28] 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 37bfc6828..ffb58d62c 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 @@ -592,4 +593,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 01bcf5869d1a5c6b3af34a4f1f40ec1e4131228b Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 22:31:40 -0700 Subject: [PATCH 26/28] 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 f70a5a92ef4f81242cd4f17bbfb59db11c2d20cd Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 22:50:27 -0700 Subject: [PATCH 27/28] 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 1f24d8479d15ea70ded42a6cc4d32f20c4c10dbe Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 31 Oct 2024 23:10:25 -0700 Subject: [PATCH 28/28] 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 db3e36804..6bdcc38a2 100644 --- a/cython/core/basic.pyx +++ b/cython/core/basic.pyx @@ -18,7 +18,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