diff --git a/.gitignore b/.gitignore index 2cec8a0cf62..ca58c587af7 100644 --- a/.gitignore +++ b/.gitignore @@ -168,6 +168,9 @@ __pycache__/ build/temp.*/ build/bin/sage-build-env-config +# Vendored on sdist/install +/src/sage/libs/mpmath/_vendor/mpmath* + # Generated files in the top-level source trees /pkgs/*/build /pkgs/*/dist @@ -195,6 +198,7 @@ build/bin/sage-build-env-config /pkgs/sagemath-categories/setup.cfg /pkgs/sagemath-environment/setup.cfg /pkgs/sagemath-repl/setup.cfg +/pkgs/sagemath-mpmath/setup.cfg /pkgs/sagemath-objects/pyproject.toml /pkgs/sagemath-bliss/pyproject.toml /pkgs/sagemath-coxeter3/pyproject.toml @@ -205,6 +209,7 @@ build/bin/sage-build-env-config /pkgs/sagemath-categories/pyproject.toml /pkgs/sagemath-environment/pyproject.toml /pkgs/sagemath-repl/pyproject.toml +/pkgs/sagemath-mpmath/pyproject.toml /pkgs/sagemath-objects/requirements.txt /pkgs/sagemath-bliss/requirements.txt /pkgs/sagemath-coxeter3/requirements.txt @@ -215,8 +220,11 @@ build/bin/sage-build-env-config /pkgs/sagemath-categories/requirements.txt /pkgs/sagemath-environment/requirements.txt /pkgs/sagemath-repl/requirements.txt +/pkgs/sagemath-mpmath/requirements.txt /pkgs/sagemath-categories/MANIFEST.in +/pkgs/sagemath-mpmath/vendor.txt + # same for old locations - before Issue #31577 /build/pkgs/*/src/build /build/pkgs/*/src/dist diff --git a/build/make/Makefile.in b/build/make/Makefile.in index cc004d08c3c..01ba6168ef0 100644 --- a/build/make/Makefile.in +++ b/build/make/Makefile.in @@ -141,7 +141,8 @@ PYPI_WHEEL_PACKAGES = \ sagemath_tdlib \ sagemath_coxeter3 \ sagemath_sirocco \ - sagemath_meataxe + sagemath_meataxe \ + sagemath_mpmath # sage_docbuild is here, not in PYPI_WHEEL_PACKAGES, because it depends on sagelib WHEEL_PACKAGES = $(PYPI_WHEEL_PACKAGES) \ diff --git a/build/pkgs/click/SPKG.rst b/build/pkgs/click/SPKG.rst new file mode 100644 index 00000000000..ed291e3d831 --- /dev/null +++ b/build/pkgs/click/SPKG.rst @@ -0,0 +1,18 @@ +click: Composable command line interface toolkit +================================================ + +Description +----------- + +Composable command line interface toolkit + +License +------- + +BSD-3-Clause + +Upstream Contact +---------------- + +https://pypi.org/project/click/ + diff --git a/build/pkgs/click/checksums.ini b/build/pkgs/click/checksums.ini new file mode 100644 index 00000000000..f56ef4d8a92 --- /dev/null +++ b/build/pkgs/click/checksums.ini @@ -0,0 +1,5 @@ +tarball=click-VERSION-py3-none-any.whl +sha1=d066d29afdc61b0ba89ff9a58803fce84d47682b +md5=37a41134cc8a13400234746942d5d180 +cksum=437758716 +upstream_url=https://pypi.io/packages/py3/c/click/click-VERSION-py3-none-any.whl diff --git a/build/pkgs/click/dependencies b/build/pkgs/click/dependencies new file mode 100644 index 00000000000..47296a7bace --- /dev/null +++ b/build/pkgs/click/dependencies @@ -0,0 +1,4 @@ + | $(PYTHON_TOOLCHAIN) $(PYTHON) + +---------- +All lines of this file are ignored except the first. diff --git a/build/pkgs/click/install-requires.txt b/build/pkgs/click/install-requires.txt new file mode 100644 index 00000000000..dca9a909647 --- /dev/null +++ b/build/pkgs/click/install-requires.txt @@ -0,0 +1 @@ +click diff --git a/build/pkgs/click/package-version.txt b/build/pkgs/click/package-version.txt new file mode 100644 index 00000000000..5f349af8b7a --- /dev/null +++ b/build/pkgs/click/package-version.txt @@ -0,0 +1 @@ +8.1.7 diff --git a/build/pkgs/click/type b/build/pkgs/click/type new file mode 100644 index 00000000000..a6a7b9cd726 --- /dev/null +++ b/build/pkgs/click/type @@ -0,0 +1 @@ +standard diff --git a/build/pkgs/markdown_it_py/SPKG.rst b/build/pkgs/markdown_it_py/SPKG.rst new file mode 100644 index 00000000000..756b7a8a4bc --- /dev/null +++ b/build/pkgs/markdown_it_py/SPKG.rst @@ -0,0 +1,16 @@ +markdown_it_py: Python port of markdown-it. Markdown parsing, done right! +========================================================================= + +Description +----------- + +Python port of markdown-it. Markdown parsing, done right! + +License +------- + +Upstream Contact +---------------- + +https://pypi.org/project/markdown-it-py/ + diff --git a/build/pkgs/markdown_it_py/checksums.ini b/build/pkgs/markdown_it_py/checksums.ini new file mode 100644 index 00000000000..446f3725667 --- /dev/null +++ b/build/pkgs/markdown_it_py/checksums.ini @@ -0,0 +1,5 @@ +tarball=markdown_it_py-VERSION-py3-none-any.whl +sha1=3982b43b7efd8f976d0d89f7ea110a7db73194c4 +md5=261d52f83b11ca9280c84c7692de7c9d +cksum=1940511663 +upstream_url=https://pypi.io/packages/py3/m/markdown_it_py/markdown_it_py-VERSION-py3-none-any.whl diff --git a/build/pkgs/markdown_it_py/dependencies b/build/pkgs/markdown_it_py/dependencies new file mode 100644 index 00000000000..27a6d9a4865 --- /dev/null +++ b/build/pkgs/markdown_it_py/dependencies @@ -0,0 +1,4 @@ +mdurl | $(PYTHON_TOOLCHAIN) $(PYTHON) + +---------- +All lines of this file are ignored except the first. diff --git a/build/pkgs/markdown_it_py/install-requires.txt b/build/pkgs/markdown_it_py/install-requires.txt new file mode 100644 index 00000000000..ad6bebcd4c9 --- /dev/null +++ b/build/pkgs/markdown_it_py/install-requires.txt @@ -0,0 +1 @@ +markdown-it-py diff --git a/build/pkgs/markdown_it_py/package-version.txt b/build/pkgs/markdown_it_py/package-version.txt new file mode 100644 index 00000000000..4a36342fcab --- /dev/null +++ b/build/pkgs/markdown_it_py/package-version.txt @@ -0,0 +1 @@ +3.0.0 diff --git a/build/pkgs/markdown_it_py/type b/build/pkgs/markdown_it_py/type new file mode 100644 index 00000000000..a6a7b9cd726 --- /dev/null +++ b/build/pkgs/markdown_it_py/type @@ -0,0 +1 @@ +standard diff --git a/build/pkgs/mdurl/SPKG.rst b/build/pkgs/mdurl/SPKG.rst new file mode 100644 index 00000000000..e5548425392 --- /dev/null +++ b/build/pkgs/mdurl/SPKG.rst @@ -0,0 +1,16 @@ +mdurl: Markdown URL utilities +============================= + +Description +----------- + +Markdown URL utilities + +License +------- + +Upstream Contact +---------------- + +https://pypi.org/project/mdurl/ + diff --git a/build/pkgs/mdurl/checksums.ini b/build/pkgs/mdurl/checksums.ini new file mode 100644 index 00000000000..f429e0c01eb --- /dev/null +++ b/build/pkgs/mdurl/checksums.ini @@ -0,0 +1,5 @@ +tarball=mdurl-VERSION-py3-none-any.whl +sha1=a26cf93cb2fe37f85fee4ea2f1c372cde26dd8b9 +md5=7db14dc5d739bfca141f035953620659 +cksum=1224661636 +upstream_url=https://pypi.io/packages/py3/m/mdurl/mdurl-VERSION-py3-none-any.whl diff --git a/build/pkgs/mdurl/dependencies b/build/pkgs/mdurl/dependencies new file mode 100644 index 00000000000..47296a7bace --- /dev/null +++ b/build/pkgs/mdurl/dependencies @@ -0,0 +1,4 @@ + | $(PYTHON_TOOLCHAIN) $(PYTHON) + +---------- +All lines of this file are ignored except the first. diff --git a/build/pkgs/mdurl/install-requires.txt b/build/pkgs/mdurl/install-requires.txt new file mode 100644 index 00000000000..38dba49310d --- /dev/null +++ b/build/pkgs/mdurl/install-requires.txt @@ -0,0 +1 @@ +mdurl diff --git a/build/pkgs/mdurl/package-version.txt b/build/pkgs/mdurl/package-version.txt new file mode 100644 index 00000000000..d917d3e26ad --- /dev/null +++ b/build/pkgs/mdurl/package-version.txt @@ -0,0 +1 @@ +0.1.2 diff --git a/build/pkgs/mdurl/type b/build/pkgs/mdurl/type new file mode 100644 index 00000000000..a6a7b9cd726 --- /dev/null +++ b/build/pkgs/mdurl/type @@ -0,0 +1 @@ +standard diff --git a/build/pkgs/rich/SPKG.rst b/build/pkgs/rich/SPKG.rst new file mode 100644 index 00000000000..2348f3fce95 --- /dev/null +++ b/build/pkgs/rich/SPKG.rst @@ -0,0 +1,18 @@ +rich: Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal +===================================================================================================== + +Description +----------- + +Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal + +License +------- + +MIT + +Upstream Contact +---------------- + +https://pypi.org/project/rich/ + diff --git a/build/pkgs/rich/checksums.ini b/build/pkgs/rich/checksums.ini new file mode 100644 index 00000000000..094dfa801d2 --- /dev/null +++ b/build/pkgs/rich/checksums.ini @@ -0,0 +1,5 @@ +tarball=rich-VERSION-py3-none-any.whl +sha1=93aa7984e7e7524718bfb541cc2dc42809c5cd8d +md5=a8d2aa27ea73def9c1091c64a34746bc +cksum=2586776835 +upstream_url=https://pypi.io/packages/py3/r/rich/rich-VERSION-py3-none-any.whl diff --git a/build/pkgs/rich/dependencies b/build/pkgs/rich/dependencies new file mode 100644 index 00000000000..871af582e04 --- /dev/null +++ b/build/pkgs/rich/dependencies @@ -0,0 +1,4 @@ +$(PYTHON) markdown_it_py | $(PYTHON_TOOLCHAIN) + +---------- +All lines of this file are ignored except the first. diff --git a/build/pkgs/rich/install-requires.txt b/build/pkgs/rich/install-requires.txt new file mode 100644 index 00000000000..3f382dd0d62 --- /dev/null +++ b/build/pkgs/rich/install-requires.txt @@ -0,0 +1 @@ +rich diff --git a/build/pkgs/rich/package-version.txt b/build/pkgs/rich/package-version.txt new file mode 100644 index 00000000000..fc9c00c1b3c --- /dev/null +++ b/build/pkgs/rich/package-version.txt @@ -0,0 +1 @@ +13.6.0 diff --git a/build/pkgs/rich/type b/build/pkgs/rich/type new file mode 100644 index 00000000000..a6a7b9cd726 --- /dev/null +++ b/build/pkgs/rich/type @@ -0,0 +1 @@ +standard diff --git a/build/pkgs/sagelib/dependencies b/build/pkgs/sagelib/dependencies index 5dc2efe1d31..e608b98b016 100644 --- a/build/pkgs/sagelib/dependencies +++ b/build/pkgs/sagelib/dependencies @@ -1,4 +1,4 @@ -FORCE $(SCRIPTS) arb boost_cropped $(BLAS) brial cliquer cypari cysignals cython ecl eclib ecm flint libgd gap giac givaro glpk gmpy2 gsl iml importlib_metadata importlib_resources jupyter_core lcalc lrcalc_python libbraiding libhomfly libpng linbox m4ri m4rie memory_allocator mpc mpfi mpfr $(MP_LIBRARY) ntl numpy pari pip pkgconfig planarity ppl pplpy primesieve primecount primecountpy pycygwin $(PYTHON) requests rw sage_conf singular symmetrica typing_extensions $(PCFILES) | $(PYTHON_TOOLCHAIN) sage_setup $(PYTHON) pythran +FORCE $(SCRIPTS) arb boost_cropped $(BLAS) brial cliquer cypari cysignals cython ecl eclib ecm flint libgd gap giac givaro glpk gmpy2 gsl iml importlib_metadata importlib_resources jupyter_core lcalc lrcalc_python libbraiding libhomfly libpng linbox m4ri m4rie memory_allocator mpc mpfi mpfr $(MP_LIBRARY) ntl numpy pari pip pkgconfig planarity ppl pplpy primesieve primecount primecountpy pycygwin $(PYTHON) requests rw sage_conf sagemath_mpmath singular symmetrica typing_extensions $(PCFILES) | $(PYTHON_TOOLCHAIN) sage_setup $(PYTHON) pythran ---------- All lines of this file are ignored except the first. diff --git a/build/pkgs/sagelib/spkg-install b/build/pkgs/sagelib/spkg-install index 730829b3101..00715217097 100755 --- a/build/pkgs/sagelib/spkg-install +++ b/build/pkgs/sagelib/spkg-install @@ -62,7 +62,7 @@ if [ "$SAGE_EDITABLE" = yes ]; then # under the old distribution name "sage" (before #30912, which switched to setuptools # and renamed the distribution to "sagemath-standard"). There is no clean way to uninstall # them, so we just use rm. - (cd "$SITEPACKAGESDIR" && rm -rf sage sage-[1-9]*.egg-info sage-[1-9]*.dist-info) + (cd "$SITEPACKAGESDIR" && rm -rf sage/__init__.py sage-[1-9]*.egg-info sage-[1-9]*.dist-info) time sdh_pip_editable_install . if [ "$SAGE_WHEELS" = yes ]; then diff --git a/build/pkgs/sagemath_mpmath/SPKG.rst b/build/pkgs/sagemath_mpmath/SPKG.rst new file mode 120000 index 00000000000..b4545b4bda6 --- /dev/null +++ b/build/pkgs/sagemath_mpmath/SPKG.rst @@ -0,0 +1 @@ +src/README.rst \ No newline at end of file diff --git a/build/pkgs/sagemath_mpmath/bootstrap b/build/pkgs/sagemath_mpmath/bootstrap new file mode 120000 index 00000000000..40542346a4e --- /dev/null +++ b/build/pkgs/sagemath_mpmath/bootstrap @@ -0,0 +1 @@ +../sagelib/bootstrap \ No newline at end of file diff --git a/build/pkgs/sagemath_mpmath/dependencies b/build/pkgs/sagemath_mpmath/dependencies new file mode 100644 index 00000000000..7ca5ccc53d2 --- /dev/null +++ b/build/pkgs/sagemath_mpmath/dependencies @@ -0,0 +1 @@ +$(PYTHON) cysignals mpmath | $(PYTHON_TOOLCHAIN) sage_setup cython pkgconfig vendoring diff --git a/build/pkgs/sagemath_mpmath/install-requires.txt b/build/pkgs/sagemath_mpmath/install-requires.txt new file mode 100644 index 00000000000..4a424928b7c --- /dev/null +++ b/build/pkgs/sagemath_mpmath/install-requires.txt @@ -0,0 +1,2 @@ +# This file is updated on every release by the sage-update-version script +sagemath-mpmath diff --git a/build/pkgs/sagemath_mpmath/package-version.txt b/build/pkgs/sagemath_mpmath/package-version.txt new file mode 120000 index 00000000000..c4540217bba --- /dev/null +++ b/build/pkgs/sagemath_mpmath/package-version.txt @@ -0,0 +1 @@ +src/VERSION.txt \ No newline at end of file diff --git a/build/pkgs/sagemath_mpmath/spkg-install b/build/pkgs/sagemath_mpmath/spkg-install new file mode 100755 index 00000000000..5da8998ae19 --- /dev/null +++ b/build/pkgs/sagemath_mpmath/spkg-install @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# From sage-spkg. +# For type=script packages, the build rule in build/make/Makefile sources +# sage-env but not sage-dist-helpers. +lib="$SAGE_ROOT/build/bin/sage-dist-helpers" +source "$lib" +if [ $? -ne 0 ]; then + echo >&2 "Error: failed to source $lib" + echo >&2 "Is $SAGE_ROOT the correct SAGE_ROOT?" + exit 1 +fi +cd src + +rm -rf build *.egg_info + +export PIP_NO_INDEX=true +export PIP_FIND_LINKS="file://$SAGE_DISTFILES" +vendoring sync || sdh_die "Vendoring failed" + +export PIP_FIND_LINKS="file://$SAGE_SPKG_WHEELS" + +# The metadata are set up to use the modularized distributions as dependencies. +# Hence here we install with --no-build-isolation --no-deps +sdh_pip_install --no-build-isolation --no-deps . diff --git a/build/pkgs/sagemath_mpmath/spkg-src b/build/pkgs/sagemath_mpmath/spkg-src new file mode 100755 index 00000000000..6da34c40f97 --- /dev/null +++ b/build/pkgs/sagemath_mpmath/spkg-src @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# +# Script to prepare an sdist tarball for sagemath-mpmath +# This script is not used during build. +# +# HOW TO MAKE THE TARBALL: +# ./sage --sh build/pkgs/sagemath_mpmath/spkg-src + +if [ -z "$SAGE_ROOT" ] ; then + echo >&2 "Error - SAGE_ROOT undefined ... exiting" + echo >&2 "Maybe run 'sage -sh'?" + exit 1 +fi + +# Exit on failure +set -e + +cd build/pkgs/sagemath_mpmath + +cd src +# Get rid of old *.egg-info/SOURCES.txt +rm -Rf *.egg-info + +python3 -m build --sdist --no-isolation --skip-dependency-check --outdir "$SAGE_DISTFILES" diff --git a/build/pkgs/sagemath_mpmath/src b/build/pkgs/sagemath_mpmath/src new file mode 120000 index 00000000000..7eaada6dc6b --- /dev/null +++ b/build/pkgs/sagemath_mpmath/src @@ -0,0 +1 @@ +../../../pkgs/sagemath-mpmath \ No newline at end of file diff --git a/build/pkgs/sagemath_mpmath/type b/build/pkgs/sagemath_mpmath/type new file mode 100644 index 00000000000..a6a7b9cd726 --- /dev/null +++ b/build/pkgs/sagemath_mpmath/type @@ -0,0 +1 @@ +standard diff --git a/build/pkgs/toml/SPKG.rst b/build/pkgs/toml/SPKG.rst new file mode 100644 index 00000000000..e1b53b8f79e --- /dev/null +++ b/build/pkgs/toml/SPKG.rst @@ -0,0 +1,18 @@ +toml: Python Library for Tom's Obvious, Minimal Language +======================================================== + +Description +----------- + +Python Library for Tom's Obvious, Minimal Language + +License +------- + +MIT + +Upstream Contact +---------------- + +https://pypi.org/project/toml/ + diff --git a/build/pkgs/toml/checksums.ini b/build/pkgs/toml/checksums.ini new file mode 100644 index 00000000000..6156a2a61c9 --- /dev/null +++ b/build/pkgs/toml/checksums.ini @@ -0,0 +1,5 @@ +tarball=toml-VERSION-py2.py3-none-any.whl +sha1=a55ae166e643e6c7a28c16fe005efc32ee98ee76 +md5=dc26cd71b80d6757139f38156a43c545 +cksum=1596064333 +upstream_url=https://pypi.io/packages/py2.py3/t/toml/toml-VERSION-py2.py3-none-any.whl diff --git a/build/pkgs/toml/dependencies b/build/pkgs/toml/dependencies new file mode 100644 index 00000000000..47296a7bace --- /dev/null +++ b/build/pkgs/toml/dependencies @@ -0,0 +1,4 @@ + | $(PYTHON_TOOLCHAIN) $(PYTHON) + +---------- +All lines of this file are ignored except the first. diff --git a/build/pkgs/toml/distros/arch.txt b/build/pkgs/toml/distros/arch.txt new file mode 100644 index 00000000000..821ee775ac7 --- /dev/null +++ b/build/pkgs/toml/distros/arch.txt @@ -0,0 +1 @@ +python-toml diff --git a/build/pkgs/toml/distros/debian.txt b/build/pkgs/toml/distros/debian.txt new file mode 100644 index 00000000000..543e89d2a6f --- /dev/null +++ b/build/pkgs/toml/distros/debian.txt @@ -0,0 +1 @@ +python3-toml diff --git a/build/pkgs/toml/distros/fedora.txt b/build/pkgs/toml/distros/fedora.txt new file mode 100644 index 00000000000..821ee775ac7 --- /dev/null +++ b/build/pkgs/toml/distros/fedora.txt @@ -0,0 +1 @@ +python-toml diff --git a/build/pkgs/toml/distros/gentoo.txt b/build/pkgs/toml/distros/gentoo.txt new file mode 100644 index 00000000000..64fcea3559f --- /dev/null +++ b/build/pkgs/toml/distros/gentoo.txt @@ -0,0 +1 @@ +dev-python/toml diff --git a/build/pkgs/toml/distros/opensuse.txt b/build/pkgs/toml/distros/opensuse.txt new file mode 100644 index 00000000000..fbc340aee15 --- /dev/null +++ b/build/pkgs/toml/distros/opensuse.txt @@ -0,0 +1 @@ +python3${PYTHON_MINOR}-toml diff --git a/build/pkgs/toml/install-requires.txt b/build/pkgs/toml/install-requires.txt new file mode 100644 index 00000000000..bd79a658fe7 --- /dev/null +++ b/build/pkgs/toml/install-requires.txt @@ -0,0 +1 @@ +toml diff --git a/build/pkgs/toml/package-version.txt b/build/pkgs/toml/package-version.txt new file mode 100644 index 00000000000..5eef0f10e8c --- /dev/null +++ b/build/pkgs/toml/package-version.txt @@ -0,0 +1 @@ +0.10.2 diff --git a/build/pkgs/toml/type b/build/pkgs/toml/type new file mode 100644 index 00000000000..a6a7b9cd726 --- /dev/null +++ b/build/pkgs/toml/type @@ -0,0 +1 @@ +standard diff --git a/build/pkgs/vendoring/SPKG.rst b/build/pkgs/vendoring/SPKG.rst new file mode 100644 index 00000000000..a7ccc45437b --- /dev/null +++ b/build/pkgs/vendoring/SPKG.rst @@ -0,0 +1,16 @@ +vendoring: A command line tool, to simplify vendoring pure Python dependencies. +=============================================================================== + +Description +----------- + +A command line tool, to simplify vendoring pure Python dependencies. + +License +------- + +Upstream Contact +---------------- + +https://pypi.org/project/vendoring/ + diff --git a/build/pkgs/vendoring/checksums.ini b/build/pkgs/vendoring/checksums.ini new file mode 100644 index 00000000000..c69250da739 --- /dev/null +++ b/build/pkgs/vendoring/checksums.ini @@ -0,0 +1,5 @@ +tarball=vendoring-VERSION-py2.py3-none-any.whl +sha1=583c5cbf3fd512f4f683afbea7d60f7e3234c3ac +md5=a97f7f74700be564a9f8ad1fa33b5e1f +cksum=2501073473 +upstream_url=https://pypi.io/packages/py2.py3/v/vendoring/vendoring-VERSION-py2.py3-none-any.whl diff --git a/build/pkgs/vendoring/dependencies b/build/pkgs/vendoring/dependencies new file mode 100644 index 00000000000..5ed609488d3 --- /dev/null +++ b/build/pkgs/vendoring/dependencies @@ -0,0 +1,4 @@ +rich click toml | $(PYTHON_TOOLCHAIN) $(PYTHON) + +---------- +All lines of this file are ignored except the first. diff --git a/build/pkgs/vendoring/install-requires.txt b/build/pkgs/vendoring/install-requires.txt new file mode 100644 index 00000000000..03bd62cb35c --- /dev/null +++ b/build/pkgs/vendoring/install-requires.txt @@ -0,0 +1 @@ +vendoring diff --git a/build/pkgs/vendoring/package-version.txt b/build/pkgs/vendoring/package-version.txt new file mode 100644 index 00000000000..26aaba0e866 --- /dev/null +++ b/build/pkgs/vendoring/package-version.txt @@ -0,0 +1 @@ +1.2.0 diff --git a/build/pkgs/vendoring/type b/build/pkgs/vendoring/type new file mode 100644 index 00000000000..a6a7b9cd726 --- /dev/null +++ b/build/pkgs/vendoring/type @@ -0,0 +1 @@ +standard diff --git a/pkgs/sagemath-mpmath/MANIFEST.in b/pkgs/sagemath-mpmath/MANIFEST.in new file mode 100644 index 00000000000..efa99e06fa6 --- /dev/null +++ b/pkgs/sagemath-mpmath/MANIFEST.in @@ -0,0 +1,25 @@ +prune sage + +include VERSION.txt +include vendor.txt + +include sage/libs/mpfr/*.pxd # FIXME +include sage/rings/real_mpfr.pxd # FIXME +include sage/rings/complex_mpfr.pxd # FIXME + +graft sage/libs/mpmath + +global-exclude *.c +global-exclude *.cpp + +global-exclude all__sagemath*.py +global-include all__sagemath_mpmath.py + +global-exclude __pycache__ +global-exclude *.py[co] +global-exclude *.bak +global-exclude *.so +global-exclude *~ +prune .tox +prune build +prune dist diff --git a/pkgs/sagemath-mpmath/README.rst b/pkgs/sagemath-mpmath/README.rst new file mode 100644 index 00000000000..21b6fe1e9be --- /dev/null +++ b/pkgs/sagemath-mpmath/README.rst @@ -0,0 +1,26 @@ +======================================================================================== + Sage: Open Source Mathematics Software: Vendored copy of mpmath using the Sage backend +======================================================================================== + +About SageMath +-------------- + + "Creating a Viable Open Source Alternative to + Magma, Maple, Mathematica, and MATLAB" + + Copyright (C) 2005-2023 The Sage Development Team + + https://www.sagemath.org + +SageMath fully supports all major Linux distributions, recent versions of +macOS, and Windows (using Cygwin or Windows Subsystem for Linux). + +The traditional and recommended way to install SageMath is from source via +Sage-the-distribution (https://www.sagemath.org/download-source.html). +Sage-the-distribution first builds a large number of open source packages from +source (unless it finds suitable versions installed in the system) and then +installs the Sage Library (sagelib, implemented in Python and Cython). + + +About this pip-installable source distribution +---------------------------------------------- diff --git a/pkgs/sagemath-mpmath/VERSION.txt b/pkgs/sagemath-mpmath/VERSION.txt new file mode 100644 index 00000000000..2f52450b31d --- /dev/null +++ b/pkgs/sagemath-mpmath/VERSION.txt @@ -0,0 +1 @@ +10.0 diff --git a/pkgs/sagemath-mpmath/pyproject.toml.m4 b/pkgs/sagemath-mpmath/pyproject.toml.m4 new file mode 100644 index 00000000000..ebb4d3848e0 --- /dev/null +++ b/pkgs/sagemath-mpmath/pyproject.toml.m4 @@ -0,0 +1,31 @@ +[build-system] +# Minimum requirements for the build system to execute. +requires = [ + esyscmd(`sage-get-system-packages install-requires-toml \ + setuptools \ + sage_setup \ + sagemath_environment \ + sagemath_categories \ + cython \ + cysignals \ + ')] +build-backend = "setuptools.build_meta" + + +[tool.vendoring] +# Following example at https://github.com/pypa/pip/blob/main/pyproject.toml#L30 + +destination = "sage/libs/mpmath/_vendor/" +requirements = "vendor.txt" +namespace = "sage.libs.mpmath._vendor" + +protected-files = ["all.py", "vendor.txt", "nodoctest.py"] +patches-dir = "vendoring_patches" + +[tool.vendoring.transformations] +substitute = [ + {match='sage[.]all', replace='sage.libs.mpmath.hooks'}, + {match="(?ms)if 'MPMATH_NOGMPY'.*?except:\\s*pass", replace=''}, + {match="(?ms)if [(]*'MPMATH_NOSAGE'.*?:(.*?)except:", replace='if True:\1except ():'}, + {match='from mpmath', replace='from sage.libs.mpmath._vendor.mpmath'}, +] diff --git a/pkgs/sagemath-mpmath/requirements.txt.m4 b/pkgs/sagemath-mpmath/requirements.txt.m4 new file mode 100644 index 00000000000..8b6ca03b0b9 --- /dev/null +++ b/pkgs/sagemath-mpmath/requirements.txt.m4 @@ -0,0 +1,2 @@ +Cython==esyscmd(`printf $(sed "s/[.]p.*//;" ../cython/package-version.txt)') +sagemath-standard==esyscmd(`printf $(sed "s/[.]p.*//;" ../sagelib/package-version.txt)') diff --git a/pkgs/sagemath-mpmath/sage b/pkgs/sagemath-mpmath/sage new file mode 120000 index 00000000000..e0da5daa6f2 --- /dev/null +++ b/pkgs/sagemath-mpmath/sage @@ -0,0 +1 @@ +../../src/sage \ No newline at end of file diff --git a/pkgs/sagemath-mpmath/setup.cfg.m4 b/pkgs/sagemath-mpmath/setup.cfg.m4 new file mode 100644 index 00000000000..76b45e62468 --- /dev/null +++ b/pkgs/sagemath-mpmath/setup.cfg.m4 @@ -0,0 +1,38 @@ +# -*- conf-unix -*- +[metadata] +name = sagemath-mpmath +version = file: VERSION.txt +description = Sage: Open Source Mathematics Software: Vendored copy of mpmath using the Sage backend +long_description = file: README.rst +long_description_content_type = text/x-rst +license = GNU General Public License (GPL) v2 or later +author = The Sage Developers +author_email = sage-support@googlegroups.com +url = https://www.sagemath.org + +classifiers = + Development Status :: 6 - Mature + Intended Audience :: Education + Intended Audience :: Science/Research + License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+) + Operating System :: POSIX + Operating System :: MacOS :: MacOS X + Programming Language :: Python :: 3 :: Only + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 + Programming Language :: Python :: 3.11 + Programming Language :: Python :: Implementation :: CPython + Topic :: Scientific/Engineering :: Mathematics + +[options] +python_requires = >=3.8, <3.12 +install_requires = + esyscmd(`sage-get-system-packages install-requires \ + sagemath_categories \ + | sed "2,\$s/^/ /;"')dnl + +[options.package_data] + +sage.libs.mpmath = + *.pxd diff --git a/pkgs/sagemath-mpmath/setup.py b/pkgs/sagemath-mpmath/setup.py new file mode 100644 index 00000000000..72ce8b5ea5a --- /dev/null +++ b/pkgs/sagemath-mpmath/setup.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python + +from distutils import log +from setuptools import setup + +# Work around a Cython problem in Python 3.8.x on macOS +# https://github.com/cython/cython/issues/3262 +import os +if os.uname().sysname == 'Darwin': + import multiprocessing + multiprocessing.set_start_method('fork', force=True) + +# If build isolation is not in use and setuptools_scm is installed, +# then its file_finders entry point is invoked, which we don't need. +# Workaround from ​https://github.com/pypa/setuptools_scm/issues/190#issuecomment-351181286 +try: + import setuptools_scm.integration + setuptools_scm.integration.find_files = lambda _: [] +except ImportError: + pass + +# PEP 517 builds do not have . in sys.path +import sys +sys.path.insert(0, os.path.dirname(__file__)) + +if len(sys.argv) > 1 and (sys.argv[1] == "sdist" or sys.argv[1] == "egg_info"): + sdist = True +else: + sdist = False + +if sdist: + cmdclass = {} +else: + from sage_setup.excepthook import excepthook + sys.excepthook = excepthook + + from sage_setup.setenv import setenv + setenv() + + import sage.env + sage.env.default_required_modules = sage.env.default_optional_modules = () + + from sage_setup.command.sage_build_cython import sage_build_cython + from sage_setup.command.sage_build_ext import sage_build_ext + sage_build_cython.built_distributions = ['sagemath-mpmath'] + + cmdclass = dict(build_cython=sage_build_cython, + build_ext=sage_build_ext) + +from sage_setup.find import find_python_sources +python_packages, python_modules, cython_modules = find_python_sources( + '.', ['sage/libs/mpmath'], distributions=['', 'sagemath-mpmath']) + + + +log.warn('python_packages = {0}'.format(python_packages)) +log.warn('python_modules = {0}'.format(python_modules)) +log.warn('cython_modules = {0}'.format(cython_modules)) + +setup( + cmdclass = cmdclass, + packages = python_packages, + py_modules = python_modules, + ext_modules = cython_modules, +) diff --git a/pkgs/sagemath-mpmath/tox.ini b/pkgs/sagemath-mpmath/tox.ini new file mode 100644 index 00000000000..f7088ef368f --- /dev/null +++ b/pkgs/sagemath-mpmath/tox.ini @@ -0,0 +1,103 @@ +# To build and test in the tox environment: +# +# make SAGE_WHEELS=yes sagemath_mpmath-build-deps sagemath_repl && ./sage -sh -c '(cd pkgs/sagemath-mpmath && SAGE_NUM_THREADS=8 tox -v -v -v -e sagepython-sagewheels-nopypi-norequirements)' +# +# After this, to test interactively: +# +# pkgs/sagemath-mpmath/.tox/sagepython-sagewheels-nopypi-norequirements/bin/sage +# +[tox] +envlist = + sagepython-sagewheels-nopypi-norequirements + +requires = + # Auto-provision a modern tox. + # [pkgenv] added in 4.2 - https://tox.wiki/en/latest/upgrading.html#packaging-configuration-and-inheritance + tox>=4.2 + +[pkgenv] +# Environment in which to build the sdist. +# https://tox.wiki/en/latest/upgrading.html#packaging-environments +passenv = + # Variables set by .homebrew-build-env + CPATH + LIBRARY_PATH + PKG_CONFIG_PATH + # Parallel build + SAGE_NUM_THREADS + SAGE_NUM_THREADS_PARALLEL + # SAGE_VENV only for referring to the basepython or finding the wheels + sagepython, sagewheels: SAGE_VENV + # Location of the wheels + sagewheels: SAGE_SPKG_WHEELS + +setenv = + # We supply pip options by environment variables so that they + # apply both to the installation of the dependencies and of the package + sagewheels: PIP_FIND_LINKS=file://{env:SAGE_SPKG_WHEELS:{env:SAGE_VENV:{toxinidir}/../../../../venv}/var/lib/sage/wheels} + nopypi: PIP_NO_INDEX=true + +[testenv] +deps = + !norequirements: -rrequirements.txt + +extras = test + +passenv = {[pkgenv]passenv} + +setenv = {[pkgenv]setenv} + # Sage scripts such as sage-runtests like to use $HOME/.sage + HOME={envdir} + # Stop 'sage -t --installed' from picking up doc installed in SAGE_LOCAL + SAGE_DOC=/doesnotexist + +allowlist_externals = + bash + +commands = # Cannot be imported because of dependency on real_mpfr + # Beware of the treacherous non-src layout. "./sage/" shadows the installed sage package. + # {envpython} -c 'import sys; "" in sys.path and sys.path.remove(""); import sage.cpython.builtin_types, sage.cpython.cython_metaclass, sage.cpython.debug, sage.structure.all, sage.libs.mpmath._vendor.mpmath' + + ## bash -c 'cd $(python -c "import sys; \"\" in sys.path and sys.path.remove(\"\"); from sage.env import SAGE_LIB; print(SAGE_LIB)") \ + ## && sage-runtests -p --initial --environment=sage.all__sagemath_mpmath --baseline-stats-path={toxinidir}/known-test-failures.json --optional=sage --installed' + +[testenv:.tox] +# Allow access to PyPI for auto-provisioning a suitable tox version +passenv = +setenv = PIP_NO_INDEX=false + +[testenv:.pkg-sagepython] +# Environment in which to build the sdist. +# inherits from [pkgenv] - https://tox.wiki/en/latest/upgrading.html#packaging-environments +basepython = {env:SAGE_VENV}/bin/python3 + +[testenv:.pkg-sagepython-sagewheels-nopypi] +passenv = {[pkgenv]passenv} + SAGE_VENV + SAGE_SPKG_WHEELS + +setenv = {[pkgenv]setenv} + PIP_FIND_LINKS=file://{env:SAGE_SPKG_WHEELS:{env:SAGE_VENV:{toxinidir}/../../../../venv}/var/lib/sage/wheels} + PIP_NO_INDEX=true + +basepython = {env:SAGE_VENV}/bin/python3 + +[testenv:sagepython] +basepython = {env:SAGE_VENV}/bin/python3 +package_env = .pkg-sagepython + +[testenv:sagepython-sagewheels-nopypi] +basepython = {env:SAGE_VENV}/bin/python3 +package_env = .pkg-sagepython-sagewheels-nopypi + +[testenv:sagepython-sagewheels-nopypi-norequirements] +basepython = {env:SAGE_VENV}/bin/python3 +package_env = .pkg-sagepython-sagewheels-nopypi + +[testenv:sagepython-sagewheels] +basepython = {env:SAGE_VENV}/bin/python +package_env = .pkg-sagepython + +[testenv:sagepython-norequirements] +basepython = {env:SAGE_VENV}/bin/python3 +package_env = .pkg-sagepython diff --git a/pkgs/sagemath-mpmath/vendor.txt.m4 b/pkgs/sagemath-mpmath/vendor.txt.m4 new file mode 100644 index 00000000000..8dd3966a9f3 --- /dev/null +++ b/pkgs/sagemath-mpmath/vendor.txt.m4 @@ -0,0 +1 @@ +mpmath ~= 1.2.1 diff --git a/pkgs/sagemath-standard/setup.py b/pkgs/sagemath-standard/setup.py index 7f6318a0fa0..bed69830451 100755 --- a/pkgs/sagemath-standard/setup.py +++ b/pkgs/sagemath-standard/setup.py @@ -77,7 +77,7 @@ print("Discovering Python/Cython source code....") t = time.time() from sage.misc.package import is_package_installed_and_updated -distributions = [''] +distributions = ['', 'sagemath-mpmath'] optional_packages_with_extensions = os.environ.get('SAGE_OPTIONAL_PACKAGES_WITH_EXTENSIONS', '').split(',') distributions += ['sagemath-{}'.format(pkg) for pkg in optional_packages_with_extensions diff --git a/src/doc/en/reference/libs/index.rst b/src/doc/en/reference/libs/index.rst index 0fde7b179e0..1f4dff66fd1 100644 --- a/src/doc/en/reference/libs/index.rst +++ b/src/doc/en/reference/libs/index.rst @@ -121,7 +121,7 @@ mpmath .. toctree:: :maxdepth: 1 - sage/libs/mpmath/utils + sage/libs/mpmath/sage_utils NTL --- diff --git a/src/sage/libs/mpmath/__init__.py b/src/sage/all__sagemath_mpmath.py similarity index 100% rename from src/sage/libs/mpmath/__init__.py rename to src/sage/all__sagemath_mpmath.py diff --git a/src/sage/doctest/forker.py b/src/sage/doctest/forker.py index b5521868dd5..4ce83631758 100644 --- a/src/sage/doctest/forker.py +++ b/src/sage/doctest/forker.py @@ -204,7 +204,8 @@ def init_sage(controller=None): if controller is None: import sage.repl.ipython_kernel.all_jupyter else: - controller.load_environment() + import sage + sage.all = controller.load_environment() try: from sage.interfaces.quit import invalidate_all diff --git a/src/sage/doctest/sources.py b/src/sage/doctest/sources.py index 5064496052b..a4f31f1613e 100644 --- a/src/sage/doctest/sources.py +++ b/src/sage/doctest/sources.py @@ -843,6 +843,9 @@ def _test_enough_doctests(self, check_extras=True, verbose=True): ....: path = os.path.relpath(path) ....: dirs.sort(); files.sort() ....: for F in files: + ....: if F == 'nodoctest.py': + ....: dirs.clear() + ....: break ....: _, ext = os.path.splitext(F) ....: if ext in ('.py', '.pyx', '.pxd', '.pxi', '.sage', '.spyx', '.rst'): ....: filename = os.path.join(path, F) diff --git a/src/sage/env.py b/src/sage/env.py index f4899639a6d..63c148bdd2a 100644 --- a/src/sage/env.py +++ b/src/sage/env.py @@ -235,8 +235,9 @@ def var(key: str, *fallbacks: Optional[str], force: bool = False) -> Optional[st OPENMP_CFLAGS = var("OPENMP_CFLAGS", "") OPENMP_CXXFLAGS = var("OPENMP_CXXFLAGS", "") -# Make sure mpmath uses Sage types -os.environ['MPMATH_SAGE'] = '1' +# Make sure that a non-vendored copy of mpmath (e.g. used by SymPy) does not use Sage types +os.environ.pop('MPMATH_SAGE', None) +os.environ['MPMATH_NOSAGE'] = '1' # misc SAGE_BANNER = var("SAGE_BANNER", "") diff --git a/src/sage/features/standard.py b/src/sage/features/standard.py index c2090fc53a4..dcfd94445d4 100644 --- a/src/sage/features/standard.py +++ b/src/sage/features/standard.py @@ -22,7 +22,7 @@ def all_features(): PythonModule('fpylll', spkg='fpylll', type='standard'), JoinFeature('ipython', (PythonModule('IPython'),), spkg='ipython', type='standard'), JoinFeature('lrcalc_python', (PythonModule('lrcalc'),), spkg='lrcalc_python', type='standard'), - PythonModule('mpmath', spkg='mpmath', type='standard'), + JoinFeature('mpmath', (PythonModule('sage.libs.mpmath.all'),), spkg='sagemath_mpmath', type='standard'), PythonModule('networkx', spkg='networkx', type='standard'), PythonModule('numpy', spkg='numpy', type='standard'), PythonModule('pexpect', spkg='pexpect', type='standard'), diff --git a/src/sage/functions/airy.py b/src/sage/functions/airy.py index 11f4c56be8c..eabccbec298 100644 --- a/src/sage/functions/airy.py +++ b/src/sage/functions/airy.py @@ -54,8 +54,8 @@ lazy_import('sage.symbolic.ring', 'SR') -lazy_import('sage.libs.mpmath.utils', 'call', as_='_mpmath_utils_call') -lazy_import('mpmath', ['airyai', 'airybi'], +lazy_import('sage.libs.mpmath.sage_utils', 'call', as_='_mpmath_call') +lazy_import('sage.libs.mpmath.all', ['airyai', 'airybi'], as_=['_mpmath_airyai', '_mpmath_airybi']) @@ -148,7 +148,7 @@ def _evalf_(self, alpha, x, parent=None, algorithm=None): sage: airy_ai_general(-2, 1.0) # needs mpmath 0.136645379421096 """ - return _mpmath_utils_call(_mpmath_airyai, x, derivative=alpha, + return _mpmath_call(_mpmath_airyai, x, derivative=alpha, parent=parent) @@ -252,7 +252,7 @@ def _evalf_(self, x, **kwargs): return CC(y) return parent(y) elif algorithm == 'mpmath': - return _mpmath_utils_call(_mpmath_airyai, x, parent=parent) + return _mpmath_call(_mpmath_airyai, x, parent=parent) else: raise ValueError("unknown algorithm '%s'" % algorithm) @@ -352,7 +352,7 @@ def _evalf_(self, x, **kwargs): return CC(y) return parent(y) elif algorithm == 'mpmath': - return _mpmath_utils_call(_mpmath_airyai, x, derivative=1, + return _mpmath_call(_mpmath_airyai, x, derivative=1, parent=parent) else: raise ValueError("unknown algorithm '%s'" % algorithm) @@ -584,9 +584,8 @@ def _evalf_(self, alpha, x, **kwargs): """ parent = kwargs.get('parent') - import mpmath from sage.libs.mpmath import utils as mpmath_utils - return _mpmath_utils_call(_mpmath_airybi, x, derivative=alpha, + return _mpmath_call(_mpmath_airybi, x, derivative=alpha, parent=parent) @@ -692,9 +691,8 @@ def _evalf_(self, x, **kwargs): return CC(y) return parent(y) elif algorithm == 'mpmath': - import mpmath from sage.libs.mpmath import utils as mpmath_utils - return _mpmath_utils_call(_mpmath_airybi, x, parent=parent) + return _mpmath_call(_mpmath_airybi, x, parent=parent) else: raise ValueError("unknown algorithm '%s'" % algorithm) @@ -794,7 +792,7 @@ def _evalf_(self, x, **kwargs): return CC(y) return parent(y) elif algorithm == 'mpmath': - return _mpmath_utils_call(_mpmath_airybi, x, derivative=1, + return _mpmath_call(_mpmath_airybi, x, derivative=1, parent=parent) else: raise ValueError("unknown algorithm '%s'" % algorithm) diff --git a/src/sage/functions/bessel.py b/src/sage/functions/bessel.py index 24ee74b561c..0f58bd382b3 100644 --- a/src/sage/functions/bessel.py +++ b/src/sage/functions/bessel.py @@ -230,8 +230,8 @@ lazy_import('sage.symbolic.constants', 'pi') lazy_import('sage.symbolic.ring', 'SR') -lazy_import('sage.libs.mpmath.utils', 'call', as_='_mpmath_utils_call') -lazy_import('mpmath', +lazy_import('sage.libs.mpmath.sage_utils', 'call', as_='_mpmath_call') +lazy_import('sage.libs.mpmath.all', ['besseli', 'besselj', 'besselk', 'bessely', 'hankel1', 'hankel2', 'struveh', 'struvel'], @@ -418,7 +418,7 @@ def _evalf_(self, n, x, parent=None, algorithm=None): pass n, x = get_coercion_model().canonical_coercion(n, x) - return _mpmath_utils_call(_mpmath_besselj, n, x, parent=parent) + return _mpmath_call(_mpmath_besselj, n, x, parent=parent) def _derivative_(self, n, x, diff_param): """ @@ -638,7 +638,7 @@ def _evalf_(self, n, x, parent=None, algorithm=None): pass n, x = get_coercion_model().canonical_coercion(n, x) - return _mpmath_utils_call(_mpmath_bessely, n, x, parent=parent) + return _mpmath_call(_mpmath_bessely, n, x, parent=parent) def _derivative_(self, n, x, diff_param): """ @@ -831,7 +831,7 @@ def _evalf_(self, n, x, parent=None, algorithm=None): sage: bessel_I(1,3).n(digits=20) # needs sage.symbolic 3.9533702174026093965 """ - return _mpmath_utils_call(_mpmath_besseli, n, x, parent=parent) + return _mpmath_call(_mpmath_besseli, n, x, parent=parent) def _derivative_(self, n, x, diff_param): """ @@ -1029,7 +1029,7 @@ def _evalf_(self, n, x, parent=None, algorithm=None): sage: bessel_K(0, RealField(128)(1)) # needs sage.rings.real_mpfr 0.42102443824070833333562737921260903614 """ - return _mpmath_utils_call(_mpmath_besselk, n, x, parent=parent) + return _mpmath_call(_mpmath_besselk, n, x, parent=parent) def _derivative_(self, n, x, diff_param): """ @@ -1331,7 +1331,7 @@ def _evalf_(self, a, z, parent=None, algorithm=None): sage: struve_H(1/2, pi).n(200) # needs sage.symbolic 0.9003163161571060695551991910... """ - return _mpmath_utils_call(_mpmath_struveh, a, z, parent=parent) + return _mpmath_call(_mpmath_struveh, a, z, parent=parent) def _derivative_(self, a, z, diff_param=None): """ @@ -1446,7 +1446,7 @@ def _evalf_(self, a, z, parent=None, algorithm=None): sage: struve_L(1/2, pi).n(200) # needs sage.symbolic 4.768054176962864289162484345... """ - return _mpmath_utils_call(_mpmath_struvel, a, z, parent=parent) + return _mpmath_call(_mpmath_struvel, a, z, parent=parent) def _derivative_(self, a, z, diff_param=None): """ @@ -1524,7 +1524,7 @@ def _evalf_(self, nu, z, parent, algorithm=None): sage: hankel1(I, I).n() # needs sage.symbolic -0.886357449263715*I """ - return _mpmath_utils_call(_mpmath_hankel1, nu, z, parent=parent) + return _mpmath_call(_mpmath_hankel1, nu, z, parent=parent) def _latex_(self): r""" @@ -1611,7 +1611,7 @@ def _evalf_(self, nu, z, parent, algorithm=None): sage: hankel2(I, I).n() # needs sage.symbolic 0.790274862674015 + 0.444006335520019*I """ - return _mpmath_utils_call(_mpmath_hankel2, nu, z, parent=parent) + return _mpmath_call(_mpmath_hankel2, nu, z, parent=parent) def _latex_(self): r""" @@ -1709,7 +1709,7 @@ def _evalf_(self, n, z, parent, algorithm=None): sage: spherical_bessel_J(I, I).n() # needs sage.symbolic 0.215520585196889 - 0.282308805801851*I """ - return _mpmath_utils_call(spherical_bessel_f, 'besselj', n, z, + return _mpmath_call(spherical_bessel_f, 'besselj', n, z, parent=parent) def _latex_(self): @@ -1808,7 +1808,7 @@ def _evalf_(self, n, z, parent, algorithm=None): sage: spherical_bessel_Y(I, I).n() # needs sage.symbolic -0.174225389805399 + 1.36247234140312*I """ - return _mpmath_utils_call(spherical_bessel_f, 'bessely', n, z, + return _mpmath_call(spherical_bessel_f, 'bessely', n, z, parent=parent) def _latex_(self): @@ -1906,7 +1906,7 @@ def _evalf_(self, n, z, parent, algorithm=None): sage: spherical_hankel1(I, I).n() # needs sage.symbolic -1.14695175620623 - 0.456534195607250*I """ - return _mpmath_utils_call(spherical_bessel_f, 'hankel1', n, z, + return _mpmath_call(spherical_bessel_f, 'hankel1', n, z, parent=parent) def _latex_(self): @@ -2007,7 +2007,7 @@ def _evalf_(self, n, z, parent, algorithm=None): sage: spherical_hankel2(I, I).n() # needs sage.symbolic 1.57799292660001 - 0.108083415996452*I """ - return _mpmath_utils_call(spherical_bessel_f, 'hankel2', n, z, + return _mpmath_call(spherical_bessel_f, 'hankel2', n, z, parent=parent) def _latex_(self): @@ -2084,7 +2084,7 @@ def spherical_bessel_f(F, n, z): sage: spherical_bessel_f('bessely', 3, -4) # needs mpmath mpc(real='-0.21864196590306359', imag='0.0') """ - from mpmath import mp as ctx + from sage.libs.mpmath.all import mp as ctx prec = ctx.prec try: n = ctx.convert(n) diff --git a/src/sage/functions/error.py b/src/sage/functions/error.py index 1e4b74d5afe..170045801a6 100644 --- a/src/sage/functions/error.py +++ b/src/sage/functions/error.py @@ -53,7 +53,7 @@ lazy_import('sage.symbolic.constants', ['I', 'pi']) -lazy_import('sage.libs.mpmath.utils', 'call', as_='_mpmath_utils_call') +lazy_import('sage.libs.mpmath.sage_utils', 'call', as_='_mpmath_call') lazy_import('sage.libs.mpmath.all', 'erf', as_='_mpmath_erf') lazy_import('sage.libs.mpmath.all', 'erfc', as_='_mpmath_erfc') lazy_import('sage.libs.mpmath.all', 'erfi', as_='_mpmath_erfi') @@ -283,7 +283,7 @@ def _evalf_(self, x, parent=None, algorithm=None): [0.99999999999846254020557196514981165651 +/- 7.33e-39] """ R = parent or s_parent(x) - y = _mpmath_utils_call(_mpmath_erf, x, parent=R) + y = _mpmath_call(_mpmath_erf, x, parent=R) return y def _derivative_(self, x, diff_param=None): @@ -373,7 +373,7 @@ def _evalf_(self, x, parent=None, algorithm=None): -0.99532226501895273416206925637*I """ R = parent or s_parent(x) - return _mpmath_utils_call(_mpmath_erfi, x, parent=R) + return _mpmath_call(_mpmath_erfi, x, parent=R) def _derivative_(self, x, diff_param=None): """ @@ -478,7 +478,7 @@ def _evalf_(self, x, parent=None, algorithm=None): 1.0000000000000000000000000000 - 1.2969597307176392315279409506e6*I """ R = parent or s_parent(x) - return _mpmath_utils_call(_mpmath_erfc, x, parent=R) + return _mpmath_call(_mpmath_erfc, x, parent=R) def _derivative_(self, x, diff_param=None): """ @@ -566,7 +566,7 @@ def _evalf_(self, x, parent=None, algorithm=None): 0.17914345462129167649274901663 """ R = parent or s_parent(x) - return _mpmath_utils_call(_mpmath_erfinv, x, parent=R) + return _mpmath_call(_mpmath_erfinv, x, parent=R) def _derivative_(self, x, diff_param=None): """ @@ -671,7 +671,7 @@ def _evalf_(self, x, parent=None, algorithm=None): sage: fresnel_sin(1.0+2*I) # needs sage.symbolic 36.7254648839914 + 15.5877511044046*I """ - return _mpmath_utils_call(_mpmath_fresnels, x, parent=parent) + return _mpmath_call(_mpmath_fresnels, x, parent=parent) def _derivative_(self, x, diff_param=None): """ @@ -769,7 +769,7 @@ def _evalf_(self, x, parent=None, algorithm=None): sage: fresnel_cos(1.0+2*I) # needs sage.symbolic 16.0878713741255 - 36.2256879928817*I """ - return _mpmath_utils_call(_mpmath_fresnelc, x, parent=parent) + return _mpmath_call(_mpmath_fresnelc, x, parent=parent) def _derivative_(self, x, diff_param=None): """ diff --git a/src/sage/functions/exp_integral.py b/src/sage/functions/exp_integral.py index 5fb024c877c..59941c7e14b 100644 --- a/src/sage/functions/exp_integral.py +++ b/src/sage/functions/exp_integral.py @@ -63,7 +63,7 @@ lazy_import('sage.symbolic.ring', 'SR') -lazy_import('sage.libs.mpmath.utils', 'call', as_='_mpmath_utils_call') +lazy_import('sage.libs.mpmath.sage_utils', 'call', as_='_mpmath_call') lazy_import('mpmath', ['chi', 'ci', 'e1', 'ei', 'expint', 'ei', 'li', 'shi', 'si'], as_=['_mpmath_chi', '_mpmath_ci', '_mpmath_e1', '_mpmath_ei', '_mpmath_expint', @@ -225,7 +225,7 @@ def _evalf_(self, n, z, parent=None, algorithm=None): sage: exp_integral_e(1, RealField(100)(1)) # needs sage.rings.real_mpfr 0.21938393439552027367716377546 """ - return _mpmath_utils_call(_mpmath_expint, n, z, parent=parent) + return _mpmath_call(_mpmath_expint, n, z, parent=parent) def _print_latex_(self, n, z): r""" @@ -337,7 +337,7 @@ def _evalf_(self, z, parent=None, algorithm=None): 0.55977359477616081174679593931508523522684689031635351524829 """ - return _mpmath_utils_call(_mpmath_e1, z, parent=parent) + return _mpmath_call(_mpmath_e1, z, parent=parent) def _print_latex_(self, z): r""" @@ -484,7 +484,7 @@ def _evalf_(self, z, parent=None, algorithm=None): 78627.549159462181919862910747947261161321874382421767074759 """ - return _mpmath_utils_call(_mpmath_li, z, parent=parent) + return _mpmath_call(_mpmath_li, z, parent=parent) def _derivative_(self, z, diff_param=None): r""" @@ -680,7 +680,7 @@ def _evalf_(self, z, parent=None, algorithm=None): 0.000000000000000 """ - return _mpmath_utils_call(_mpmath_li, z, offset=True, parent=parent) + return _mpmath_call(_mpmath_li, z, offset=True, parent=parent) def _derivative_(self, z, diff_param=None): r""" @@ -871,7 +871,7 @@ def _evalf_(self, z, parent=None, algorithm=None): sage: sin_integral(-1e23) # needs mpmath -1.57079632679490 """ - return _mpmath_utils_call(_mpmath_si, z, parent=parent) + return _mpmath_call(_mpmath_si, z, parent=parent) def _derivative_(self, z, diff_param=None): r""" @@ -1015,7 +1015,7 @@ def _evalf_(self, z, parent=None, algorithm=None): 0.83786694098020824089467857943 + 1.5707963267948966192313216916*I """ - return _mpmath_utils_call(_mpmath_ci, z, parent=parent) + return _mpmath_call(_mpmath_ci, z, parent=parent) def _derivative_(self, z, diff_param=None): r""" @@ -1167,7 +1167,7 @@ def _evalf_(self, z, parent=None, algorithm=None): 0.94608307036718301494135331382*I """ - return _mpmath_utils_call(_mpmath_shi, z, parent=parent) + return _mpmath_call(_mpmath_shi, z, parent=parent) def _derivative_(self, z, diff_param=None): r""" @@ -1295,7 +1295,7 @@ def _evalf_(self, z, parent=None, algorithm=None): 0.33740392290096813466264620389 + 1.5707963267948966192313216916*I """ - return _mpmath_utils_call(_mpmath_chi, z, parent=parent) + return _mpmath_call(_mpmath_chi, z, parent=parent) def _derivative_(self, z, diff_param=None): r""" @@ -1415,7 +1415,7 @@ def _evalf_(self, x, parent=None, algorithm=None): sage: Ei(3+I).n() 7.82313467600158 + 6.09751978399231*I """ - return _mpmath_utils_call(_mpmath_ei, x, parent=parent) + return _mpmath_call(_mpmath_ei, x, parent=parent) def _derivative_(self, x, diff_param=None): """ diff --git a/src/sage/functions/gamma.py b/src/sage/functions/gamma.py index 8ecf834a8a8..84f6f7af48d 100644 --- a/src/sage/functions/gamma.py +++ b/src/sage/functions/gamma.py @@ -17,8 +17,8 @@ lazy_import('sage.symbolic.constants', 'pi') -lazy_import('sage.libs.mpmath.utils', 'call', as_='_mpmath_utils_call') -lazy_import('mpmath', 'gammainc', as_='_mpmath_gammainc') +lazy_import('sage.libs.mpmath.sage_utils', 'call', as_='_mpmath_call') +lazy_import('sage.libs.mpmath.all', 'gammainc', as_='_mpmath_gammainc') class Function_gamma(GinacFunction): @@ -158,7 +158,7 @@ def __init__(self): Check that the implementations roughly agrees (note there might be difference of several ulp on more complicated entries):: - sage: import mpmath # needs mpmath + sage: import sage.libs.mpmath as mpmath # needs mpmath sage: float(gamma(10.)) == gamma(10.r) == float(gamma(mpmath.mpf(10))) # needs mpmath True sage: float(gamma(8.5)) == gamma(8.5r) == float(gamma(mpmath.mpf(8.5))) # needs mpmath @@ -481,7 +481,7 @@ def _evalf_(self, x, y, parent=None, algorithm='pari'): if algorithm == 'pari': v = ComplexField(prec)(x).gamma_inc(y) else: - v = ComplexField(prec)(_mpmath_utils_call(_mpmath_gammainc, x, y, parent=R)) + v = ComplexField(prec)(_mpmath_call(_mpmath_gammainc, x, y, parent=R)) if v.is_real(): return R(v) else: @@ -612,7 +612,7 @@ def _evalf_(self, x, y, parent=None, algorithm='mpmath'): Cx = ComplexField(prec)(x) v = Cx.gamma() - Cx.gamma_inc(y) else: - v = ComplexField(prec)(_mpmath_utils_call(_mpmath_gammainc, x, 0, y, parent=R)) + v = ComplexField(prec)(_mpmath_call(_mpmath_gammainc, x, 0, y, parent=R)) return R(v) if v.is_real() else C(v) def _derivative_(self, x, y, diff_param=None): diff --git a/src/sage/functions/hypergeometric.py b/src/sage/functions/hypergeometric.py index 1c2712382f3..eeeaf475c0f 100644 --- a/src/sage/functions/hypergeometric.py +++ b/src/sage/functions/hypergeometric.py @@ -192,10 +192,10 @@ lazy_import('sage.symbolic.constants', 'pi') lazy_import('sage.symbolic.ring', 'SR') -lazy_import('sage.libs.mpmath.utils', 'call', as_='_mpmath_utils_call') -lazy_import('mpmath', 'hyp1f1', as_='_mpmath_hyp1f1') -lazy_import('mpmath', 'hyper', as_='_mpmath_hyper') -lazy_import('mpmath', 'hyperu', as_='_mpmath_hyperu') +lazy_import('sage.libs.mpmath.sage_utils', 'call', as_='_mpmath_call') +lazy_import('sage.libs.mpmath.all', 'hyp1f1', as_='_mpmath_hyp1f1') +lazy_import('sage.libs.mpmath.all', 'hyper', as_='_mpmath_hyper') +lazy_import('sage.libs.mpmath.all', 'hyperu', as_='_mpmath_hyperu') def rational_param_as_tuple(x): @@ -374,7 +374,7 @@ def _evalf_(self, a, b, z, parent, algorithm=None): raise TypeError("The first two parameters must be of type list") aa = [rational_param_as_tuple(c) for c in a] bb = [rational_param_as_tuple(c) for c in b] - return _mpmath_utils_call(_mpmath_hyper, aa, bb, z, parent=parent) + return _mpmath_call(_mpmath_hyper, aa, bb, z, parent=parent) def _tderivative_(self, a, b, z, *args, **kwargs): """ @@ -1010,7 +1010,7 @@ def _evalf_(self, a, b, z, parent, algorithm=None): sage: hypergeometric_M(1,1,1).n() # needs mpmath 2.71828182845905 """ - return _mpmath_utils_call(_mpmath_hyp1f1, a, b, z, parent=parent) + return _mpmath_call(_mpmath_hyp1f1, a, b, z, parent=parent) def _derivative_(self, a, b, z, diff_param): """ @@ -1115,7 +1115,7 @@ def _evalf_(self, a, b, z, parent, algorithm=None): sage: hypergeometric_U(1,1,1).n() # needs mpmath 0.596347362323194 """ - return _mpmath_utils_call(_mpmath_hyperu, a, b, z, parent=parent) + return _mpmath_call(_mpmath_hyperu, a, b, z, parent=parent) def _derivative_(self, a, b, z, diff_param): """ diff --git a/src/sage/functions/jacobi.py b/src/sage/functions/jacobi.py index 629b24ce930..016165473ef 100644 --- a/src/sage/functions/jacobi.py +++ b/src/sage/functions/jacobi.py @@ -158,8 +158,8 @@ lazy_import('sage.misc.latex', 'latex') -lazy_import('sage.libs.mpmath.utils', 'call', as_='_mpmath_utils_call') -lazy_import('mpmath', 'ellipfun', as_='_mpmath_ellipfun') +lazy_import('sage.libs.mpmath.sage_utils', 'call', as_='_mpmath_call') +lazy_import('sage.libs.mpmath.all', 'ellipfun', as_='_mpmath_ellipfun') HALF = QQ((1, 2)) @@ -367,7 +367,7 @@ def _evalf_(self, x, m, parent, algorithm=None): sage: jacobi_dn(I, I).n() # needs mpmath sage.symbolic 0.874189950651018 + 0.667346865048825*I """ - return _mpmath_utils_call(_mpmath_ellipfun, self.kind, x, m, parent=parent) + return _mpmath_call(_mpmath_ellipfun, self.kind, x, m, parent=parent) def _derivative_(self, x, m, diff_param): r""" @@ -377,7 +377,7 @@ def _derivative_(self, x, m, diff_param): that the derivatives are correct by computing the series:: sage: # needs mpmath sage.symbolic - sage: from mpmath import almosteq + sage: from sage.libs.mpmath.all import almosteq sage: a = 0.9327542442482303 sage: b = 0.7402326293643771 sage: almosteq(jacobi_sn(x, b).series(x, 10).subs(x=a), @@ -568,7 +568,7 @@ def _eval_(self, x, m): Check that the simplifications are correct:: sage: # needs mpmath sage.symbolic - sage: from mpmath import almosteq + sage: from sage.libs.mpmath.all import almosteq sage: almosteq(n(inverse_jacobi_cd(1, -8, hold=True)), ....: n(inverse_jacobi_cd(1, -8))) True @@ -725,7 +725,7 @@ def _evalf_(self, x, m, parent, algorithm=None): sage: inverse_jacobi_cd(3, 4).n(100) # needs mpmath -0.67214752201235862490069823239 + 2.1565156474996432354386749988*I """ - return _mpmath_utils_call(inverse_jacobi_f, self.kind, x, m, parent=parent) + return _mpmath_call(inverse_jacobi_f, self.kind, x, m, parent=parent) def _derivative_(self, x, m, diff_param): r""" @@ -735,7 +735,7 @@ def _derivative_(self, x, m, diff_param): ``x = inverse_jacobi_pq(y, m)``:: sage: # needs mpmath sage.symbolic - sage: from mpmath import almosteq + sage: from sage.libs.mpmath.all import almosteq sage: a = 0.130103220857094 sage: b = 0.437176765041986 sage: m = var('m') @@ -1110,7 +1110,7 @@ def _evalf_(self, x, m, parent, algorithm=None): sage: jacobi_am(1, 2).n(100) # needs mpmath 0.73704379494724574105101929735 """ - return _mpmath_utils_call(jacobi_am_f, x, m, parent=parent) + return _mpmath_call(jacobi_am_f, x, m, parent=parent) def _derivative_(self, x, m, diff_param): r""" @@ -1160,7 +1160,7 @@ def inverse_jacobi_f(kind, x, m): TESTS:: - sage: from mpmath import ellipfun, chop # needs mpmath + sage: from sage.libs.mpmath.all import ellipfun, chop # needs mpmath sage: from sage.functions.jacobi import inverse_jacobi_f sage: # needs mpmath @@ -1294,7 +1294,7 @@ def inverse_jacobi_f(kind, x, m): sage: chop(ellipfun('ds', inverse_jacobi_f('ds', 4, 0.25), 0.25)) # needs mpmath mpf('4.0') """ - from mpmath import mp as ctx + from sage.libs.mpmath.all import mp as ctx prec = ctx.prec try: x = ctx.convert(x) @@ -1636,7 +1636,7 @@ def jacobi_am_f(x, m): TESTS:: sage: # needs mpmath - sage: from mpmath import ellipf + sage: from sage.libs.mpmath.all import ellipf sage: from sage.functions.jacobi import jacobi_am_f sage: ellipf(jacobi_am_f(0.5, 1), 1) mpf('0.5') @@ -1651,7 +1651,7 @@ def jacobi_am_f(x, m): sage: jacobi_am_f(-3, 2) mpf('0.36067407399586108') """ - from mpmath import mp as ctx + from sage.libs.mpmath.all import mp as ctx prec = ctx.prec try: x = ctx.convert(x) diff --git a/src/sage/functions/log.py b/src/sage/functions/log.py index 38c6ca08bbe..ef848351c7b 100644 --- a/src/sage/functions/log.py +++ b/src/sage/functions/log.py @@ -29,9 +29,9 @@ lazy_import('sage.libs.flint.arith', 'harmonic_number', as_='_flint_harmonic_number') -lazy_import('sage.libs.mpmath.utils', 'call', as_='_mpmath_utils_call') -lazy_import('mpmath', 'harmonic', as_='_mpmath_harmonic') -lazy_import('mpmath', 'lambertw', as_='_mpmath_lambertw') +lazy_import('sage.libs.mpmath.sage_utils', 'call', as_='_mpmath_call') +lazy_import('sage.libs.mpmath.all', 'harmonic', as_='_mpmath_harmonic') +lazy_import('sage.libs.mpmath.all', 'lambertw', as_='_mpmath_lambertw') lazy_import('sympy', 'polylog', as_='_sympy_polylog') lazy_import('sympy', 'sympify', as_='_sympify') @@ -812,7 +812,7 @@ def _evalf_(self, n, z, parent=None, algorithm=None): elif R is complex or R is CDF: return R(_scipy_lambertw(z, n)) else: - return _mpmath_utils_call(_mpmath_lambertw, z, n, parent=R) + return _mpmath_call(_mpmath_lambertw, z, n, parent=R) def _derivative_(self, n, z, diff_param=None): r""" @@ -1375,7 +1375,7 @@ def _evalf_(self, z, parent=None, algorithm='mpmath'): sage: harmonic_number(1.0*I) # needs sage.symbolic 0.671865985524010 + 1.07667404746858*I """ - return _mpmath_utils_call(_mpmath_harmonic, z, parent=parent) + return _mpmath_call(_mpmath_harmonic, z, parent=parent) def _derivative_(self, z, diff_param=None): """ diff --git a/src/sage/functions/orthogonal_polys.py b/src/sage/functions/orthogonal_polys.py index 7a9322973ad..012b87545ac 100644 --- a/src/sage/functions/orthogonal_polys.py +++ b/src/sage/functions/orthogonal_polys.py @@ -414,7 +414,7 @@ lazy_import('sage.symbolic.ring', 'SR') lazy_import('sage.calculus.calculus', 'maxima', as_='_maxima') -lazy_import('sage.libs.mpmath.utils', 'call', as_='_mpmath_utils_call') +lazy_import('sage.libs.mpmath.sage_utils', 'call', as_='_mpmath_call') lazy_import('sage.libs.mpmath.all', 'chebyt', as_='_mpmath_chebyt') lazy_import('sage.libs.mpmath.all', 'chebyu', as_='_mpmath_chebyu') lazy_import('sage.libs.mpmath.all', 'laguerre', as_='_mpmath_laguerre') @@ -633,8 +633,8 @@ def _eval_(self, n, x): # n is not an integer and neither n nor x is symbolic. # We assume n and x are real/complex and evaluate numerically + import sage.libs.mpmath.all as mpmath try: - import sage.libs.mpmath.all as mpmath return self._evalf_(n, x) except mpmath.NoConvergence: warnings.warn("mpmath failed, keeping expression unevaluated", @@ -800,7 +800,7 @@ def _evalf_(self, n, x, **kwds): if not isinstance(real_parent, (sage.rings.abc.RealField, sage.rings.abc.ComplexField)): raise TypeError("cannot evaluate chebyshev_T with parent {}".format(real_parent)) - return _mpmath_utils_call(_mpmath_chebyt, n, x, parent=real_parent) + return _mpmath_call(_mpmath_chebyt, n, x, parent=real_parent) def eval_formula(self, n, x): """ @@ -1168,7 +1168,7 @@ def _evalf_(self, n, x, **kwds): if not isinstance(real_parent, (sage.rings.abc.RealField, sage.rings.abc.ComplexField)): raise TypeError("cannot evaluate chebyshev_U with parent {}".format(real_parent)) - return _mpmath_utils_call(_mpmath_chebyu, n, x, parent=real_parent) + return _mpmath_call(_mpmath_chebyu, n, x, parent=real_parent) def _eval_special_values_(self, n, x): """ @@ -1457,7 +1457,7 @@ def _evalf_(self, n, x, parent=None, **kwds): if ret is not None: return ret - return _mpmath_utils_call(_mpmath_legenq, n, 0, x, parent=parent) + return _mpmath_call(_mpmath_legenq, n, 0, x, parent=parent) def eval_recursive(self, n, arg, **kwds): """ @@ -1839,7 +1839,7 @@ def _evalf_(self, n, m, x, parent=None, **kwds): -0.773063511309286 """ - return _mpmath_utils_call(_mpmath_legenp, n, m, x, parent=parent) + return _mpmath_call(_mpmath_legenp, n, m, x, parent=parent) def eval_gen_poly(self, n, m, arg, **kwds): r""" @@ -1981,7 +1981,7 @@ def _evalf_(self, n, m, x, parent=None, **kwds): if ret is not None: return ret - return _mpmath_utils_call(_mpmath_legenq, n, m, x, parent=parent) + return _mpmath_call(_mpmath_legenq, n, m, x, parent=parent) def eval_recursive(self, n, m, x, **kwds): """ @@ -2343,8 +2343,8 @@ class Func_ultraspherical(GinacFunction): Numerical evaluation with the mpmath library:: sage: # needs mpmath - sage: from mpmath import gegenbauer as gegenbauer_mp - sage: from mpmath import mp + sage: from sage.libs.mpmath.all import gegenbauer as gegenbauer_mp + sage: from sage.libs.mpmath.all import mp sage: mp.pretty = True; mp.dps=25 sage: gegenbauer_mp(-7,0.5,0.3) 0.1291811875 @@ -2514,9 +2514,9 @@ def _evalf_(self, n, x, **kwds): if n < 0: # work around mpmath issue 307 from sage.functions.log import exp - return exp(x) * _mpmath_utils_call(_mpmath_laguerre, -n-1, 0, -x, parent=the_parent) + return exp(x) * _mpmath_call(_mpmath_laguerre, -n-1, 0, -x, parent=the_parent) else: - return _mpmath_utils_call(_mpmath_laguerre, n, 0, x, parent=the_parent) + return _mpmath_call(_mpmath_laguerre, n, 0, x, parent=the_parent) def _derivative_(self, n, x, *args, **kwds): """ @@ -2656,7 +2656,7 @@ def _evalf_(self, n, a, x, **kwds): the_parent = kwds.get('parent', None) if the_parent is None: the_parent = parent(x) - return _mpmath_utils_call(_mpmath_laguerre, n, a, x, parent=the_parent) + return _mpmath_call(_mpmath_laguerre, n, a, x, parent=the_parent) def _derivative_(self, n, a, x, diff_param): """ diff --git a/src/sage/functions/special.py b/src/sage/functions/special.py index 93e032d0677..2368669ed19 100644 --- a/src/sage/functions/special.py +++ b/src/sage/functions/special.py @@ -157,8 +157,8 @@ lazy_import('sage.symbolic.constants', ['I', 'pi']) -lazy_import('sage.libs.mpmath.utils', 'call', as_='_mpmath_utils_call') -lazy_import('mpmath', +lazy_import('sage.libs.mpmath.sage_utils', 'call', as_='_mpmath_call') +lazy_import('sage.libs.mpmath.all', ['spherharm', 'ellipe', 'ellipf', 'ellipk', 'ellippi'], as_=['_mpmath_spherharm', '_mpmath_ellipe', '_mpmath_ellipf', '_mpmath_ellipk', '_mpmath_ellippi']) @@ -329,7 +329,7 @@ def _evalf_(self, n, m, theta, phi, parent, **kwds): True """ - return _mpmath_utils_call(_mpmath_spherharm, n, m, theta, phi, parent=parent) + return _mpmath_call(_mpmath_spherharm, n, m, theta, phi, parent=parent) def _derivative_(self, n, m, theta, phi, diff_param): r""" @@ -591,7 +591,7 @@ def _evalf_(self, z, m, parent=None, algorithm=None): 0.535647771608740 + 1.63996015168665*I """ R = parent or s_parent(z) - return _mpmath_utils_call(_mpmath_ellipe, z, m, parent=R) + return _mpmath_call(_mpmath_ellipe, z, m, parent=R) def _derivative_(self, z, m, diff_param): """ @@ -697,7 +697,7 @@ def _evalf_(self, x, parent=None, algorithm=None): 1.63241178144043 - 0.369219492375499*I """ R = parent or s_parent(x) - return _mpmath_utils_call(_mpmath_ellipe, x, parent=R) + return _mpmath_call(_mpmath_ellipe, x, parent=R) def _derivative_(self, x, diff_param): """ @@ -770,7 +770,7 @@ def _evalf_(self, u, m, parent=None, algorithm=None): 0.7615941559557648881194582... """ R = parent or s_parent(u) - return _mpmath_utils_call(elliptic_eu_f, u, m, parent=R) + return _mpmath_call(elliptic_eu_f, u, m, parent=R) def _derivative_(self, u, m, diff_param): """ @@ -822,7 +822,8 @@ def elliptic_eu_f(u, m): sage: elliptic_eu_f(0.5, 0.1) # needs mpmath mpf('0.49605455128659691') """ - from mpmath import mp as ctx + from sage.functions.jacobi import jacobi_am_f + from sage.libs.mpmath.all import mp as ctx prec = ctx.prec try: u = ctx.convert(u) @@ -942,7 +943,7 @@ def _evalf_(self, z, m, parent=None, algorithm=None): 0.149965060031782 + 0.925097284105771*I """ R = parent or s_parent(z) - return _mpmath_utils_call(_mpmath_ellipf, z, m, parent=R) + return _mpmath_call(_mpmath_ellipf, z, m, parent=R) def _derivative_(self, z, m, diff_param): """ @@ -1065,7 +1066,7 @@ def _evalf_(self, z, parent=None, algorithm=None): 1.42127228104504 + 0.295380284214777*I """ R = parent or s_parent(z) - return _mpmath_utils_call(_mpmath_ellipk, z, parent=R) + return _mpmath_call(_mpmath_ellipk, z, parent=R) def _derivative_(self, z, diff_param): """ @@ -1157,7 +1158,7 @@ def _evalf_(self, n, z, m, parent=None, algorithm=None): 0.0542471560940594 + 0.552096453413081*I """ R = parent or s_parent(z) - return _mpmath_utils_call(_mpmath_ellippi, n, z, m, parent=R) + return _mpmath_call(_mpmath_ellippi, n, z, m, parent=R) def _derivative_(self, n, z, m, diff_param): """ diff --git a/src/sage/functions/transcendental.py b/src/sage/functions/transcendental.py index d0a30362fdf..40c91d80fb4 100644 --- a/src/sage/functions/transcendental.py +++ b/src/sage/functions/transcendental.py @@ -33,8 +33,8 @@ lazy_import('sage.rings.real_double', 'RDF') lazy_import('sage.rings.real_mpfr', ['RR', 'RealField', 'is_RealNumber']) -lazy_import('sage.libs.mpmath.utils', 'call', as_='_mpmath_utils_call') -lazy_import('mpmath', 'zeta', as_='_mpmath_zeta') +lazy_import('sage.libs.mpmath.sage_utils', 'call', as_='_mpmath_call') +lazy_import('sage.libs.mpmath.all', 'zeta', as_='_mpmath_zeta') class Function_zeta(GinacFunction): @@ -272,7 +272,7 @@ def _evalf_(self, s, x, parent=None, algorithm=None): sage: hurwitz_zeta(11/10, 1 + 1j).n() 9.85014164287853 - 1.06139499403981*I """ - return _mpmath_utils_call(_mpmath_zeta, s, x, parent=parent) + return _mpmath_call(_mpmath_zeta, s, x, parent=parent) def _derivative_(self, s, x, diff_param): r""" @@ -360,7 +360,7 @@ def __init__(self): zetaderiv(n, x) sage: zetaderiv(1, 4).n() -0.0689112658961254 - sage: import mpmath; mpmath.diff(lambda x: mpmath.zeta(x), 4) # needs mpmath + sage: import sage.libs.mpmath.all as mpmath; mpmath.diff(lambda x: mpmath.zeta(x), 4) # needs mpmath mpf('-0.068911265896125382') TESTS:: @@ -389,7 +389,7 @@ def _evalf_(self, n, x, parent=None, algorithm=None): sage: zetaderiv(2, 3 + I).n() # needs sage.symbolic 0.0213814086193841 - 0.174938812330834*I """ - return _mpmath_utils_call(_mpmath_zeta, x, 1, n, parent=parent) + return _mpmath_call(_mpmath_zeta, x, 1, n, parent=parent) def _method_arguments(self, k, x, **args): r""" diff --git a/src/sage/interfaces/mathics.py b/src/sage/interfaces/mathics.py index 0bf0bc78829..e01a5a1f3fd 100644 --- a/src/sage/interfaces/mathics.py +++ b/src/sage/interfaces/mathics.py @@ -1058,7 +1058,7 @@ def _sage_(self, locals={}): if self.is_inexact(): m = self.to_mpmath() if self is not m and m is not None: - from sage.libs.mpmath.utils import mpmath_to_sage + from sage.libs.mpmath.sage_utils import mpmath_to_sage return mpmath_to_sage(m, self.get_precision()) s = self.to_sympy() if self is not s and s is not None: diff --git a/src/sage/libs/all__sagemath_mpmath.py b/src/sage/libs/all__sagemath_mpmath.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/sage/libs/mpmath/_vendor/all.py b/src/sage/libs/mpmath/_vendor/all.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/sage/libs/mpmath/_vendor/nodoctest.py b/src/sage/libs/mpmath/_vendor/nodoctest.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/sage/libs/mpmath/all.py b/src/sage/libs/mpmath/all.py index cae40f79314..c06db9707c0 100644 --- a/src/sage/libs/mpmath/all.py +++ b/src/sage/libs/mpmath/all.py @@ -1,16 +1,16 @@ -import mpmath +# sage_setup: distribution = sagemath-mpmath # Patch mpmath to use Cythonized functions from . import utils as _utils # Also import internal functions -from mpmath.libmp import * +from sage.libs.mpmath._vendor.mpmath.libmp import * # Main namespace -from mpmath import * +from sage.libs.mpmath._vendor.mpmath import * -# Utilities -from .utils import call, mpmath_to_sage, sage_to_mpmath +# Utilities used by the Sage library +from .sage_utils import call, mpmath_to_sage, sage_to_mpmath # Use mpmath internal functions for constants, to avoid unnecessary overhead _constants_funcs = { diff --git a/src/sage/libs/mpmath/ext_impl.pxd b/src/sage/libs/mpmath/ext_impl.pxd index b934826ef56..76e1da11aad 100644 --- a/src/sage/libs/mpmath/ext_impl.pxd +++ b/src/sage/libs/mpmath/ext_impl.pxd @@ -1,3 +1,4 @@ +# sage_setup: distribution = sagemath-mpmath from sage.libs.gmp.all cimport mpz_t ctypedef struct MPopts: diff --git a/src/sage/libs/mpmath/ext_impl.pyx b/src/sage/libs/mpmath/ext_impl.pyx index 2d8d2470273..97b09634639 100644 --- a/src/sage/libs/mpmath/ext_impl.pyx +++ b/src/sage/libs/mpmath/ext_impl.pyx @@ -1,3 +1,4 @@ +# sage_setup: distribution = sagemath-mpmath """ This module provides the core implementation of multiprecision floating-point arithmetic. Operations are done in-place. @@ -6,12 +7,12 @@ TESTS: See if :trac:`15118` is fixed:: - sage: import mpmath - sage: mpmath.mpf(0)^(-2) + sage: import sage.libs.mpmath + sage: sage.libs.mpmath.all.mpf(0)^(-2) Traceback (most recent call last): ... ZeroDivisionError - sage: mpmath.zeta(2r, -3r) + sage: sage.libs.mpmath.all.zeta(2r, -3r) Traceback (most recent call last): ... ZeroDivisionError @@ -1063,9 +1064,9 @@ cdef MPF_pow_int(MPF *r, MPF *x, mpz_t n, MPopts opts): mpz_mul(r.exp, x.exp, n) return # TODO: implement efficiently here - import mpmath.libmp + import sage.libs.mpmath._vendor.mpmath.libmp MPF_set_tuple(r, - mpmath.libmp.mpf_pow_int(MPF_to_tuple(x), mpzi(n), + sage.libs.mpmath._vendor.mpmath.libmp.mpf_pow_int(MPF_to_tuple(x), mpzi(n), opts.prec, rndmode_to_python(opts.rounding))) cdef mpz_t _pi_value @@ -1083,7 +1084,7 @@ cdef mpz_set_pi(mpz_t x, int prec): if prec <= _pi_prec: mpz_tdiv_q_2exp(x, _pi_value, _pi_prec-prec) else: - from mpmath.libmp import pi_fixed + from sage.libs.mpmath._vendor.mpmath.libmp import pi_fixed if _pi_prec < 0: mpz_init(_pi_value) mpz_set_integer(_pi_value, pi_fixed(prec)) @@ -1099,7 +1100,7 @@ cdef mpz_set_ln2(mpz_t x, int prec): if prec <= _ln2_prec: mpz_tdiv_q_2exp(x, _ln2_value, _ln2_prec-prec) else: - from mpmath.libmp import ln2_fixed + from sage.libs.mpmath._vendor.mpmath.libmp import ln2_fixed if _ln2_prec < 0: mpz_init(_ln2_value) mpz_set_integer(_ln2_value, ln2_fixed(prec)) @@ -1547,7 +1548,7 @@ cdef _MPF_cos_python(MPF *c, MPF *x, MPopts opts): """ Computes c = cos(x) by calling the mpmath.libmp Python implementation. """ - from mpmath.libmp.libelefun import mpf_cos_sin + from sage.libs.mpmath._vendor.mpmath.libmp.libelefun import mpf_cos_sin ct = mpf_cos_sin(MPF_to_tuple(x), opts.prec, rndmode_to_python(opts.rounding), 1, False) MPF_set_tuple(c, ct) @@ -1556,7 +1557,7 @@ cdef _MPF_sin_python(MPF *s, MPF *x, MPopts opts): """ Computes s = sin(x) by calling the mpmath.libmp Python implementation. """ - from mpmath.libmp.libelefun import mpf_cos_sin + from sage.libs.mpmath._vendor.mpmath.libmp.libelefun import mpf_cos_sin st = mpf_cos_sin(MPF_to_tuple(x), opts.prec, rndmode_to_python(opts.rounding), 2, False) MPF_set_tuple(s, st) @@ -1852,7 +1853,7 @@ cdef MPF_complex_pow_int(MPF *zre, MPF *zim, MPF *xre, MPF *xim, mpz_t n, MPopts xret = MPF_to_tuple(xre) ximt = MPF_to_tuple(xim) - from mpmath.libmp import mpc_pow_int + from sage.libs.mpmath._vendor.mpmath.libmp import mpc_pow_int vr, vi = mpc_pow_int((xret, ximt), mpzi(n), opts.prec, rndmode_to_python(opts.rounding)) MPF_set_tuple(zre, vr) @@ -1897,7 +1898,7 @@ cdef MPF_complex_pow_re(MPF *zre, MPF *zim, MPF *xre, MPF *xim, MPF *y, MPopts o xret = MPF_to_tuple(xre) ximt = MPF_to_tuple(xim) yret = MPF_to_tuple(y) - from mpmath.libmp import mpc_pow_mpf + from sage.libs.mpmath._vendor.mpmath.libmp import mpc_pow_mpf vr, vi = mpc_pow_mpf((xret, ximt), yret, opts.prec, rndmode_to_python(opts.rounding)) MPF_set_tuple(zre, vr) @@ -1915,7 +1916,7 @@ cdef MPF_complex_pow(MPF *zre, MPF *zim, MPF *xre, MPF *xim, MPF *yre, MPF *yim, ximt = MPF_to_tuple(xim) yret = MPF_to_tuple(yre) yimt = MPF_to_tuple(yim) - from mpmath.libmp import mpc_pow + from sage.libs.mpmath._vendor.mpmath.libmp import mpc_pow vr, vi = mpc_pow((xret, ximt), (yret, yimt), opts.prec, rndmode_to_python(opts.rounding)) MPF_set_tuple(zre, vr) @@ -2212,7 +2213,7 @@ cdef MPF_hypsum(MPF *a, MPF *b, int p, int q, param_types, str ztype, coeffs, z, break if n > MAX: - from mpmath.libmp import NoConvergence + from sage.libs.mpmath._vendor.mpmath.libmp import NoConvergence raise NoConvergence('Hypergeometric series converges too slowly. Try increasing maxterms.') # +1 all parameters for next iteration diff --git a/src/sage/libs/mpmath/ext_libmp.pyx b/src/sage/libs/mpmath/ext_libmp.pyx index 5dccf596a91..d63511d4bfe 100644 --- a/src/sage/libs/mpmath/ext_libmp.pyx +++ b/src/sage/libs/mpmath/ext_libmp.pyx @@ -1,3 +1,4 @@ +# sage_setup: distribution = sagemath-mpmath """ Faster versions of some key functions in mpmath.libmp """ @@ -60,14 +61,14 @@ def mpf_sqrt(tuple x, int prec, str rnd='d'): EXAMPLES:: - sage: from mpmath.libmp import mpf_sqrt, from_float, to_float + sage: from sage.libs.mpmath._vendor.mpmath.libmp import mpf_sqrt, from_float, to_float sage: x = from_float(2) sage: y = mpf_sqrt(x, 53, 'n') sage: to_float(y) 1.4142135623730951 """ if x[0]: - import mpmath.libmp as libmp + import sage.libs.mpmath._vendor.mpmath.libmp as libmp raise libmp.ComplexResult("square root of a negative number") cdef MPopts opts MPF_set_tuple(&tmp1, x) @@ -83,14 +84,14 @@ def mpf_log(tuple x, int prec, str rnd='d'): EXAMPLES:: - sage: from mpmath.libmp import mpf_log, from_float, to_float + sage: from sage.libs.mpmath._vendor.mpmath.libmp import mpf_log, from_float, to_float sage: x = from_float(2) sage: y = mpf_log(x, 53, 'n') sage: to_float(y) 0.6931471805599453 """ if x[0]: - import mpmath.libmp as libmp + import sage.libs.mpmath._vendor.mpmath.libmp as libmp raise libmp.ComplexResult("logarithm of a negative number") cdef MPopts opts MPF_set_tuple(&tmp1, x) @@ -106,7 +107,7 @@ def mpf_exp(tuple x, int prec, str rnd='d'): EXAMPLES:: - sage: from mpmath.libmp import mpf_exp, from_float, to_float + sage: from sage.libs.mpmath._vendor.mpmath.libmp import mpf_exp, from_float, to_float sage: x = from_float(2) sage: z = mpf_exp(x, 53, 'n') sage: to_float(z) @@ -126,7 +127,7 @@ def mpf_cos(tuple x, int prec, str rnd='d'): EXAMPLES:: - sage: from mpmath.libmp import mpf_cos, from_float, to_float + sage: from sage.libs.mpmath._vendor.mpmath.libmp import mpf_cos, from_float, to_float sage: x = from_float(1) sage: y = mpf_cos(x, 53, 'n') sage: to_float(y) @@ -146,7 +147,7 @@ def mpf_sin(tuple x, int prec, str rnd='d'): EXAMPLES:: - sage: from mpmath.libmp import mpf_sin, from_float, to_float + sage: from sage.libs.mpmath._vendor.mpmath.libmp import mpf_sin, from_float, to_float sage: x = from_float(1) sage: y = mpf_sin(x, 53, 'n') sage: to_float(y) @@ -166,7 +167,7 @@ def mpc_sqrt(tuple z, int prec, str rnd='d'): EXAMPLES:: - sage: from mpmath.libmp import mpc_sqrt, from_float, to_float + sage: from sage.libs.mpmath._vendor.mpmath.libmp import mpc_sqrt, from_float, to_float sage: z = from_float(-2), from_float(0) sage: re, im = mpc_sqrt(z, 53, 'n') sage: to_float(re), to_float(im) @@ -189,7 +190,7 @@ def mpc_exp(tuple z, int prec, str rnd='d'): EXAMPLES:: - sage: from mpmath.libmp import mpc_exp, from_float, to_float + sage: from sage.libs.mpmath._vendor.mpmath.libmp import mpc_exp, from_float, to_float sage: z = from_float(0), from_float(1) sage: re, im = mpc_exp(z, 53, 'n') sage: to_float(re), to_float(im) @@ -212,7 +213,7 @@ def mpf_pow(tuple x, tuple y, int prec, str rnd='d'): EXAMPLES:: - sage: from mpmath.libmp import mpf_pow, from_float, to_float + sage: from sage.libs.mpmath._vendor.mpmath.libmp import mpf_pow, from_float, to_float sage: x = from_float(2) sage: y = from_float(3) sage: z = mpf_pow(x, y, 53, 'n') @@ -226,6 +227,6 @@ def mpf_pow(tuple x, tuple y, int prec, str rnd='d'): opts.rounding = rndmode_from_python(rnd) opts.prec = prec if MPF_pow(&tmp1, &tmp1, &tmp2, opts): - import mpmath.libmp as libmp + import sage.libs.mpmath._vendor.mpmath.libmp as libmp raise libmp.ComplexResult("negative number raised to a fractional power") return MPF_to_tuple(&tmp1) diff --git a/src/sage/libs/mpmath/ext_main.pxd b/src/sage/libs/mpmath/ext_main.pxd index d810e75f544..a3f040af6b7 100644 --- a/src/sage/libs/mpmath/ext_main.pxd +++ b/src/sage/libs/mpmath/ext_main.pxd @@ -1 +1,2 @@ +# sage_setup: distribution = sagemath-mpmath from .ext_impl cimport * diff --git a/src/sage/libs/mpmath/ext_main.pyx b/src/sage/libs/mpmath/ext_main.pyx index 845c85234a6..9dc289e0984 100644 --- a/src/sage/libs/mpmath/ext_main.pyx +++ b/src/sage/libs/mpmath/ext_main.pyx @@ -1,3 +1,4 @@ +# sage_setup: distribution = sagemath-mpmath """ mpmath floating-point numbers @@ -40,11 +41,11 @@ DEF S_NAN = 5 from .ext_impl cimport * -import mpmath.rational as rationallib -import mpmath.libmp as libmp -import mpmath.function_docs as function_docs -from mpmath.libmp import to_str -from mpmath.libmp import repr_dps, prec_to_dps, dps_to_prec +import sage.libs.mpmath._vendor.mpmath.rational as rationallib +import sage.libs.mpmath._vendor.mpmath.libmp as libmp +import sage.libs.mpmath._vendor.mpmath.function_docs as function_docs +from sage.libs.mpmath._vendor.mpmath.libmp import to_str +from sage.libs.mpmath._vendor.mpmath.libmp import repr_dps, prec_to_dps, dps_to_prec DEF OP_ADD = 0 DEF OP_SUB = 1 @@ -395,9 +396,9 @@ cdef class Context: """ At present, only a single global context should exist :: - sage: from mpmath import mp + sage: from sage.libs.mpmath.all import mp sage: type(mp) - + """ global global_opts, global_context global_opts = opts_double_precision @@ -414,10 +415,10 @@ cdef class Context: TESTS :: - sage: import mpmath - sage: mpmath.mp.prec = 100 - sage: mpmath.mp.default() - sage: mpmath.mp.prec + sage: import sage.libs.mpmath + sage: sage.libs.mpmath.all.mp.prec = 100 + sage: sage.libs.mpmath.all.mp.default() + sage: sage.libs.mpmath.all.mp.prec 53 """ global global_opts @@ -429,7 +430,7 @@ cdef class Context: """ Controls the working precision in bits :: - sage: from mpmath import mp + sage: from sage.libs.mpmath.all import mp sage: mp.prec = 100 sage: mp.prec 100 @@ -443,7 +444,7 @@ cdef class Context: """ Controls the working precision in bits :: - sage: from mpmath import mp + sage: from sage.libs.mpmath.all import mp sage: mp.prec = 100 sage: mp.prec 100 @@ -457,7 +458,7 @@ cdef class Context: """ Controls the working precision in decimal digits :: - sage: from mpmath import mp + sage: from sage.libs.mpmath.all import mp sage: mp.dps = 100 sage: mp.prec 336 @@ -471,7 +472,7 @@ cdef class Context: """ Controls the working precision in decimal digits :: - sage: from mpmath import mp + sage: from sage.libs.mpmath.all import mp sage: mp.dps = 100 sage: mp.prec 336 @@ -490,7 +491,7 @@ cdef class Context: """ Returns the precision and rounding mode :: - sage: from mpmath import mp + sage: from sage.libs.mpmath.all import mp sage: mp._get_prec_rounding() (53, 'n') """ @@ -502,8 +503,8 @@ cdef class Context: """ Creates an mpf from tuple data :: - sage: import mpmath - sage: float(mpmath.mp.make_mpf((0,1,-1,1))) + sage: import sage.libs.mpmath + sage: float(sage.libs.mpmath.all.mp.make_mpf((0,1,-1,1))) 0.5 """ cdef mpf x @@ -515,8 +516,8 @@ cdef class Context: """ Creates an mpc from tuple data :: - sage: import mpmath - sage: complex(mpmath.mp.make_mpc(((0,1,-1,1), (1,1,-2,1)))) + sage: import sage.libs.mpmath + sage: complex(sage.libs.mpmath.all.mp.make_mpc(((0,1,-1,1), (1,1,-2,1)))) (0.5-0.25j) """ cdef mpc x @@ -537,7 +538,7 @@ cdef class Context: TESTS :: - sage: from mpmath import mp, convert + sage: from sage.libs.mpmath.all import mp, convert sage: mp.dps = 15; mp.pretty = False sage: convert(3.5) mpf('3.5') @@ -571,7 +572,7 @@ cdef class Context: TESTS:: - sage: from mpmath import isnan, nan + sage: from sage.libs.mpmath.all import isnan, nan sage: isnan(nan), isnan(3) (True, False) """ @@ -602,7 +603,7 @@ cdef class Context: TESTS:: - sage: from mpmath import isinf, inf, mpc + sage: from sage.libs.mpmath.all import isinf, inf, mpc sage: isinf(inf) True sage: isinf(-inf) @@ -648,7 +649,7 @@ cdef class Context: TESTS :: - sage: from mpmath import isnormal, inf, nan, mpc + sage: from sage.libs.mpmath.all import isnormal, inf, nan, mpc sage: isnormal(3) True sage: isnormal(0) @@ -689,7 +690,7 @@ cdef class Context: TESTS :: - sage: from mpmath import isint, mpf, inf + sage: from sage.libs.mpmath.all import isint, mpf, inf sage: isint(3) True sage: isint(mpf(3)) @@ -747,7 +748,7 @@ cdef class Context: TESTS :: - sage: from mpmath import mp, fsum + sage: from sage.libs.mpmath.all import mp, fsum sage: mp.dps = 15; mp.pretty = False sage: fsum([1, 2, 0.5, 7]) mpf('10.5') @@ -866,7 +867,7 @@ cdef class Context: TESTS:: - sage: from mpmath import mp, fdot + sage: from sage.libs.mpmath.all import mp, fdot sage: mp.dps = 15; mp.pretty = False sage: A = [2, 1.5r, 3] sage: B = [1, -1, 2] @@ -978,7 +979,7 @@ cdef class Context: TESTS :: - sage: from mpmath import mp + sage: from sage.libs.mpmath.all import mp sage: mp.pretty = True sage: (x, T) = mp._convert_param(3) sage: (x, type(x).__name__, T) @@ -1052,7 +1053,7 @@ cdef class Context: TESTS:: - sage: from mpmath import * + sage: from sage.libs.mpmath.all import * sage: mp.pretty = True sage: mag(10), mag(10.0), mag(mpf(10)), int(ceil(log(10,2))) (4, 4, 4, 4) @@ -1129,7 +1130,7 @@ cdef class Context: TESTS :: - sage: from mpmath import mp + sage: from sage.libs.mpmath.all import mp sage: mp.pretty = False sage: f = lambda x, prec, rnd: x sage: g = mp._wrap_libmp_function(f) @@ -1154,7 +1155,7 @@ cdef class Context: TESTS :: - sage: from mpmath import mp + sage: from sage.libs.mpmath.all import mp sage: mp._wrap_specfun("foo", lambda ctx, x: ctx.prec + x, True) sage: mp.pretty = False; mp.prec = 53 sage: mp.foo(5) # 53 + 10 guard bits + 5 @@ -1195,7 +1196,7 @@ cdef class Context: TESTS :: - sage: from mpmath import mp + sage: from sage.libs.mpmath.all import mp sage: mp.dps = 15 sage: print(mp.sqrt(2)) # indirect doctest 1.4142135623731 @@ -1233,7 +1234,7 @@ cdef class Context: EXAMPLES:: - sage: from mpmath import mp + sage: from sage.libs.mpmath.all import mp sage: mp.dps = 15 sage: print(mp.exp(2)) # indirect doctest 7.38905609893065 @@ -1265,7 +1266,7 @@ cdef class Context: EXAMPLES:: - sage: from mpmath import mp + sage: from sage.libs.mpmath.all import mp sage: mp.dps = 15 sage: print(mp.cos(2)) # indirect doctest -0.416146836547142 @@ -1302,7 +1303,7 @@ cdef class Context: EXAMPLES:: - sage: from mpmath import mp + sage: from sage.libs.mpmath.all import mp sage: mp.dps = 15 sage: print(mp.sin(2)) # indirect doctest 0.909297426825682 @@ -1339,7 +1340,7 @@ cdef class Context: EXAMPLES:: - sage: from mpmath import mp + sage: from sage.libs.mpmath.all import mp sage: print(mp.ln(2)) # indirect doctest 0.693147180559945 sage: print(mp.ln(-2)) @@ -1400,8 +1401,8 @@ cdef class wrapped_libmp_function: TESTS :: sage: from sage.libs.mpmath.ext_main import wrapped_libmp_function - sage: from mpmath import mp - sage: from mpmath.libmp import mpf_exp, mpf_sqrt + sage: from sage.libs.mpmath.all import mp + sage: from sage.libs.mpmath._vendor.mpmath.libmp import mpf_exp, mpf_sqrt sage: f = lambda x, prec, rnd: mpf_exp(mpf_sqrt(x, prec, rnd), prec, rnd) sage: g = wrapped_libmp_function(f) sage: g(mp.mpf(3)) @@ -1427,7 +1428,7 @@ cdef class wrapped_libmp_function: conversions and uses the default working precision unless overridden :: - sage: from mpmath import mp + sage: from sage.libs.mpmath.all import mp sage: mp.sinh(2) mpf('3.6268604078470186') sage: mp.sinh(2, prec=10) @@ -1491,7 +1492,7 @@ cdef class wrapped_specfun: TESTS :: - sage: import mpmath + sage: import sage.libs.mpmath sage: from sage.libs.mpmath.ext_main import wrapped_specfun sage: f = wrapped_specfun("f", lambda ctx, x: x) sage: f.name @@ -1507,7 +1508,7 @@ cdef class wrapped_specfun: to mpmath number, and the internal working precision is increased by a few bits to suppress typical rounding errors :: - sage: from mpmath import mp + sage: from sage.libs.mpmath.all import mp sage: from sage.libs.mpmath.ext_main import wrapped_specfun sage: f = wrapped_specfun("f", lambda ctx, x: x + ctx.prec) sage: f("1") # 53 + 10 guard bits + 1 @@ -1532,7 +1533,7 @@ cdef class mpnumber: Comparison of mpmath numbers. Compatible numerical types are automatically converted to mpmath numbers :: - sage: from mpmath import mpf, mpc + sage: from sage.libs.mpmath.all import mpf, mpc sage: mpf(3) == mpc(3) True sage: mpf(3) == mpc(4) @@ -1554,7 +1555,7 @@ cdef class mpnumber: Addition of mpmath numbers. Compatible numerical types are automatically converted to mpmath numbers :: - sage: from mpmath import mpf, mpc + sage: from sage.libs.mpmath.all import mpf, mpc sage: mpf(3) + mpc(3) mpc(real='6.0', imag='0.0') sage: float(4) + mpf(3) @@ -1567,7 +1568,7 @@ cdef class mpnumber: Subtraction of mpmath numbers. Compatible numerical types are automatically converted to mpmath numbers :: - sage: from mpmath import mpf, mpc + sage: from sage.libs.mpmath.all import mpf, mpc sage: mpf(5) - mpc(3) mpc(real='2.0', imag='0.0') sage: float(4) - mpf(3) @@ -1580,7 +1581,7 @@ cdef class mpnumber: Multiplication of mpmath numbers. Compatible numerical types are automatically converted to mpmath numbers :: - sage: from mpmath import mpf, mpc + sage: from sage.libs.mpmath.all import mpf, mpc sage: mpf(5) * mpc(3) mpc(real='15.0', imag='0.0') sage: float(4) * mpf(3) @@ -1593,7 +1594,7 @@ cdef class mpnumber: Division of mpmath numbers. Compatible numerical types are automatically converted to mpmath numbers :: - sage: from mpmath import mpf, mpc + sage: from sage.libs.mpmath.all import mpf, mpc sage: mpf(10) / mpc(5) mpc(real='2.0', imag='0.0') sage: float(9) / mpf(3) @@ -1606,7 +1607,7 @@ cdef class mpnumber: Remainder of mpmath numbers. Compatible numerical types are automatically converted to mpmath numbers :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: mpf(12) % float(7) mpf('5.0') """ @@ -1617,7 +1618,7 @@ cdef class mpnumber: Exponentiation of mpmath numbers. Compatible numerical types are automatically converted to mpmath numbers :: - sage: from mpmath import mpf, mpc + sage: from sage.libs.mpmath.all import mpf, mpc sage: mpf(10) ** mpc(3) mpc(real='1000.0', imag='0.0') sage: mpf(3) ** float(2) @@ -1632,7 +1633,7 @@ cdef class mpnumber: Check if two numbers are approximately equal to within the specified tolerance (see mp.almosteq for documentation) :: - sage: from mpmath import mpf, mpc + sage: from sage.libs.mpmath.all import mpf, mpc sage: mpf(3).ae(mpc(3,1e-10)) False sage: mpf(3).ae(mpc(3,1e-10), rel_eps=1e-5) @@ -1651,7 +1652,7 @@ cdef class mpf_base(mpnumber): """ Support hashing of derived classes :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: from sage.libs.mpmath.ext_main import mpf_base sage: class X(mpf_base): _mpf_ = mpf(3.25)._mpf_ sage: hash(X()) == hash(float(X())) @@ -1663,7 +1664,7 @@ cdef class mpf_base(mpnumber): """ Support repr() of derived classes :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: from sage.libs.mpmath.ext_main import mpf_base sage: class X(mpf_base): _mpf_ = mpf(3.25)._mpf_ sage: repr(X()) @@ -1678,7 +1679,7 @@ cdef class mpf_base(mpnumber): """ Support str() of derived classes :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: from sage.libs.mpmath.ext_main import mpf_base sage: class X(mpf_base): _mpf_ = mpf(3.25)._mpf_ sage: str(X()) @@ -1691,7 +1692,7 @@ cdef class mpf_base(mpnumber): """ Support real part of derived classes :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: from sage.libs.mpmath.ext_main import mpf_base sage: class X(mpf_base): _mpf_ = mpf(3.25)._mpf_ sage: X().real @@ -1704,7 +1705,7 @@ cdef class mpf_base(mpnumber): """ Support imaginary part of derived classes :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: from sage.libs.mpmath.ext_main import mpf_base sage: class X(mpf_base): _mpf_ = mpf(3.25)._mpf_ sage: X().imag @@ -1716,7 +1717,7 @@ cdef class mpf_base(mpnumber): """ Support complex conjugate of derived classes :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: from sage.libs.mpmath.ext_main import mpf_base sage: class X(mpf_base): _mpf_ = mpf(3.25)._mpf_ sage: X().conjugate() @@ -1729,7 +1730,7 @@ cdef class mpf_base(mpnumber): """ Support mantissa extraction of derived classes :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: from sage.libs.mpmath.ext_main import mpf_base sage: class X(mpf_base): _mpf_ = mpf(3.25)._mpf_ sage: X().man @@ -1742,7 +1743,7 @@ cdef class mpf_base(mpnumber): """ Support exponent extraction of derived classes :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: from sage.libs.mpmath.ext_main import mpf_base sage: class X(mpf_base): _mpf_ = mpf(3.25)._mpf_ sage: X().exp @@ -1755,7 +1756,7 @@ cdef class mpf_base(mpnumber): """ Support bitcount extraction of derived classes :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: from sage.libs.mpmath.ext_main import mpf_base sage: class X(mpf_base): _mpf_ = mpf(3.25)._mpf_ sage: X().bc @@ -1768,7 +1769,7 @@ cdef class mpf_base(mpnumber): """ Support integer conversion for derived classes :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: from sage.libs.mpmath.ext_main import mpf_base sage: class X(mpf_base): _mpf_ = mpf(3.25)._mpf_ sage: int(X()) @@ -1780,7 +1781,7 @@ cdef class mpf_base(mpnumber): """ Support float conversion for derived classes :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: from sage.libs.mpmath.ext_main import mpf_base sage: class X(mpf_base): _mpf_ = mpf(3.25)._mpf_ sage: float(X()) @@ -1792,7 +1793,7 @@ cdef class mpf_base(mpnumber): """ Support complex conversion for derived classes :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: from sage.libs.mpmath.ext_main import mpf_base sage: class X(mpf_base): _mpf_ = mpf(3.25)._mpf_ sage: complex(X()) @@ -1804,7 +1805,7 @@ cdef class mpf_base(mpnumber): """ Support conversion to a fixed-point integer for derived classes :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: from sage.libs.mpmath.ext_main import mpf_base sage: class X(mpf_base): _mpf_ = mpf(3.25)._mpf_ sage: X().to_fixed(30) @@ -1835,7 +1836,7 @@ cdef class mpf(mpf_base): TESTS :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: mpf() mpf('0.0') sage: mpf(5) @@ -1869,7 +1870,7 @@ cdef class mpf(mpf_base): """ Support pickling :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: loads(dumps(mpf(0.5))) == mpf(0.5) True """ @@ -1880,7 +1881,7 @@ cdef class mpf(mpf_base): Returns internal representation of self as a tuple of (sign bit, mantissa, exponent, bitcount) :: - sage: from mpmath import mp + sage: from sage.libs.mpmath.all import mp sage: mp.mpf(-3)._mpf_ (1, 3, 0, 2) """ @@ -1890,7 +1891,7 @@ cdef class mpf(mpf_base): """ Sets tuple value of self (warning: unsafe) :: - sage: from mpmath import mp + sage: from sage.libs.mpmath.all import mp sage: x = mp.mpf(-3) sage: x._mpf_ = (1, 3, -1, 2) sage: x @@ -1904,7 +1905,7 @@ cdef class mpf(mpf_base): """ Returns whether the number is nonzero :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: bool(mpf(3.5)) True sage: bool(mpf(0.0)) @@ -1917,7 +1918,7 @@ cdef class mpf(mpf_base): Hash values are compatible with builtin Python floats when the precision is small enough :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: hash(mpf(2.5)) == hash(float(2.5)) True sage: hash(mpf('inf')) == hash(float(Infinity)) @@ -1930,7 +1931,7 @@ cdef class mpf(mpf_base): """ Real part, leaves self unchanged :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: mpf(2.5).real mpf('2.5') """ @@ -1941,7 +1942,7 @@ cdef class mpf(mpf_base): """ Imaginary part, equal to zero :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: mpf(2.5).imag mpf('0.0') """ @@ -1951,7 +1952,7 @@ cdef class mpf(mpf_base): """ Complex conjugate, leaves self unchanged :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: mpf(2.5).conjugate() mpf('2.5') """ @@ -1963,7 +1964,7 @@ cdef class mpf(mpf_base): Returns the binary mantissa of self. The result is a Sage integer :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: mpf(-500.5).man 1001 sage: type(_) @@ -1976,7 +1977,7 @@ cdef class mpf(mpf_base): """ Returns the binary exponent of self :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: mpf(1/64.).exp -6 """ @@ -1987,7 +1988,7 @@ cdef class mpf(mpf_base): """ Returns the number of bits in the mantissa of self :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: mpf(-256).bc 1 sage: mpf(-255).bc @@ -1999,7 +2000,7 @@ cdef class mpf(mpf_base): """ Convert to a fixed-point integer of the given precision :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: mpf(7.25).to_fixed(30) 7784628224 sage: ZZ(7.25 * 2**30) @@ -2016,7 +2017,7 @@ cdef class mpf(mpf_base): """ Convert to a Python integer (truncating if necessary) :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: int(mpf(2.5)) 2 sage: type(_) @@ -2029,7 +2030,7 @@ cdef class mpf(mpf_base): """ Convert to a double-precision Python float :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: float(mpf(2.5)) 2.5 sage: type(_) @@ -2041,7 +2042,7 @@ cdef class mpf(mpf_base): """ Support pickling :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: loads(dumps(mpf(3))) == mpf(3) True """ @@ -2051,7 +2052,7 @@ cdef class mpf(mpf_base): """ Support pickling :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: loads(dumps(mpf(3))) == mpf(3) True """ @@ -2061,7 +2062,7 @@ cdef class mpf(mpf_base): """ Create a new mpf :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: x = mpf() """ @@ -2074,7 +2075,7 @@ cdef class mpf(mpf_base): """ Negates self, rounded to the current working precision :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: -mpf(2) mpf('-2.0') """ @@ -2087,7 +2088,7 @@ cdef class mpf(mpf_base): """ Rounds the number to the current working precision :: - sage: from mpmath import mp, mpf + sage: from sage.libs.mpmath.all import mp, mpf sage: mp.prec = 200 sage: x = mpf(1) / 3 sage: x.man @@ -2108,7 +2109,7 @@ cdef class mpf(mpf_base): Computes the absolute value, rounded to the current working precision :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: abs(mpf(-2)) mpf('2.0') """ @@ -2122,7 +2123,7 @@ cdef class mpf(mpf_base): Computes the square root, rounded to the current working precision :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: mpf(2).sqrt() mpf('1.4142135623730951') """ @@ -2134,7 +2135,7 @@ cdef class mpf(mpf_base): """ Compares numbers :: - sage: from mpmath import mpf + sage: from sage.libs.mpmath.all import mpf sage: mpf(3) > 2 True sage: mpf(3) == 3 @@ -2161,7 +2162,7 @@ cdef class constant(mpf_base): Creates a constant from a function computing an mpf tuple value :: - sage: from mpmath import mp, mpf + sage: from sage.libs.mpmath.all import mp, mpf sage: q = mp.constant(lambda prec, rnd: mpf(0.25)._mpf_, "quarter", "q") sage: q @@ -2178,7 +2179,7 @@ cdef class constant(mpf_base): Calling a constant is equivalent to rounding it. A custom precision and rounding direction can also be passed :: - sage: from mpmath import pi + sage: from sage.libs.mpmath.all import pi sage: print(pi(dps=5, rounding='d')) 3.1415901184082 sage: print(pi(dps=5, rounding='u')) @@ -2198,7 +2199,7 @@ cdef class constant(mpf_base): Returns the tuple value of the constant as if rounded to an mpf at the present working precision :: - sage: from mpmath import pi + sage: from sage.libs.mpmath.all import pi sage: pi._mpf_ (0, 884279719003555, -48, 50) sage: 884279719003555 / 2.0**48 @@ -2213,7 +2214,7 @@ cdef class constant(mpf_base): Represents self as a string. With mp.pretty=False, the representation differs from that of an ordinary mpf :: - sage: from mpmath import mp, pi + sage: from sage.libs.mpmath.all import mp, pi sage: mp.pretty = True sage: repr(pi) '3.14159265358979' @@ -2230,7 +2231,7 @@ cdef class constant(mpf_base): """ Returns whether the constant is nonzero :: - sage: from mpmath import pi + sage: from sage.libs.mpmath.all import pi sage: bool(pi) True """ @@ -2240,7 +2241,7 @@ cdef class constant(mpf_base): """ Negates the constant :: - sage: from mpmath import pi + sage: from sage.libs.mpmath.all import pi sage: -pi mpf('-3.1415926535897931') """ @@ -2250,7 +2251,7 @@ cdef class constant(mpf_base): """ Instantiates the constant as an mpf :: - sage: from mpmath import pi + sage: from sage.libs.mpmath.all import pi sage: +pi mpf('3.1415926535897931') """ @@ -2260,7 +2261,7 @@ cdef class constant(mpf_base): """ Computes the absolute value of the constant :: - sage: from mpmath import pi + sage: from sage.libs.mpmath.all import pi sage: abs(pi) mpf('3.1415926535897931') """ @@ -2270,7 +2271,7 @@ cdef class constant(mpf_base): """ Computes the square root of the constant :: - sage: from mpmath import pi + sage: from sage.libs.mpmath.all import pi sage: print(pi.sqrt()) 1.77245385090552 """ @@ -2281,7 +2282,7 @@ cdef class constant(mpf_base): """ Convert to a fixed-point integer :: - sage: from mpmath import pi + sage: from sage.libs.mpmath.all import pi sage: float(pi.to_fixed(10) / 2.0**10) 3.140625 """ @@ -2298,7 +2299,7 @@ cdef class constant(mpf_base): """ A constant hashes as if instantiated to a number :: - sage: from mpmath import pi + sage: from sage.libs.mpmath.all import pi sage: hash(pi) == hash(+pi) True """ @@ -2308,7 +2309,7 @@ cdef class constant(mpf_base): """ A constant hashes as if instantiated to a number :: - sage: from mpmath import pi + sage: from sage.libs.mpmath.all import pi sage: pi == pi True sage: pi > 3.14 @@ -2333,7 +2334,7 @@ cdef class mpc(mpnumber): """ Creates a new mpc:: - sage: from mpmath import mpc + sage: from sage.libs.mpmath.all import mpc sage: mpc() == mpc(0,0) == mpc(1,0)-1 == 0 True @@ -2351,7 +2352,7 @@ cdef class mpc(mpnumber): """ Create a new mpc :: - sage: from mpmath import mpc + sage: from sage.libs.mpmath.all import mpc sage: x = mpc() """ @@ -2366,7 +2367,7 @@ cdef class mpc(mpnumber): """ Support pickling :: - sage: from mpmath import mpc + sage: from sage.libs.mpmath.all import mpc sage: loads(dumps(mpc(1,3))) == mpc(1,3) True """ @@ -2376,7 +2377,7 @@ cdef class mpc(mpnumber): """ Support pickling :: - sage: from mpmath import mpc + sage: from sage.libs.mpmath.all import mpc sage: loads(dumps(mpc(1,3))) == mpc(1,3) True """ @@ -2386,7 +2387,7 @@ cdef class mpc(mpnumber): """ TESTS :: - sage: from mpmath import mp + sage: from sage.libs.mpmath.all import mp sage: mp.pretty = True sage: repr(mp.mpc(2,3)) '(2.0 + 3.0j)' @@ -2404,7 +2405,7 @@ cdef class mpc(mpnumber): """ TESTS :: - sage: from mpmath import mp + sage: from sage.libs.mpmath.all import mp sage: str(mp.mpc(2,3)) '(2.0 + 3.0j)' """ @@ -2414,7 +2415,7 @@ cdef class mpc(mpnumber): """ TESTS :: - sage: from mpmath import mp + sage: from sage.libs.mpmath.all import mp sage: bool(mp.mpc(0,1)) True sage: bool(mp.mpc(1,0)) @@ -2432,7 +2433,7 @@ cdef class mpc(mpnumber): """ TESTS :: - sage: from mpmath import mp + sage: from sage.libs.mpmath.all import mp sage: complex(mp.mpc(1,2)) == complex(1,2) True """ @@ -2442,7 +2443,7 @@ cdef class mpc(mpnumber): """ Returns tuple value of self :: - sage: from mpmath import mp + sage: from sage.libs.mpmath.all import mp sage: mp.mpc(2,3)._mpc_ ((0, 1, 1, 1), (0, 3, 0, 2)) """ @@ -2452,7 +2453,7 @@ cdef class mpc(mpnumber): """ Sets tuple value of self (warning: unsafe) :: - sage: from mpmath import mp + sage: from sage.libs.mpmath.all import mp sage: x = mp.mpc(2,3) sage: x._mpc_ = (x._mpc_[1], x._mpc_[0]) sage: x @@ -2468,7 +2469,7 @@ cdef class mpc(mpnumber): """ Returns the real part of self as an mpf :: - sage: from mpmath import mp + sage: from sage.libs.mpmath.all import mp sage: mp.mpc(1,2).real mpf('1.0') """ @@ -2481,7 +2482,7 @@ cdef class mpc(mpnumber): """ Returns the imaginary part of self as an mpf :: - sage: from mpmath import mp + sage: from sage.libs.mpmath.all import mp sage: mp.mpc(1,2).imag mpf('2.0') """ @@ -2495,7 +2496,7 @@ cdef class mpc(mpnumber): EXAMPLES:: - sage: from mpmath import mp + sage: from sage.libs.mpmath.all import mp sage: hash(mp.mpc(2,3)) == hash(complex(2,3)) True @@ -2503,7 +2504,7 @@ cdef class mpc(mpnumber): Check that :trac:`31676` is fixed:: - sage: from mpmath import mpc + sage: from sage.libs.mpmath.all import mpc sage: hash(mpc(1, -1)) == hash(mpc(-1, -1)) # should not return OverflowError: Python int too large to convert to C ssize_t False """ @@ -2513,7 +2514,7 @@ cdef class mpc(mpnumber): """ Negates the number :: - sage: from mpmath import mpc + sage: from sage.libs.mpmath.all import mpc sage: -mpc(1,2) mpc(real='-1.0', imag='-2.0') """ @@ -2528,7 +2529,7 @@ cdef class mpc(mpnumber): """ Returns the complex conjugate :: - sage: from mpmath import mpc + sage: from sage.libs.mpmath.all import mpc sage: mpc(1,2).conjugate() mpc(real='1.0', imag='-2.0') """ @@ -2543,7 +2544,7 @@ cdef class mpc(mpnumber): """ Rounds the number to the current working precision :: - sage: from mpmath import mp + sage: from sage.libs.mpmath.all import mp sage: mp.prec = 200 sage: x = mp.mpc(1) / 3 sage: x.real.man @@ -2565,7 +2566,7 @@ cdef class mpc(mpnumber): """ Returns the absolute value of self :: - sage: from mpmath import mpc + sage: from sage.libs.mpmath.all import mpc sage: abs(mpc(3,4)) mpf('5.0') """ @@ -2577,7 +2578,7 @@ cdef class mpc(mpnumber): """ Complex numbers can be compared for equality :: - sage: from mpmath import mpc + sage: from sage.libs.mpmath.all import mpc sage: mpc(2,3) == complex(2,3) True sage: mpc(-2,3) == complex(2,3) @@ -2596,7 +2597,7 @@ def hypsum_internal(int p, int q, param_types, str ztype, coeffs, z, EXAMPLES:: - sage: from mpmath import mp # indirect doctest + sage: from sage.libs.mpmath.all import mp # indirect doctest sage: mp.dps = 15 sage: print(mp.hyp1f1(1,2,3)) 6.36184564106256 diff --git a/src/sage/libs/mpmath/hooks.py b/src/sage/libs/mpmath/hooks.py new file mode 100644 index 00000000000..df9ff64c82b --- /dev/null +++ b/src/sage/libs/mpmath/hooks.py @@ -0,0 +1,13 @@ +# sage_setup: distribution = sagemath-mpmath +r""" +Sage functions called by the vendored copy of mpmath + +Upstream mpmath imports these functions from :mod:`sage.all`. + +Our vendored copy of mpmath, :mod:`sage.libs.mpmath._vendor.mpmath`, +imports them from this module instead, see +``SAGE_ROOT/pkgs/sagemath-mpmath/pyproject.toml``. +""" +from sage.arith.misc import factorial, primes +from sage.combinat.combinat import fibonacci +from sage.rings.integer import Integer diff --git a/src/sage/libs/mpmath/utils.pxd b/src/sage/libs/mpmath/mpfr_to_mpmath.pxd similarity index 60% rename from src/sage/libs/mpmath/utils.pxd rename to src/sage/libs/mpmath/mpfr_to_mpmath.pxd index 686b108da9a..e88bfd58f38 100644 --- a/src/sage/libs/mpmath/utils.pxd +++ b/src/sage/libs/mpmath/mpfr_to_mpmath.pxd @@ -1,3 +1,4 @@ +# sage_setup: distribution = sagemath-mpmath from sage.libs.mpfr.types cimport mpfr_t cdef mpfr_to_mpfval(mpfr_t) diff --git a/src/sage/libs/mpmath/mpfr_to_mpmath.pyx b/src/sage/libs/mpmath/mpfr_to_mpmath.pyx new file mode 100644 index 00000000000..e42619f5eef --- /dev/null +++ b/src/sage/libs/mpmath/mpfr_to_mpmath.pyx @@ -0,0 +1,44 @@ +# sage_setup: distribution = sagemath-mpmath + +from sage.ext.stdsage cimport PY_NEW +from sage.libs.mpfr cimport * +from sage.libs.gmp.all cimport * +from sage.rings.integer cimport Integer + +cdef object finf, fnan, fninf, fzero + + +cdef inline late_import(): + global finf, fnan, fninf, fzero + if finf is None: + from sage.libs.mpmath._vendor.mpmath.libmp import finf, fnan, fninf, fzero + + +cdef mpfr_to_mpfval(mpfr_t value): + """ + Given an MPFR value, return an mpmath mpf data tuple representing + the same number. + """ + late_import() + if mpfr_nan_p(value): + return fnan + if mpfr_inf_p(value): + if mpfr_sgn(value) > 0: + return finf + else: + return fninf + if mpfr_sgn(value) == 0: + return fzero + sign = 0 + cdef Integer man = PY_NEW(Integer) + exp = mpfr_get_z_exp(man.value, value) + if mpz_sgn(man.value) < 0: + mpz_neg(man.value, man.value) + sign = 1 + cdef unsigned long trailing + trailing = mpz_scan1(man.value, 0) + if trailing: + mpz_tdiv_q_2exp(man.value, man.value, trailing) + exp += trailing + bc = mpz_sizeinbase(man.value, 2) + return (sign, man, int(exp), bc) diff --git a/src/sage/libs/mpmath/sage_utils.pyx b/src/sage/libs/mpmath/sage_utils.pyx new file mode 100644 index 00000000000..876eb16ee42 --- /dev/null +++ b/src/sage/libs/mpmath/sage_utils.pyx @@ -0,0 +1,277 @@ +# sage_setup: distribution = sagemath-mpmath +r""" +Utility functions called by the Sage library +""" + +from sage.ext.stdsage cimport PY_NEW +from sage.libs.mpfr cimport * +from sage.libs.gmp.all cimport * +from sage.libs.mpmath._vendor.mpmath import mp +from sage.libs.mpmath._vendor.mpmath.libmp import finf, fninf +from sage.rings.complex_mpfr cimport ComplexNumber +from sage.rings.complex_mpfr import ComplexField +from sage.rings.integer cimport Integer +from sage.rings.real_mpfr cimport RealField, RealNumber +from sage.structure.element cimport Element + + +cdef mpfr_from_mpfval(mpfr_t res, tuple x): + """ + Set value of an MPFR number (in place) to that of a given mpmath mpf + data tuple. + """ + cdef int sign + cdef Integer man + cdef long exp + cdef long bc + sign, man, exp, bc = x + if man: + mpfr_set_z(res, man.value, MPFR_RNDZ) + if sign: + mpfr_neg(res, res, MPFR_RNDZ) + mpfr_mul_2si(res, res, exp, MPFR_RNDZ) + return + if exp == 0: + mpfr_set_ui(res, 0, MPFR_RNDZ) + elif x == finf: + mpfr_set_inf(res, 1) + elif x == fninf: + mpfr_set_inf(res, -1) + else: + mpfr_set_nan(res) + +def mpmath_to_sage(x, prec): + """ + Convert any mpmath number (mpf or mpc) to a Sage RealNumber or + ComplexNumber of the given precision. + + EXAMPLES:: + + sage: import sage.libs.mpmath.all as a + sage: a.mpmath_to_sage(a.mpf('2.5'), 53) + 2.50000000000000 + sage: a.mpmath_to_sage(a.mpc('2.5','-3.5'), 53) + 2.50000000000000 - 3.50000000000000*I + sage: a.mpmath_to_sage(a.mpf('inf'), 53) + +infinity + sage: a.mpmath_to_sage(a.mpf('-inf'), 53) + -infinity + sage: a.mpmath_to_sage(a.mpf('nan'), 53) + NaN + sage: a.mpmath_to_sage(a.mpf('0'), 53) + 0.000000000000000 + + A real example:: + + sage: RealField(100)(pi) # optional - sage.symbolic + 3.1415926535897932384626433833 + sage: t = RealField(100)(pi)._mpmath_(); t # optional - sage.symbolic + mpf('3.1415926535897932') + sage: a.mpmath_to_sage(t, 100) # optional - sage.symbolic + 3.1415926535897932384626433833 + + We can ask for more precision, but the result is undefined:: + + sage: a.mpmath_to_sage(t, 140) # random # optional - sage.symbolic + 3.1415926535897932384626433832793333156440 + sage: ComplexField(140)(pi) # optional - sage.symbolic + 3.1415926535897932384626433832795028841972 + + A complex example:: + + sage: ComplexField(100)([0, pi]) # optional - sage.symbolic + 3.1415926535897932384626433833*I + sage: t = ComplexField(100)([0, pi])._mpmath_(); t # optional - sage.symbolic + mpc(real='0.0', imag='3.1415926535897932') + sage: sage.libs.mpmath.all.mpmath_to_sage(t, 100) # optional - sage.symbolic + 3.1415926535897932384626433833*I + + Again, we can ask for more precision, but the result is undefined:: + + sage: sage.libs.mpmath.all.mpmath_to_sage(t, 140) # random # optional - sage.symbolic + 3.1415926535897932384626433832793333156440*I + sage: ComplexField(140)([0, pi]) # optional - sage.symbolic + 3.1415926535897932384626433832795028841972*I + """ + cdef RealNumber y + cdef ComplexNumber z + if hasattr(x, "_mpf_"): + y = RealField(prec)() + mpfr_from_mpfval(y.value, x._mpf_) + return y + elif hasattr(x, "_mpc_"): + z = ComplexField(prec)(0) + re, im = x._mpc_ + mpfr_from_mpfval(z.__re, re) + mpfr_from_mpfval(z.__im, im) + return z + else: + raise TypeError("cannot convert %r to Sage", x) + +def sage_to_mpmath(x, prec): + """ + Convert any Sage number that can be coerced into a RealNumber + or ComplexNumber of the given precision into an mpmath mpf or mpc. + Integers are currently converted to int. + + Lists, tuples and dicts passed as input are converted + recursively. + + EXAMPLES:: + + sage: import sage.libs.mpmath.all as a + sage: a.mp.dps = 15 + sage: print(a.sage_to_mpmath(2/3, 53)) + 0.666666666666667 + sage: print(a.sage_to_mpmath(2./3, 53)) + 0.666666666666667 + sage: print(a.sage_to_mpmath(3+4*I, 53)) + (3.0 + 4.0j) + sage: print(a.sage_to_mpmath(1+pi, 53)) # optional - sage.symbolic + 4.14159265358979 + sage: a.sage_to_mpmath(infinity, 53) + mpf('+inf') + sage: a.sage_to_mpmath(-infinity, 53) + mpf('-inf') + sage: a.sage_to_mpmath(NaN, 53) # optional - sage.symbolic + mpf('nan') + sage: a.sage_to_mpmath(0, 53) + 0 + sage: a.sage_to_mpmath([0.5, 1.5], 53) + [mpf('0.5'), mpf('1.5')] + sage: a.sage_to_mpmath((0.5, 1.5), 53) + (mpf('0.5'), mpf('1.5')) + sage: a.sage_to_mpmath({'n':0.5}, 53) + {'n': mpf('0.5')} + + """ + if isinstance(x, Element): + if isinstance(x, Integer): + return int(x) + try: + if isinstance(x, RealNumber): + return x._mpmath_() + else: + x = RealField(prec)(x) + return x._mpmath_() + except TypeError: + if isinstance(x, ComplexNumber): + return x._mpmath_() + else: + x = ComplexField(prec)(x) + return x._mpmath_() + if isinstance(x, (tuple, list)): + return type(x)([sage_to_mpmath(v, prec) for v in x]) + if isinstance(x, dict): + return dict([(k, sage_to_mpmath(v, prec)) for (k, v) in x.items()]) + return x + +def call(func, *args, **kwargs): + """ + Call an mpmath function with Sage objects as inputs and + convert the result back to a Sage real or complex number. + + By default, a RealNumber or ComplexNumber with the current + working precision of mpmath (mpmath.mp.prec) will be returned. + + If prec=n is passed among the keyword arguments, the temporary + working precision will be set to n and the result will also + have this precision. + + If parent=P is passed, P.prec() will be used as working + precision and the result will be coerced to P (or the + corresponding complex field if necessary). + + Arguments should be Sage objects that can be coerced into RealField + or ComplexField elements. Arguments may also be tuples, lists or + dicts (which are converted recursively), or any type that mpmath + understands natively (e.g. Python floats, strings for options). + + EXAMPLES:: + + sage: import sage.libs.mpmath.all as a + sage: a.mp.prec = 53 + sage: a.call(a.erf, 3+4*I) + -120.186991395079 - 27.7503372936239*I + sage: a.call(a.polylog, 2, 1/3+4/5*I) + 0.153548951541433 + 0.875114412499637*I + sage: a.call(a.barnesg, 3+4*I) + -0.000676375932234244 - 0.0000442236140124728*I + sage: a.call(a.barnesg, -4) + 0.000000000000000 + sage: a.call(a.hyper, [2,3], [4,5], 1/3) + 1.10703578162508 + sage: a.call(a.hyper, [2,3], [4,(2,3)], 1/3) + 1.95762943509305 + sage: a.call(a.quad, a.erf, [0,1]) + 0.486064958112256 + sage: a.call(a.gammainc, 3+4*I, 2/3, 1-pi*I, prec=100) # optional - sage.symbolic + -274.18871130777160922270612331 + 101.59521032382593402947725236*I + sage: x = (3+4*I).n(100) + sage: y = (2/3).n(100) + sage: z = (1-pi*I).n(100) # optional - sage.symbolic + sage: a.call(a.gammainc, x, y, z, prec=100) # optional - sage.symbolic + -274.18871130777160922270612331 + 101.59521032382593402947725236*I + sage: a.call(a.erf, infinity) + 1.00000000000000 + sage: a.call(a.erf, -infinity) + -1.00000000000000 + sage: a.call(a.gamma, infinity) + +infinity + sage: a.call(a.polylog, 2, 1/2, parent=RR) + 0.582240526465012 + sage: a.call(a.polylog, 2, 2, parent=RR) + 2.46740110027234 - 2.17758609030360*I + sage: a.call(a.polylog, 2, 1/2, parent=RealField(100)) + 0.58224052646501250590265632016 + sage: a.call(a.polylog, 2, 2, parent=RealField(100)) + 2.4674011002723396547086227500 - 2.1775860903036021305006888982*I + sage: a.call(a.polylog, 2, 1/2, parent=CC) + 0.582240526465012 + sage: type(_) + + sage: a.call(a.polylog, 2, 1/2, parent=RDF) + 0.5822405264650125 + sage: type(_) + + + Check that :trac:`11885` is fixed:: + + sage: a.call(a.ei, 1.0r, parent=float) + 1.8951178163559366 + + Check that :trac:`14984` is fixed:: + + sage: a.call(a.log, -1.0r, parent=float) + 3.141592653589793j + + """ + orig = mp.prec + prec = kwargs.pop('prec', orig) + parent = kwargs.pop('parent', None) + if parent is not None: + try: + prec = parent.prec() + except AttributeError: + pass + prec2 = prec + 20 + args = sage_to_mpmath(args, prec2) + kwargs = sage_to_mpmath(kwargs, prec2) + try: + mp.prec = prec + y = func(*args, **kwargs) + finally: + mp.prec = orig + y = mpmath_to_sage(y, prec) + if parent is None: + return y + try: + return parent(y) + except TypeError as error: + try: + return parent.complex_field()(y) + except AttributeError: + if parent is float: + return complex(y) + else: + raise TypeError(error) diff --git a/src/sage/libs/mpmath/utils.pyx b/src/sage/libs/mpmath/utils.pyx index 83f8108be08..9203218d354 100644 --- a/src/sage/libs/mpmath/utils.pyx +++ b/src/sage/libs/mpmath/utils.pyx @@ -1,28 +1,28 @@ +# sage_setup: distribution = sagemath-mpmath """ -Utilities for Sage-mpmath interaction +Utility functions called by mpmath -Also patches some mpmath functions for speed +Upstream mpmath uses these functions when it detects Sage. + +Our vendored copy of mpmath, :mod:`sage.libs.mpmath._vendor.mpmath`, +uses these functions unconditionally, +see ``SAGE_ROOT/pkgs/sagemath-mpmath/pyproject.toml``. """ from sage.ext.stdsage cimport PY_NEW from sage.rings.integer cimport Integer -from sage.rings.real_mpfr cimport RealNumber -from sage.rings.complex_mpfr cimport ComplexNumber -from sage.structure.element cimport Element from sage.libs.mpfr cimport * from sage.libs.gmp.all cimport * -from sage.rings.real_mpfr cimport RealField - cpdef int bitcount(n): """ Bitcount of a Sage Integer or Python int/long. EXAMPLES:: - sage: from mpmath.libmp import bitcount + sage: from sage.libs.mpmath._vendor.mpmath.libmp import bitcount sage: bitcount(0) 0 sage: bitcount(1) @@ -53,7 +53,7 @@ cpdef isqrt(n): EXAMPLES:: - sage: from mpmath.libmp import isqrt + sage: from sage.libs.mpmath._vendor.mpmath.libmp import isqrt sage: isqrt(0) 0 sage: isqrt(100) @@ -86,7 +86,7 @@ cpdef from_man_exp(man, exp, long prec = 0, str rnd = 'd'): EXAMPLES:: - sage: from mpmath.libmp import from_man_exp + sage: from sage.libs.mpmath._vendor.mpmath.libmp import from_man_exp sage: from_man_exp(-6, -1) (1, 3, 0, 2) sage: from_man_exp(-6, -1, 1, 'd') @@ -112,7 +112,7 @@ cpdef normalize(long sign, Integer man, exp, long bc, long prec, str rnd): EXAMPLES:: - sage: from mpmath.libmp import normalize + sage: from sage.libs.mpmath._vendor.mpmath.libmp import normalize sage: normalize(0, 4, 5, 3, 53, 'n') (0, 1, 7, 1) """ @@ -120,7 +120,7 @@ cpdef normalize(long sign, Integer man, exp, long bc, long prec, str rnd): cdef Integer res cdef unsigned long trail if mpz_sgn(man.value) == 0: - from mpmath.libmp import fzero + from sage.libs.mpmath._vendor.mpmath.libmp import fzero return fzero if bc <= prec and mpz_odd_p(man.value): return (sign, man, exp, bc) @@ -153,300 +153,3 @@ cpdef normalize(long sign, Integer man, exp, long bc, long prec, str rnd): exp += trail bc = mpz_sizeinbase(res.value, 2) return (sign, res, int(exp), bc) - -cdef mpfr_from_mpfval(mpfr_t res, tuple x): - """ - Set value of an MPFR number (in place) to that of a given mpmath mpf - data tuple. - """ - cdef int sign - cdef Integer man - cdef long exp - cdef long bc - sign, man, exp, bc = x - if man: - mpfr_set_z(res, man.value, MPFR_RNDZ) - if sign: - mpfr_neg(res, res, MPFR_RNDZ) - mpfr_mul_2si(res, res, exp, MPFR_RNDZ) - return - from mpmath.libmp import finf, fninf - if exp == 0: - mpfr_set_ui(res, 0, MPFR_RNDZ) - elif x == finf: - mpfr_set_inf(res, 1) - elif x == fninf: - mpfr_set_inf(res, -1) - else: - mpfr_set_nan(res) - -cdef mpfr_to_mpfval(mpfr_t value): - """ - Given an MPFR value, return an mpmath mpf data tuple representing - the same number. - """ - if mpfr_nan_p(value): - from mpmath.libmp import fnan - return fnan - if mpfr_inf_p(value): - from mpmath.libmp import finf, fninf - if mpfr_sgn(value) > 0: - return finf - else: - return fninf - if mpfr_sgn(value) == 0: - from mpmath.libmp import fzero - return fzero - sign = 0 - cdef Integer man = PY_NEW(Integer) - exp = mpfr_get_z_exp(man.value, value) - if mpz_sgn(man.value) < 0: - mpz_neg(man.value, man.value) - sign = 1 - cdef unsigned long trailing - trailing = mpz_scan1(man.value, 0) - if trailing: - mpz_tdiv_q_2exp(man.value, man.value, trailing) - exp += trailing - bc = mpz_sizeinbase(man.value, 2) - return (sign, man, int(exp), bc) - -def mpmath_to_sage(x, prec): - """ - Convert any mpmath number (mpf or mpc) to a Sage RealNumber or - ComplexNumber of the given precision. - - EXAMPLES:: - - sage: import sage.libs.mpmath.all as a - sage: a.mpmath_to_sage(a.mpf('2.5'), 53) - 2.50000000000000 - sage: a.mpmath_to_sage(a.mpc('2.5','-3.5'), 53) - 2.50000000000000 - 3.50000000000000*I - sage: a.mpmath_to_sage(a.mpf('inf'), 53) - +infinity - sage: a.mpmath_to_sage(a.mpf('-inf'), 53) - -infinity - sage: a.mpmath_to_sage(a.mpf('nan'), 53) - NaN - sage: a.mpmath_to_sage(a.mpf('0'), 53) - 0.000000000000000 - - A real example:: - - sage: RealField(100)(pi) - 3.1415926535897932384626433833 - sage: t = RealField(100)(pi)._mpmath_(); t - mpf('3.1415926535897932') - sage: a.mpmath_to_sage(t, 100) - 3.1415926535897932384626433833 - - We can ask for more precision, but the result is undefined:: - - sage: a.mpmath_to_sage(t, 140) # random - 3.1415926535897932384626433832793333156440 - sage: ComplexField(140)(pi) - 3.1415926535897932384626433832795028841972 - - A complex example:: - - sage: ComplexField(100)([0, pi]) - 3.1415926535897932384626433833*I - sage: t = ComplexField(100)([0, pi])._mpmath_(); t - mpc(real='0.0', imag='3.1415926535897932') - sage: sage.libs.mpmath.all.mpmath_to_sage(t, 100) - 3.1415926535897932384626433833*I - - Again, we can ask for more precision, but the result is undefined:: - - sage: sage.libs.mpmath.all.mpmath_to_sage(t, 140) # random - 3.1415926535897932384626433832793333156440*I - sage: ComplexField(140)([0, pi]) - 3.1415926535897932384626433832795028841972*I - """ - cdef RealNumber y - cdef ComplexNumber z - if hasattr(x, "_mpf_"): - y = RealField(prec)() - mpfr_from_mpfval(y.value, x._mpf_) - return y - elif hasattr(x, "_mpc_"): - from sage.rings.complex_mpfr import ComplexField - z = ComplexField(prec)(0) - re, im = x._mpc_ - mpfr_from_mpfval(z.__re, re) - mpfr_from_mpfval(z.__im, im) - return z - else: - raise TypeError("cannot convert %r to Sage", x) - -def sage_to_mpmath(x, prec): - """ - Convert any Sage number that can be coerced into a RealNumber - or ComplexNumber of the given precision into an mpmath mpf or mpc. - Integers are currently converted to int. - - Lists, tuples and dicts passed as input are converted - recursively. - - EXAMPLES:: - - sage: import sage.libs.mpmath.all as a - sage: a.mp.dps = 15 - sage: print(a.sage_to_mpmath(2/3, 53)) - 0.666666666666667 - sage: print(a.sage_to_mpmath(2./3, 53)) - 0.666666666666667 - sage: print(a.sage_to_mpmath(3+4*I, 53)) - (3.0 + 4.0j) - sage: print(a.sage_to_mpmath(1+pi, 53)) - 4.14159265358979 - sage: a.sage_to_mpmath(infinity, 53) - mpf('+inf') - sage: a.sage_to_mpmath(-infinity, 53) - mpf('-inf') - sage: a.sage_to_mpmath(NaN, 53) - mpf('nan') - sage: a.sage_to_mpmath(0, 53) - 0 - sage: a.sage_to_mpmath([0.5, 1.5], 53) - [mpf('0.5'), mpf('1.5')] - sage: a.sage_to_mpmath((0.5, 1.5), 53) - (mpf('0.5'), mpf('1.5')) - sage: a.sage_to_mpmath({'n':0.5}, 53) - {'n': mpf('0.5')} - - """ - cdef RealNumber y - if isinstance(x, Element): - if isinstance(x, Integer): - return int(x) - try: - if isinstance(x, RealNumber): - return x._mpmath_() - else: - x = RealField(prec)(x) - return x._mpmath_() - except TypeError: - if isinstance(x, ComplexNumber): - return x._mpmath_() - else: - from sage.rings.complex_mpfr import ComplexField - x = ComplexField(prec)(x) - return x._mpmath_() - if isinstance(x, (tuple, list)): - return type(x)([sage_to_mpmath(v, prec) for v in x]) - if isinstance(x, dict): - return dict([(k, sage_to_mpmath(v, prec)) for (k, v) in x.items()]) - return x - -def call(func, *args, **kwargs): - """ - Call an mpmath function with Sage objects as inputs and - convert the result back to a Sage real or complex number. - - By default, a RealNumber or ComplexNumber with the current - working precision of mpmath (mpmath.mp.prec) will be returned. - - If prec=n is passed among the keyword arguments, the temporary - working precision will be set to n and the result will also - have this precision. - - If parent=P is passed, P.prec() will be used as working - precision and the result will be coerced to P (or the - corresponding complex field if necessary). - - Arguments should be Sage objects that can be coerced into RealField - or ComplexField elements. Arguments may also be tuples, lists or - dicts (which are converted recursively), or any type that mpmath - understands natively (e.g. Python floats, strings for options). - - EXAMPLES:: - - sage: import sage.libs.mpmath.all as a - sage: a.mp.prec = 53 - sage: a.call(a.erf, 3+4*I) - -120.186991395079 - 27.7503372936239*I - sage: a.call(a.polylog, 2, 1/3+4/5*I) - 0.153548951541433 + 0.875114412499637*I - sage: a.call(a.barnesg, 3+4*I) - -0.000676375932234244 - 0.0000442236140124728*I - sage: a.call(a.barnesg, -4) - 0.000000000000000 - sage: a.call(a.hyper, [2,3], [4,5], 1/3) - 1.10703578162508 - sage: a.call(a.hyper, [2,3], [4,(2,3)], 1/3) - 1.95762943509305 - sage: a.call(a.quad, a.erf, [0,1]) - 0.486064958112256 - sage: a.call(a.gammainc, 3+4*I, 2/3, 1-pi*I, prec=100) - -274.18871130777160922270612331 + 101.59521032382593402947725236*I - sage: x = (3+4*I).n(100) - sage: y = (2/3).n(100) - sage: z = (1-pi*I).n(100) - sage: a.call(a.gammainc, x, y, z, prec=100) - -274.18871130777160922270612331 + 101.59521032382593402947725236*I - sage: a.call(a.erf, infinity) - 1.00000000000000 - sage: a.call(a.erf, -infinity) - -1.00000000000000 - sage: a.call(a.gamma, infinity) - +infinity - sage: a.call(a.polylog, 2, 1/2, parent=RR) - 0.582240526465012 - sage: a.call(a.polylog, 2, 2, parent=RR) - 2.46740110027234 - 2.17758609030360*I - sage: a.call(a.polylog, 2, 1/2, parent=RealField(100)) - 0.58224052646501250590265632016 - sage: a.call(a.polylog, 2, 2, parent=RealField(100)) - 2.4674011002723396547086227500 - 2.1775860903036021305006888982*I - sage: a.call(a.polylog, 2, 1/2, parent=CC) - 0.582240526465012 - sage: type(_) - - sage: a.call(a.polylog, 2, 1/2, parent=RDF) - 0.5822405264650125 - sage: type(_) - - - Check that :trac:`11885` is fixed:: - - sage: a.call(a.ei, 1.0r, parent=float) - 1.8951178163559366 - - Check that :trac:`14984` is fixed:: - - sage: a.call(a.log, -1.0r, parent=float) - 3.141592653589793j - - """ - from mpmath import mp - orig = mp.prec - prec = kwargs.pop('prec', orig) - parent = kwargs.pop('parent', None) - if parent is not None: - try: - prec = parent.prec() - except AttributeError: - pass - prec2 = prec + 20 - args = sage_to_mpmath(args, prec2) - kwargs = sage_to_mpmath(kwargs, prec2) - try: - mp.prec = prec - y = func(*args, **kwargs) - finally: - mp.prec = orig - y = mpmath_to_sage(y, prec) - if parent is None: - return y - try: - return parent(y) - except TypeError as error: - try: - return parent.complex_field()(y) - except AttributeError: - if parent is float: - return complex(y) - else: - raise TypeError(error) diff --git a/src/sage/rings/complex_mpfr.pyx b/src/sage/rings/complex_mpfr.pyx index 1862cea7bbf..a8f9fda8210 100644 --- a/src/sage/rings/complex_mpfr.pyx +++ b/src/sage/rings/complex_mpfr.pyx @@ -53,7 +53,7 @@ from .complex_double cimport ComplexDoubleElement from .real_mpfr cimport RealNumber from sage.libs.gsl.complex cimport * -from sage.libs.mpmath.utils cimport mpfr_to_mpfval +from sage.libs.mpmath.mpfr_to_mpmath cimport mpfr_to_mpfval from sage.rings.integer_ring import ZZ cimport gmpy2 diff --git a/src/sage/rings/integer.pyx b/src/sage/rings/integer.pyx index 4202bcc9a10..cb68d3c384f 100644 --- a/src/sage/rings/integer.pyx +++ b/src/sage/rings/integer.pyx @@ -3446,8 +3446,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: divmod(1, sys.maxsize+1r) # should not raise OverflowError: Python int too large to convert to C long (0, 1) - - sage: import mpmath # needs mpmath + sage: import sage.libs.mpmath.all as mpmath # needs mpmath sage: mpmath.mp.prec = 1000 # needs mpmath sage: root = mpmath.findroot(lambda x: x^2 - 3, 2) # needs mpmath sage: len(str(root)) # needs mpmath diff --git a/src/sage/rings/real_mpfr.pyx b/src/sage/rings/real_mpfr.pyx index fb2eb1d718c..cd0304a327f 100644 --- a/src/sage/rings/real_mpfr.pyx +++ b/src/sage/rings/real_mpfr.pyx @@ -146,7 +146,7 @@ from cypari2.paridecl cimport * from cypari2.gen cimport Gen from cypari2.stack cimport new_gen -from sage.libs.mpmath.utils cimport mpfr_to_mpfval +from sage.libs.mpmath.mpfr_to_mpmath cimport mpfr_to_mpfval from .integer cimport Integer from .rational cimport Rational @@ -5333,8 +5333,8 @@ cdef class RealNumber(sage.structure.element.RingElement): if parent._prec > SIG_PREC_THRESHOLD: sig_off() return x - from sage.libs.mpmath.utils import call - from mpmath import loggamma + from sage.libs.mpmath.sage_utils import call + from sage.libs.mpmath.all import loggamma return call(loggamma, mpfr_to_mpfval(self.value), parent=parent) def zeta(self): diff --git a/src/sage/structure/coerce.pyx b/src/sage/structure/coerce.pyx index d8c3f684217..d30b111deaa 100644 --- a/src/sage/structure/coerce.pyx +++ b/src/sage/structure/coerce.pyx @@ -468,8 +468,8 @@ cpdef bint is_numpy_type(t): cpdef bint is_mpmath_type(t): r""" - Check whether the type ``t`` is a type whose name starts with either - ``mpmath.`` or ``sage.libs.mpmath.``. + Check whether the type ``t`` is a type whose name starts with + ``sage.libs.mpmath.``. EXAMPLES:: @@ -477,12 +477,12 @@ cpdef bint is_mpmath_type(t): sage: from sage.structure.coerce import is_mpmath_type sage: is_mpmath_type(int) False - sage: import mpmath - sage: is_mpmath_type(mpmath.mpc(2)) + sage: import sage.libs.mpmath.all # optional - mpmath + sage: is_mpmath_type(sage.libs.mpmath.all.mpc(2)) # optional - mpmath False - sage: is_mpmath_type(type(mpmath.mpc(2))) + sage: is_mpmath_type(type(sage.libs.mpmath.all.mpc(2))) # optional - mpmath True - sage: is_mpmath_type(type(mpmath.mpf(2))) + sage: is_mpmath_type(type(sage.libs.mpmath.all.mpf(2))) # optional - mpmath True """ return isinstance(t, type) and \ diff --git a/src/sage/symbolic/function.pyx b/src/sage/symbolic/function.pyx index f4bd22df0a6..5df995cdb6d 100644 --- a/src/sage/symbolic/function.pyx +++ b/src/sage/symbolic/function.pyx @@ -490,7 +490,7 @@ cdef class Function(SageObject): Make sure we can pass mpmath arguments (:trac:`13608`):: - sage: import mpmath # needs mpmath + sage: import sage.libs.mpmath as mpmath # needs mpmath sage: with mpmath.workprec(128): sin(mpmath.mpc('0.5', '1.2')) # needs mpmath mpc(real='0.86807452059118713192871150787046523179886', imag='1.3246769633571289324095313649562791720086') @@ -779,7 +779,7 @@ cdef class Function(SageObject): implementation, using sage reals instead of mpmath ones. This might change when aliases for these functions are established:: - sage: import mpmath # needs mpmath + sage: import sage.libs.mpmath as mpmath # needs mpmath sage: with mpmath.workprec(128): arcsin(mpmath.mpf('0.5')) # needs mpmath mpf('0.52359877559829887307710723054658381403157') @@ -790,7 +790,7 @@ cdef class Function(SageObject): will certainly never get created in mpmath. :: sage: # needs mpmath - sage: import mpmath + sage: from sage.libs.mpmath import workprec, mpf sage: from sage.symbolic.function import BuiltinFunction sage: class NoMpmathFn(BuiltinFunction): ....: def _eval_(self, arg): @@ -799,22 +799,21 @@ cdef class Function(SageObject): ....: assert parent == RealField(prec) ....: return prec sage: noMpmathFn = NoMpmathFn("noMpmathFn") - sage: with mpmath.workprec(64): noMpmathFn(sqrt(mpmath.mpf('2'))) + sage: with workprec(64): noMpmathFn(sqrt(mpf('2'))) 64 - sage: mpmath.noMpmathFn = lambda x: 123 - sage: with mpmath.workprec(64): noMpmathFn(sqrt(mpmath.mpf('2'))) + sage: sage.libs.mpmath.noMpmathFn = lambda x: 123 + sage: with workprec(64): noMpmathFn(sqrt(mpf('2'))) 123 - sage: del mpmath.noMpmathFn + sage: del sage.libs.mpmath.noMpmathFn """ - import mpmath - from sage.libs.mpmath.utils import mpmath_to_sage, sage_to_mpmath - prec = mpmath.mp.prec - args = [mpmath_to_sage(x, prec) - if isinstance(x, (mpmath.mpf, mpmath.mpc)) else x + from sage.libs.mpmath.all import mp, mpf, mpc + from sage.libs.mpmath.sage_utils import mpmath_to_sage, sage_to_mpmath + args = [mpmath_to_sage(x, mp.prec) + if isinstance(x, (mpf, mpc)) else x for x in args] res = self(*args) - res = sage_to_mpmath(res, prec) + res = sage_to_mpmath(res, mp.prec) return res @@ -957,10 +956,10 @@ cdef class BuiltinFunction(Function): sage: assert type(_) is complex sage: # needs mpmath - sage: import mpmath + sage: import sage.libs.mpmath.all as mpmath sage: cos(mpmath.mpf('1.321412')) mpf('0.24680737898640387') - sage: cos(mpmath.mpc(1,1)) + sage: cos(sage.libs.mpmath.mpc(1,1)) mpc(real='0.83373002513114902', imag='-0.98889770576286506') sage: import numpy # needs numpy @@ -993,7 +992,7 @@ cdef class BuiltinFunction(Function): import numpy as module custom = self._eval_numpy_ elif any(is_mpmath_type(type(arg)) for arg in args): - import mpmath as module + import sage.libs.mpmath.all as module custom = self._eval_mpmath_ elif all(isinstance(arg, float) for arg in args): # We do not include the factorial here as diff --git a/src/sage/symbolic/pynac_impl.pxi b/src/sage/symbolic/pynac_impl.pxi index 68c31dcfde7..00239548e3c 100644 --- a/src/sage/symbolic/pynac_impl.pxi +++ b/src/sage/symbolic/pynac_impl.pxi @@ -43,7 +43,13 @@ from sage.libs.gmp.all cimport * from sage.libs.gsl.types cimport * from sage.libs.gsl.complex cimport * from sage.libs.gsl.gamma cimport gsl_sf_lngamma_complex_e -from sage.libs.mpmath import utils as mpmath_utils +from sage.libs.mpmath.sage_utils import call as _mpmath_call +from sage.libs.mpmath.all import ( + loggamma as _mpmath_loggamma, + polylog as _mpmath_polylog, + psi as _mpmath_psi, + stieltjes as _mpmath_stieltjes +) from sage.libs.pari.all import pari from sage.misc.persist import loads, dumps from sage.rings.integer_ring import ZZ @@ -1630,12 +1636,11 @@ cdef py_stieltjes(x): n = ZZ(x) if n < 0: raise ValueError("Stieltjes constant of negative index") - import mpmath if isinstance(x, Element) and hasattr((x)._parent, 'prec'): prec = (x)._parent.prec() else: prec = 53 - return mpmath_utils.call(mpmath.stieltjes, n, prec=prec) + return _mpmath_call(_mpmath_stieltjes, n, prec=prec) def py_stieltjes_for_doctests(x): """ @@ -1987,8 +1992,6 @@ cdef py_lgamma(x): sage: py_lgamma(ComplexField(100).0) -0.65092319930185633888521683150 - 1.8724366472624298171188533494*I """ - from mpmath import loggamma - try: return x.log_gamma() except AttributeError: @@ -1996,7 +1999,7 @@ cdef py_lgamma(x): try: return RR(x).log_gamma() except TypeError: - return mpmath_utils.call(loggamma, x, parent=parent(x)) + return _mpmath_call(_mpmath_loggamma, x, parent=parent(x)) def py_lgamma_for_doctests(x): @@ -2130,12 +2133,11 @@ cdef py_li(x, n, parent): sage: py_li(0, 1, float) 0.000000000000000 """ - import mpmath try: prec = parent.prec() except AttributeError: prec = 53 - return mpmath_utils.call(mpmath.polylog, n, x, prec=prec) + return _mpmath_call(_mpmath_polylog, n, x, prec=prec) def py_li_for_doctests(x, n, parent): @@ -2166,12 +2168,11 @@ cdef py_psi(x): sage: euler_gamma.n() 0.577215664901533 """ - import mpmath if isinstance(x, Element) and hasattr((x)._parent, 'prec'): prec = (x)._parent.prec() else: prec = 53 - return mpmath_utils.call(mpmath.psi, 0, x, prec=prec) + return _mpmath_call(_mpmath_psi, 0, x, prec=prec) def py_psi_for_doctests(x): @@ -2195,12 +2196,11 @@ cdef py_psi2(n, x): sage: py_psi2(2, 1) -2.40411380631919 """ - import mpmath if isinstance(x, Element) and hasattr((x)._parent, 'prec'): prec = (x)._parent.prec() else: prec = 53 - return mpmath_utils.call(mpmath.psi, n, x, prec=prec) + return _mpmath_call(_mpmath_psi, n, x, prec=prec) def py_psi2_for_doctests(n, x): """ @@ -2223,12 +2223,11 @@ cdef py_li2(x): sage: py_li2(-1.1) -0.890838090262283 """ - import mpmath if isinstance(x, Element) and hasattr((x)._parent, 'prec'): prec = (x)._parent.prec() else: prec = 53 - return mpmath_utils.call(mpmath.polylog, 2, x, prec=prec) + return _mpmath_call(_mpmath_polylog, 2, x, prec=prec) def py_li2_for_doctests(x): diff --git a/src/sage/tests/books/computational-mathematics-with-sagemath/integration_doctest.py b/src/sage/tests/books/computational-mathematics-with-sagemath/integration_doctest.py index dbe787aa5ff..e6d6e800b6e 100644 --- a/src/sage/tests/books/computational-mathematics-with-sagemath/integration_doctest.py +++ b/src/sage/tests/books/computational-mathematics-with-sagemath/integration_doctest.py @@ -128,7 +128,7 @@ Sage example in ./integration.tex, line 785:: - sage: import mpmath + sage: import sage.libs.mpmath.all as mpmath sage: mpmath.mp.prec = 53 sage: mpmath.quad(lambda x: mpmath.sin(mpmath.sin(x)), [0, 1]) mpf('0.43060610312069059') @@ -258,7 +258,6 @@ Sage example in ./integration.tex, line 1399:: - sage: import mpmath sage: mpmath.mp.prec = 53 sage: sol = mpmath.odefun(lambda t, y: y, 0, 1) sage: sol(1) diff --git a/src/tox.ini b/src/tox.ini index 5021d0aa691..a11af1e4009 100644 --- a/src/tox.ini +++ b/src/tox.ini @@ -172,6 +172,7 @@ commands = find {posargs:{toxinidir}/sage/} \ -name "*.zip" -prune -o \ -name "*~*" -prune -o \ -name ".DS_Store" -prune -o \ + -name "_vendor" -prune -o \ -exec relint -c {toxinidir}/.relint.yml \{\} + [testenv:codespell]