Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoeppe committed Oct 21, 2021
2 parents a1d748d + 451ac27 commit 8823eac
Show file tree
Hide file tree
Showing 57 changed files with 247 additions and 216 deletions.
3 changes: 2 additions & 1 deletion src/sage/coding/code_bounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@
from sage.rings.all import QQ, RR, ZZ, RDF
from sage.arith.misc import is_prime_power
from sage.arith.all import binomial
from sage.functions.all import log, sqrt
from sage.functions.all import log
from sage.misc.functional import sqrt
from .delsarte_bounds import (delsarte_bound_hamming_space,
delsarte_bound_additive_hamming_space)

Expand Down
3 changes: 2 additions & 1 deletion src/sage/coding/guruswami_sudan/gs_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
from sage.coding.guruswami_sudan.utils import (johnson_radius,
gilt,
solve_degree2_to_integer_range)
from sage.functions.other import floor, sqrt
from sage.functions.other import floor
from sage.misc.functional import sqrt

def n_k_params(C, n_k):
r"""
Expand Down
3 changes: 2 additions & 1 deletion src/sage/coding/guruswami_sudan/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
#*****************************************************************************


from sage.functions.other import floor, sqrt
from sage.functions.other import floor
from sage.misc.functional import sqrt
from sage.rings.integer_ring import ZZ
from sage.rings.integer import Integer

Expand Down
2 changes: 1 addition & 1 deletion src/sage/coding/linear_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ def chinen_polynomial(self):
- Chinen, K. "An abundance of invariant polynomials satisfying the
Riemann hypothesis", April 2007 preprint.
"""
from sage.functions.all import sqrt
from sage.misc.functional import sqrt
C = self
n = C.length()
RT = PolynomialRing(QQ,2,"Ts")
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/binary_recurrence_sequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
from sage.rings.integer import Integer
from sage.arith.all import lcm, next_prime, is_prime, next_prime_power, legendre_symbol
from sage.functions.log import log
from sage.functions.other import sqrt
from sage.misc.functional import sqrt


class BinaryRecurrenceSequence(SageObject):
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/parallelogram_polyomino.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from sage.combinat.combinat import catalan_number
from sage.combinat.combinatorial_map import combinatorial_map
from sage.functions.trig import cos, sin
from sage.functions.other import sqrt
from sage.misc.functional import sqrt

from sage.plot.graphics import Graphics
from sage.plot.line import line
Expand Down
3 changes: 2 additions & 1 deletion src/sage/combinat/posets/poset_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -1924,7 +1924,8 @@ def _random_lattice(n, p):
meet for `e, m` for all `m \in M`. We do that by keeping
track of meet matrix and list of maximal elements.
"""
from sage.functions.other import floor, sqrt
from sage.functions.other import floor
from sage.misc.functional import sqrt
from sage.misc.prandom import random

n = n-1
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/root_system/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1574,7 +1574,7 @@ def barycentric_projection_matrix(n, angle=0):
"""
from sage.matrix.constructor import matrix
from sage.functions.other import sqrt
from sage.misc.functional import sqrt
n = ZZ(n)
if n == 0:
return matrix(QQ, 0, 1)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/symmetric_group_representations.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# ****************************************************************************

from sage.symbolic.ring import SR
from sage.functions.all import sqrt
from sage.misc.functional import sqrt
from sage.combinat.partition import Partition, Partitions
from sage.combinat.permutation import Permutation, Permutations, from_cycles
from sage.combinat.tableau import StandardTableaux, Tableau
Expand Down
3 changes: 2 additions & 1 deletion src/sage/combinat/words/word_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,8 @@ def FibonacciWord(self, alphabet=(0, 1), construction_method="recursive"):
return w

elif construction_method == "function":
from sage.functions.other import sqrt, floor
from sage.functions.other import floor
from sage.misc.functional import sqrt
phi = (1 + sqrt(5))/2 # the golden ratio
f = lambda n:a if floor((n+2)*phi) - floor((n+1)*phi) == 2 else b
return W(f)
Expand Down
3 changes: 2 additions & 1 deletion src/sage/crypto/lwe.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@
"""

from sage.functions.log import log
from sage.functions.other import sqrt, floor, ceil
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.prandom import randint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from copy import copy, deepcopy
from sage.combinat.subset import Subsets
from sage.functions.all import sqrt
from sage.misc.functional import sqrt
from itertools import permutations, combinations, product
from sage.matrix.constructor import matrix
from sage.structure.element import is_Matrix
Expand Down
2 changes: 1 addition & 1 deletion src/sage/dynamics/arithmetic_dynamics/projective_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class initialization directly.
from sage.categories.number_fields import NumberFields
from sage.categories.homset import End
from sage.dynamics.arithmetic_dynamics.generic_ds import DynamicalSystem
from sage.functions.all import sqrt
from sage.misc.functional import sqrt
from sage.functions.other import ceil
from sage.libs.pari.all import PariError
from sage.matrix.constructor import matrix, identity_matrix
Expand Down
2 changes: 1 addition & 1 deletion src/sage/dynamics/arithmetic_dynamics/wehlerK3.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from sage.calculus.functions import jacobian
from sage.categories.fields import Fields
from sage.categories.number_fields import NumberFields
from sage.functions.all import sqrt
from sage.misc.functional import sqrt
from sage.misc.cachefunc import cached_method
from sage.misc.mrange import xmrange
from sage.rings.all import CommutativeRing
Expand Down
2 changes: 1 addition & 1 deletion src/sage/functions/bessel.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
# https://www.gnu.org/licenses/
# ****************************************************************************

from sage.functions.other import sqrt
from sage.misc.functional import sqrt
from sage.functions.log import exp
from sage.functions.hyperbolic import sinh, cosh
from sage.functions.trig import sin, cos
Expand Down
3 changes: 2 additions & 1 deletion src/sage/functions/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
from sage.symbolic.function import BuiltinFunction
from sage.libs.mpmath import utils as mpmath_utils
from sage.symbolic.expression import Expression
from sage.functions.all import sqrt, exp
from sage.functions.all import exp
from sage.misc.functional import sqrt
from sage.symbolic.constants import pi
from sage.rings.rational import Rational
from sage.rings.infinity import unsigned_infinity
Expand Down
2 changes: 1 addition & 1 deletion src/sage/functions/orthogonal_polys.py
Original file line number Diff line number Diff line change
Expand Up @@ -1824,7 +1824,7 @@ def eval_recursive(self, n, m, x, **kwds):
sage: gen_legendre_Q(2,2,x).subs(x=2).expand()
9/2*I*pi - 9/2*log(3) + 14/3
"""
from sage.functions.all import sqrt
from sage.misc.functional import sqrt
if m == n + 1 or n == 0:
if m.mod(2).is_zero():
denom = (1 - x**2)**(m/2)
Expand Down
160 changes: 7 additions & 153 deletions src/sage/functions/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@
'gamma_inc_lower', 'psi', 'beta'), deprecation=24411)

from sage.symbolic.function import GinacFunction, BuiltinFunction
from sage.symbolic.expression import Expression, register_symbol, symbol_table, I
from sage.symbolic.expression import Expression, register_symbol, symbol_table
from sage.symbolic.ring import SR
from sage.rings.all import Integer, Rational, RealField, ZZ, ComplexField
from sage.rings.integer import Integer
from sage.rings.integer_ring import ZZ
from sage.rings.rational import Rational
from sage.rings.complex_mpfr import ComplexField
from sage.rings.real_mpfr import RealField
from sage.misc.latex import latex
from sage.structure.element import Element
import math
Expand All @@ -35,7 +39,7 @@

from sage.arith.all import binomial as arith_binomial

one_half = SR.one() / SR(2)
from sage.misc.functional import sqrt


class Function_abs(GinacFunction):
Expand Down Expand Up @@ -752,156 +756,6 @@ def _eval_(self, x):
frac = Function_frac()


def _do_sqrt(x, prec=None, extend=True, all=False):
r"""
Used internally to compute the square root of x.
INPUT:
- ``x`` - a number
- ``prec`` - None (default) or a positive integer
(bits of precision) If not None, then compute the square root
numerically to prec bits of precision.
- ``extend`` - bool (default: True); this is a place
holder, and is always ignored since in the symbolic ring everything
has a square root.
- ``extend`` - bool (default: True); whether to extend
the base ring to find roots. The extend parameter is ignored if
prec is a positive integer.
- ``all`` - bool (default: False); whether to return
a list of all the square roots of x.
EXAMPLES::
sage: from sage.functions.other import _do_sqrt
sage: _do_sqrt(3)
sqrt(3)
sage: _do_sqrt(3,prec=10)
1.7
sage: _do_sqrt(3,prec=100)
1.7320508075688772935274463415
sage: _do_sqrt(3,all=True)
[sqrt(3), -sqrt(3)]
Note that the extend parameter is ignored in the symbolic ring::
sage: _do_sqrt(3,extend=False)
sqrt(3)
"""
if prec:
if x >= 0:
return RealField(prec)(x).sqrt(all=all)
else:
return ComplexField(prec)(x).sqrt(all=all)
if x == -1:
z = I
else:
z = SR(x) ** one_half

if all:
if z:
return [z, -z]
else:
return [z]
return z

def sqrt(x, *args, **kwds):
r"""
INPUT:
- ``x`` - a number
- ``prec`` - integer (default: None): if None, returns
an exact square root; otherwise returns a numerical square root if
necessary, to the given bits of precision.
- ``extend`` - bool (default: True); this is a place
holder, and is always ignored or passed to the sqrt function for x,
since in the symbolic ring everything has a square root.
- ``all`` - bool (default: False); if True, return all
square roots of self, instead of just one.
EXAMPLES::
sage: sqrt(-1)
I
sage: sqrt(2)
sqrt(2)
sage: sqrt(2)^2
2
sage: sqrt(4)
2
sage: sqrt(4,all=True)
[2, -2]
sage: sqrt(x^2)
sqrt(x^2)
For a non-symbolic square root, there are a few options.
The best is to numerically approximate afterward::
sage: sqrt(2).n()
1.41421356237310
sage: sqrt(2).n(prec=100)
1.4142135623730950488016887242
Or one can input a numerical type.
sage: sqrt(2.)
1.41421356237310
sage: sqrt(2.000000000000000000000000)
1.41421356237309504880169
sage: sqrt(4.0)
2.00000000000000
To prevent automatic evaluation, one can use the ``hold`` parameter
after coercing to the symbolic ring::
sage: sqrt(SR(4),hold=True)
sqrt(4)
sage: sqrt(4,hold=True)
Traceback (most recent call last):
...
TypeError: ..._do_sqrt() got an unexpected keyword argument 'hold'
This illustrates that the bug reported in :trac:`6171` has been fixed::
sage: a = 1.1
sage: a.sqrt(prec=100) # this is supposed to fail
Traceback (most recent call last):
...
TypeError: ...sqrt() got an unexpected keyword argument 'prec'
sage: sqrt(a, prec=100)
1.0488088481701515469914535137
sage: sqrt(4.00, prec=250)
2.0000000000000000000000000000000000000000000000000000000000000000000000000
One can use numpy input as well::
sage: import numpy
sage: a = numpy.arange(2,5)
sage: sqrt(a)
array([1.41421356, 1.73205081, 2. ])
"""
if isinstance(x, float):
return math.sqrt(x)
elif type(x).__module__ == 'numpy':
from numpy import sqrt
return sqrt(x)
try:
return x.sqrt(*args, **kwds)
# The following includes TypeError to catch cases where sqrt
# is called with a "prec" keyword, for example, but the sqrt
# method for x doesn't accept such a keyword.
except (AttributeError, TypeError):
pass
return _do_sqrt(x, *args, **kwds)

# register sqrt in pynac symbol_table for conversion back from other systems
register_symbol(sqrt, dict(mathematica='Sqrt'))
symbol_table['functions']['sqrt'] = sqrt
Expand Down
3 changes: 2 additions & 1 deletion src/sage/functions/special.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@
from sage.symbolic.constants import pi
from sage.symbolic.function import BuiltinFunction
from sage.libs.mpmath import utils as mpmath_utils
from sage.functions.all import sqrt, sin, cot, exp
from sage.functions.all import sin, cot, exp
from sage.misc.functional import sqrt
from sage.symbolic.constants import I


Expand Down
3 changes: 2 additions & 1 deletion src/sage/geometry/hyperbolic_space/hyperbolic_coercion.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
from sage.modules.free_module_element import vector
from sage.rings.integer import Integer
from sage.rings.infinity import infinity
from sage.functions.other import real, imag, sqrt
from sage.functions.other import real, imag
from sage.misc.functional import sqrt
from sage.misc.lazy_import import lazy_import
lazy_import('sage.misc.call', 'attrcall')

Expand Down
3 changes: 2 additions & 1 deletion src/sage/geometry/hyperbolic_space/hyperbolic_geodesic.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@
from sage.symbolic.constants import pi
from sage.modules.free_module_element import vector
from sage.matrix.constructor import matrix
from sage.functions.other import real, imag, sqrt
from sage.functions.other import real, imag
from sage.misc.functional import sqrt
from sage.functions.trig import arccos
from sage.functions.log import exp
from sage.functions.hyperbolic import sinh, cosh, arcsinh
Expand Down
3 changes: 2 additions & 1 deletion src/sage/geometry/hyperbolic_space/hyperbolic_isometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
from sage.rings.infinity import infinity
from sage.misc.latex import latex
from sage.rings.real_double import RDF
from sage.functions.other import imag, sqrt
from sage.functions.other import imag
from sage.misc.functional import sqrt
from sage.functions.all import arccosh, sign

from sage.geometry.hyperbolic_space.hyperbolic_constants import EPSILON
Expand Down
3 changes: 2 additions & 1 deletion src/sage/geometry/hyperbolic_space/hyperbolic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
from sage.structure.parent import Parent
from sage.misc.bindable_class import BindableClass
from sage.misc.lazy_import import lazy_import
from sage.functions.other import imag, real, sqrt
from sage.functions.other import imag, real
from sage.misc.functional import sqrt
from sage.functions.all import arccosh
from sage.rings.all import CC
from sage.rings.real_double import RDF
Expand Down
Loading

0 comments on commit 8823eac

Please sign in to comment.