Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sage.{arith,crypto,databases,dynamics,lfunctions,quadratic_forms}: Replace imports from sage.*.all for namespace packages #35106

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
53ede8c
sage.rings.finite_rings: Deprecate is_FiniteField, is_PrimeFiniteField
mkoeppe Dec 5, 2022
8d4d8e5
sage.rings.finite_rings: Make it a namespace package
mkoeppe Dec 5, 2022
6ce26bc
src/sage/rings/finite_rings/finite_field_constructor.py: Restore re-e…
mkoeppe Dec 5, 2022
98a5484
src/sage/rings/finite_rings/hom_finite_field.pyx: Import ABC as Finit…
mkoeppe Dec 5, 2022
2e6b5ef
sage.rings.finite_rings: Deprecate is_FiniteFieldElent
mkoeppe Dec 5, 2022
3be7c97
Fixups
mkoeppe Dec 6, 2022
97a363e
Fixups
mkoeppe Dec 6, 2022
0c01403
Fixup: Elements of finite fields are not instances of FieldElement
mkoeppe Dec 6, 2022
9f4d1c4
src/sage/crypto/mq/rijndael_gf.py: Fix imports
mkoeppe Dec 6, 2022
9ebadcf
Merge tag '9.8.beta6' into t/32664/add_sage_rings_abc_finitefield__de…
mkoeppe Jan 7, 2023
30bc1c6
Merge remote-tracking branch 'upstream/develop' into t/32664/add_sage…
mkoeppe Feb 13, 2023
7265733
Merge branch 'develop' into t/32664/add_sage_rings_abc_finitefield__d…
mkoeppe Feb 19, 2023
40a7d57
src/sage/rings/finite_rings: Update doctest output (trac->github)
mkoeppe Feb 21, 2023
12b4440
Merge tag '10.0.beta3' into t/32664/add_sage_rings_abc_finitefield__d…
mkoeppe Mar 3, 2023
2459849
Merge tag '10.0.beta4' into t/32664/add_sage_rings_abc_finitefield__d…
mkoeppe Mar 13, 2023
d591aec
sage -fiximports src/sage/{arith,crypto,databases,dynamics,lfunctions…
alexchandler100 Jan 29, 2023
9435a7e
git grep -l -E ' (Q as QQ|Z as ZZ)' | xargs sed -i.bak 's/ Q as QQ/ Q…
mkoeppe Jan 30, 2023
3d51e7b
src/sage/databases/findstat.py: Hide a legitimate .all import from re…
mkoeppe Jan 30, 2023
350979e
sage.{crypto,databases,dynamics,lfunctions,quadratic_forms}: Consolid…
mkoeppe Jan 30, 2023
f210dce
src/sage/quadratic_forms/ternary_qf.py: Fix import syntax
mkoeppe Feb 13, 2023
feb6525
src/sage/crypto/public_key/blum_goldwasser.py: Fix up relative imports
mkoeppe Feb 13, 2023
6e96393
Replace relative imports by absolute imports because pytest
mkoeppe Feb 14, 2023
4571804
Fix up syntax
mkoeppe Feb 14, 2023
9721de1
git grep -l 'GCD as gcd' src/sage/{arith,crypto,databases,dynamics,lf…
mkoeppe Feb 14, 2023
f9f6542
git grep -l 'XGCD as xgcd' src/sage/{arith,crypto,databases,dynamics,…
mkoeppe Feb 14, 2023
e62066f
src/sage/rings/padics/padic_template_element.pxi: Restore import lost…
mkoeppe Mar 13, 2023
a9d9420
Merge branch 't/32664/add_sage_rings_abc_finitefield__deprecate_is_fi…
mkoeppe Mar 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/.relint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@
Hint: namespace package. Type import_statements("SOME_IDENTIFIER") to find a more specific import,
Hint: or use 'sage --fiximports' to fix automatically in the source file.
# Keep in sync with SAGE_ROOT/src/sage/misc/replace_dot_all.py
pattern: 'from\s+sage(|[.](arith|categories|combinat|ext|graphs(|[.]decompositions)|interfaces|libs|matrix|misc|numerical(|[.]backends)|rings|sets))[.]all\s+import'
pattern: 'from\s+sage(|[.](arith|categories|combinat|ext|graphs(|[.]decompositions)|interfaces|libs|matrix|misc|numerical(|[.]backends)|rings(|[.]finite_rings)|sets))[.]all\s+import'
filePattern: '.*[.](py|pyx|pxi)$'
error: false # Make this a warning instead of an error for now
2 changes: 1 addition & 1 deletion src/sage/arith/multi_modular.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ from cysignals.memory cimport check_allocarray, check_reallocarray, sig_free

from sage.libs.gmp.mpz cimport *
from sage.rings.integer cimport Integer, smallInteger
from sage.arith.all import random_prime
from sage.arith.misc import random_prime
from types import GeneratorType
from sage.ext.stdsage cimport PY_NEW
from cpython.object cimport PyObject_RichCompare
Expand Down
4 changes: 3 additions & 1 deletion src/sage/arith/numerical_approx.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ Generic numerical approximation function
from sage.structure.parent cimport Parent
from sage.structure.element cimport parent
cdef Parent CDF
from sage.rings.all import RealField, ComplexField, CDF
from sage.rings.real_mpfr import RealField
from sage.rings.complex_mpfr import ComplexField
from sage.rings.complex_double import CDF


def numerical_approx_generic(x, prec):
Expand Down
13 changes: 8 additions & 5 deletions src/sage/crypto/boolean_function.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ from sage.rings.integer_ring import ZZ
from sage.rings.integer cimport Integer
from sage.rings.finite_rings.finite_field_constructor import GF
from sage.rings.polynomial.pbori.pbori import BooleanPolynomial
from sage.rings.finite_rings.finite_field_constructor import is_FiniteField
from sage.rings.finite_rings.finite_field_givaro import FiniteField_givaro
from sage.rings.finite_rings.finite_field_base import FiniteField
from sage.rings.polynomial.polynomial_element import Polynomial

from sage.misc.superseded import deprecated_function_alias
Expand Down Expand Up @@ -329,11 +328,15 @@ cdef class BooleanFunction(SageObject):

elif isinstance(x, Polynomial):
K = x.base_ring()
if is_FiniteField(K) and K.characteristic() == 2:
if isinstance(K, FiniteField) and K.characteristic() == 2:
self._nvariables = K.degree()
bitset_init(self._truth_table, <mp_bitcnt_t> (1<<self._nvariables))
bitset_zero(self._truth_table)
if isinstance(K,FiniteField_givaro): #the ordering is not the same in this case
try:
from sage.rings.finite_rings.finite_field_givaro import FiniteField_givaro
except ImportError:
FiniteField_givaro = ()
if isinstance(K, FiniteField_givaro): # the ordering is not the same in this case
for u in K:
bitset_set_to(self._truth_table, ZZ(u._vector_().list(),2) , (x(u)).trace())
else:
Expand Down Expand Up @@ -1008,7 +1011,7 @@ cdef class BooleanFunction(SageObject):
from sage.misc.misc_c import prod

from sage.matrix.constructor import Matrix
from sage.arith.all import binomial
from sage.arith.misc import binomial
M = Matrix(GF(2), sum(binomial(self._nvariables,i) for i in range(d+1)), len(s))

cdef long i
Expand Down
2 changes: 1 addition & 1 deletion src/sage/crypto/classical.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
from sage.rings.integer import Integer
from sage.rings.integer_ring import ZZ
from sage.rings.finite_rings.integer_mod_ring import IntegerModRing
from sage.arith.all import xgcd, inverse_mod
from sage.arith.misc import inverse_mod, xgcd
from random import randint
from sage.matrix.matrix_space import MatrixSpace

Expand Down
2 changes: 1 addition & 1 deletion src/sage/crypto/lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def gen_lattice(type='modular', n=4, m=8, q=11, seed=None,
A = A.stack(R.random_element().matrix())

elif type == 'cyclotomic':
from sage.arith.all import euler_phi
from sage.arith.misc import euler_phi
from sage.misc.functional import cyclotomic_polynomial

# we assume that n+1 <= min( euler_phi^{-1}(n) ) <= 2*n
Expand Down
7 changes: 4 additions & 3 deletions src/sage/crypto/lfsr.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@
import copy

from sage.structure.all import Sequence
from sage.rings.all import Integer, PolynomialRing
from sage.rings.finite_rings.finite_field_constructor import is_FiniteField
from sage.rings.finite_rings.finite_field_base import FiniteField
from sage.rings.integer import Integer
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing


def lfsr_sequence(key, fill, n):
Expand Down Expand Up @@ -179,7 +180,7 @@ def lfsr_sequence(key, fill, n):
raise TypeError("key must be a list")
key = Sequence(key)
F = key.universe()
if not is_FiniteField(F):
if not isinstance(F, FiniteField):
raise TypeError("universe of sequence must be a finite field")

s = fill
Expand Down
14 changes: 8 additions & 6 deletions src/sage/crypto/lwe.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,25 @@
- [CGW2013]_
"""

from sage.arith.misc import euler_phi, next_prime
from sage.functions.log import log
from sage.functions.other import floor, ceil
from sage.misc.functional import sqrt
from sage.misc.functional import cyclotomic_polynomial, round
from sage.misc.randstate import set_random_seed
from sage.misc.functional import sqrt
from sage.misc.prandom import randint
from sage.misc.randstate import set_random_seed
from sage.modules.free_module import FreeModule
from sage.modules.free_module_element import random_vector, vector
from sage.numerical.optimize import find_root
from sage.rings.all import ZZ, IntegerModRing, RR
from sage.arith.all import next_prime, euler_phi
from sage.rings.finite_rings.integer_mod_ring import IntegerModRing
from sage.rings.integer_ring import ZZ
from sage.rings.real_mpfr import RR
from sage.stats.distributions.discrete_gaussian_integer import DiscreteGaussianDistributionIntegerSampler
from sage.stats.distributions.discrete_gaussian_polynomial import DiscreteGaussianDistributionPolynomialSampler
from sage.structure.element import parent
from sage.structure.sage_object import SageObject
from sage.symbolic.constants import pi
from sage.symbolic.ring import SR
from sage.stats.distributions.discrete_gaussian_integer import DiscreteGaussianDistributionIntegerSampler
from sage.stats.distributions.discrete_gaussian_polynomial import DiscreteGaussianDistributionPolynomialSampler


class UniformSampler(SageObject):
Expand Down
9 changes: 4 additions & 5 deletions src/sage/crypto/mq/rijndael_gf.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,8 @@

from sage.matrix.constructor import matrix
from sage.matrix.constructor import column_matrix
from sage.structure.element import Matrix
from sage.structure.element import Element, Matrix
from sage.rings.finite_rings.finite_field_base import FiniteField as FiniteField_base
from sage.rings.finite_rings.finite_field_constructor import FiniteField
from sage.structure.sage_object import SageObject
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
Expand Down Expand Up @@ -757,10 +758,9 @@ def _GF_to_hex(self, GF):
sage: rgf._GF_to_hex(output)
'e142cd5fcd9d6d94a3340793034391b5'
"""
from sage.rings.finite_rings.element_base import is_FiniteFieldElement
if not isinstance(GF, Matrix) and \
not isinstance(GF, list) and \
not is_FiniteFieldElement(GF):
not (isinstance(GF, Element) and isinstance(GF.parent(), FiniteField_base)):
msg = ("keyword 'GF' must be a matrix over {0}, a list of "
"elements from {0}, or a single element from {0}")
raise TypeError(msg.format(self._F))
Expand Down Expand Up @@ -883,10 +883,9 @@ def _GF_to_bin(self, GF):
sage: rgf._GF_to_bin(output)
'11011000000111111111100000011011110110000001111111111000000110111101100000011111111110000001101111011000000111111111100000011011'
"""
from sage.rings.finite_rings.element_base import is_FiniteFieldElement
if not isinstance(GF, Matrix) and \
not isinstance(GF, list) and \
not is_FiniteFieldElement(GF):
not (isinstance(GF, Element) and isinstance(GF.parent(), FiniteField_base)):
msg = ("keyword 'GF' must be a matrix over {0}, a list of "
"elements from {0}, or a single element from {0}")
raise TypeError(msg.format(self))
Expand Down
7 changes: 3 additions & 4 deletions src/sage/crypto/public_key/blum_goldwasser.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,16 @@

from operator import xor

from sage.arith.misc import gcd, power_mod, xgcd
from sage.crypto.cryptosystem import PublicKeyCryptosystem
from sage.crypto.util import is_blum_prime
from sage.crypto.util import least_significant_bits
from sage.crypto.util import random_blum_prime
from sage.crypto.util import is_blum_prime, least_significant_bits, random_blum_prime
from sage.functions.log import log
from sage.functions.other import Function_floor
from sage.monoids.string_monoid import BinaryStrings
from sage.arith.all import gcd, power_mod, xgcd
from sage.rings.finite_rings.integer_mod import Mod as mod
from sage.rings.finite_rings.integer_mod_ring import IntegerModFactory


floor = Function_floor()
IntegerModRing = IntegerModFactory("IntegerModRing")

Expand Down
4 changes: 2 additions & 2 deletions src/sage/crypto/sbox.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ from sage.misc.functional import is_even
from sage.misc.misc_c import prod as mul
from sage.misc.superseded import deprecated_function_alias
from sage.modules.free_module_element import vector
from sage.rings.finite_rings.element_base import is_FiniteFieldElement
from sage.rings.finite_rings.finite_field_base import FiniteField
from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF
from sage.rings.ideal import FieldIdeal, Ideal
from sage.rings.integer_ring import ZZ
Expand Down Expand Up @@ -195,7 +195,7 @@ cdef class SBox(SageObject):

_S_list = []
for e in S:
if is_FiniteFieldElement(e):
if isinstance(e, Element) and isinstance(e.parent(), FiniteField):
e = e.polynomial().change_ring(ZZ).subs(e.parent().characteristic())
_S_list.append(e)
S = _S_list
Expand Down
7 changes: 3 additions & 4 deletions src/sage/crypto/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
# http://www.gnu.org/licenses/
#*****************************************************************************

from .cryptosystem import SymmetricKeyCryptosystem
from .stream_cipher import LFSRCipher, ShrinkingGeneratorCipher

from sage.arith.misc import gcd, power_mod
from sage.crypto.cryptosystem import SymmetricKeyCryptosystem
from sage.crypto.stream_cipher import LFSRCipher, ShrinkingGeneratorCipher
from sage.crypto.util import random_blum_prime
from sage.monoids.string_monoid import BinaryStrings
from sage.arith.all import gcd, power_mod
from sage.rings.finite_rings.finite_field_constructor import FiniteField
from sage.rings.finite_rings.integer_mod_ring import IntegerModFactory
from sage.rings.polynomial.polynomial_element import Polynomial
Expand Down
8 changes: 5 additions & 3 deletions src/sage/crypto/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
# http://www.gnu.org/licenses/
#*****************************************************************************

from sage.arith.functions import lcm
from sage.arith.misc import is_prime, primes, random_prime
from sage.misc.lazy_import import lazy_import
from sage.monoids.string_monoid import BinaryStrings
from sage.arith.all import is_prime, lcm, primes, random_prime
from sage.rings.integer import Integer
from sage.rings.finite_rings.integer_mod import Mod as mod
from sage.rings.integer import Integer

from sage.misc.lazy_import import lazy_import
lazy_import('sage.arith.misc', ('carmichael_lambda'), deprecation=34719)


def ascii_integer(B):
r"""
Return the ASCII integer corresponding to the binary string ``B``.
Expand Down
3 changes: 2 additions & 1 deletion src/sage/databases/findstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1499,7 +1499,8 @@ def __call__(self, elt):
from sage.repl.preparse import preparse
try:
l = {}
code = "from sage.all import *\n" + preparse(self.sage_code())
environment = 'sage.all'
code = f"from {environment} import *\n" + preparse(self.sage_code())
dimpase marked this conversation as resolved.
Show resolved Hide resolved
exec(code, l)
except SyntaxError:
raise ValueError("could not execute verified code for %s" % self)
Expand Down
4 changes: 3 additions & 1 deletion src/sage/databases/jones.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@

import os

from sage.rings.all import NumberField, RationalField, PolynomialRing
from sage.rings.number_field.number_field import NumberField
from sage.rings.rational_field import RationalField
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.misc.misc import powerset
from sage.env import SAGE_SHARE

Expand Down
10 changes: 5 additions & 5 deletions src/sage/dynamics/arithmetic_dynamics/affine_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ class initialization directly.
from sage.misc.cachefunc import cached_method
from sage.misc.classcall_metaclass import typecall
from sage.rings.integer import Integer
from sage.rings.finite_rings.finite_field_constructor import is_PrimeFiniteField
from sage.rings.finite_rings.finite_field_constructor import is_FiniteField
from sage.rings.finite_rings.finite_field_base import FiniteField
from sage.rings.fraction_field import FractionField
from sage.rings.fraction_field import is_FractionField
from sage.rings.quotient_ring import is_QuotientRing
Expand Down Expand Up @@ -251,7 +250,7 @@ def __classcall_private__(cls, morphism_or_polys, domain=None):
raise ValueError('domain and codomain do not agree')
if R not in Fields():
return typecall(cls, polys, domain)
if is_FiniteField(R):
if isinstance(R, FiniteField):
return DynamicalSystem_affine_finite_field(polys, domain)
return DynamicalSystem_affine_field(polys, domain)
elif isinstance(morphism_or_polys,(list, tuple)):
Expand Down Expand Up @@ -299,7 +298,7 @@ def __classcall_private__(cls, morphism_or_polys, domain=None):

if R not in Fields():
return typecall(cls, polys, domain)
if is_FiniteField(R):
if isinstance(R, FiniteField):
return DynamicalSystem_affine_finite_field(polys, domain)
return DynamicalSystem_affine_field(polys, domain)

Expand All @@ -319,7 +318,8 @@ def __init__(self, polys_or_rat_fncts, domain):
"""
L = polys_or_rat_fncts
# Next attribute needed for _fast_eval and _fastpolys
self._is_prime_finite_field = is_PrimeFiniteField(L[0].base_ring())
R = L[0].base_ring()
self._is_prime_finite_field = isinstance(R, FiniteField) and R.is_prime_field()
DynamicalSystem.__init__(self, L, domain)

def __copy__(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,23 @@
from copy import copy, deepcopy
from itertools import permutations, combinations, product

from sage.arith.functions import lcm
from sage.arith.misc import CRT, divisors, gcd, is_square
from sage.combinat.permutation import Arrangements
from sage.combinat.subset import Subsets
from sage.misc.functional import sqrt
from sage.matrix.constructor import matrix
from sage.structure.element import is_Matrix
from sage.misc.functional import sqrt
from sage.misc.misc_c import prod
from sage.parallel.use_fork import p_iter_fork
from sage.rings.finite_rings.finite_field_constructor import GF
from sage.rings.finite_rings.integer_mod_ring import Integers
from sage.rings.integer_ring import ZZ
from sage.rings.number_field.number_field import NumberField
from sage.arith.all import gcd, lcm, CRT, is_square, divisors
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.rational_field import QQ
from sage.sets.primes import Primes
from sage.sets.set import Set
from sage.combinat.permutation import Arrangements
from sage.parallel.use_fork import p_iter_fork
from sage.structure.element import is_Matrix


def automorphism_group_QQ_fixedpoints(rational_function, return_functions=False, iso_type=False):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from sage.rings.rational_field import QQ
from sage.schemes.affine.affine_space import AffineSpace
from sage.symbolic.constants import e
from sage.arith.all import gcd
from sage.arith.misc import gcd
from copy import copy

def bCheck(c, v, p, b):
Expand Down
8 changes: 4 additions & 4 deletions src/sage/dynamics/arithmetic_dynamics/generic_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class initialization directly.
from sage.schemes.affine.affine_space import is_AffineSpace
from sage.schemes.affine.affine_subscheme import AlgebraicScheme_subscheme_affine
from sage.rings.algebraic_closure_finite_field import AlgebraicClosureFiniteField_generic
from sage.rings.finite_rings.finite_field_constructor import is_FiniteField
from sage.rings.finite_rings.finite_field_base import FiniteField
from sage.rings.qqbar import AlgebraicField_common
from sage.schemes.berkovich.berkovich_space import is_Berkovich_Cp
from sage.rings.rational_field import QQ
Expand Down Expand Up @@ -416,7 +416,7 @@ def field_of_definition_critical(self, return_embedding=False, simplify_all=Fals
CR = CR.ring()
x = CR.gen(0)
poly = (g*CR(f).derivative(x) - f*CR(g).derivative(x)).univariate_polynomial()
if is_FiniteField(ds.base_ring()):
if isinstance(ds.base_ring(), FiniteField):
return poly.splitting_field(names, map=return_embedding)
else:
K = poly.splitting_field(names, map=return_embedding, simplify_all=simplify_all)
Expand Down Expand Up @@ -536,7 +536,7 @@ def field_of_definition_periodic(self, n, formal=False, return_embedding=False,
fn = ds.nth_iterate_map(n)
f,g = fn[0].numerator(), fn[0].denominator()
poly = (f - g*x).univariate_polynomial()
if is_FiniteField(ds.base_ring()):
if isinstance(ds.base_ring(), FiniteField):
return poly.splitting_field(names, map=return_embedding)
else:
K = poly.splitting_field(names, map=return_embedding, simplify_all=simplify_all)
Expand Down Expand Up @@ -630,7 +630,7 @@ def field_of_definition_preimage(self, point, n, return_embedding=False, simplif
#want the polynomial ring not the fraction field
CR = CR.ring()
poly = (f*point[1] - g*CR(point[0])).univariate_polynomial()
if is_FiniteField(ds.base_ring()):
if isinstance(ds.base_ring(), FiniteField):
return poly.splitting_field(names, map=return_embedding)
else:
K = poly.splitting_field(names, map=return_embedding, simplify_all=simplify_all)
Expand Down
Loading